<?xml version="1.0"?>
<!--
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1

The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is PharmGen.

The Initial Developer of the Original Code is
PharmGKB (The Pharmacogenetics and Pharmacogenetics Knowledge Base,
supported by NIH U01GM61374).
Portions created by the Initial Developer are Copyright (C) 2005
the Initial Developer. All Rights Reserved.

Contributor(s):

Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or the
GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in
which case the provisions of the GPL or the LGPL are applicable instead of
those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.

***** END LICENSE BLOCK *****
-->

<xsd:schema version="4.0"
  targetNamespace="http://www.pharmgkb.org/schema/"
  xmlns="http://www.pharmgkb.org/schema/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:sch="http://www.ascc.net/xml/schematron"
  elementFormDefault="qualified">

  <xsd:annotation>
    <xsd:documentation>
      This XML schema defines common entities used throughout the PharmGKB XML schema.
      For complete documentation, see http://www.pharmgkb.org/schema/.
    </xsd:documentation>
  </xsd:annotation>



  <!-- operation attribute -->
  <xsd:attribute name="operation">
    <xsd:annotation>
      <xsd:documentation>
        This attribute can be used on any element to denote the
        operation that should be performed on the element.  The default
        value is add.
      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleType>
      <xsd:restriction base="xsd:token">
        <xsd:enumeration value="add">
          <xsd:annotation>
            <xsd:documentation>
              The data in this element will be added.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:enumeration>
        <xsd:enumeration value="edit">
          <xsd:annotation>
            <xsd:documentation>
              The data in this element will replace any existing value.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:enumeration>
        <xsd:enumeration value="delete">
          <xsd:annotation>
            <xsd:documentation>
              The data in this element will be deleted.
            </xsd:documentation>
          </xsd:annotation>
        </xsd:enumeration>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:attribute>


  <!-- AccessionIdType -->
  <xsd:simpleType name="AccessionIdType">
    <xsd:annotation>
      <xsd:documentation>
        A PharmGKB Accession ID.
        See http://www.pharmgkb.org/schema/faq.html#accessionId for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1"/>
      <xsd:pattern value="([Pp][Aa])?\d+"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- AccessionObjectClass -->
  <xsd:complexType name="AccessionObjectClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a PharmGKB object with an Accession ID.
      </xsd:documentation>
    </xsd:annotation>
    <!-- subelements -->
    <xsd:sequence>
      <!-- note -->
      <xsd:element name="note" minOccurs="0" maxOccurs="1">
        <xsd:annotation>
          <xsd:documentation>
            A note on the object.
          </xsd:documentation>
        </xsd:annotation>
        <xsd:simpleType>
          <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="4000"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>
    </xsd:sequence>
    <!-- attributes -->
    <xsd:attribute name="pharmgkbId" type="AccessionIdType" use="optional">
      <xsd:annotation>
        <xsd:documentation>
          A unique identifier assigned by the PharmGKB (the PharmGKB Accession
          ID). This attribute is used to refer to data that is already in the
          PharmGKB and is only supplied when editing or adding to such data.
          See http://www.pharmgkb.org/schema/faq.html#localVsPharmgkbId for
          details.
        </xsd:documentation>
      </xsd:annotation>
    </xsd:attribute>
    <xsd:attribute name="localId" type="NonEmptyTokenType" use="optional">
      <xsd:annotation>
        <xsd:documentation>
          A unique identifier for this element assigned by the submitter. The
          only rule it must follow is that no two XML elements can be assigned
          the same localId within a single XML document. See
          http://www.pharmgkb.org/schema/faq.html#localVsPharmgkbId for
          details.
        </xsd:documentation>
      </xsd:annotation>
    </xsd:attribute>
  </xsd:complexType>


  <!-- OrganismClass -->
  <xsd:complexType name="OrganismClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines an organism.
      </xsd:documentation>
    </xsd:annotation>
    <!-- subelements -->
    <xsd:sequence>
      <xsd:element name="type" type="OrganismEnum" minOccurs="1" maxOccurs="1" default="Human"/>
      <xsd:element name="classification" type="OrganismClassificationEnum" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="strain" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>

  <!-- OrganismEnum -->
  <xsd:simpleType name="OrganismEnum">
    <xsd:annotation>
      <xsd:documentation>
        The list of accepted organisms.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="Human"/>
      <xsd:enumeration value="Mouse"/>
      <xsd:enumeration value="Rat"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- OrganismClassificationEnum -->
  <xsd:simpleType name="OrganismClassificationEnum">
    <xsd:annotation>
      <xsd:documentation>
        The list of accepted classifications for orgnisms.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="Homo sapiens"/>
      <xsd:enumeration value="Mus musculus castaneus"/>
      <xsd:enumeration value="Mus musculus domesticus"/>
      <xsd:enumeration value="Mus musculus molossinus"/>
      <xsd:enumeration value="Mus musculus musculus"/>
      <xsd:enumeration value="Rattus norvegicus"/>
      <xsd:enumeration value="Rattus rattus"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- GenderEnum -->
  <xsd:simpleType name="GenderEnum">
    <xsd:annotation>
      <xsd:documentation>
        The list of accepted genders.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="Male"/>
      <xsd:enumeration value="Female"/>
      <xsd:enumeration value="Hermaphrodite"/>
      <xsd:enumeration value="NA"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- XrefClass -->
  <xsd:complexType name="XrefClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a cross-reference to another resource.
        See http://www.pharmgkb.org/schema/docs/xref.html for details.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Constraints for xref">
          <sch:rule context="pgkb:xref">
            <sch:report test="@resource='PharmGKB' and
                              not((starts-with(., 'PA') and floor(substring(., 3))=number(substring(., 3))) or
                              floor(.)=number(.))">Cross-reference resource from PharmGKB does not appear to have a valid PharmGKB Accession ID</sch:report>
          </sch:rule>
        </sch:pattern>
      </xsd:appinfo>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:extension base="NonEmptyTokenType">
        <!-- attributes -->
        <xsd:attribute name="resource" use="required">
          <xsd:annotation>
            <xsd:documentation>
              The cross-referenced resource.
            </xsd:documentation>
          </xsd:annotation>
          <!-- restrictions -->
          <xsd:simpleType>
            <xsd:restriction base="xsd:token">
              <xsd:enumeration value="ABI Assay"/>
              <xsd:enumeration value="ALFRED"/>
              <xsd:enumeration value="dbSNP"/>
              <xsd:enumeration value="dbSTS"/>
              <xsd:enumeration value="Ensembl"/>
              <xsd:enumeration value="Entrez Gene"/>
              <xsd:enumeration value="GDB"/>
              <xsd:enumeration value="GenAtlas"/>
              <xsd:enumeration value="GenBank"/>
              <xsd:enumeration value="GeneCard"/>
              <xsd:enumeration value="GO"/>
              <xsd:enumeration value="local"/>
              <xsd:enumeration value="MedLine"/>
              <xsd:enumeration value="MutDb"/>
              <xsd:enumeration value="OMIM"/>
              <xsd:enumeration value="PharmGKB"/>
              <xsd:enumeration value="PubMed"/>
              <xsd:enumeration value="RefSeqNM"/>
              <xsd:enumeration value="RefSeqNP"/>
              <xsd:enumeration value="RefSeqNT"/>
              <xsd:enumeration value="SOURCE"/>
              <xsd:enumeration value="SWISS-PROT"/>
              <xsd:enumeration value="UCSC Genome Browser"/>
              <xsd:enumeration value="UniGene"/>
              <xsd:enumeration value="URL"/>
              <!-- sample set resources -->
              <xsd:enumeration value="ATCC"/>
              <xsd:enumeration value="BD Cytosol Sample" />
              <xsd:enumeration value="BD Microsome Sample" />
              <xsd:enumeration value="Coriell Subject"/>
              <xsd:enumeration value="GCF Subject"/>
              <xsd:enumeration value="PDR Subject"/>
              <xsd:enumeration value="SOPHIE Subject"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:attribute>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>


  <!-- OntologyTermClass -->
  <xsd:complexType name="OntologyTermClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines an ontology term.  The content of this element should
        be a unique term in an ontology.  Submitters interested in adding
        ontology types should contact Michelle Carrillo at mikki@stanford.edu.
      </xsd:documentation>
      <xsd:appinfo>
        <sch:pattern name="Constraints for term">
          <sch:rule context="pgkb:term">
            <sch:report test="not(@ontologyId) and
            not(normalize-space(.))">Missing value:  ontology term is required if ontologyId attribute is not defined</sch:report>
          </sch:rule>
        </sch:pattern>
      </xsd:appinfo>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:extension base="xsd:string">
        <!-- attributes -->
        <xsd:attribute name="ontology" use="required">
          <xsd:annotation>
            <xsd:documentation>
              The ontology to this term is from.
            </xsd:documentation>
          </xsd:annotation>
          <!-- restrictions -->
          <xsd:simpleType>
            <xsd:restriction base="xsd:token">
              <xsd:enumeration value="GO"/>
              <xsd:enumeration value="MeSH"/>
              <xsd:enumeration value="Phenotype"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="ontologyId" type="NonEmptyTokenType" use="optional"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>


  <!-- PharmacogeneticKnowledgeCategoryEnum -->
  <xsd:simpleType name="PharmacogeneticKnowledgeCategoryEnum">
    <xsd:annotation>
      <xsd:documentation>
        The list of categories of pharmacogenetic knowledge.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="Clinical Outcome"/>
      <xsd:enumeration value="Pharmacodynamics and Drug Response"/>
      <xsd:enumeration value="Pharmacokinetics"/>
      <xsd:enumeration value="Molecular and Cellular Functional Assays"/>
      <xsd:enumeration value="Genotype"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- PersonClass -->
  <xsd:complexType name="PersonClass">
    <xsd:annotation>
      <xsd:documentation>
        This class defines a person.
        See http://www.pharmgkb.org/schema/docs/person.html for details.
      </xsd:documentation>
    </xsd:annotation>
    <!-- subelements -->
    <xsd:sequence>
      <xsd:element name="name" type="NonEmptyTokenType" minOccurs="1" maxOccurs="1"/>
      <xsd:element name="email" type="NonEmptyTokenType" minOccurs="0" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>


  <!-- NonEmptyTokenType -->
  <xsd:simpleType name="NonEmptyTokenType">
    <xsd:annotation>
      <xsd:documentation>
        A non-empty token.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:minLength value="1"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- NonEmptyStringType -->
  <xsd:simpleType name="NonEmptyStringType">
    <xsd:annotation>
      <xsd:documentation>
        A non-empty string.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- NonEmptyString4000Type -->
  <xsd:simpleType name="NonEmptyString4000Type">
    <xsd:annotation>
      <xsd:documentation>
        A non-empty string.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:string">
      <xsd:minLength value="1"/>
      <xsd:maxLength value="4000"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="NonNegativeIntegerOrNType">
    <xsd:annotation>
      <xsd:documentation>
        A non-negative integer or "N".
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:pattern value="\d+|N" />
    </xsd:restriction>
  </xsd:simpleType>

  <!-- BooleanUnknownNaType -->
  <xsd:simpleType name="BooleanUnknownNaType">
    <xsd:annotation>
      <xsd:documentation>
        An extended boolean type with unknown and not applicable (NA) values.
      </xsd:documentation>
    </xsd:annotation>
    <!-- restrictions -->
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="True"/>
      <xsd:enumeration value="true"/>
      <xsd:enumeration value="False"/>
      <xsd:enumeration value="false"/>
      <xsd:enumeration value="Unknown"/>
      <xsd:enumeration value="NA"/>
    </xsd:restriction>
  </xsd:simpleType>


  <!-- UnitOfMeasureEnum -->
  <xsd:simpleType name="UnitOfMeasureEnum">
    <xsd:annotation>
      <xsd:documentation>
        The type of unit of measure.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="Area"/>
      <xsd:enumeration value="BMI"/>
      <xsd:enumeration value="Concentration"/>
      <xsd:enumeration value="Concentration per Unit Mass"/>
      <xsd:enumeration value="Concentration per Unit Volume by Time"/>
      <xsd:enumeration value="Height"/>
      <xsd:enumeration value="Mass"/>
      <xsd:enumeration value="Mass per Unit Area"/>
      <xsd:enumeration value="Mass per Unit Time"/>
      <xsd:enumeration value="Mass per Unit Volume"/>
      <xsd:enumeration value="Mass per Unit Volume by Time"/>
      <xsd:enumeration value="Number per Unit Mass"/>
      <xsd:enumeration value="Number per Unit Mass per Unit Time"/>
      <xsd:enumeration value="Number per Unit Time per Unit Mass"/>
      <xsd:enumeration value="Percentage"/>
      <xsd:enumeration value="Temperature"/>
      <xsd:enumeration value="Volume per Unit Area"/>
      <xsd:enumeration value="Volume per Unit Time"/>
      <xsd:enumeration value="Volume per Unit Time per Unit Area"/>
      <xsd:enumeration value="Volume per Cell per Unit Time"/>
    </xsd:restriction>
  </xsd:simpleType>


</xsd:schema>