<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://crown.esrd.net/crown" 
  targetNamespace="http://crown.esrd.net/crown" 
  xmlns:crown="http://crown.esrd.net/crown" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
>
  <xsd:include schemaLocation="crown-global.xsd" />
  <xsd:include schemaLocation="crown-patient.xsd" />
  <xsd:include schemaLocation="crown-clinical-cpms.xsd" />

  <xsd:complexType name="Clinical">
    <xsd:annotation>
        <xsd:documentation>
          Clinical data submission - A sequence of patients' clinical records.

          "clinicalPeriod": either a month and year together or a date 
              to indicate the data-collection period.
          "clinicalPeriod.month":       period month.
          "clinicalPeriod.year":        period year.
          or
          "clinicalPeriod.periodDate":  identifying date for the period.
        </xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="orgAffiliation" type="OrganizationAffiliation" />
      <xsd:element name="clinicalPeriod" type="Period" />
      <xsd:element name="patientClinical" type="PatientClinical" 
                    maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="PatientClinical">
    <xsd:annotation>
      <xsd:documentation>Clinical data associated with a patient.</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="orgFacilityCode" type="xsd:string" />
      <xsd:element name="orgPatientId" type="xsd:string" />
      <xsd:element name="patientId" type="PatientIdentifier" minOccurs="0" />
      <xsd:element name="clinicalRecord" type="ClinicalRecord" minOccurs="0"  maxOccurs="unbounded" />
    </xsd:sequence>
    <xsd:attribute name="noClinicalData" type="xsd:boolean" default="false" />
  </xsd:complexType>

  <xsd:complexType name="ClinicalRecord">
    <xsd:annotation>
      <xsd:documentation>Clinical data for a patient.</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="collectionType" type="CollectionType" />
      <xsd:element name="labValues" type="LabValues" minOccurs="0" />
      <xsd:element name="vascularAccess" type="VascularAccess" minOccurs="0" />
      <xsd:element name="cpms" type="CPMs" minOccurs="0" maxOccurs="unbounded" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:simpleType name="CollectionType" >
    <xsd:annotation>
      <xsd:documentation>
        Clinical Collection Types
        -  HD: Hemodialysis
        -  PD: Peritoneal Dialysis
        -  VA: Vascular Access
      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="HD" />
      <xsd:enumeration value="PD" />
      <xsd:enumeration value="VA" />
    </xsd:restriction>
  </xsd:simpleType>

</xsd:schema>
