<?xml version="1.0" encoding="UTF-8"?>
<!--
Template derived pattern
===========================================
ID: 2.16.840.1.113883.3.4424.13.10.2.6
Name: [2] Wystawca dokumentu (bazowy)
Description: BAzowy szablon struktury CDA dla wystawcy dokumentu
-->
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
         id="template-2.16.840.1.113883.3.4424.13.10.2.6-2018-06-30T000000">
   <title>[2] Wystawca dokumentu (bazowy)</title>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]
Item: (plCdaBaseLegalAuthenticator)
-->

   <rule fpi="RULC-1"
         context="*[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]"
         id="d16e6063-false-d25355e0">
      <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.6-2018-06-30T000000.html"
              test="count(hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]
Item: (plCdaBaseLegalAuthenticator)
-->

   <rule fpi="RULC-1"
         context="*[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]"
         id="d16e6095-false-d25396e0">
      <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.6-2018-06-30T000000.html"
              test="string(@typeCode) = ('LA') or not(@typeCode)">(plCdaBaseLegalAuthenticator): The value for typeCode SHALL be 'LA'. 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.6-2018-06-30T000000.html"
              test="string(@contextControlCode) = ('OP') or not(@contextControlCode)">(plCdaBaseLegalAuthenticator): The value for contextControlCode SHALL be 'OP'. Found: "<value-of select="@contextControlCode"/>"</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.6-2018-06-30T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']) &gt;= 1">(plCdaBaseLegalAuthenticator): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.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.6-2018-06-30T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.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.6-2018-06-30T000000.html"
              test="count(hl7:time) &gt;= 1">(plCdaBaseLegalAuthenticator): element hl7:time 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.6-2018-06-30T000000.html"
              test="count(hl7:time) &lt;= 1">(plCdaBaseLegalAuthenticator): 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.6-2018-06-30T000000.html"
              test="count(hl7:signatureCode[@code = doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/*/@code or @nullFlavor]) &gt;= 1">(plCdaBaseLegalAuthenticator): element hl7:signatureCode[@code = doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/*/@code or @nullFlavor] 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.6-2018-06-30T000000.html"
              test="count(hl7:signatureCode[@code = doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/*/@code or @nullFlavor]) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:signatureCode[@code = doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/*/@code 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.6-2018-06-30T000000.html"
              test="count(hl7:assignedEntity[not(@nullFlavor)]) &gt;= 1">(plCdaBaseLegalAuthenticator): element hl7:assignedEntity[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.6-2018-06-30T000000.html"
              test="count(hl7:assignedEntity[not(@nullFlavor)]) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:assignedEntity[not(@nullFlavor)] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']
Item: (plCdaBaseLegalAuthenticator)
-->

   <rule fpi="RULC-1"
         context="*[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']"
         id="d16e6101-false-d25462e0">
      <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.6-2018-06-30T000000.html"
              test="string(@root) = ('2.16.840.1.113883.3.4424.13.10.2.6')">(plCdaBaseLegalAuthenticator): The value for root SHALL be '2.16.840.1.113883.3.4424.13.10.2.6'. Found: "<value-of select="@root"/>"</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:time
Item: (plCdaBaseLegalAuthenticator)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:signatureCode[@code = doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/*/@code or @nullFlavor]
Item: (plCdaBaseLegalAuthenticator)
-->

   <rule fpi="RULC-1"
         context="*[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:signatureCode[@code = doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/*/@code or @nullFlavor]"
         id="d16e6108-false-d25484e0">
      <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.6-2018-06-30T000000.html"
              test="@nullFlavor or exists(doc('include/voc-2.16.840.1.113883.1.11.10282-DYNAMIC.xml')//valueSet[1]/conceptList/concept[@code = $theCode] or completeCodeSystem)">(plCdaBaseLegalAuthenticator): The element value SHALL be one of '2.16.840.1.113883.1.11.10282 ParticipationSignature (DYNAMIC)'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]
Item: (plCdaBaseLegalAuthenticator)
-->

   <rule fpi="RULC-1"
         context="*[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]"
         id="d16e6114-false-d25514e0">
      <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.6-2018-06-30T000000.html"
              test="string(@classCode) = ('ASSIGNED') or not(@classCode)">(plCdaBaseLegalAuthenticator): The value for classCode SHALL be 'ASSIGNED'. Found: "<value-of select="@classCode"/>"</assert>
      <report 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.6-2018-06-30T000000.html"
              test="not(hl7:assignedPerson/hl7:name) and not(hl7:id[@root=/hl7:ClinicalDocument/hl7:author/hl7:assignedAuthor/hl7:id/@root and @extension=/hl7:ClinicalDocument/hl7:author/hl7:assignedAuthor/hl7:id/@extension])">(plCdaBaseLegalAuthenticator): Jeśli wystawca dokumentu jest również jego autorem to identyfikator wystawcy musi być taki sam jak identyfikator autora. W przeciwnym wypadku należy podać dane personalne wystawcy dokumentu.</report>
      <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.6-2018-06-30T000000.html"
              test="count(hl7:id[not(@nullFlavor)]) &gt;= 1">(plCdaBaseLegalAuthenticator): element hl7:id[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.6-2018-06-30T000000.html"
              test="count(hl7:code) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:code 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.6-2018-06-30T000000.html"
              test="count(hl7:assignedPerson[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.1']]) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:assignedPerson[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.1']] 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.6-2018-06-30T000000.html"
              test="count(hl7:representedOrganization[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.2']]) &lt;= 1">(plCdaBaseLegalAuthenticator): element hl7:representedOrganization[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.2']] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:id[not(@nullFlavor)]
Item: (plCdaBaseLegalAuthenticator)
-->

   <rule fpi="RULC-1"
         context="*[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:id[not(@nullFlavor)]"
         id="d16e6118-false-d25573e0">
      <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.6-2018-06-30T000000.html"
              test="@root">(plCdaBaseLegalAuthenticator): attribute @root SHALL be present.</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.6-2018-06-30T000000.html"
              test="not(@root) or matches(@root,'^[0-2](\.(0|[1-9]\d*))*$') or matches(@root,'^[A-Fa-f\d]{8}-[A-Fa-f\d]{4}-[A-Fa-f\d]{4}-[A-Fa-f\d]{4}-[A-Fa-f\d]{12}$') or matches(@root,'^[A-Za-z][A-Za-z\d\-]*$')">(plCdaBaseLegalAuthenticator): Attribute @root SHALL be of data type 'uid'  - '<value-of select="@root"/>'</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.6-2018-06-30T000000.html"
              test="@extension">(plCdaBaseLegalAuthenticator): attribute @extension SHALL be present.</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.6-2018-06-30T000000.html"
              test="not(@extension) or string-length(@extension)&gt;0">(plCdaBaseLegalAuthenticator): Attribute @extension SHALL be of data type 'st'  - '<value-of select="@extension"/>'</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:code
Item: (plCdaBaseLegalAuthenticator)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:addr
Item: (plCdaBaseLegalAuthenticator)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:telecom
Item: (plCdaBaseLegalAuthenticator)
-->


   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:assignedPerson[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.1']]
Item: (plCdaBaseLegalAuthenticator)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.6
Context: *[hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]]/hl7:legalAuthenticator[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.6']]/hl7:assignedEntity[not(@nullFlavor)]/hl7:representedOrganization[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.2']]
Item: (plCdaBaseLegalAuthenticator)
--></pattern>
