<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:hl7-org:v3/mif" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron" targetNamespace="urn:hl7-org:v3/mif" elementFormDefault="qualified">
	<xs:annotation>
		<xs:documentation>
********************************************************************************
Author: Initial development by Lloyd McKenzie, Dec. 2002
(c) 2002, 2003 by HL7 Inc.

Purpose:
	Defines the various simple type patterns used by mif elements.
	This file may be overridden to 'bypass' some of the enforced rules.
********************************************************************************
		</xs:documentation>
		<xs:documentation>
			UML: **ALL** types defined in this package are handled as datatypes. 
			There is a mapping from some schema datatypes directly to existing UML datatypes:
				xs:boolean -> Boolean
				xs:integer -> Integer
				xs:string -> String
 			Most of the types defined here will be new datatypes (some may be restrictions of the above).
 			Where there is a mapping to an existing UML datatype, this will be documented.
 		</xs:documentation>
		<xs:appinfo>
			<sch:ns prefix="mif" uri="urn:hl7-org:v3/mif"/>
		</xs:appinfo>
	</xs:annotation>
	<xs:simpleType name="DateOrTimestamp">
		<xs:annotation>
			<xs:documentation>Used when we might have just a date, or a full-blown timestamp.  Format is YYYY-MM-DD['T'HH:MM:SS[('-'|'+')ZZ:ZZ]]</xs:documentation>
		</xs:annotation>
		<xs:union memberTypes="xs:dateTime xs:date"/>
	</xs:simpleType>
	<xs:simpleType name="Years">
		<xs:annotation>
			<xs:documentation>A list of years</xs:documentation>
		</xs:annotation>
		<xs:list itemType="Year"/>
	</xs:simpleType>
	<xs:simpleType name="Year">
		<xs:annotation>
			<xs:documentation>A year (restricted to 20th and 21st century)</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:integer">
			<xs:pattern value="(19|20)\d{2}"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="SingleNonNegativeInteger">
		<xs:annotation>
			<xs:documentation>An integer that is greater than or equal to zero, with a maximum length of 1 character</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:nonNegativeInteger">
			<xs:maxExclusive value="10"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="SmallNonNegativeInteger">
		<xs:annotation>
			<xs:documentation>An integer that is greater than or equal to zero, with a maximum length of 6 characters</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:nonNegativeInteger">
			<xs:maxInclusive value="1000000"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="SmallPositiveInteger">
		<xs:annotation>
			<xs:documentation>An integer that is greater than or equal to 1, with a maximum length of 6 characters</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:positiveInteger">
			<xs:maxInclusive value="1000000"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="GraphicMeasurement">
		<xs:annotation>
			<xs:documentation>A real number that is greater than or equal to 0. Used when you want a positive number that can be fractional.</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:decimal">
			<xs:maxInclusive value="1000000"/>
			<xs:fractionDigits value="5"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="PositiveDecimal">
		<xs:annotation>
			<xs:documentation>A real number that is restricted to a maximum of 10 characters, and may have no more than 3 decimal places.</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:decimal">
			<xs:maxInclusive value="1000000"/>
			<xs:minInclusive value="1"/>
			<xs:fractionDigits value="5"/>
		</xs:restriction>
	</xs:simpleType>
	<!-- Simple types used in defining various attributes -->
	<xs:simpleType name="Uuid">
		<xs:annotation>
			<xs:documentation>Universal Unique Identifier (aka GUID).  Used for identifiers</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:token">
			<xs:maxLength value="38"/>
			<xs:pattern value="\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}"/>
			<xs:pattern value="[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="HashCode">
		<xs:annotation>
			<xs:documentation>Base64 representation of a 160 bit RSA-1 hashcode</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:pattern value="([A-Za-z0-9/+]){27}="/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Oid">
		<xs:annotation>
			<xs:documentation>ISO Object Identifier.  Used for identifiers</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:token">
			<xs:maxLength value="255"/>
			<xs:pattern value="[1-9][0-9]*(\.[1-9][0-9]*)*"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Url">
		<xs:annotation>
			<xs:documentation>Used for hypertext references.  (Must be prefixed by "http://")</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:anyURI">
			<xs:maxLength value="255"/>
			<xs:pattern value="http://.+"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="EMail">
		<xs:annotation>
			<xs:documentation>Used for email references.  (Must be prefixed by "mailto://")</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:anyURI">
			<xs:maxLength value="255"/>
			<xs:pattern value="mailto://.+"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="LocalFileReference">
		<xs:annotation>
			<xs:documentation>Used for file references.  (Must be prefixed by "file://")</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:anyURI">
			<xs:maxLength value="255"/>
			<xs:pattern value="(file://)?([A-Za-z0-9_\-\.]+/)*[A-Za-z0-9_\-\.]+"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="NonEmptyString">
		<xs:annotation>
			<xs:documentation>Used as the base for most string datatypes.  (Ensures that empty strings are not allowed.).  Should never be implemented directly because it has no length limits.</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:token">
			<xs:minLength value="1"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="LowerCamelCase">
		<xs:annotation>
			<xs:documentation>Type for attribute and association type names.  Should never be implemented directly because it has no length limits.</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:pattern value="[a-z][a-z0-9\.]*([A-Z][a-z0-9\.]*)*"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="UpperCamelCase">
		<xs:annotation>
			<xs:documentation>Type for class and type names</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:pattern value="([A-Z][a-z0-9_\.\-]*)+"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="PrefixedUpperCamelCase">
		<xs:annotation>
			<xs:documentation>Used for CMET type names.  (Basically class names with a prefix separated by an underscore)</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:maxLength value="255"/>
			<xs:pattern value="[A-Z]+_([A-Z][a-z0-9_\-]*)+"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="BasicFormalName">
		<xs:annotation>
			<xs:documentation>Used for formal names and short descriptions</xs:documentation>
		</xs:annotation>
		<xs:restriction base="NonEmptyString">
			<xs:maxLength value="120"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="FormalProperName">
		<xs:annotation>
			<xs:documentation>Used for class and type names</xs:documentation>
		</xs:annotation>
		<xs:restriction base="NonEmptyString">
			<xs:maxLength value="700"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="AllClassName">
		<xs:annotation>
			<xs:documentation>Choice of a class name or a CMET name</xs:documentation>
		</xs:annotation>
		<xs:union memberTypes="FormalProperName PrefixedUpperCamelCase"/>
	</xs:simpleType>
	<xs:simpleType name="FormalPropertyName">
		<xs:annotation>
			<xs:documentation>Used for attribute, association and property names</xs:documentation>
		</xs:annotation>
		<xs:restriction base="NonEmptyString">
			<xs:maxLength value="700"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="EnumerationValue">
		<xs:annotation>
			<xs:documentation>Used as the base class for all 'codes'</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:maxLength value="50"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ShortDescriptiveName">
		<xs:annotation>
			<xs:documentation>Used when descriptions are intended to be very short</xs:documentation>
		</xs:annotation>
		<xs:restriction base="NonEmptyString">
			<xs:maxLength value="80"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="LongDescriptiveName">
		<xs:annotation>
			<xs:documentation>Used when descriptions can be potentially quite long</xs:documentation>
		</xs:annotation>
		<xs:restriction base="NonEmptyString">
			<xs:maxLength value="255"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="DomainName">
		<xs:annotation>
			<xs:documentation>Used for vocabulary domains that may include 'x-domains'</xs:documentation>
		</xs:annotation>
		<xs:union memberTypes="BasicFormalName XDomainName"/>
	</xs:simpleType>
	<xs:simpleType name="XDomainName">
		<xs:annotation>
			<xs:documentation>Used for x-domains</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:maxLength value="50"/>
			<xs:pattern value="(x_)?([A-Z][a-z0-9_]*)+"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="DatatypeName">
		<xs:annotation>
			<xs:documentation>Used for datatype names</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:maxLength value="40"/>
			<xs:pattern value="[A-Z.]+|([A-Z.]+.)?diff"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Version">
		<xs:annotation>
			<xs:documentation>Used for version numbers</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:minLength value="1"/>
			<xs:maxLength value="16"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="BasicId">
		<xs:annotation>
			<xs:documentation>Used for generic identifiers</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:NMTOKEN">
			<xs:minLength value="1"/>
			<xs:maxLength value="40"/>
		</xs:restriction>
	</xs:simpleType>
	<!--	<xs:simpleType name="DatatypeId">
		<xs:restriction base="xs:token">
			<xs:maxLength value="20"/>
			<xs:pattern value="(dt-[A-Z]+(&lt;[A-Z]+(,[A-Z])*&gt;)?)"/>
		</xs:restriction>
	</xs:simpleType>-->
	<xs:attributeGroup name="MultiplicityRange">
		<xs:annotation>
			<xs:appinfo>
				<sch:pattern name="Validate MultiplicityRange type">
					<sch:rule abstract="true" id="MultiplicityRange">
						<sch:report test="@maximumMultiplicity!='*' and number(@minimumMultiplicity)&gt;number(@maximumMultiplicity)">
							ERROR: MinimumMultiplicity must be less than or equal to maximumMultiplicity.</sch:report>
						<sch:report test="@mandatory='true' and @conformance!='R'">
							ERROR: Conformance must be 'R' when 'mandatory' is true.</sch:report>
						<sch:report test="@mandatory='true' and @minimumMultiplicity=0">
							ERROR: MinimumMultiplicity must be at least 1 when 'mandatory' is true.</sch:report>
						<sch:report test="@updateModeDefault and @allowedUpdateModes and not(contains(concat(';', translate(@allowedUpdateModes, ' ', ';'), ';'), concat(';', @updateModeDefault, ';')))">
							ERROR: DefaultUpdateMode must be part of allowedUpdateModes.</sch:report>
						<sch:report test="@updateModeDefault and contains('ESA;ESD;ESC;ESAC', @updateModeDefault) and @maximumMultiplicity=1">
							ERROR: Default update mode may not be one of the Edit Set values when maximumMultiplicity is 1.</sch:report>
						<sch:report test="@allowedUpdateModes and contains(concat(' ', @allowedUpdateModes), ' E') and @maximumMultiplicity=1">
							ERROR: Update mode set may not be one of the Edit Set values when maximumMultiplicity is 1.</sch:report>
					</sch:rule>
				</sch:pattern>
			</xs:appinfo>
			<xs:documentation>Used to define multiplicty</xs:documentation>
			<xs:documentation>UML: Corresponds to UML type MultiplicityRange, with exception that upper boundary cannot be 0</xs:documentation>
		</xs:annotation>
		<xs:attribute name="minimumMultiplicity" type="SmallNonNegativeInteger" use="required">
			<xs:annotation>
				<xs:documentation>Identifies the minimum number of repetitions of this element that may occur within the containing element.</xs:documentation>
				<xs:documentation>UML: multiplicity (lower-bound)</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="maximumMultiplicity" type="UnlimitedInteger" use="required">
			<xs:annotation>
				<xs:documentation>Identifies the maximum number of repetitions of this element that may occur within the containing element.</xs:documentation>
				<xs:documentation>UML: multiplicity (upper-bound)</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:simpleType name="UnlimitedInteger">
		<xs:annotation>
			<xs:documentation>UML: Corresponds to UnlimitedInteger.  (Only distinction is that this type does not allow 0 while UML does)</xs:documentation>
		</xs:annotation>
		<xs:union memberTypes="SmallPositiveInteger UnlimitedMultiplicity"/>
	</xs:simpleType>
	<xs:simpleType name="UnlimitedMultiplicity">
		<xs:annotation>
			<xs:documentation>Used as a 'part' of the UnlimitedInteger type</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:enumeration value="*">
				<xs:annotation>
					<xs:documentation>Unlimited</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
</xs:schema>
