<?xml version="1.0" encoding="UTF-8"?>

<!--
    XSD for v3 patient reports validation

    ==== Example Schema =====
    <patientReport schemaVersion="3">
      <name>…</name>
      <rows>
        <patientQuery>
          <population>
            <patientQueryReference>ALL</patientQueryReference>
            OR
            <patientQueryReference>nhs-england/GMS_REG</patientQueryReference>
            OR
            <patientQuery> <- another full inline query
              <population>…</population>
              <codeLists>…</codeLists>
              <variables>…</variables>
              <rules>…</rules>
            </patientQuery>
            OR
            <patientReportReference>report-uuid</patientReportReference>
            OR
            <patientIdList>
              <patientId>uuid-1</patientId>
              <patientId>uuid-2</patientId>
            </patientIdList>
          </population>
          <codeLists>
            <codeList>
              <name>MY_COD</name>
              <codeListReference>nhs-england/MY_COD</codeListReference>
            </codeList>
            <codeList>
              <name>ECL_COD</name>
              <codeListDefinition>
                <rules>
                  <inclusion>&lt;&lt; 73211009 |Diabetes mellitus|</inclusion>
                </rules>
              </codeListDefinition>
            </codeList>
          </codeLists>
          <variables>…</variables>
          <rules>…</rules>
        </patientQuery>
      </rows>
      <columns>…</columns>
    </patientReport>
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:include schemaLocation="report-common.xsd"/>

    <!--Verify root of report has required tags/attributes  -->
    <xs:element name="patientReport">
        <xs:complexType>
            <xs:sequence>
                <!-- reportNameType caps at 255 chars to match the custom_report.name DB column. -->
                <xs:element name="name" type="reportNameType"/>
                <xs:element name="rows" type="rowsType"/>
                <xs:element name="columns" type="columnsType"/>
                <xs:element name="exportColumns" type="exportColumnsType" minOccurs="0"/>
            </xs:sequence>
            <!--
                Which of the two patient-shaped focuses built this. Both produce a patientReport
                with the same columns and the same population, so nothing in the definition
                distinguishes them and reopening one had to guess. Optional, because every report
                saved before this existed has no stamp and still has to open.
            -->
            <xs:attribute name="focus" use="optional">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="patients"/>
                        <xs:enumeration value="identifiers"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="schemaVersion" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:integer">
                        <xs:enumeration value="3"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>

</xs:schema>
