<?xml version="1.0" encoding="UTF-8"?>
<!--
Template derived pattern
===========================================
ID: 2.16.840.1.113883.3.4424.13.10.4.15
Name: [4] Dane podmiotu związanego z fragmentem treści dokumentu
Description: Szablon CDA dla danych podmiotu związenego z fragmentem treści dokumentu
-->
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
         id="template-2.16.840.1.113883.3.4424.13.10.4.15-2018-06-30T000000">
   <title>[4] Dane podmiotu związanego z fragmentem treści dokumentu</title>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]"
         id="d16e4932-false-d21750e0">
      <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.4.15-2018-06-30T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']) &gt;= 1">(plCdaBaseBodySubject): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15'] 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.4.15-2018-06-30T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']) &lt;= 1">(plCdaBaseBodySubject): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15'] 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.4.15-2018-06-30T000000.html"
              test="count(hl7:awarenessCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10310-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]) &lt;= 1">(plCdaBaseBodySubject): element hl7:awarenessCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10310-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.4.15-2018-06-30T000000.html"
              test="count(hl7:relatedSubject[@classCode]) &gt;= 1">(plCdaBaseBodySubject): element hl7:relatedSubject[@classCode] 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.4.15-2018-06-30T000000.html"
              test="count(hl7:relatedSubject[@classCode]) &lt;= 1">(plCdaBaseBodySubject): element hl7:relatedSubject[@classCode] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']"
         id="d16e4989-false-d21784e0">
      <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.4.15-2018-06-30T000000.html"
              test="string(@root) = ('2.16.840.1.113883.3.4424.13.10.4.15')">(plCdaBaseBodySubject): The value for root SHALL be '2.16.840.1.113883.3.4424.13.10.4.15'. Found: "<value-of select="@root"/>"</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:awarenessCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10310-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:awarenessCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.10310-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]"
         id="d16e4994-false-d21798e0">
      <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.4.15-2018-06-30T000000.html"
              test="@nullFlavor or exists(doc('include/voc-2.16.840.1.113883.1.11.10310-DYNAMIC.xml')//valueSet[1][conceptList/concept[@code = $theCode][@codeSystem = $theCodeSystem]])">(plCdaBaseBodySubject): The element value SHALL be one of '2.16.840.1.113883.1.11.10310 TargetAwareness (DYNAMIC)'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]"
         id="d16e4999-false-d21815e0">
      <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.4.15-2018-06-30T000000.html"
              test="@classCode">(plCdaBaseBodySubject): attribute @classCode SHALL be present.</assert>
      <let name="theAttValue"
           value="distinct-values(tokenize(normalize-space(@classCode),'\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.4.15-2018-06-30T000000.html"
              test="not(@classCode) or empty($theAttValue[not(. = (doc('include/voc-2.16.840.1.113883.1.11.19368-DYNAMIC.xml')/*/valueSet/conceptList/concept/@code))])">(plCdaBaseBodySubject): The value for classCode SHALL be selected from value set '2.16.840.1.113883.1.11.19368' x_DocumentSubject (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.4.15-2018-06-30T000000.html"
              test="count(hl7:code[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.19563-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]) &lt;= 1">(plCdaBaseBodySubject): element hl7:code[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.19563-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.4.15-2018-06-30T000000.html"
              test="count(hl7:subject) &lt;= 1">(plCdaBaseBodySubject): element hl7:subject appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:code[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.19563-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:code[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.19563-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]"
         id="d16e5006-false-d21864e0">
      <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.4.15-2018-06-30T000000.html"
              test="@nullFlavor or exists(doc('include/voc-2.16.840.1.113883.1.11.19563-DYNAMIC.xml')//valueSet[1][conceptList/concept[@code = $theCode][@codeSystem = $theCodeSystem]])">(plCdaBaseBodySubject): The element value SHALL be one of '2.16.840.1.113883.1.11.19563 PersonalRelationshipRoleType (DYNAMIC)'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:addr
Item: (plCdaBaseBodySubject)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:telecom
Item: (plCdaBaseBodySubject)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject"
         id="d16e5015-false-d21897e0">
      <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.4.15-2018-06-30T000000.html"
              test="string(@classCode) = ('PSN') or not(@classCode)">(plCdaBaseBodySubject): The value for classCode SHALL be 'PSN'. 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.4.15-2018-06-30T000000.html"
              test="string(@determinerCode) = ('INSTANCE') or not(@determinerCode)">(plCdaBaseBodySubject): The value for determinerCode SHALL be 'INSTANCE'. Found: "<value-of select="@determinerCode"/>"</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.4.15-2018-06-30T000000.html"
              test="count(hl7:administrativeGenderCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.1-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]) &lt;= 1">(plCdaBaseBodySubject): element hl7:administrativeGenderCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.1-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.4.15-2018-06-30T000000.html"
              test="count(hl7:birthTime) &lt;= 1">(plCdaBaseBodySubject): element hl7:birthTime appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject/hl7:name
Item: (plCdaBaseBodySubject)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject/hl7:administrativeGenderCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.1-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject/hl7:administrativeGenderCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.1-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]"
         id="d16e5023-false-d21943e0">
      <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.4.15-2018-06-30T000000.html"
              test="@nullFlavor or exists(doc('include/voc-2.16.840.1.113883.1.11.1-DYNAMIC.xml')//valueSet[1][conceptList/concept[@code = $theCode][@codeSystem = $theCodeSystem]])">(plCdaBaseBodySubject): The element value SHALL be one of '2.16.840.1.113883.1.11.1 AdministrativeGender (DYNAMIC)'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.15
Context: *[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject/hl7:birthTime
Item: (plCdaBaseBodySubject)
-->

   <rule fpi="RULC-1"
         context="*[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.4.15']]/hl7:relatedSubject[@classCode]/hl7:subject/hl7:birthTime"
         id="d16e5028-false-d21960e0">
      <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.4.15-2018-06-30T000000.html"
              test="concat(substring(@value,1,4),'-',substring(@value,5,2),'-',substring(@value,7,2)) castable as xs:date">(plCdaBaseBodySubject): Pierwsze 8 cyfr daty urodzenia powinno być w formacie YYYYMMDD.</assert>
   </rule>
</pattern>
