<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="prescription">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="hostSystemId">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:minLength value="1"/>
						<xsd:maxLength value="64"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
			<xsd:element name="physician">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="userId">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="32"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="password">
							<xsd:simpleType>
									<xsd:restriction base="xsd:string">
										<xsd:minLength value="1"/>
										<xsd:maxLength value="64"/>
									</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:group ref="nameGroup"/>
						<xsd:element name="address" type="addressType"/>										
						<xsd:element name="phone">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="10"/>
									<xsd:pattern value="([0-9])+"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>

			<xsd:element name="patient">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:group ref="nameGroup"/>
						<xsd:element name="birthDate">
							<xsd:simpleType>
								<xsd:restriction base="xsd:date"/>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="gender">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:enumeration value="M"/>
									<xsd:enumeration value="F"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="address" type="addressType"/>			
						<xsd:element name="phone" minOccurs="0" maxOccurs="2">								
							<xsd:complexType>
								<xsd:sequence>
									<xsd:element name="number">
										<xsd:simpleType>
											<xsd:restriction base="xsd:string">
												<xsd:maxLength value="10"/>
												<xsd:pattern value="(|([0-9]){10})"/>
											</xsd:restriction>
										</xsd:simpleType>
									</xsd:element>
									<xsd:element name="type">
										<xsd:simpleType>
											<xsd:restriction base="xsd:string">							
    											<xsd:enumeration value="TE"/>
    											<xsd:enumeration value="WP"/>
    											<xsd:enumeration value="HP"/>
											</xsd:restriction>
										</xsd:simpleType>
									</xsd:element>
								</xsd:sequence>
							</xsd:complexType>
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
				
			<xsd:element name="drug" maxOccurs="unbounded">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="drugId">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="20"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="dataSourceName">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:enumeration value="Medispan"/>
									<xsd:enumeration value="FDA"/>
								</xsd:restriction>
							</xsd:simpleType>
					  	</xsd:element>
						<xsd:choice>
							<xsd:group ref="ndcGroup"/>
							<xsd:element name="drugAttributes">
								<xsd:complexType>
									<xsd:sequence>
										<xsd:element name="description">
											<xsd:simpleType>											
												<xsd:restriction base="xsd:string">
													<xsd:minLength value="1"/>
													<xsd:maxLength value="150"/>
												</xsd:restriction>
											</xsd:simpleType>
										</xsd:element>
										<xsd:element name="dosageForm" minOccurs="0">
											<xsd:simpleType>											
												<xsd:restriction base="xsd:string">
													<xsd:maxLength value="64"/>
												</xsd:restriction>
											</xsd:simpleType>
										</xsd:element>
										<xsd:element name="strength" type="strengthType"/>
										<xsd:element name="strengthUnit" type="strengthUnitType"/>
									</xsd:sequence>
								</xsd:complexType>
							</xsd:element>
						</xsd:choice>
						<xsd:element name="packageSizeUnitCode" minOccurs="0"/>
						<xsd:element name="sig">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="140"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="notes" minOccurs="0">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string" >
									<xsd:minLength value="1"/>
									<xsd:maxLength value="210"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="days" type="xsd:integer" minOccurs="0"/>
						<xsd:element name="quantity" type="xsd:string"/>
						<xsd:element name="refills" type="xsd:integer" minOccurs="0"/>
						<xsd:element name="substitution">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:enumeration value="0"/>
									<xsd:enumeration value="1"/>
									<xsd:enumeration value="2"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>							
					</xsd:sequence>																		
				</xsd:complexType>																					
			</xsd:element>
			<xsd:element name="pharmacy" type="pharmacyType"/>
		</xsd:sequence>
	</xsd:complexType>
	<xsd:key name="drugIdUnq">
		<xsd:selector xpath=".//drug"/>
		<xsd:field xpath="drugId"/>
	</xsd:key>
	<xsd:unique name="ndcId">
		<xsd:selector xpath=".//drug"/>
		<xsd:field xpath="ndc"/>
	</xsd:unique>
	<xsd:unique name="description">
		<xsd:selector xpath=".//drug/drugAttributes"/>
		<xsd:field xpath="description"/>
	</xsd:unique>
</xsd:element>	
			
<xsd:element name="drugSearchCriteria">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="hostSystemId">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:minLength value="1"/>
						<xsd:maxLength value="64"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>			
			<xsd:element name="name">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:minLength value="1"/>
						<xsd:maxLength value="32"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
			<xsd:element name="type">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:enumeration value="All"/>
						<xsd:enumeration value="Branded"/>
						<xsd:enumeration value="Generic"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>
	
<xsd:element name="drugs">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="drug" maxOccurs="unbounded">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="ndc" type="ndcType"/>
						<xsd:element name="description">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="150"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="strength" type="strengthType"/>
						<xsd:element name="form">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="32"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="route">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="32"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
						<xsd:element name="type">
							<xsd:simpleType>
								<xsd:restriction base="xsd:string">
									<xsd:minLength value="1"/>
									<xsd:maxLength value="32"/>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>

<xsd:group name="nameGroup">
	<xsd:sequence>
		<xsd:element name="firstName">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:minLength value="1"/>
					<xsd:maxLength value="32"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="middleName" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="16"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="lastName">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:minLength value="1"/>
					<xsd:maxLength value="32"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
	</xsd:sequence>
</xsd:group>

<xsd:simpleType name="strengthType">
	<xsd:restriction base="xsd:string">
		<xsd:minLength value="1"/>
		<xsd:maxLength value="15"/>
	</xsd:restriction>
</xsd:simpleType>
	
<xsd:simpleType name="ndcType">
	<xsd:restriction base="xsd:string">
		<xsd:minLength value="1"/>
		<xsd:maxLength value="20"/>
	</xsd:restriction>
</xsd:simpleType>
		
<xsd:simpleType name="strengthUnitType">
	<xsd:restriction base="xsd:string">
		<xsd:minLength value="1"/>
		<xsd:maxLength value="15"/>
	</xsd:restriction>
</xsd:simpleType>
								
<xsd:group name="ndcGroup">
	<xsd:sequence>
		<xsd:element name="ndc" type="ndcType"/>
		<xsd:element name="description" minOccurs="0">
			<xsd:simpleType>											
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="150"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>				
		<xsd:element name="strength" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="15"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="strengthUnit" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="15"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
	</xsd:sequence>
</xsd:group>
	
<xsd:complexType name="pharmacyType">
	<xsd:sequence>
		<xsd:choice>
			<xsd:element name="pharmacyId" minOccurs="0">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:maxLength value="32"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
			<xsd:group ref="pharmacyOptionalElements"/>
		</xsd:choice>
	</xsd:sequence>
</xsd:complexType>
	
<xsd:element name="pharmacies">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="pharmacy" type="pharmacyType" minOccurs="0" maxOccurs="unbounded"/>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>
	
<xsd:element name="pharmacySearchCriteria">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="hostSystemId">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:minLength value="1"/>
						<xsd:maxLength value="64"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
			<xsd:element name="pharmacy" type="othPharmacyType"/>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>
	
<xsd:complexType name="othPharmacyType">
	<xsd:sequence>
		<xsd:choice>
			<xsd:element name="pharmacyId">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:minLength value="1"/>
						<xsd:maxLength value="32"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
			<xsd:group ref="pharmacyOptionalElementsGroup"/>
		</xsd:choice>
	</xsd:sequence>
</xsd:complexType>
	
<xsd:group name="pharmacyOptElements">
	<xsd:sequence>
		<xsd:element name="pharmacyName">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:minLength value="1"/>
					<xsd:maxLength value="64"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="addressLine1" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="45"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="addressLine2" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="45"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="city" type="cityType"/>
		<xsd:element name="stateCode" type="stateType"/>	
	</xsd:sequence>
</xsd:group>
	
<xsd:group name="pharmacyOptionalElements">
	<xsd:sequence>
		<xsd:element name="pharmacyName" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="32"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="addressLine1" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="45"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="addressLine2" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:minLength value="1"/>
					<xsd:maxLength value="45"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="city" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="32"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="stateCode" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="2"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="zipCode" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="10"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>
		<xsd:element name="phone">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:length value="10"/>
				</xsd:restriction>
			</xsd:simpleType>
		 </xsd:element>
		 <xsd:element name="fax" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="20"/>
				</xsd:restriction>
			</xsd:simpleType>
		 </xsd:element>
	</xsd:sequence>
</xsd:group>
	
<xsd:group name="pharmacyOptionalElementsGroup">
	<xsd:sequence>
		<xsd:group ref="pharmacyOptElements"/>
			<xsd:element name="zipCode" minOccurs="0">
				<xsd:simpleType>
					<xsd:restriction base="xsd:string">
						<xsd:maxLength value="10"/>
					</xsd:restriction>
				</xsd:simpleType>
			</xsd:element>
	</xsd:sequence>
</xsd:group>

<xsd:simpleType name="addressLine1Type">
	<xsd:restriction base="xsd:string">
		<xsd:minLength value="1"/>
		<xsd:maxLength value="64"/>
	</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="addressLine2Type">
	<xsd:restriction base="xsd:string">
		<xsd:maxLength value="32"/>
	</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="cityType">
	<xsd:restriction base="xsd:string">
		<xsd:minLength value="1"/>
		<xsd:maxLength value="32"/>
	</xsd:restriction>
</xsd:simpleType>
			
<xsd:simpleType name="stateType">
	<xsd:restriction base="xsd:string">
		<xsd:length value="2"/>
	</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="zipCodeType">
	<xsd:restriction base="xsd:string">
		<xsd:minLength value="5"/>
		<xsd:maxLength value="10"/>
	</xsd:restriction>
</xsd:simpleType>
				
<xsd:complexType name="addressType">
	<xsd:sequence>
		<xsd:element name="addressLine1" type="addressLine1Type"/>
		<xsd:element name="addressLine2" type="addressLine2Type" minOccurs="0"/>
		<xsd:element name="city" type="cityType"/>
		<xsd:element name="stateCode" type="stateType"/>
		<xsd:element name="zipCode" type="zipCodeType"/>
	</xsd:sequence>
</xsd:complexType>
	
</xsd:schema>