<?xml version="1.0"?>
<!--

    Copyright (C) 2013 Julian Atienza Herrero <j.atienza at har.mrc.ac.uk>

    MEDICAL RESEARCH COUNCIL UK MRC

    Harwell Mammalian Genetics Unit

    http://www.har.mrc.ac.uk

    Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    License for the specific language governing permissions and limitations under
    the License.

-->
<xs:schema xmlns="http://www.mousephenotype.org/dcc/exportlibrary/datastructure/core/procedure"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:pc="http://www.mousephenotype.org/dcc/exportlibrary/datastructure/core/common"
           targetNamespace="http://www.mousephenotype.org/dcc/exportlibrary/datastructure/core/procedure" elementFormDefault="qualified"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">
           
    <xs:import namespace="http://www.mousephenotype.org/dcc/exportlibrary/datastructure/core/common"  schemaLocation="common.xsd"/>
     
    <xs:element name="centreProcedureSet">
        <xs:complexType>
            <xs:annotation>
                <xs:documentation xml:lang="en"> Top level term of the experimental data document. An
                    xml document following this xsd must have at least one centreProcedure element.
                </xs:documentation>
            </xs:annotation>
            <xs:sequence minOccurs="1" maxOccurs="unbounded">
                <xs:element name="centre" type="CentreProcedure"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    
    <xs:complexType name="CentreProcedure">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                A Centre submits at least one experiment. 
                Attributes:
                centreID : ILAR code of the centre this data was generated.
                If one centre is submitting data from other centres, centreID should be original's.
                pipeline : IMPReSS identifier from which this data was generated. 
                project  : The IMPC  project under which this data was generated.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="housing"    type="Housing"    minOccurs="0" maxOccurs="2"/>
            <xs:element name="line"       type="Line"       minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="experiment" type="Experiment" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="centreID"          type="pc:CentreILARcode" use="required"/>
        <xs:attribute name="pipeline"          type="xs:string"         use="required"/>
        <xs:attribute name="project"           type="xs:string"         use="required"/>
        
    </xs:complexType>


    <xs:complexType name="Experiment">
        <xs:annotation>
            <xs:documentation xml:lang="en"> An experiment performed on an animal or posibbly a
                group of animals (mice or embryos). It if is performed on a group of animals, each
                measurement should apply to all the animals of that group. It is envisaged that for
                most cases, this will only apply to a single animal.
                An experiment follows one and single type of procedure.
                A procedure can have multiple types of parameters.
                Attributes: 
                sequenceID       : if a  procedure is repeated multiple times for an animal (eg. body weight), then the
                indidual measurements must have different sequenceID values, (eg age of the animal)
                experimentID     : centre's experiment identifier. 
                dateOfExperiment : only the date the  procedure started, no time of the day, following the pattern yyyy-MM-dd eg. 2012-12-31 
                
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="specimenID"   type="xs:string"  minOccurs="1" maxOccurs="unbounded"/>
            <xs:element name="procedure"    type="Procedure"  minOccurs="1" maxOccurs="1"/>
            <xs:element name="statusCode"   type="pc:StatusCode" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="sequenceID"       type="xs:string" use="optional"/>
        <xs:attribute name="experimentID"     type="xs:string" use="required"/>
        <xs:attribute name="dateOfExperiment" type="xs:date"   use="required"/>
    </xs:complexType>

    <xs:complexType name="Housing">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                This is an optional element to describe the housing and husbandry or experimental design conditions using the procedure keys IMPC_HOU_002 or IMPC_EXD_002. 
                This data can be submitted via the crawler, consult the procedure protocols and wranglers@mousephenotype.org for any additional information.
                Attributes:
                fromLIMS : not in use. 
                lastUpdated : not in use.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="procedure"    type="Procedure"  minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="fromLIMS"    type="xs:boolean" use="optional"/>
        <xs:attribute name="lastUpdated" type="xs:date"    use="optional"/>
    </xs:complexType>
    
    <xs:complexType name="Line">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                A line procedure is one when the data relates to a whole mutant line rather than to a single specimen.
                eg. fertility and viability where the data reported is the number of homs out of a certain number of pubs weaned.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="procedure"    type="Procedure"     minOccurs="1" maxOccurs="1"/>
            <xs:element name="statusCode"   type="pc:StatusCode" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="colonyID"    type="xs:string"  use="required"/>
        <xs:attribute name="sequenceID"  type="xs:string" use="optional"/>
    </xs:complexType>
    
    <xs:complexType name="Procedure">
        <xs:annotation>
            <xs:documentation xml:lang="en"> This holds all the actual parameters for one
                experiment. The actual Std Operating Procedures are defined in IMPReSS.  procedureID is the IMPReSSID
                for the procedure. 
                A procedure can have no parameters if you cannot perform the experiment. 
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="1">
            <xs:element name="simpleParameter"      type="SimpleParameter"      minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="ontologyParameter"    type="OntologyParameter"    minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="seriesParameter"      type="SeriesParameter"      minOccurs="0"  maxOccurs="unbounded"/>
            
            <xs:element name="mediaParameter"       type="MediaParameter"       minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="mediaSampleParameter" type="MediaSampleParameter" minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="seriesMediaParameter" type="SeriesMediaParameter" minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="procedureMetadata"    type="ProcedureMetadata"    minOccurs="0"  maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="procedureID" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:simpleType name="string_1024">
        <xs:restriction base="xs:string">
            <xs:maxLength value="1024" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="string_255">
        <xs:restriction base="xs:string">
            <xs:maxLength value="255" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="SimpleParameter">
        <xs:annotation>
            <xs:documentation xml:lang="en"> A parameter that has a single textual or numerical
                result. 
                ParameterStatus allows additional information about the parameter to be
                recorded, including the reason why there is no result for this parameter.
                Attributes:
                parameterID : IMPReSS parameterKey for the parameter. These are available from http://www.mousephenotype.org/impress.
                sequenceID  : Currently the only acceptable use is to add multiple free text comments about a procedure. 
                unit        : This will allow validation of the units submitted to those accepable in IMPReSS. 
                
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="value"           type="string_1024" minOccurs="0" maxOccurs="1"/>
            <xs:element name="parameterStatus" type="xs:string" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string"  use="required"/>
        <xs:attribute name="unit"        type="xs:string"  use="optional"/>
        <xs:attribute name="sequenceID"  type="xs:integer" use="optional"/>
    </xs:complexType>

    <xs:complexType name="OntologyParameter">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                A parameter that has one or more ontology annotations.
                It differs from simple parameter only in the cardinality, term must happen at least
                once. 
                ParameterStatus allows additional information about the parameter to be
                recorded, including the reason why there is no result for this parameter.
                parameterID : IMPReSS parameterKey for the parameter.These are available from http://www.mousephenotype.org/impress.
                sequenceID  : this allows multiple distinct features of an organ of structure defined by this parameter to be described.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="term"            type="string_255" minOccurs="1" maxOccurs="unbounded"/>
            <xs:element name="parameterStatus" type="xs:string" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string"  use="required"/>
        <xs:attribute name="sequenceID"  type="xs:integer" use="optional"/>
    </xs:complexType>

    <xs:complexType name="SeriesParameter">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                A series parameter that has multiple textual or numerical results. 
                ParameterStatus allows additional information about the parameter to be recorded, including the reason why there is no result for this parameter.
                Attributes
                parameterID : IMPReSS parameterKey for the parameter.These are available from http://www.mousephenotype.org/impress.
                sequenceID  : Currently the only acceptable use is to submit multiple traces for multiple amplitudes for a single frequency for the ABR procedure 
                unit        : This will allow validation of the units submitted to those accepable in IMPReSS.  
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="value"           type="SeriesParameterValue" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="parameterStatus" type="xs:string"            minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string"  use="required"/>
        <xs:attribute name="sequenceID"  type="xs:integer" use="optional"/>
        <xs:attribute name="unit"        type="xs:string"  use="optional"/>
    </xs:complexType>
    
  

    <xs:complexType name="SeriesParameterValue">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                This is a single result as part of series of results.
                The incrementValue attribute should be a unique for each occurring element, eg. the
                repeat number or the time of measurement. 
                incrementStatus: allows additional information about the parameter to be recorded, including the reason why there is no result for this increment.
            </xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="incrementValue"  type="string_255" use="required"/>
                <xs:attribute name="incrementStatus" type="xs:string" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="MediaParameter">
        <xs:annotation>
            <xs:documentation xml:lang="en"> A media parameter is a parameter with a single media
                file 
                Attributes: 
                parameterID : IMPReSS parameterKey for the parameter.These are available from http://www.mousephenotype.org/impress.
                uri         : location from which the dcc can download this file.
                fileType    : find a list at
                <a href="http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/docs/conf/mime.types?view=annotate">list</a> 
                link        : External url that points to a high resolution version of this media file
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="parameterStatus"      type="xs:string"            minOccurs="0"  maxOccurs="1"/>
            <xs:element name="parameterAssociation" type="ParameterAssociation" minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="procedureMetadata"    type="ProcedureMetadata"    minOccurs="0"  maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string" use="required"/>
        <xs:attribute name="URI"         type="string_255" use="required"/>
        <xs:attribute name="fileType"    type="xs:string" use="required"/>
        <xs:attribute name="link"        type="string_255" use="optional"/>
    </xs:complexType>

    <xs:complexType name="MediaSampleParameter">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                It represents one or more samples that have come from an animal
                eg. the set of block generated by the LacZ Protocol. 
                ParameterStatus allows additional information about the parameter to be recorded, including the reason why there is no result for this parameter.
                Attributes
                parameterID : IMPReSS parameterKey for the parameter. These are available from http://www.mousephenotype.org/impress.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="mediaSample"     type="MediaSample" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="parameterStatus" type="xs:string"   minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="MediaSample">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                An individual sample that has come from an animal eg
                individual block generated by the LacZ Protocol. A block can be sectioned into multiple mediaSections. 
                Attributes:
                localID :identifier from wich the individual section can be found at the participating centre. 
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="mediaSection" type="MediaSection" minOccurs="1" maxOccurs="unbounded"
            />
        </xs:sequence>
        <xs:attribute name="localId" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="MediaSection">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                Individual section from one sample eg a section of one block. 
                A section can have multiple files derived from it. 
                Attributes:
                localID : identifier from wich the individual section can be found at the participating centre eg slide
                15 in box 32 on shelf 43 
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="mediaFile" type="MediaFile" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="localId"     type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="MediaFile">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                An individual media file that is derived from a media
                section.
                Attributes:
                localID  : is an identifier from wich the individual section can be found at
                the participating centre. 
                URI     : the location from which the dcc can download this file.
                fileType : find a list at
                <a href="http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/docs/conf/mime.types?view=annotate">list</a> 
                link     : External url that points to a high resolution version of this media file
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="procedureMetadata"    type="ProcedureMetadata"    minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="parameterAssociation" type="ParameterAssociation" minOccurs="0"  maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="localId"  type="xs:string"  use="required"/>
        <xs:attribute name="URI"      type="xs:string"  use="required"/>
        <xs:attribute name="fileType" type="xs:string"  use="required"/>
        <xs:attribute name="link"     type="xs:string" use="optional"/>        
    </xs:complexType>

    <xs:complexType name="ParameterAssociation">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                to relate a particular simpleParameter or ontologyParameter result to the region of interest of a mediaFile.
                Attributes:
                parameterID : IMPReSS parameterKey for the biological structure present in the specified region. These are available from http://www.mousephenotype.org/impress.
                sequenceID  : sequenceID of the result related to this image or region if present.
                link       : External url that points to this assosiation
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="1">
            <xs:element name="dim" type="Dimension" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string"  use="required"/>
        <xs:attribute name="sequenceID"  type="xs:integer" use="optional"/>
        <xs:attribute name="link"     type="string_255" use="optional"/>        
    </xs:complexType>

    <xs:complexType name="Dimension">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                A dimension can be x, y, z, time or a set of points defining a region.
                Attributes:
                id     : is the identifier of the dimension: x,y,z,time...
                origin : where do you start measuring from. In 2D images is topleft by default but it can be any of the sides. 
                Unit   : is optional. It would be assumed to be pixel if no present.
            </xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:decimal">
                <xs:attribute name="id"     type="xs:string" use="required"/>
                <xs:attribute name="origin" type="xs:string" use="required"/>
                <xs:attribute name="unit"   type="xs:string" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>


    <xs:complexType name="SeriesMediaParameter">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                It can have one or more media files associated with it
                eg two xrays taken at different orientations. 
                Attributes:
                parameterID : IMPReSS parameterKey for the parameter.These are available from http://www.mousephenotype.org/impress.  
                For example, to submit the images for the Gross Pathology and Tissue Collection procedure you would use parameterID="IMPC_PAT_057_001".
                
            </xs:documentation> 
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="value"             type="SeriesMediaParameterValue" minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="parameterStatus"   type="xs:string"                 minOccurs="0"  maxOccurs="1"/>
            <xs:element name="procedureMetadata" type="ProcedureMetadata"         minOccurs="0"  maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="SeriesMediaParameterValue">
        <xs:annotation>
            <xs:documentation xml:lang="en"> 
                This is a single media file as part of series of  results. 
                Attributes:
                incrementValue : attribute should be unique for each occurring element. eg. the orientation of the XRay.
                URI            : the location from which the dcc can download this file. 
                fileType       : find a list   at
                <a href="http://svn.apache.org/viewvc/httpd/httpd/branches/2.2.x/docs/conf/mime.types?view=annotate">list</a>
                link           : External url that points to this assosiation
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="parameterAssociation" type="ParameterAssociation" minOccurs="0"  maxOccurs="unbounded"/>
            <xs:element name="procedureMetadata"    type="ProcedureMetadata"    minOccurs="0"  maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="incrementValue" type="xs:string" use="required"/>
        <xs:attribute name="URI"            type="string_255" use="required"/>
        <xs:attribute name="fileType"       type="xs:string" use="optional"/>
        <xs:attribute name="link"           type="string_255" use="optional"/>
    </xs:complexType>

    <xs:complexType name="ProcedureMetadata">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                A metadata parameter that has a single textual or numerical result. 
                ParameterStatus allows additional information about the parameter to be recorded, including the reason why there is no result for this parameter.
                Attributes:
                parameterID  : IMPReSS parameterKey for the parameter. These are available from http://www.mousephenotype.org/impress.
                sequenceID   : if there are multiple values for a single metadata parameter this can be submitted with different sequence ids.  
            </xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="1" maxOccurs="1">
            <xs:element name="parameterStatus" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="value"           type="string_255" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="parameterID" type="xs:string"  use="required"/>
        <xs:attribute name="sequenceID"  type="xs:integer" use="optional"/>
    </xs:complexType>
</xs:schema>
