<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="tce">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="schemaVersion" type="xs:string" minOccurs="0" maxOccurs="1"/>

				<!-- "inclusionCriterias" (opional):  description of TCE collection criteria such as new regimen should include NFV or boosted PI  -->
				<xs:element name="inclusionCriterias" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>  

 				<!-- "requiredTCEComponents" (optional): for example, baseline genotype is required within 24 weeks from baseline-->
				<xs:element name="requiredTCEComponents" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>

				<!-- "patient" (optional): patient alias, age or race, etc. can be included -->
				<xs:element name="patient" type="Patient" minOccurs="0" maxOccurs="1"/>

 				<!-- either of "baselineDate" (a date in YYYY-MM-DD format) or  "baselineYear" (just a year in YYYY format) is required -->
				<xs:choice>
					<xs:element name="baselineDate" type="xs:date"/>
					<xs:element name="baselineYear" type="xs:nonNegativeInteger"/>
				</xs:choice>

 				<!-- either of day, week, or month which is the time unit to produce the time-points relative to a baseline -->
				<xs:element name="dateUnit" type="DateUnitType"/>


				<!-- baselineRNA and baselineCD4 are required, only one instance for each. -->
				<xs:element name="baselineRNA" type="RNAMeasurement" minOccurs="1" maxOccurs="1"/>
				<xs:element name="baselineCD4" type="CD4Measurement" minOccurs="1" maxOccurs="1"/>

				<!-- "baselineNewTreatment" (required): list of drugs given at the baseline -->
				<xs:element name="baselineNewTreatment" type="Regimen" minOccurs="1" maxOccurs="1"/>

				<!-- "baselineIsolate" (required): sequence at the baseline, each gene separately, one protease and one RT at the minimum -->
				<xs:element name="baselineIsolate" type="Isolate" minOccurs="2" maxOccurs="3"/>
				
				<!-- "followupRNA" (required):  HIV-1 plasma RNA levels during the new therapy-->
				<xs:element name="followupRNA" type="RNAMeasurement" minOccurs="1" maxOccurs="unbounded"/>

				<!-- "followupCD4" (optional):  CD4 counts during the new therapy-->
				<xs:element name="followupCD4" type="CD4Measurement" minOccurs="0" maxOccurs="unbounded"/>
				
				
				<!-- the drugs received prior to baseline can be expressed in two ways: "pastRegimenTreatments"  and "pastCummulativeDrugTreatments" -->
				<!-- using "pastRegimenTreatments, the drugs received can be listed regimen by regimen -->
				<!-- using "pastCummulativeDrugTreatments", the list of drugs can be listed drug by drug -->  
				<xs:element name="pastRegimenTreatments" type="Regimen" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element name="pastCummulativeDrugTreatments" type="CummulativeDrug" minOccurs="0" maxOccurs="unbounded"/>

				<!-- "pastRNA" and "pastCD4" (both optional): list of plasma HIV-1 RNA levels or CD4 counts  measured prior to "baselineRNA" or ""baselineCD4" -->
				<xs:element name="pastRNA" type="RNAMeasurement" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element name="pastCD4" type="CD4Measurement" minOccurs="0" maxOccurs="unbounded"/>

				<!-- past genotypes (optional) can be expressed in two ways: "pastIsolate" or "pastCummulativeMutation" -->
				<xs:element name="pastIsolate" type="Isolate" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element name="pastCummulativeMutation" type="CummulativeMutations" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
	<xs:complexType name="Patient">
		<xs:all>
			<xs:element name="patientAlias" type="xs:string" minOccurs="0" maxOccurs="1"/>
			<xs:element name="geographicRegion" type="xs:string" minOccurs="0" maxOccurs="1"/>
			<xs:element name="CD4NadirBeforeTCE" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
			<xs:element name="age" type="xs:float" minOccurs="0" maxOccurs="1"/>
			<xs:element name="gender" type="xs:string" minOccurs="0" maxOccurs="1"/>
			<xs:element name="race" type="xs:string" minOccurs="0" maxOccurs="1"/>
		</xs:all>
	</xs:complexType>

	<xs:complexType name="Regimen">
		<xs:sequence>
			<!-- time when regimen started (required). time can be expressed as an actual date ("YYYY-MM-DD" format) or a relative time from the baseline. ie, "relativeStartDate" is "-2" and the unit of time defined in the entity "dateUnit" is "week", then it means the regimen started 2 weeks prior to the baseline -->
			<xs:choice>
				<xs:element name="startDate" type="xs:date"/>
				<xs:element name="relativeStartDate" type="xs:float"/>
			</xs:choice>
			<xs:choice>
				<xs:element name="stopDate" type="xs:date"/>
				<xs:element name="relativeStopDate" type="xs:float"/>
			</xs:choice>
			<xs:element name="duration" type="xs:nonNegativeInteger"/>
			<xs:element name="drug" type="ARVDrug" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="CummulativeDrug">
		<xs:sequence>
			<xs:element name="duration" type="xs:nonNegativeInteger"/>
			<xs:element name="drug" type="ARVDrug" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="ARVDrug">
		<xs:sequence>
			<xs:element name="drugCode" type="xs:string"/>
			<xs:element name="drugClass" type="ARTDrugClass" minOccurs="0" maxOccurs="1"/>
			<xs:element name="dosage" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
			<xs:element name="frequency" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
			<xs:element name="adherence" type="xs:string" minOccurs="0" maxOccurs="1"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="Isolate">
		<xs:sequence>
			<!-- time when isolate was sequenced or obtained (required). time can be expressed as an actual date ("YYYY-MM-DD" format) or a relative time from the baseline. ie, "relativeDate" is "-2" and the unit of time defined in the entity "dateUnit" is "week", then it means the isolate was obtained at 2 weeks prior to the baseline -->
			<xs:choice>
				<xs:element name="date" type="xs:date"/>
				<xs:element name="relativeDate" type="xs:float"/>
			</xs:choice>

			<!-- "gene" (required)  -->
			<xs:element name="gene" type="GeneType"/>
			<xs:element name="subtype" type="xs:string" minOccurs="0" maxOccurs="1"/>
			<xs:element name="aaStart" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
			<xs:element name="aaStop" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
			<xs:element name="nucleotideSequence" type="xs:string" minOccurs="0" maxOccurs="1"/>
			<xs:element name="aaSequence" type="xs:string" minOccurs="0" maxOccurs="1"/>
			<xs:element name="aaMutation" type="Mutation" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="CummulativeMutations">
		<xs:sequence>
			<xs:choice>
				<xs:element name="date" type="xs:date"/>
				<xs:element name="relativeDate" type="xs:float"/>
			</xs:choice>
			<xs:element name="gene" type="GeneType"/>
			<xs:element name="aaMutations" type="Mutation" minOccurs="1" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	
	<xs:complexType name="Mutation">
		<xs:sequence>
			<xs:element name="position" type="xs:nonNegativeInteger"/>
			
			<!-- "aminoAcid" contains one amino acid code which is non-wildtype for this position. Amino acid code is one of 20 amino acid codes (in upper-case letter) or a lower-case "i" for insertion or a lower-case "d" for deletion -->
			<xs:element name="aminoAcid" type="xs:string"/>
			<!-- "mixtures" contains the other amino acids (than the one in "aminoAcid")  when there are mixtures at this position --> 
			<xs:element name="mixtures" type="xs:string"/>
		</xs:sequence>
	</xs:complexType>
	
	<!--
    legitimate values for anti-retroviral drug types:
      'NRTI' - nucleoside reverse transcriptase inhibitor
      'NNRTI' - non-nucleoside reverse transcriptase inhibitor
      'PI' - protease inhibitor
      'FI' - fusion inhibitor
      'INI' - integrase inhibitor
      'CRI' - CCR5 inhibitor
  	-->
	<xs:simpleType name="ARTDrugClass">
		<xs:restriction base="xs:string">
			<xs:enumeration value="NRTI"/>
			<xs:enumeration value="NNRTI"/>
			<xs:enumeration value="PI"/>
			<xs:enumeration value="FI"/>
			<xs:enumeration value="INI"/>
			<xs:enumeration value="CRI"/>
			<xs:enumeration value="OTH"/>
			<xs:enumeration value=""/>
		</xs:restriction>
	</xs:simpleType>

	<!--
	    Code for Protease, Reverse Transciptase, and Integrase genes
	-->
	<xs:simpleType name="GeneType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="PR"/>
			<xs:enumeration value="RT"/>
			<xs:enumeration value="IN"/>
		</xs:restriction>
	</xs:simpleType>

	<!--
	Enumeration for type of values that Match elements (viral load, Date Match etc.) can take.
	-->
	<xs:simpleType name="MatchEnum">
		<xs:restriction base="xs:string">
			<xs:enumeration value="&gt;"/>
			<xs:enumeration value="&lt;"/>
			<xs:enumeration value="&lt;="/>
			<xs:enumeration value="="/>
			<xs:enumeration value=""/>
		</xs:restriction>
	</xs:simpleType>

	<xs:simpleType name="DateUnitType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="day"/>
			<xs:enumeration value="week"/>
			<xs:enumeration value="month"/>
		</xs:restriction>
	</xs:simpleType>

	<!-- viral load information -->
	<xs:complexType name="RNAMeasurement">
		<xs:sequence>
			<xs:choice>
				<xs:element name="date" type="xs:date"/>
				<xs:element name="relativeDate" type="xs:float"/>
			</xs:choice>

			<!-- "vLoadMatch" (required): '>' if RNA level is over the upper detection limit 
			     '<' if RNA level is under the lower detection limit -->
			<xs:element name="vLoadMatch" type="MatchEnum"/>
			<xs:element name="logLoad" type="xs:float"/>
			<xs:element name="rawLoad" type="xs:nonNegativeInteger"/>
			<xs:element name="undetectableLevel" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="1"/>
		</xs:sequence>
	</xs:complexType>
	
	<!-- CD4 count information -->
	<xs:complexType name="CD4Measurement">
		<xs:sequence>
			<xs:choice>
				<xs:element name="date" type="xs:date"/>
				<xs:element name="relativeDate" type="xs:float"/>
			</xs:choice>
			<xs:element name="count" type="xs:nonNegativeInteger"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>
<!-- version 1.1 schema validated ?? http://www.w3.org/2001/03/webdata/xsv -->

