<?xml version="1.0" encoding="UTF-8"?>
<!--
Template derived pattern
===========================================
ID: 2.16.840.1.113883.3.4424.13.10.4.182
Name: [4] Opis mikroskopowy w cytologii dla pojedynczego badanego materiału
Description: Szablon CDA dla referencji do opisu mikroskopowego w cytologii dla pojedynczego badanego materiału
-->
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
         id="template-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000">
   <title>[4] Opis mikroskopowy w cytologii dla pojedynczego badanego materiału</title>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.182
Context: *[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]
Item: (plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship)
-->

   <rule context="*[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]"
         id="tmp-">
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182'])&gt;=1 and not(hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/@nullFlavor)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182'] jest mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182'])&lt;=1">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182'] występuje zbyt często [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.182
Context: *[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']
Item: (plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship)
-->

   <rule context="*[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']"
         id="tmp-">
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="string(@classCode)='OBS' or not(@classCode)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Wartość dla @classCode MUSI wynosić 'OBS'.</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="not(@classCode) or (string-length(@classCode)&gt;0 and not(matches(@classCode,'\s')))">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Atrybut @classCode MUSI być typu 'cs'</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="string(@moodCode)='EVN' or not(@moodCode)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Wartość dla @moodCode MUSI wynosić 'EVN'.</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="not(@moodCode) or (string-length(@moodCode)&gt;0 and not(matches(@moodCode,'\s')))">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Atrybut @moodCode MUSI być typu 'cs'</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182'])&gt;=1 and not(hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182']/@nullFlavor)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182'] jest mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182'])&lt;=1">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182'] występuje zbyt często [max 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')])&gt;=1 and not(hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')]/@nullFlavor)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')] jest mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')])&lt;=1">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')] występuje zbyt często [max 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:text)&gt;=1 and not(hl7:text/@nullFlavor)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:text jest mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:text)&lt;=1">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:text występuje zbyt często [max 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:statusCode[@code='completed'])&gt;=1 and not(hl7:statusCode[@code='completed']/@nullFlavor)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:statusCode[@code='completed'] jest mandatory [min 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:statusCode[@code='completed'])&lt;=1">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:statusCode[@code='completed'] występuje zbyt często [max 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:value)&gt;=1 ">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:value jest required [min 1x].</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="count(hl7:value)&lt;=1">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): element hl7:value występuje zbyt często [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.182
Context: *[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182']
Item: (plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship)
-->

   <rule context="*[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:templateId[@root='2.16.840.1.113883.3.4424.13.10.4.182']"
         id="tmp-">
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="(local-name-from-QName(resolve-QName(@xsi:type,.))='II' and namespace-uri-from-QName(resolve-QName(@xsi:type,.))='urn:hl7-org:v3') or not(@xsi:type)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Jeśli występuje instrukcja @xsi:type, to MUSI mieć wartość "{urn:hl7-org:v3}:II", znaleziono "{<value-of select="namespace-uri-from-QName(resolve-QName(@xsi:type,.))"/>}:<value-of select="local-name-from-QName(resolve-QName(@xsi:type,.))"/>"</assert>
      <extends rule="II"/>
      <let name="theValue" value="@value"/>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="string(@root)='2.16.840.1.113883.3.4424.13.10.4.182'">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Wartość dla @root MUSI wynosić '2.16.840.1.113883.3.4424.13.10.4.182'.</assert>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="not(@root) or matches(@root,'^[0-2](\.(0|[1-9][0-9]*))*$')">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Atrybut @root MUSI być typu 'oid'</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.182
Context: *[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')]
Item: (plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship)
-->

   <rule context="*[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:code[(@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18')]"
         id="tmp-">
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="(local-name-from-QName(resolve-QName(@xsi:type,.))='CD' and namespace-uri-from-QName(resolve-QName(@xsi:type,.))='urn:hl7-org:v3') or not(@xsi:type)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Jeśli występuje instrukcja @xsi:type, to MUSI mieć wartość "{urn:hl7-org:v3}:CD", znaleziono "{<value-of select="namespace-uri-from-QName(resolve-QName(@xsi:type,.))"/>}:<value-of select="local-name-from-QName(resolve-QName(@xsi:type,.))"/>"</assert>
      <extends rule="CD"/>
      <let name="theValue" value="@value"/>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="@nullFlavor or (@code='OpisOcenyMikro' and @codeSystem='2.16.840.1.113883.3.4424.13.5.18' and @displayName='Opis oceny mikroskopowej' and @codeSystemName='AtrybutyWBCYT')">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Wartość elementu MUSI wynosić code 'OpisOcenyMikro' codeSystem '2.16.840.1.113883.3.4424.13.5.18' displayName='Opis oceny mikroskopowej' codeSystemName='AtrybutyWBCYT'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.182
Context: *[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:statusCode[@code='completed']
Item: (plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship)
-->

   <rule context="*[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:statusCode[@code='completed']"
         id="tmp-">
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="(local-name-from-QName(resolve-QName(@xsi:type,.))='CS' and namespace-uri-from-QName(resolve-QName(@xsi:type,.))='urn:hl7-org:v3') or not(@xsi:type)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Jeśli występuje instrukcja @xsi:type, to MUSI mieć wartość "{urn:hl7-org:v3}:CS", znaleziono "{<value-of select="namespace-uri-from-QName(resolve-QName(@xsi:type,.))"/>}:<value-of select="local-name-from-QName(resolve-QName(@xsi:type,.))"/>"</assert>
      <extends rule="CS"/>
      <let name="theValue" value="@value"/>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="@nullFlavor or (@code='completed')">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Wartość elementu MUSI wynosić code 'completed'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.4424.13.10.4.182
Context: *[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:value
Item: (plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship)
-->

   <rule context="*[hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']]/hl7:observation[hl7:templateId/@root='2.16.840.1.113883.3.4424.13.10.4.182']/hl7:value"
         id="tmp-">
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="(local-name-from-QName(resolve-QName(@xsi:type,.))='ST' and namespace-uri-from-QName(resolve-QName(@xsi:type,.))='urn:hl7-org:v3') or not(@xsi:type)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Jeśli występuje instrukcja @xsi:type, to MUSI mieć wartość "{urn:hl7-org:v3}:ST", znaleziono "{<value-of select="namespace-uri-from-QName(resolve-QName(@xsi:type,.))"/>}:<value-of select="local-name-from-QName(resolve-QName(@xsi:type,.))"/>"</assert>
      <extends rule="ST"/>
      <let name="theValue" value="text()"/>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="not(@nullFlavor) or (string-length(@nullFlavor)&gt;0 and not(matches(@nullFlavor,'\s')))">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Atrybut @nullFlavor MUSI być typu 'cs'</assert>
      <let name="theAttValue"
           value="distinct-values(tokenize(normalize-space(@nullFlavor),' '))"/>
      <let name="theAttCheck"
           value="distinct-values(for $code in tokenize(@nullFlavor,' ') return if ($code=('NA')) then ($code) else ())"/>
      <assert role="error"
              see="https://www.cez.gov.pl/HL7POL-1.3.2/plcda-html-1.3.2/plcda-html/plcda-html-develop/tmp-2.16.840.1.113883.3.4424.13.10.4.182-2023-04-27T000000.html"
              test="not(@nullFlavor) or count($theAttValue) = count($theAttCheck)">(plCdaMicroscopicDescriptionReferenceInCytologyPerExaminedMaterialEntryRelationship): Wartość dla nullFlavor MUSI wynosić 'kod NA'.</assert>
   </rule>
</pattern>
