<!--  CCD v1.0 Templates Root: 2.16.840.1.113883.10.20.1 -->

<!-- errors -->

<pattern id='p-2.16.840.1.113883.10.20.1-errors' see='#p-2.16.840.1.113883.10.20.1-errors'>
	<title>CCD v1.0 Templates Root - errors validation phase</title>
	<rule context='*[cda:templateId/@root="2.16.840.1.113883.10.20.1"]'>
	<assert test="self::cda:ClinicalDocument">The root of a CCD document must be ClinicalDocument in the HL7 namespace</assert>
	<assert test="cda:code[@code='34133-9'][@codeSystem='2.16.840.1.113883.6.1']">The ClinicalDocument/code element SHALL be present, and SHALL be valued with LOINC code 34133-9 (SUMMARIZATION OF EPISODE NOTE).</assert>
	<assert test="cda:documentationOf/cda:serviceEvent">A CCD SHALL contain exactly one ClinicalDocument / documentationOf / serviceEvent.</assert>
	<assert test="cda:documentationOf/cda:serviceEvent/@classCode='PCPR'">The value for "ClinicalDocument / documentationOf / serviceEvent / classCode" SHALL be "PCPR" "Care provision" 2.16.840.1.113883.5.6 ActClass STATIC.</assert>
	<assert test="cda:documentationOf/cda:serviceEvent/cda:effectiveTime/cda:low">ClinicalDocument / documentationOf / serviceEvent SHALL contain exactly one serviceEvent / effectiveTime / low and exactly one serviveEvent / effectiveTime / high.</assert>
	<assert test="cda:documentationOf/cda:serviceEvent/cda:effectiveTime/cda:high">ClinicalDocument / documentationOf / serviceEvent SHALL contain exactly one serviceEvent / effectiveTime / low and exactly one serviveEvent / effectiveTime / high.</assert>
	<assert test="count(cda:languageCode)=1">CCD SHALL contain exactly one ClinicalDocument / languageCode.</assert>
	<assert test="count(cda:templateId)&gt;=1">CCD SHALL contain one or more ClinicalDocument / templateId.</assert>
	<assert test="cda:templateId[@root='2.16.840.1.113883.10.20.1' and not(@extension)]">At least one ClinicalDocument / templateId SHALL value ClinicalDocument / templateId / @root with "2.16.840.1.113883.10.20.1", and SHALL NOT contain ClinicalDocument / templateId / @extension.</assert>
	<assert test="string-length(cda:effectiveTime/@value) &gt; 18">ClinicalDocument / effectiveTime SHALL be expressed with precision to include seconds.</assert>
	<assert test='contains(translate(cda:effectiveTime/@value,"+-","ZZ"),"Z")'>ClinicalDocument / effectiveTime SHALL include an explicit time zone offset.</assert>
	<assert test="count(cda:recordTarget)&lt;=2">CCD shall contain one to two ClinicalDocument / recordTarget.</assert>
	<assert test="cda:author/cda:assignedAuthor/cda:assignedPerson | cda:author/cda:assignedAuthor/cda:representedOrganization">CCD SHALL contain one or more ClinicalDocument / author / assignedAuthor / assignedPerson and/or ClinicalDocument / author / assignedAuthor / representedOrganization.</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.13"]) &lt;= 1'>CCD MAY contain exactly one and SHALL NOT contain more than one Purpose section (templateId 2.16.840.1.113883.10.20.1.13).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.9"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Payers section (templateId 2.16.840.1.113883.10.20.1.9).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.1"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Advance directives section (templateId 2.16.840.1.113883.10.20.1.1).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.11"]) &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Problem section (templateId 2.16.840.1.113883.10.20.1.11). </assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.7"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Medical Equipment section (templateId 2.16.840.1.113883.10.20.1.7).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.6"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Immunizations section (templateId 2.16.840.1.113883.10.20.1.6).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.9"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Payers section (templateId 2.16.840.1.113883.10.20.1.9).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.1"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Advance directives section (templateId 2.16.840.1.113883.10.20.1.1).</assert>
	<assert test='count(.//cda:templateId[@root="2.16.840.1.113883.10.20.1.5"])  &lt;= 1'>CCD SHOULD contain exactly one and SHALL NOT contain more than one Functional status section (templateId 2.16.840.1.113883.10.20.1.5).</assert>
	<assert test="count(.//cda:templateId[@root='2.16.840.1.113883.10.20.1.14']) &lt;= 1">CCD SHOULD contain exactly one and SHALL NOT contain more than one Results section (templateId 2.16.840.1.113883.10.20.1.14).</assert>
	<assert test="count(.//cda:templateId[@root='2.16.840.1.113883.10.20.1.12']) &lt;=1">CCD SHOULD contain exactly one and SHALL NOT contain more than one Procedures section (templateId 2.16.840.1.113883.10.20.1.12). </assert>
	<assert test="count(.//cda:templateId[@root='2.16.840.1.113883.10.20.1.3'])  &lt;= 1">CCD SHOULD contain exactly one and SHALL NOT contain more than one Encounters section (templateId 2.16.840.1.113883.10.20.1.3). </assert>
	</rule>
</pattern>

<!-- warning -->

<pattern id='p-2.16.840.1.113883.10.20.1-warning' see='#p-2.16.840.1.113883.10.20.1-warning'>
	<title>CCD v1.0 Templates Root - warning validation phase</title>
	<rule context='*[cda:templateId/@root="2.16.840.1.113883.10.20.1"]'>
	<report test='.'></report>
	</rule>
</pattern>

<!-- manual -->

<pattern id='p-2.16.840.1.113883.10.20.1-manual' see='#p-2.16.840.1.113883.10.20.1-manual'>
	<title>CCD v1.0 Templates Root - manual validation phase</title>
	<rule context='*[cda:templateId/@root="2.16.840.1.113883.10.20.1"]'>
	<report test='.'></report>
	</rule>
</pattern>

