<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.roche.com/drugsafety"
    xmlns="http://www.roche.com/drugsafety" elementFormDefault="qualified">

    <!--
        Represents a single version of MedDRA dictionary
    -->
    <xs:element name="dictionary" type="dictionary"/>

    <!--
        Represents a collection of versions of MedDRA dictionaries 
    -->
    <xs:element name="dictionaries">
    	<xs:complexType>
    		<xs:sequence>
    			<xs:element name="dictionary" type="dictionary" minOccurs="0" maxOccurs="unbounded"/>
    		</xs:sequence>
    	</xs:complexType>
    </xs:element>
    
    <!--
        Represents a list of baskets availabale within the system. 
        Each element contains basket full set of basket metadata, but does not contain their definition. 
        The complete definition can be obtained by subsequent call to getBasket operation. 
        
        This elements is used as a return type for getBaskets operation 
    -->
    <xs:element name="baskets">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="basket" type="basketMetaData" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <!--
        Represents a definition of a basket. Complete set of basket metadata is followed by list of nested baskets and terms included and excluded. 
        
        This element might be used both as a parameter (e.g. for applyBasket) and a return value (e.g. getBasket).
    -->
    <xs:element name="basket" type="basket"/>

    <!-- defines single version of MedDRA dictionary  -->
    <xs:complexType name="dictionary">
        <xs:sequence>
            <xs:element name="meddra-term" type="medDRATerm" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="version" type="xs:string" use="required"/>
        <xs:attribute name="current" type="xs:boolean"/>
    </xs:complexType>

    <!-- defines MedDRA term element -->
    <xs:element name="meddra-term" type="medDRATerm"/>
    
    <!-- defines MedDRA Code type -->
    <xs:simpleType name="medDRACode">
        <xs:restriction base="xs:string">
            <!-- xs:pattern value="[1-2][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" -->
            <xs:pattern value="[0-9]{8}"/>
        </xs:restriction>
    </xs:simpleType>
    
    <!-- defines basket scope type -->
    <xs:simpleType name="groupScope">
        <xs:restriction base="xs:string">
            <xs:enumeration value="SMQ"/>
            <xs:enumeration value="AEGT"/>
            <xs:enumeration value="private"/>
        </xs:restriction>
    </xs:simpleType>
    
    <!-- defines basket metadata type -->
    <xs:complexType name="basketMetaData">
        <xs:sequence>
            <xs:element name="description" type="xs:string" minOccurs="0"/>
            <xs:element name="smq-level" type="xs:string" minOccurs="0"/>
            <xs:element name="smq-source" type="xs:string" minOccurs="0"/>
            <xs:element name="smq-note" type="xs:string" minOccurs="0"/>
            <xs:element name="smq-algorithm" type="xs:string" minOccurs="0"/>
            <xs:element name="created-by" type="xs:string" minOccurs="0"/>
            <xs:element name="creation-date" type="xs:string" minOccurs="0"/>
            <xs:element name="modified-by" type="xs:string" minOccurs="0"/>
            <xs:element name="modification-date" type="xs:string" minOccurs="0"/>
            <xs:element name="reviewer" type="xs:string" minOccurs="0"/>
            <xs:element name="review-date" type="xs:string" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="reference-no" type="xs:string"/>
        <xs:attribute name="basket-version" type="xs:int"/>
        <xs:attribute name="medDRA-version" type="xs:string"/>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="scope" type="groupScope"/>
    </xs:complexType>
    
    <!-- defines complete basket definition type -->
    <xs:complexType name="basket">
        <xs:complexContent>
            <xs:extension base="basketMetaData">
                <xs:sequence>
                    <xs:element name="included-baskets" type="groupOfBaskets" minOccurs="0"/>
                    <xs:element name="excluded-baskets" type="groupOfBaskets" minOccurs="0"/>
                    <xs:element name="included-terms" type="groupOfTerms" minOccurs="0"/>
                    <xs:element name="excluded-terms" type="groupOfTerms" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- defines a type used to represent nested baskets -->
    <xs:complexType name="groupOfBaskets">
        <xs:sequence>
            <xs:element name="basket" type="basket" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <!-- defines a type used to represent set  of terms included in the basket-->
    <xs:complexType name="groupOfTerms">
        <xs:sequence>
            <xs:element name="meddra-term" type="medDRATerm" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <!-- defines MedDRA Term type -->
    <xs:complexType name="medDRATerm">
        <xs:sequence>
            <xs:element name="meddra-term" type="medDRATerm" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="level" use="required" type="termLevel"/>
        <xs:attribute name="code" use="required" type="medDRACode"/>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="isCurrent" type="xs:boolean"/>
        <xs:attribute name="path-type" type="pathType"/>
        <xs:attribute name="term-scope" type="medDRATermScope"/>
    </xs:complexType>
    <!-- defines MedDRA hierarchy level type -->
    <xs:simpleType name="termLevel">
        <xs:restriction base="xs:string">
            <xs:enumeration value="SOC"/>
            <xs:enumeration value="HLGT"/>
            <xs:enumeration value="HLT"/>
            <xs:enumeration value="PT"/>
            <xs:enumeration value="LLT"/>
        </xs:restriction>
    </xs:simpleType>
    <!-- defines MedDRA term scope type -->
    <xs:simpleType name="medDRATermScope">
        <xs:restriction base="xs:string">
            <xs:enumeration value="narrow"/>
            <xs:enumeration value="broad"/>
            <xs:enumeration value="undefined"/>
        </xs:restriction>
    </xs:simpleType>
    <!-- defines MedDRA term path type -->
    <xs:simpleType name="pathType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="single"/>
            <xs:enumeration value="primary"/>
            <xs:enumeration value="secondary"/>
            <xs:enumeration value="undeterminable"/>
        </xs:restriction>
    </xs:simpleType>
    
</xs:schema>
