<?xml version="1.0" encoding="utf-8" ?> 
  <!-- openEHR Release 1.0.1 Template XML schema -->
  <!-- Authored by Ocean Informatics 2007.09.27  -->
  <!-- Updated by Ocean Informatics 2010.05.03  -->
  <xs:schema xmlns="http://schemas.openehr.org/v2" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://schemas.openehr.org/v2" elementFormDefault="qualified" version="1.4"
    id="Template.xsd">
    <xs:include schemaLocation="OpenehrProfile.xsd"/>
    
    <xs:element name="template" type="OPERATIONAL_TEMPLATE"/>
    
    <xs:complexType name="OPERATIONAL_TEMPLATE">
    	<xs:sequence>
    		<xs:annotation id="annotations_added_20100503">
    			<xs:documentation>Element 'annotations' added 3 May 2010 to provide a location for
    			annotations on any template node. The location of the annotations is intended to be 
    			forwardly compatible with the upcoming Template specification (and Template Object Model)
    			which adds an annotations attribute to the AUTHORED_RESOURCE class (from which
    			the operational template as represented in this schema will inherit).</xs:documentation>
    		</xs:annotation>
    		
    		<xs:element name="language" type="CODE_PHRASE"/>
    		<xs:element name="is_controlled" type="xs:boolean" minOccurs="0"/>
    		<xs:element name="description" type="RESOURCE_DESCRIPTION" minOccurs="0"/>
    		<xs:element name="revision_history" type="REVISION_HISTORY" minOccurs="0"/>

    		<xs:element name="uid" type="HIER_OBJECT_ID" minOccurs="0"/>
    		<xs:element name="template_id" type="TEMPLATE_ID"/>
    		<!--<xs:element name="adl_version" type="xs:string" minOccurs="0"/>-->
    		<xs:element name="concept" type="xs:string"/>
    		<xs:element name="definition" type="C_ARCHETYPE_ROOT"/>
        	<xs:element name="ontology" type="FLAT_ARCHETYPE_ONTOLOGY" minOccurs="0" />
    		<xs:element name="component_ontologies" type="FLAT_ARCHETYPE_ONTOLOGY" minOccurs="0" maxOccurs="unbounded"/>

    		<xs:element name="annotations" type="ANNOTATION" minOccurs="0" maxOccurs="unbounded"/>

    		<xs:element name="constraints" type="T_CONSTRAINT" minOccurs="0"/>
    		<xs:element name="view" type="T_VIEW" minOccurs="0"/>
    	</xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="C_ARCHETYPE_ROOT">
      <xs:complexContent>
        <xs:extension base="C_COMPLEX_OBJECT">
          <xs:sequence>
            <xs:element name="archetype_id" type="ARCHETYPE_ID"/>
            <xs:element name="template_id" type="TEMPLATE_ID" minOccurs="0"/>
            <xs:element name="term_definitions" type="ARCHETYPE_TERM" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="term_bindings" type="TermBindingSet" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="FLAT_ARCHETYPE_ONTOLOGY">
      <xs:complexContent>
        <xs:extension base="ARCHETYPE_ONTOLOGY">
          <xs:attribute name="archetype_id" type="xs:string" use="required"/>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
   
    <xs:complexType name="ANNOTATION">
      <xs:sequence>
        <xs:element name="items" type="StringDictionaryItem" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="path" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="T_VIEW">
      <xs:sequence>
        <xs:element name="constraints"  minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="items" maxOccurs="unbounded" >
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="value" type="xs:anySimpleType"/>
                  </xs:sequence>
                  <xs:attribute name="id" type="xs:string" use="required"/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="path" type="xs:string" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>

	  <xs:complexType  name="T_CONSTRAINT">
		  <xs:sequence>
			  <xs:element name="attributes" type="T_ATTRIBUTE" minOccurs="0" maxOccurs="unbounded"/>
		  </xs:sequence>
	  </xs:complexType>

	  <xs:complexType  name="T_ATTRIBUTE">
				  <xs:sequence>
					<xs:element name="rm_attribute_name" type="xs:string"/>
					<xs:element name="children" minOccurs="0" maxOccurs="unbounded" type="T_COMPLEX_OBJECT"/>
					<!-- parent object path -->
					<xs:element name="differential_path" type="xs:string"/>
				  </xs:sequence>
	  </xs:complexType>

	  <xs:complexType  name="T_COMPLEX_OBJECT">
		  <xs:complexContent>
			  <xs:extension base="C_COMPLEX_OBJECT">
				  <xs:sequence>
					  <xs:element name="default_value" minOccurs="0" type="DATA_VALUE" />
				  </xs:sequence>
			  </xs:extension>
		  </xs:complexContent>
	  </xs:complexType>

	  <xs:complexType name="C_CODE_REFERENCE">
      <xs:complexContent>
        <xs:extension base="C_CODE_PHRASE">
          <xs:sequence>
            <xs:element name="referenceSetUri" type="xs:anyURI"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:schema>
