<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://schedule.pharmac.govt.nz/2006/07/Schedule#" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:nzmt="nzmt.org.nz" targetNamespace="http://schedule.pharmac.govt.nz/2006/07/Schedule#" elementFormDefault="qualified">
 
  <xs:annotation>
    <xs:appinfo>
      <ChangeLog>
        <Revision date="2021-03-23">Allow QQQQ for Draft form numbers</Revision>
        <Revision date="2021-03-23">Added ToBePSS</Revision>
        <Revision date="2021-03-23">Added PSS. Change www.pharmac.govt.nz to schedule.pharmac.govt.nz</Revision>
        <Revision date="2020-06-16">Added new applicant type paediatric immunologist</Revision>        	
        <Revision date="2020-03-16">Added new applicant type respiratory physician</Revision>        	
        <Revision date="2018-08-14">Added new applicant type sexual health specialist</Revision>  
      	<Revision date="2018-01-13">Added new applicant type optometrist</Revision>   
        <Revision date="2017-01-17">Added new applicant type paediatric haematologist and paediatric oncologist</Revision>   
        <Revision date="2016-02-04">Added S26 attribute to Brand</Revision>   
        <Revision date="2016-01-18">Added nurse practitioner applicant type</Revision>     
        <Revision date="2015-11-13">Added transplant specialist applicant type</Revision>       
        <Revision date="2015-05-21">Added several new applicant types</Revision>
        <Revision date="2015-06-04">Allow 'RS' as prefix for Request/@Form attributes (HML restrictions have the same format as Special Authorities)</Revision>
        <Revision date="2015-05-04">Added several new applicant types</Revision>
        <Revision date="2015-04-15">Added new applicant type - medical oncologist</Revision>
        <Revision date="2015-04-01">Added Lapse period Request Case</Revision>
        <Revision date="2015-03-18">Allow rules to precede other child elements</Revision>
        <Revision date="2014-09-02">Added new applicant type - palliative care specialist</Revision>
        <Revision date="2014-07-03">Added new applicant types - hepatologist, paediatric endocrinologist, paediatric gastroenterologist, paediatric hepatologist</Revision>
        <Revision date="2014-02-14">Allow xs:date value for SoleSupply attribute to indicate SoleSupply expiry</Revision>
        <Revision date="2013-11-13">Added new Rule type - RFPP</Revision>
        <Revision date="2012-10-17">Added new applicant type - haematologist</Revision>
        <Revision date="2012-07-16">Added new applicant types - clinical immunologist, clinical microbiologist and allergist</Revision>
        <Revision date="2012-07-16">Added SafetyListMedicine rule</Revision>
        <Revision date="2012-03-15">Added new applicant types - metabolic physician and paediatric neurologist</Revision>
        <Revision date="2012-02-14">Added ToBeSoleSupply attribute to Brand</Revision>
        <Revision date="2011-11-17">Added OraProduct rule</Revision>
        <Revision date="2011-06-29">Added new applicant type - dietitian</Revision>
        <Revision date="2011-01-27">Added ProvAllow rule</Revision>
        <Revision date="2010-10-19">Added Brandswitch rule</Revision>
        <Revision date="2010-09-02">Added Request element to BrandType</Revision>
        <Revision date="2009-08-06">Added ``HSS'' attribute to Brand and ``DVLimit'' rule type to ``rules''</Revision>
        <Revision date="2009-07-24">Added new approvers - CML/GIST and Pharmac</Revision>
        <Revision date="2009-06-30">Remove restriction to value ``Yes'' on Referring attribute to allow named referrer types</Revision>
        <Revision date="2009-05-30">Added new approver - Pulmonary Arterial Hypertension Panel</Revision>
        <Revision date="2009-05-04">Added new applicant type - Practitioner</Revision>
        <Revision date="2008-07-17">Added new approver - Levetiracetam Special Access Panel</Revision>
        <Revision date="2007-10-23">Page attribute of Chemical is deprecated</Revision>
        <Revision date="2007-03-27">Added SubRxF Waiver</Revision>
        <Revision date="2007-03-09">approvers: Cystic Fibrosis DN'ase Advisory Panel -> Cystic Fibrosis Advisory Panel. Previous deprecated</Revision>
        <Revision date="2007-03-08">SAForms/Group may have zero Requests; doc fixes</Revision>
        <Revision date="2007-02-13">merged in documentation from SiMPle.mdb</Revision>
        <Revision date="2006-12-19">Added ``Guideline'' rule type to ``rules''</Revision>
        <Revision date="2006-11-23">Added ``Repeat'' rule type to ``rules''</Revision>
        <Revision date="2006-10-26">RuleType/@XRef, XRef and XRefType deprecated, replaced by xlink attributes (imported from xlink.xsd)</Revision>
        <Revision date="2006-09-19">Optional XRef annotation for Chemical</Revision>
        <Revision date="2006-08-29">Request has optional Edition attribute</Revision>
        <Revision date="2006-08-21">SAForms/Group: added Name as first child</Revision>
        <Revision date="2006-08-21">html:div replaces Foreword as SAForms child</Revision>
        <Revision date="2006-07-31">initial release</Revision>
      </ChangeLog>
    </xs:appinfo>
  </xs:annotation>

  <xs:annotation>
    <xs:appinfo xmlns:dc="http://purl.org/dc/elements/1.1/">
      <dc:title> Pharmaceutical Schedule XML Schema </dc:title>
      <dc:rights> Copyright (c) 2002-2006 Pharmac </dc:rights>
      <dc:description> Pharmaceutical classification based on that developed by the WHO Collaborating Centre for Drug Statistics Methodology (www.whocc.nmd.no). Drugs are classified by their
        Anatomical, Therapeutic and Chemical properties. This schema can be considered the authoritive Pharmaceutical Schedule XML Schema as of July 2006, see the ChangeLog annotation for revision
        details. </dc:description>
    </xs:appinfo>
  </xs:annotation>


  <xs:annotation>
    <xs:documentation xml:lang="en"> (xhtml:block) Annotations in the Pharmaceutical Schedule. These are usually restrictions or prescribing guidelines that can apply to a therapeutic group, chemical,
      formulation and/or brand. They are expressed in xhtml contained in a valid xhtml block with class attribute set to "Note" or "Guideline". </xs:documentation>
  </xs:annotation>


  <!-- namespace imports -->

  <xs:import namespace="http://www.w3.org/1998/Math/MathML" schemaLocation="mathml2/mathml2.xsd">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Request elements make use of MathML for Special Authority form criteria. Schema location is relative to this resource. </xs:documentation>
    </xs:annotation>
  </xs:import>

  <xs:import namespace="http://www.w3.org/1999/xhtml" schemaLocation="xhtml1-strict.xsd">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Schedule Notes are encoded in xhtml. Schema location is relative to this resource. </xs:documentation>
    </xs:annotation>
  </xs:import>

  <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink.xsd">
    <xs:annotation>
      <xs:documentation xml:lang="en"> xlink:href attributes are used to reference parts of the schedule </xs:documentation>
    </xs:annotation>
  </xs:import>


  <!-- most common root elements -->
  <xs:element name="Schedule" type="ScheduleType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Schedule elements contain ATC1, 2, 3, Chemical, etc and Delisted for the month. </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="SAForms" type="SAFormsType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> SAForms elements contain Request children either directly or in Group elements. </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Request" type="RequestType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Request elements are Special Authority forms/criteria. </xs:documentation>
    </xs:annotation>
  </xs:element>


  <!-- enumerations -->

  <xs:simpleType name="terms">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Acceptable time interval values for Special Authority applications. Term is in weeks, months, years or life of patient. </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="day"/>
      <xs:enumeration value="week"/>
      <xs:enumeration value="month"/>
      <xs:enumeration value="year"/>
      <xs:enumeration value="patient's lifetime"/>
      <xs:enumeration value="dose"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="approvers">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Applications can be (addressed to and) approved by the enumerated organisations. </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Cystic Fibrosis Advisory Panel"/>
      <!-- deprecated (DN'ase) -->
      <xs:enumeration value="Cystic Fibrosis DN'ase Advisory Panel"/>
      <xs:enumeration value="Gaucher Treatment Panel"/>
      <xs:enumeration value="Gaucher's Treatment Panel"/>
      <!-- deprecated (Glivec) -->
      <xs:enumeration value="Glivec Co-ordinator"/>
      <xs:enumeration value="CML/GIST Co-ordinator"/>
      <xs:enumeration value="Growth Hormone Committee"/>
      <xs:enumeration value="HealthPAC"/>
      <xs:enumeration value="Hepatitis C Treatment Panel (HepCTP)"/>
      <xs:enumeration value="Levetiracetam Special Access Panel"/>
      <xs:enumeration value="Multiple Sclerosis Treatment Committee"/>
      <xs:enumeration value="Pulmonary Arterial Hypertension Panel"/>
      <xs:enumeration value="PHARMAC"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="entitlements">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Special Authority applications are for one of the following values. </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Subsidy"/>
      <xs:enumeration value="Manufacturers Price"/>
      <xs:enumeration value="Alternate Subsidy"/>
      <xs:enumeration value="Waiver of Rule"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="applicants">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Valid applicants -- who can apply for a Special Authority on the patient's behalf. </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="allergist"/>
      <xs:enumeration value="anaesthetist"/>
      <xs:enumeration value="any relevant practitioner"/>
      <xs:enumeration value="any specialist"/>
      <xs:enumeration value="cardiac anaesthetist"/>
      <xs:enumeration value="cardiologist"/>
      <xs:enumeration value="cardiothoracic surgeon"/>
      <xs:enumeration value="clinical immunologist"/>
      <xs:enumeration value="clinical microbiologist"/>
      <xs:enumeration value="consultant"/>
      <xs:enumeration value="dentist"/>
      <xs:enumeration value="dermatologist"/>
      <xs:enumeration value="diabetologist"/>
      <xs:enumeration value="dietitian"/>
      <xs:enumeration value="endocrinologist"/>
      <xs:enumeration value="gastroenterologist"/>
      <xs:enumeration value="general physician"/>
      <xs:enumeration value="general practitioner"/>
      <xs:enumeration value="general surgeon"/>
      <xs:enumeration value="geriatrician"/>
      <xs:enumeration value="gynaecologist"/>
      <xs:enumeration value="haematologist"/>
      <xs:enumeration value="hepatologist"/>
      <xs:enumeration value="infectious disease specialist"/>
      <xs:enumeration value="intensivist"/>   
      <xs:enumeration value="internal medicine physician"/>      
      <xs:enumeration value="maternal-foetal medicine specialist"/>
      <xs:enumeration value="medical oncologist"/>
      <xs:enumeration value="medical practitioner"/>
      <xs:enumeration value="metabolic physician"/>
      <xs:enumeration value="metabolic disorders dietitian"/>
      <xs:enumeration value="named general physician"/>
      <xs:enumeration value="named specialist"/>
      <xs:enumeration value="nephrologist"/>
      <xs:enumeration value="neuro surgeon"/>
      <xs:enumeration value="neurologist"/>
      <xs:enumeration value="nurse practitioner"/>
      <xs:enumeration value="obstetrician"/>
      <xs:enumeration value="oncologist"/>
      <xs:enumeration value="ophthalmologist"/>
      <xs:enumeration value="optometrist"/> 
      <xs:enumeration value="oral surgeon"/>
      <xs:enumeration value="otolaryngologist"/>
      <xs:enumeration value="palliative care specialist"/>
      <xs:enumeration value="paediatric cardiologist"/>
      <xs:enumeration value="paediatric endocrinologist"/>
      <xs:enumeration value="paediatric gastroenterologist"/>
      <xs:enumeration value="paediatric haematologist"/>
      <xs:enumeration value="paediatric hepatologist"/>
      <xs:enumeration value="paediatric immunologist"/>
      <xs:enumeration value="paediatric neurologist"/>
      <xs:enumeration value="paediatric oncologist"/>
      <xs:enumeration value="paediatric surgeon"/>
      <xs:enumeration value="paediatrician"/>
      <xs:enumeration value="physician for the elderly (FRACP)"/>
      <xs:enumeration value="plastic surgeon"/>
      <xs:enumeration value="Practitioner"/>
      <xs:enumeration value="psychiatrist"/>
      <xs:enumeration value="public health physician"/>
      <xs:enumeration value="radiation oncologist"/>
      <xs:enumeration value="relevant specialist">
        <xs:annotation>
          <xs:documentation>Deprecated from 1 August 2012</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="renal physician"/>
      <xs:enumeration value="respiratory specialist"/>
      <xs:enumeration value="respiratory physician"/>
      <xs:enumeration value="rheumatologist"/>
      <xs:enumeration value="sexual health specialist"/>
      <xs:enumeration value="transplant specialist"/>
      <xs:enumeration value="transplant surgeon"/>
      <xs:enumeration value="urologist"/>
      <xs:enumeration value="vascular surgeon"/>
      <xs:enumeration value="vocationally registered general practitioner"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="rules">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Schedule rule types </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:NMTOKEN">
      <xs:enumeration value="Alternate"/>
      <xs:enumeration value="Brandswitch"/>
      <xs:enumeration value="Combined"/>
      <xs:enumeration value="Contraceptive"/>
      <xs:enumeration value="Controlled"/>
      <xs:enumeration value="Dispensary"/>
      <xs:enumeration value="DoseDMax"/>
      <xs:enumeration value="DoseDWt"/>
      <xs:enumeration value="DoseMMax"/>
      <xs:enumeration value="DoseMWt"/>
      <xs:enumeration value="DoseSMax"/>
      <xs:enumeration value="DoseSWt"/>
      <xs:enumeration value="DoseWMax"/>
      <xs:enumeration value="DoseWWt"/>
      <xs:enumeration value="DVLimit"/>
      <xs:enumeration value="FormBan"/>
      <xs:enumeration value="FormMax"/>
      <xs:enumeration value="FormReqd"/>
      <xs:enumeration value="FormWt"/>
      <xs:enumeration value="Guideline"/>
      <xs:enumeration value="MaxCoPayment"/>
      <xs:enumeration value="MaxQtyDisp"/>
      <xs:enumeration value="NotCombined"/>
      <xs:enumeration value="OraProduct"/>
      <xs:enumeration value="PCT"/>
      <xs:enumeration value="ProvAllow"/>
      <xs:enumeration value="ProvReqd"/>
      <xs:enumeration value="Repeat"/>
      <xs:enumeration value="RFPP"/>
      <xs:enumeration value="SafetyListMedicine"/>
      <xs:enumeration value="SpecEnd"/>
      <xs:enumeration value="SpecOnly"/>
      <xs:enumeration value="Special"/>
      <xs:enumeration value="SubRxF"/>
      <xs:enumeration value="TreatMax"/>
      <xs:enumeration value="TreatWt"/>
      <xs:enumeration value="Wastage"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="statims">
    <xs:annotation>
      <xs:documentation xml:lang="en"> statims May or Must </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:NMTOKEN">
      <xs:enumeration value="May"/>
      <xs:enumeration value="Must"/>
    </xs:restriction>
  </xs:simpleType>


  <!-- most common root element types -->

  <!-- ScheduleType -->
  <xs:complexType name="ScheduleType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Schedule root element. Children are exactly: one Front element followed by zero of more Section elements and an optional Delisted element. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <!-- required element Front -->
      <xs:element name="Front">
        <xs:complexType>
          <!-- allow (simpleType) Front children in any order -->
          <xs:all>
            <xs:element name="Title" type="xs:string"/>
            <xs:element name="Country" type="xs:string"/>
            <xs:element name="Edition" type="xs:string"/>
            <xs:element name="Volume" type="xs:integer"/>
            <xs:element name="Number" type="xs:integer"/>
            <xs:element name="Published" type="xs:date"/>
          </xs:all>
        </xs:complexType>
      </xs:element>
      <!-- zero or more Section elements -->
      <xs:element name="Section" type="SectionType" minOccurs="0" maxOccurs="unbounded"/>
      <!-- optional Delisted element -->
      <xs:element name="Delisted" type="DelistedType" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <!-- SAFormsType -->
  <xs:complexType name="SAFormsType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> SAForms is a Request wrapper root element for Request children or byte identified Group elements containing Request children. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <!-- XXX restrict to html:div[class="Foreword"] -->
      <xs:element ref="html:div" minOccurs="0"/>
      <xs:choice>
        <!-- one or more Group elements with a Name, and Request children -->
        <xs:element name="Group" maxOccurs="unbounded">
          <xs:complexType>
            <!-- Name followed by one or more Request elements -->
            <xs:sequence>
              <xs:element name="Name" type="xs:string"/>
              <xs:element name="Request" type="RequestType" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <!-- requrired attribute ID -->
            <xs:attribute name="ID" type="xs:byte" use="required"/>
          </xs:complexType>
        </xs:element>
        <!-- one or more Request children -->
        <xs:element name="Request" type="RequestType" maxOccurs="unbounded"/>
      </xs:choice>
    </xs:sequence>
    <!-- required attribute Edition -->
    <xs:attribute name="Edition" type="xs:string" use="required"/>
  </xs:complexType>

  <!-- RequestType -->
  <xs:complexType name="RequestType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> XML coding of those Special Authority Criteria Request elements are Special Authority XML -- One Case element for each initial/renewal form criteria set.
        Optional Edition attribute: a Request element by itself should have available: an Edition attribute; for use in place of SAForms/@Edition or Schedule/Front/Edition. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <!-- optional title -->
      <xs:element name="Title" type="TitleType"/>
      <!-- one or more cases -->
      <xs:element name="Case" type="CaseType" maxOccurs="unbounded"/>
      <!-- optional elements -->
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <!-- optional element Note -->
        <xs:element ref="html:div"/>
        <!-- XXX optional element Appendix defined, deprecated. -->
        <xs:element name="Appendix" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:attribute name="Name" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:sequence>
    <!-- Required attributes: To, For and Form. -->
    <xs:attribute name="To" type="approvers" use="required"/>
    <xs:attribute name="For" type="entitlements" use="required"/>
    <xs:attribute name="Form" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <!-- eg; SA0123, SA####, SAQQQQ -->
          <xs:pattern value="(SA|RS)(\d{4}|####|QQQQ)"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <!-- optional attributes -->
    <xs:attribute name="Confidential" type="xs:boolean"/>
    <xs:attribute name="Edition" type="xs:string"/>
    <xs:attribute name="Funding">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Capped"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="tag" type="xs:string"/>
  </xs:complexType>


  <!-- Schedule element children types -->

  <!-- Section -->
  <xs:complexType name="SectionType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Section elements are Schedule children and contain ATC1 children. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:element name="ATC1" type="ATC1Type" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="ID" type="xs:ID" use="required"/>
  </xs:complexType>

  <xs:element name="Section" type="SectionType"/>


  <!-- ATC1 -->
  <xs:complexType name="ATC1Type">
    <xs:annotation>
      <xs:documentation xml:lang="en"> ATC 1st level -- Anatomical Main Group ATC1 elements are Section children and contain ATC2 children. ATC1/2/3 ID attribute is the Pharmac identifier for each
        group; it consists of character 'A' followed by a structured 6 digit integer (2 digits for each level). Optional Graphic attribute specifies the base filename of a TeX compatible graphic to be
        placed near the ATC1 in the printed schedule. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:element name="ATC2" type="ATC2Type" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <!-- required attribute ID -->
    <xs:attribute name="ID" type="xs:ID" use="required"/>
    <!-- optional attribute Graphic -->
    <xs:attribute name="Graphic" type="xs:string"/>
  </xs:complexType>

  <xs:element name="ATC1" type="ATC1Type"/>


  <!-- ATC2 -->
  <xs:complexType name="ATC2Type">
    <xs:annotation>
      <xs:documentation xml:lang="en"> ATC 2nd level -- Therapeutic Main Group ATC2 elements are ATC1 children and contain ATC3 children. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="ATC3" type="ATC3Type" minOccurs="0" maxOccurs="unbounded"/>
        <!-- optional elements -->
        <xs:element name="Guideline" type="html:Block"/>
        <xs:element ref="html:div"/>
        <xs:element name="Request" type="RequestType"/>
        <xs:element name="Rule" type="RuleType"/>
        <!-- deprecated -->
        <xs:element name="XRef" type="XRefType"/>
      </xs:choice>
    </xs:sequence>
    <!-- required attribute ID -->
    <xs:attribute name="ID" type="xs:ID" use="required"/>
  </xs:complexType>

  <xs:element name="ATC2" type="ATC2Type"/>


  <!-- ATC3 -->
  <xs:complexType name="ATC3Type">
    <xs:annotation>
      <xs:documentation xml:lang="en"> ATC 3rd level -- Therapeutic/Pharmacological Subgroup ATC3 elements are ATC2 children and contain Chemical children. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Chemical" type="ChemicalType" minOccurs="0" maxOccurs="unbounded"/>
        <!-- optional elements -->
        <xs:element name="Guideline" type="html:Block"/>
        <xs:element ref="html:div"/>
        <xs:element name="Request" type="RequestType"/>
        <xs:element name="Rule" type="RuleType"/>
        <!-- deprecated -->
        <xs:element name="XRef" type="XRefType"/>
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="ID" type="xs:ID" use="required"/>
  </xs:complexType>

  <xs:element name="ATC3" type="ATC3Type"/>


  <!-- Chemical -->
  <xs:complexType name="ChemicalType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> The chemical (generic) element of a Formulation. The same chemical can be assigned to formulations in different therapeutic groups. Chemical elements are ATC3
        children and contain Formulation children. ID attribute is Pharmac identifier for each chemical. 'C' character followed by 6 digit ATC and a 4 digit integer (chemical code). Name element is
        chemical (generic) name. Combined names exist for formulations with multiple active ingredients. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Formulation" type="FormulationType" minOccurs="1" maxOccurs="unbounded"/>
        <!-- optional annotations -->
        <xs:element name="Guideline" type="html:Block"/>
        <xs:element ref="html:div"/>
        <xs:element name="Request" type="RequestType"/>
        <xs:element name="Rule" type="RuleType"/>
        <!-- deprecated -->
        <xs:element name="XRef" type="XRefType"/>
      </xs:choice>
    </xs:sequence>
    <!-- required attribute ID -->
    <xs:attribute name="ID" type="xs:ID" use="required"/>
    <!-- optional attributes -->
    <!-- deprecated -->
    <xs:attribute name="Page" type="xs:nonNegativeInteger"/>
    <xs:attribute name="Statim" type="statims"/>
    <!-- XXX deprecated, not stateless -->
    <xs:attribute name="Update" type="xs:string"/>
  </xs:complexType>

  <xs:element name="Chemical" type="ChemicalType"/>


  <!-- Formulation -->
  <xs:complexType name="FormulationType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Formulations (presentations) qualifying for subsidy. Generally all Brands and Packs of a Formualtion have the same unit subsidy. Formulation elements are
        Chemical children and contain Brand or Ingredient children. ID attribute is Pharmac Identifier for each Formulation. 'F' character followed by structured integer (6 digit ATC, 4 digit
        ChemicalCode and a 2 digit Formulation suffix). Name element usually describes the form and strength. Can also include the flavour or a quality reference such as "BP", but should not include
        Chemical, Brand or Pack. Units attribute is unit of measure for dispensing and measuring dose (HFA specifications 2.29 "unit dispensed" and "unit claimed"). Should agree with the NZ Pharmacy
        Guild's Generic unit of measure. Weight attribute is the amount of the active ingredient in the formulation. Missing Weight attribute indicates that the 30-day dispensing rule need not be
        checked. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <!-- Brand and Ingredient are mutually exclusive -->
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Brand" type="BrandType" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="Ingredient" type="IngredientType" minOccurs="0" maxOccurs="unbounded"/>
        <!-- optional annotations -->
        <xs:element name="Guideline" type="html:Block" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="html:div" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="Request" type="RequestType" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="Rule" type="RuleType" minOccurs="0" maxOccurs="unbounded"/>
      </xs:choice>
    </xs:sequence>
    <!-- required attributes -->
    <xs:attribute name="ID" type="xs:ID" use="required"/>
    <xs:attribute name="Rank" type="xs:byte" use="required"/>
    <xs:attribute name="Units" type="xs:string" use="required"/>
    <!-- optional attributes -->
    <xs:attribute name="Statim" type="statims"/>
    <!-- XXX deprecated, not stateless -->
    <xs:attribute name="Update" type="xs:string"/>
    <xs:attribute name="variant" type="xs:string"/>
    <xs:attribute name="Weight" type="xs:decimal"/>
    <!-- optional attributes defined -->
    <xs:attribute name="Safety">
      <xs:simpleType>
        <xs:restriction base="xs:NMTOKEN">
          <xs:enumeration value="Compounded"/>
          <xs:enumeration value="Uncompounded"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:element name="Formulation" type="FormulationType"/>


  <!-- Brand -->
  <xs:complexType name="BrandType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Medicines registered by Medsafe (www.medsafe.govt.nz), Special food items and other pharmaceutical products subsidised in exceptional circumstances. Brand
        elements are Formulation children and contain Pack children. ID attribute is Pharmac identifier for each product. 'B' character followed by a 14 digit integer (6 digit ATC, 6 digit
        FormulationCode and a 2 digit Brand suffix). Name element is the trade name of the product given by the manufacturer. Should match the Medsafe registered name for registered medicines.
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Name" type="xs:string"/>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Pack" type="PackType" minOccurs="0" maxOccurs="unbounded"/>
        <!-- optional elements in any order-->
        <xs:element name="Rule" type="RuleType"/>
        <xs:element name="Request" type="RequestType"/>
        <xs:element ref="html:div"/>
      </xs:choice>
    </xs:sequence>
    <!-- required attribute ID -->
    <xs:attribute name="ID" type="xs:ID" use="required"/>
    <!-- optional attributes -->
    <xs:attribute name="HSS" type="xs:boolean"/>
    <xs:attribute name="PSS" type="SSType"/>
    <xs:attribute name="IMM" type="xs:boolean"/>
    <xs:attribute name="ToBePSS" type="xs:date"/>
    <xs:attribute name="SoleSupply" type="SSType"/>
    <xs:attribute name="ToBeSoleSupply" type="xs:date"/>
    <xs:attribute name="ToBeDelisted" type="xs:date"/>
    <!-- XXX deprecated, not stateless -->
    <xs:attribute name="Update" type="xs:string"/>
    <xs:attribute name="S26" type="xs:boolean"/>
    <xs:attribute name="S29" type="xs:boolean"/>
  </xs:complexType>

  <xs:simpleType name="SSType">
    <xs:union memberTypes="xs:boolean xs:date"/>
  </xs:simpleType>

  <xs:element name="Brand" type="BrandType"/>


  <!-- Ingredient -->
  <xs:complexType name="IngredientType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Ingredient elements are Formulation children. </xs:documentation>
    </xs:annotation>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <!-- required attribute FormulationCode -->
        <xs:attribute name="FormulationCode" type="xs:string" use="required"/>
        <!-- optional attributes -->
        <xs:attribute name="Quantity" type="xs:string"/>
        <xs:attribute name="To" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:element name="Ingredient" type="IngredientType"/>


  <!-- Pack -->
  <xs:complexType name="PackType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Subsidised retail items identifiable by a Pharmacode. In the HML, where the Brand name is 'Any', the item is identified by the last 8 digits of the Brand ID,
        Pack elements are Brand children. ID attribute is NZ Pharmacy Guild identifier for each retail pack. A 6 or 7 digit integer containing a mod 11 check digit. Quantity attribute is the quantity
        per market Pack expressed in Formulation Units. Multiple attribute is the smallest quantity that can be dispensed expressed in Formulation Units. Specified attribute identifies Pack size for
        unit pricing and inclusion in the printed schedule. Price attribute is the the subsidy value for this pack. Alternate attribute is a higher subsidy value sometimes available on Special
        Authority. Price attribute is the supplier price for this pack. CBS attribute: "Cost Brand Source" -- no price currently available for this pack; to be supplied by the claimant OP attribute:
        "Original Pack" -- this drug must be dispensed in whole packs </xs:documentation>
    </xs:annotation>
    <!-- allow (simpleType) Pack children in any order -->
    <xs:all>
      <xs:element name="Alternate" type="CurrencyType" minOccurs="0"/>
      <xs:element name="Multiple" type="xs:decimal" minOccurs="0"/>
      <xs:element name="Price" type="CurrencyType" minOccurs="0"/>
      <xs:element name="Quantity" type="xs:decimal" minOccurs="0"/>
      <xs:element name="Subsidy" type="CurrencyType" minOccurs="0"/>
      <xs:element name="Surcharge" type="xs:decimal" minOccurs="0"/>
    </xs:all>
    <!-- required attribute ID -->
    <xs:attribute name="ID" type="xs:ID" use="required"/>
    <!-- optional attributes -->
    <xs:attribute name="Specified" type="xs:boolean"/>
    <xs:attribute name="OP" type="xs:boolean"/>
    <xs:attribute name="CBS" type="xs:boolean"/>
    <xs:anyAttribute namespace="nzmt.org.nz" processContents="skip"  id="ctpp_id">
      <xs:annotation>
        <xs:documentation>
          New Zealand Medicines Terminology (NZMT) ctpp_id identifier.
          There may be some Schedule items for which there is no coresponding ctpp_id,
          or which share the same ctpp_id.
        </xs:documentation>
      </xs:annotation>
    </xs:anyAttribute>
  </xs:complexType>

  <!-- Delisted -->
  <xs:complexType name="DelistedType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Contains delisted brands for the month by way of Chemical element children. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Chemical" type="ChemicalType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="Pack" type="PackType"/>


  <!-- Schedule auxiliary -->

  <xs:attributeGroup name="xlinkattrs">
    <xs:anyAttribute namespace="http://www.w3.org/1999/xlink"/>
  </xs:attributeGroup>

  <xs:complexType name="RuleType">
    <xs:annotation>
      <xs:documentation xml:lang="en"> Claim processing rules Type attribute is the name of the rule. Value attribute is the numeric parameter. Attribute attribute is the text parameter. Waiver
        attribute is the name of a rule that can be applied instead of @Type. Only rules without parameters can be used. eg: "Special" and "SpecEnd". </xs:documentation>
    </xs:annotation>
    <!-- required attribute Type -->
    <xs:attribute name="Type" type="rules" use="required"/>
    <!-- optional attributes -->
    <xs:attribute name="Attribute" type="xs:string"/>
    <xs:attribute name="NonPrinting" type="xs:boolean"/>
    <xs:attribute name="Value" type="xs:decimal"/>

    <!-- deprecated -->
    <xs:attribute name="XRef" type="xs:string"/>

    <xs:attributeGroup ref="xlinkattrs"/>

    <!-- optional attribute Waiver defined -->
    <xs:attribute name="Waiver">
      <xs:simpleType>
        <xs:restriction base="xs:NMTOKEN">
          <xs:enumeration value="SpecEnd"/>
          <xs:enumeration value="Special"/>
          <xs:enumeration value="SubRxF"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:element name="Rule" type="RuleType"/>


  <!-- deprecated -->
  <xs:complexType name="XRefType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="To" type="xs:IDREF" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- deprecated -->
  <xs:element name="XRef" type="XRefType"/>


  <xs:simpleType name="CurrencyType">
    <xs:restriction base="xs:decimal">
      <xs:fractionDigits value="2"/>
      <xs:minInclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>


  <!-- Request children types -->

  <!-- Title -->
  <xs:complexType name="TitleType" mixed="true">
    <!-- one or more range elements -->
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="range">
        <xs:complexType mixed="true">
          <!-- zero or more instance elements -->
          <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element name="instance" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- Case -->
  <xs:complexType name="CaseType">
    <xs:sequence>
      <!-- required elements -->
      <xs:element ref="math:math"/>
      <xs:element name="Applicant" type="ApplicantType" maxOccurs="unbounded"/>
      <xs:element name="Term" type="TermType"/>
      <!-- optional elements -->
      <xs:element name="Lapse" type="LapseType" minOccurs="0"/>
      <xs:element name="History" type="HistoryType" minOccurs="0"/>
      <xs:element ref="html:div" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <!-- required attribute When defined -->
    <xs:attribute name="When" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Initial application"/>
          <xs:enumeration value="Renewal"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <!-- optional attribute Category -->
    <xs:attribute name="Category" type="xs:string"/>
    <!-- optional attributes defined -->
    <xs:attribute name="Break">
      <xs:simpleType>
        <xs:restriction base="xs:NMTOKEN">
          <xs:enumeration value="before"/>
          <xs:enumeration value="after"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="Form">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <!-- eg; SA0123, SA####, SAQQQQ -->
          <xs:pattern value="(SA[\d#Q]{4})( SA[\d#Q]{4})*"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <!-- Applicant -->
  <xs:complexType name="ApplicantType">
    <xs:simpleContent>
      <xs:extension base="applicants">
        <!-- optional attribute Location -->
        <xs:attribute name="Location" type="xs:string"/>
        <!-- optional attribute Referring defined -->
        <xs:attribute name="Referring" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- History -->
  <xs:complexType name="HistoryType">
    <xs:sequence>
      <xs:element name="Term" type="TermType"/>
      <xs:element name="Maximum" type="xs:byte"/>
    </xs:sequence>
  </xs:complexType>

  <!-- Term and supporting type IntOrNil-->
  <xs:complexType name="TermType">
    <xs:simpleContent>
      <xs:extension base="IntOrNil">
        <xs:attribute name="Measure" type="terms" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  
  <xs:complexType name="LapseType">
    <xs:simpleContent>
      <xs:extension base="LapseTimes">
        <xs:attribute name="Measure"  fixed="year" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
 
  <xs:simpleType name="LapseTimes">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="2"/>
    </xs:restriction>
  </xs:simpleType>
  
  <!-- internal type IntOrNil-->
  <xs:simpleType name="IntOrNil">
    <xs:union memberTypes="xs:byte">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value=""/>
        </xs:restriction>
      </xs:simpleType>
    </xs:union>
  </xs:simpleType>


  <!-- ChangeLog schema -->

  <xs:element name="ChangeLog">
    <xs:annotation>
      <xs:documentation xml:lang="en"> The ChangeLog element represents internal changes to the schema, therefor is not usually validated. ChangeLog elements consist of one or more Revision elements
        which is turn have a required date element and non nil cdata as content. The revision number of the schema proper is equal to the count of Revision children of the ChangeLog element.
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <!-- one or more Revision elements -->
      <xs:sequence maxOccurs="unbounded">
        <xs:element name="Revision">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="RevisionType">
                <!-- required date element date -->
                <xs:attribute name="date" type="xs:date" use="required"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="RevisionType">
    <!-- string with non nil length -->
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
