<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1.0" elementFormDefault="qualified" targetNamespace="http://euadr.biosemantic.erasmusmc.org/" xmlns="http://euadr.biosemantic.erasmusmc.org/" xmlns:common="http://common.biosemantic.erasmusmc.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:annotation>
    <xs:documentation>EU-ADR specific data types v2.6.2</xs:documentation>
  </xs:annotation>

  <xs:import id="common" namespace="http://common.biosemantic.erasmusmc.org/" schemaLocation="http://bioinformatics.ua.pt/euadr/common_types.xsd"/>

  <!-- || MAIN || -->
  <xs:element name="relationships" type="relationships"/>

  <xs:complexType name="relationships">
    <xs:annotation>
      <xs:documentation>
        This is the main document element. It must be the root of the XML file. This element must contain at least one relationship
        element and may include at most one score element.
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="globalScore" type="score" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="creator" minOccurs="0" maxOccurs="3" type="creator"/>
      <xs:element name="relationship" type="relationship" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="relationship">
    <xs:sequence>
      <xs:element name="signalId" type="xs:integer" minOccurs="0" maxOccurs="1"/>
      <xs:element name="sourceId" type="common:databaseId" minOccurs="0" maxOccurs="1"/>
      <xs:element name="targetId" type="common:databaseId" minOccurs="0" maxOccurs="1"/>
      <xs:element name="partialScore" type="score" minOccurs="0" maxOccurs="1"/>
      <xs:element name="observationDateTime" minOccurs="0" maxOccurs="1" type="xs:dateTime"/>
      <xs:element name="informationSources" minOccurs="0" maxOccurs="1">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="informationSource" type="informationSource" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!-- || ELEMENTS || -->
  <xs:complexType name="creator">
    <xs:annotation>
      <xs:documentation>
        The creator element contains a description for the triggered service and the execution status code (error handling).
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="service" minOccurs="1" maxOccurs="1" type="xs:anyURI"/>
      <xs:element name="status" minOccurs="1" maxOccurs="1" type="status"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="score">
    <xs:annotation>
      <xs:documentation>
        Score is used to present the calculated Relative Risk for the Drug/Event pair being analysed. In addition, other classification values can be added.
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="value" type="value" minOccurs="1" maxOccurs="1"/>
      <xs:element name="extraScores" minOccurs="0" maxOccurs="1">
        <xs:complexType>
          <xs:annotation>
            <xs:documentation>These are the extra calculated values.</xs:documentation>
          </xs:annotation>
          <xs:sequence>
            <xs:element name="extraScore" type="extraScore" minOccurs="1" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="extraScore">
    <xs:sequence>
      <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
      <xs:element name="value" type="xs:string" maxOccurs="1" minOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="informationSource">
    <xs:annotation>
      <xs:documentation>Relation should have one or more sources of information that support or describe this relationship.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="label" type="common:label" minOccurs="0" maxOccurs="1"/>
      <xs:element name="source" type="common:databaseSource" minOccurs="0" maxOccurs="1"/>
      <xs:element name="url" type="xs:anyURI" minOccurs="0" maxOccurs="1"/>
      <xs:element name="relationshipType" type="relationshipType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="interaction" type="interaction" minOccurs="0" maxOccurs="1"/>
      <xs:element name="evidence" type="evidence" minOccurs="0" maxOccurs="1"/>
      <xs:element name="databaseIds" minOccurs="0" maxOccurs="1">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="databaseId" type="common:databaseId" minOccurs="1" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="evidence">
    <xs:annotation>
      <xs:documentation>The strength value for this relationship.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="type" type="evidenceType"/>
      <xs:element name="value" type="xs:float" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="interaction">
    <xs:annotation>
      <xs:documentation>
        Interaction is the relation between two elements from different sets. In the case of
        an element from the set {drugs} and an element from the set {targets}, interaction refers to the
        magnitude and type of their binding or functional affinity.
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="type" type="interactionType"/>
      <xs:element name="value" type="xs:string">
        <xs:annotation>
          <xs:documentation>
            the magnitude of the interaction between an element "drug" and an element "target".
            Values are given as -log(10^-Interaction) in mol units (i.e., a value of 6 corresponds to
            micromolar affinity; a value of 9 to nanomolar affinity).
		(Changed to string by Anna's request).
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="concept">
    <xs:complexContent>
      <xs:extension base="common:concept">
        <xs:sequence>
          <xs:element name="id" type="common:databaseId">
            <xs:annotation>
              <xs:documentation>The ID of this concept.</xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="creationDateTime" type="xs:dateTime">
            <xs:annotation>
              <xs:documentation>The date and time this concept was created.</xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <!-- || ENUMERATIONS ||-->
  <xs:simpleType name="status">
    <xs:annotation>
      <xs:documentation>        
       Status is used to identify the service response status.Code list:
        <ul>
            <li>10 - Correct service execution</li>
            <li>21 - Invalid ATC Drug code: invalid ATC format (Ex. 'HOLA')</li>
            <li>22 - Unknown ATC Drug code: valid ATC code but not available in service database</li>
            <li>23 - Invalid Event code: invalid Event format (Ex. '12345')</li>
            <li>24 - Unknown Event code: valid Event code but not available in service database</li>
            <li>25 - No match for Drug-Event pair (Signal (Drug-Event pair) does not exist in database)</li>
            <li>26 - No mapping from ATC to SMILE format available in service database</li>
            <li>27 - No annotation to proteins (UniProt) for translated (SMILE) drug code</li>
            <li>28 - No annotation to proteins (UniProt) for provided Event code</li>
            <li>31 - No evidence found for Drug-Event pair: no service results for Signal (Drug-Event pair)</li>
            <li>32 - Evidence not relevant for Drug-Event pair: results were found, but are not important for the expected service output (Ex. UB2 with 1 or 2 evidences)</li>
            <li>41 - Unable to connect to database (service error)</li>
            <li>42 - Service server exception (service error)</li>
            <li>43 - Internal service error (miscellaneous internal service or server errors)</li>
		</ul>        
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:integer">
      <xs:enumeration value="10"/>
      <!-- Correct service execution -->
      <xs:enumeration value="21"/>
      <!-- Invalid ATC Drug code: invalid ATC format (Ex. 'HOLA') -->
      <xs:enumeration value="22"/>
      <!-- Unknown ATC Drug code: valid ATC code but not available in service database -->  
      <xs:enumeration value="23"/>
        <!-- Invalid Event code: invalid Event format (Ex. '12345')  -->
      <xs:enumeration value="24"/>
      <!-- Unknown Event code: valid Event code but not available in service database -->
      <xs:enumeration value="25"/>
      <!-- No match for Drug-Event pair (Signal (Drug-Event pair) does not exist in database) -->
        <xs:enumeration value="26"/>
        <!-- No mapping from ATC to SMILE format available in service database -->
        <xs:enumeration value="27"/>
        <!-- No annotation to proteins (UniProt) for translated (SMILE) drug code -->
        <xs:enumeration value="28"/>
        <!-- No annotation to proteins (UniProt) for provided Event code -->
      <xs:enumeration value="31"/>
      <!-- No evidence found for Drug-Event pair: no service results for Signal (Drug-Event pair) -->
      <xs:enumeration value="32"/>
      <!-- Evidence not relevant for Drug-Event pair: results were found, but are not important for the expected service output (Ex. UB2 with 1 or 2 evidences) -->
     <xs:enumeration value="41"/>
      <!-- Unable to connect to database (service error) -->
      <xs:enumeration value="42"/>
      <!-- Service server exception (service error) -->
        <xs:enumeration value="43"/>
      <!-- Internal service error (miscellaneous internal service or server errors) -->    
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="value">
    <xs:annotation>
      <xs:documentation>The calculated score for the relative risk.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:float">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="1"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="interactionType">
    <xs:annotation>
      <xs:documentation>
      The type of interaction between an element "source" and an element "target".
      <ul>
        <li>pKi</li>
        <li>pKd</li>
        <li>pIC50</li>
        <li>pEC50</li>
      </ul>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="pKi"/>
      <xs:enumeration value="pKd"/>
      <xs:enumeration value="pIC50"/>
      <xs:enumeration value="pEC50"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="evidenceType">
    <xs:annotation>
      <xs:documentation>
         The level of evidence.
         <ul>
        <li>FACTUAL</li>
        <li>OBSERVATIONAL</li>
        <li>TEXT_MINING</li>
        <li>CO_OCCURRENCE_SENTENCE</li>
        <li>CO_OCCURRENCE_ABSTRACT</li>
        <li>SIMILARITY</li>
      </ul>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="FACTUAL"/>
      <xs:enumeration value="OBSERVATIONAL"/>
      <xs:enumeration value="TEXT_MINING"/>
      <xs:enumeration value="CO_OCCURRENCE_SENTENCE"/>
      <xs:enumeration value="CO_OCCURRENCE_ABSTRACT"/>
      <xs:enumeration value="SIMILARITY"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="relationshipType">
    <xs:annotation>
      <xs:documentation>
        The type of relation describes what is the interaction between concepts under consideration.
        <ul>
        <li>INHIBITS</li>
        <li>CAUSES</li>
        <li>AFFECTS</li>
          <li>BINDS</li>
          <li>POSITIVELY_RELATED</li>
          <li>NEGATIVELY_RELATED</li>
      </ul>
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="INHIBITS"/>
      <xs:enumeration value="CAUSES"/>
      <xs:enumeration value="AFFECTS"/>
      <xs:enumeration value="BINDS"/>
      <xs:enumeration value="POSITIVELY_RELATED"/>      
      <xs:enumeration value="NEGATIVELY_RELATED"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>