<?xml version="1.0" encoding="UTF-8"?>
<!--
Template derived pattern
===========================================
ID: 2.16.840.1.113883.3.4424.13.10.2.7
Name: [2] Dokument powiązany (bazowy)
Description: Bazowy szablon struktury CDA dla dokumentu powiązanego.
-->
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
         id="template-2.16.840.1.113883.3.4424.13.10.2.7-2020-06-08T000000">
   <title>[2] Dokument powiązany (bazowy)</title>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.7
Context: *[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]
Item: (plCdaBaseRelatedDocument)
-->

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

   <rule fpi="RULC-1"
         context="*[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]"
         id="d16e6262-false-d25935e0">
      <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.7-2020-06-08T000000.html"
              test="@typeCode">(plCdaBaseRelatedDocument): 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.7-2020-06-08T000000.html"
              test="not(@typeCode) or empty($theAttValue[not(. = (doc('include/voc-2.16.840.1.113883.1.11.11610-DYNAMIC.xml')/*/valueSet/conceptList/concept/@code))])">(plCdaBaseRelatedDocument): The value for typeCode SHALL be selected from value set '2.16.840.1.113883.1.11.11610' x_ActRelationshipDocument (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.7-2020-06-08T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']) &gt;= 1">(plCdaBaseRelatedDocument): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7'] 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.7-2020-06-08T000000.html"
              test="count(hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']) &lt;= 1">(plCdaBaseRelatedDocument): element hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7'] 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.7-2020-06-08T000000.html"
              test="count(hl7:parentDocument) &gt;= 1">(plCdaBaseRelatedDocument): element hl7:parentDocument 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.7-2020-06-08T000000.html"
              test="count(hl7:parentDocument) &lt;= 1">(plCdaBaseRelatedDocument): element hl7:parentDocument appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.7
Context: *[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']
Item: (plCdaBaseRelatedDocument)
-->

   <rule fpi="RULC-1"
         context="*[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']"
         id="d16e6269-false-d25976e0">
      <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.7-2020-06-08T000000.html"
              test="string(@root) = ('2.16.840.1.113883.3.4424.13.10.2.7')">(plCdaBaseRelatedDocument): The value for root SHALL be '2.16.840.1.113883.3.4424.13.10.2.7'. Found: "<value-of select="@root"/>"</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.7
Context: *[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:parentDocument
Item: (plCdaBaseRelatedDocument)
-->

   <rule fpi="RULC-1"
         context="*[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:parentDocument"
         id="d16e6274-false-d25987e0">
      <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.7-2020-06-08T000000.html"
              test="string(@classCode) = ('DOCCLIN') or not(@classCode)">(plCdaBaseRelatedDocument): The value for classCode SHALL be 'DOCCLIN'. 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.7-2020-06-08T000000.html"
              test="string(@moodCode) = ('EVN') or not(@moodCode)">(plCdaBaseRelatedDocument): The value for moodCode SHALL be 'EVN'. Found: "<value-of select="@moodCode"/>"</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.7-2020-06-08T000000.html"
              test="hl7:id[@root=/hl7:ClinicalDocument/hl7:id/@root and @extension=/hl7:ClinicalDocument/hl7:id/@extension]">(plCdaBaseRelatedDocument): Idetyfikator dokumentu jest taki sam jak identyfikator dokumentu powiązanego wskazujcego na jego poprzednią wersję.</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.7-2020-06-08T000000.html"
              test="hl7:setId[@root=/hl7:ClinicalDocument/hl7:setId/@root and @extension=/hl7:ClinicalDocument/hl7:setId/@extension]">(plCdaBaseRelatedDocument): Identyfikator grupy wersji dokumentów (setId) powienien być identyczny dla dokumentu i dokumentu powiązanego wskazującego na jego poprzednią wersję.</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.7-2020-06-08T000000.html"
              test="(xs:integer(hl7:versionNumber/@value)+1)=xs:integer(/hl7:ClinicalDocument/hl7:versionNumber/@value)">(plCdaBaseRelatedDocument): Dokument powiązany powienien wskazywać poprzednią wersję dokumentu.</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.7-2020-06-08T000000.html"
              test="count(hl7:id[not(@nullFlavor)]) &gt;= 1">(plCdaBaseRelatedDocument): 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.7-2020-06-08T000000.html"
              test="count(hl7:id[not(@nullFlavor)]) &lt;= 1">(plCdaBaseRelatedDocument): element hl7:id[not(@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.7-2020-06-08T000000.html"
              test="count(hl7:setId[not(@nullFlavor)]) &gt;= 1">(plCdaBaseRelatedDocument): element hl7:setId[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.7-2020-06-08T000000.html"
              test="count(hl7:setId[not(@nullFlavor)]) &lt;= 1">(plCdaBaseRelatedDocument): element hl7:setId[not(@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.7-2020-06-08T000000.html"
              test="count(hl7:versionNumber[not(@nullFlavor)]) &gt;= 1">(plCdaBaseRelatedDocument): element hl7:versionNumber[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.7-2020-06-08T000000.html"
              test="count(hl7:versionNumber[not(@nullFlavor)]) &lt;= 1">(plCdaBaseRelatedDocument): element hl7:versionNumber[not(@nullFlavor)] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.7
Context: *[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:parentDocument/hl7:id[not(@nullFlavor)]
Item: (plCdaBaseRelatedDocument)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.2.7
Context: *[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:parentDocument/hl7:setId[not(@nullFlavor)]
Item: (plCdaBaseRelatedDocument)
-->

   <rule fpi="RULC-1"
         context="*[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:parentDocument/hl7:setId[not(@nullFlavor)]"
         id="d16e6282-false-d26035e0">
      <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.7-2020-06-08T000000.html"
              test="@root">(plCdaBaseRelatedDocument): 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.7-2020-06-08T000000.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\-]*$')">(plCdaBaseRelatedDocument): 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.7-2020-06-08T000000.html"
              test="@extension">(plCdaBaseRelatedDocument): 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.7-2020-06-08T000000.html"
              test="not(@extension) or string-length(@extension)&gt;0">(plCdaBaseRelatedDocument): 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.7
Context: *[hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]]/hl7:relatedDocument[hl7:templateId[@root = '2.16.840.1.113883.3.4424.13.10.2.7']]/hl7:parentDocument/hl7:versionNumber[not(@nullFlavor)]
Item: (plCdaBaseRelatedDocument)
-->
</pattern>
