<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:hl7-org:elm:r1" xmlns:sch="http://purl.oclc.org/dsdl/schematron" targetNamespace="urn:hl7-org:elm:r1" elementFormDefault="qualified">
	<xs:annotation>
		<xs:documentation> This file defines the root library type and element. </xs:documentation>
	</xs:annotation>
	<xs:include schemaLocation="clinicalexpression.xsd"/>
	<xs:complexType name="VersionedIdentifier">
		<xs:annotation>
			<xs:documentation>VersionedIdentifier is composed of three parts: (1) an optional system, or
        namespace, which provides a globally unique, stable scope for the identifier,
        (2) an identifier which identifies the set of all versions of a given resource, and
        (3) the actual version of the instance of interest in this set. The VersionedIdentifier
        therefore points to an individual 'versioned' instance of a resource such as the third
        version of a library.
      </xs:documentation>
		</xs:annotation>
		<xs:attribute name="id" type="xs:string"/>
		<xs:attribute name="system" type="xs:string" use="optional"/>
		<xs:attribute name="version" type="xs:string" use="optional"/>
	</xs:complexType>
	<xs:complexType name="UsingDef">
		<xs:annotation>
			<xs:documentation>Defines a data model that is available within the artifact.
      </xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="Element">
				<xs:attribute name="localIdentifier" type="xs:string" use="required"/>
				<xs:attribute name="uri" type="xs:anyURI" use="required">
					<xs:annotation>
						<xs:documentation>The URI of the model that is being referenced. This URL must also be
              defined as a namespace in the root element of the document to allow for elements of
              the model to be referenced within the artifact.</xs:documentation>
					</xs:annotation>
				</xs:attribute>
				<xs:attribute name="version" type="xs:string" use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="IncludeDef">
		<xs:annotation>
			<xs:documentation>Includes a library for use within the artifact.</xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="Element">
				<xs:attribute name="localIdentifier" type="xs:string" use="required">
					<xs:annotation>
						<xs:documentation>A unique name within this artifact for the library reference. This
              name is used within this artifact to reference components of this
              library.</xs:documentation>
					</xs:annotation>
				</xs:attribute>
				<xs:attribute name="mediaType" type="xs:anyURI" use="optional" default="application/elm+xml">
					<xs:annotation>
						<xs:documentation>Defines the type of the library. If this attribute is omitted, the
              library is assumed to be an ELM library artifact.</xs:documentation>
					</xs:annotation>
				</xs:attribute>
				<xs:attribute name="path" type="xs:anyURI" use="required">
					<xs:annotation>
						<xs:documentation>Defines the path to the library.</xs:documentation>
					</xs:annotation>
				</xs:attribute>
				<xs:attribute name="version" type="xs:string" use="optional">
					<xs:annotation>
						<xs:documentation>Optionally defines the required version number of the referenced
              library.</xs:documentation>
					</xs:annotation>
				</xs:attribute>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="ContextDef">
		<xs:annotation>
			<xs:documentation>The ContextDef type defines a context definition statement. Note that this is a placeholder for the context statement within the library. The effect of the context definition is applied by the translator to the definitions that follow.</xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="Element">
				<xs:attribute name="name" type="xs:string"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:element name="library" type="Library">
		<xs:annotation>
			<xs:documentation>library represents a serialized library of CQL-Epression Logic
        Model.</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:complexType name="Library">
		<xs:annotation>
			<xs:documentation>A Library is an instance of a CQL-ELM library. </xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="Element">
				<xs:sequence>
					<xs:element name="identifier" type="VersionedIdentifier">
						<xs:annotation>
							<xs:documentation>The identifier element defines a unique identifier for this library,
								and optionally, a system (or namespace) and version. </xs:documentation>
						</xs:annotation>
					</xs:element>
					<xs:element name="schemaIdentifier" type="VersionedIdentifier">
						<xs:annotation>
							<xs:documentation>This is the identifier of the XML schema (and its version) which
                governs the structure of this Library.</xs:documentation>
						</xs:annotation>
					</xs:element>
					<xs:element name="usings" minOccurs="0">
						<xs:annotation>
							<xs:documentation>Set of data models referenced in the Expression objects in this
                knowledge artifact. </xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="UsingDef" maxOccurs="unbounded">
									<xs:annotation>
										<xs:documentation>A reference to a data model that is used in the artifact,
                      e..g., the Virtual Medical Record. </xs:documentation>
									</xs:annotation>
								</xs:element>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="includes" minOccurs="0">
						<xs:annotation>
							<xs:documentation>Set of libraries referenced by this artifact. Components of
                referenced libraries may be used within this artifact.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="IncludeDef" maxOccurs="unbounded">
									<xs:annotation>
										<xs:documentation>A reference to a library whose components can be used within
                      the artifact. </xs:documentation>
									</xs:annotation>
								</xs:element>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="parameters" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The parameters defined within this library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="ParameterDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="codeSystems" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The code systems defined within this library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="CodeSystemDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="valueSets" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The value sets defined within this library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="ValueSetDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="codes" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The codes defined within this library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="CodeDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="concepts" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The concepts defined within this library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="ConceptDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="contexts" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The contexts defined within this library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="ContextDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
					<xs:element name="statements" minOccurs="0" maxOccurs="1">
						<xs:annotation>
							<xs:documentation>The statements section contains the expression and function
                definitions for the library.</xs:documentation>
						</xs:annotation>
						<xs:complexType>
							<xs:sequence>
								<xs:element name="def" type="ExpressionDef" minOccurs="0" maxOccurs="unbounded"/>
							</xs:sequence>
						</xs:complexType>
					</xs:element>
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>
