<?xml version="1.0" encoding="UTF-8"?>
<!--
Template derived pattern
===========================================
ID: 2.16.840.1.113883.3.4424.13.10.2.51
Name: [2] Dane wykonanej usługi (bazowy)
Description: Bazowy szablon CDA dla danych wykonanej usługi
-->
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
         id="template-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000">
   <title>[2] Dane wykonanej usługi (bazowy)</title>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]
Item: (plCdaBaseDocumentationOf)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]"
         id="d16e5956-false-d24859e0">
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="string(@typeCode) = ('DOC')">(plCdaBaseDocumentationOf): The value for typeCode SHALL be 'DOC'. Found: "<value-of select="@typeCode"/>"</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']) &gt;= 1">(plCdaBaseDocumentationOf): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51'] is mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51'] appears too often [max 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]) &gt;= 1">(plCdaBaseDocumentationOf): element hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']] is mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']"
         id="d16e5960-false-d24912e0">
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="string(@root) = ('2.16.840.1.113883.3.4424.13.10.2.51')">(plCdaBaseDocumentationOf): The value for root SHALL be '2.16.840.1.113883.3.4424.13.10.2.51'. Found: "<value-of select="@root"/>"</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]"
         id="d16e5965-false-d24946e0">
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="string(@classCode) = ('ACT')">(plCdaBaseDocumentationOf): The value for classCode SHALL be 'ACT'. Found: "<value-of select="@classCode"/>"</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="string(@moodCode) = ('EVN')">(plCdaBaseDocumentationOf): The value for moodCode SHALL be 'EVN'. Found: "<value-of select="@moodCode"/>"</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']) &gt;= 1">(plCdaBaseDocumentationOf): element hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6'] is mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6'] appears too often [max 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:effectiveTime[not(@nullFlavor)]) &gt;= 1">(plCdaBaseDocumentationOf): element hl7:effectiveTime[not(@nullFlavor)] is mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:effectiveTime[not(@nullFlavor)]) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:effectiveTime[not(@nullFlavor)] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:id
Item: (plCdaBaseDocumentationOf)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']"
         id="d16e5973-false-d25018e0">
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="@nullFlavor or (@codeSystem='2.16.840.1.113883.3.4424.11.2.6')">(plCdaBaseDocumentationOf): The element value SHALL be one of 'codeSystem '2.16.840.1.113883.3.4424.11.2.6''.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:effectiveTime[not(@nullFlavor)]
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:effectiveTime[not(@nullFlavor)]"
         id="d16e5978-false-d25031e0">
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="concat(substring(@value,1,4),'-',substring(@value,5,2),'-',substring(@value,7,2)) castable as xs:date">(plCdaBaseDocumentationOf): Pierwsze 8 cyfr daty powinno być w formacie YYYYMMDD.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:performer[hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]]
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:performer[hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]]"
         id="d16e5985-false-d25062e0">
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="@typeCode">(plCdaBaseDocumentationOf): attribute @typeCode SHALL be present.</assert>
      <let name="theAttValue"
           value="distinct-values(tokenize(normalize-space(@typeCode),'\s'))"/>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="not(@typeCode) or empty($theAttValue[not(. = (doc('include/voc-2.16.840.1.113883.1.11.19601-DYNAMIC.xml')/*/valueSet/conceptList/concept/@code))])">(plCdaBaseDocumentationOf): The value for typeCode SHALL be selected from value set '2.16.840.1.113883.1.11.19601' x_ServiceEventPerformer (DYNAMIC).</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:functionCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10267-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:functionCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10267-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor] appears too often [max 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:time) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:time appears too often [max 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]) &gt;= 1">(plCdaBaseDocumentationOf): element hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']] is required [min 1x].</assert>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="count(hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]) &lt;= 1">(plCdaBaseDocumentationOf): element hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:performer[hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]]/hl7:functionCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10267-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]
Item: (plCdaBaseDocumentationOf)
-->

   <rule fpi="RULC-1"
         context="*[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:performer[hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]]/hl7:functionCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10267-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]"
         id="d16e5992-false-d25134e0">
      <let name="theCode" value="@code"/>
      <let name="theCodeSystem" value="@codeSystem"/>
      <assert role="error"
              see="https://www.csioz.gov.pl/HL7POL/pl-cda-html-pl-PL/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.2.51-2018-06-30T000000.html"
              test="@nullFlavor or exists(doc('include/voc-2.16.840.1.113883.1.11.10267-DYNAMIC.xml')//valueSet[1][conceptList/concept[@code = $theCode][@codeSystem = $theCodeSystem]])">(plCdaBaseDocumentationOf): The element value SHALL be one of '2.16.840.1.113883.1.11.10267 ParticipationFunction (DYNAMIC)'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:performer[hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]]/hl7:time
Item: (plCdaBaseDocumentationOf)
-->


   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.51
Context: *[hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]]/hl7:documentationOf[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.51']]/hl7:serviceEvent[hl7:code[@codeSystem = '2.16.840.1.113883.3.4424.11.2.6']]/hl7:performer[hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]]/hl7:assignedEntity[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.49']]
Item: (plCdaBaseDocumentationOf)
--></pattern>
