<?xml version="1.0" encoding="UTF-8"?>
<!--
Template derived pattern
===========================================
ID: 2.16.840.1.113883.3.1937.777.63.10.687
Name: CDA inFulfillmentOf Teleconsulto
Description: Template CDA inFulfillmentOf (prototype, directly derived from POCD_RM000040 MIF)
-->
<pattern xmlns="http://purl.oclc.org/dsdl/schematron"
         id="template-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259">
   <title>CDA inFulfillmentOf Teleconsulto</title>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687
Item: (CDA inFulfillmentOf Teleconsulto)
-->

   <rule fpi="RULC-1"
         context="2.16.840.1.113883.3.1937.777.63.10.687"
         id="d44e6441-false-d928415e0">
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:inFulfillmentOf[hl7:order]) &gt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:inFulfillmentOf[hl7:order] is required [min 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:inFulfillmentOf[hl7:order]) &lt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:inFulfillmentOf[hl7:order] appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]
Item: (CDA inFulfillmentOf Teleconsulto)
-->

   <rule fpi="RULC-1"
         context="2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]"
         id="d44e6454-false-d928430e0">
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="string(@typeCode) = ('FLFS') or not(@typeCode)">(CDA inFulfillmentOf Teleconsulto): The value for typeCode SHALL be 'FLFS'. Found: "<value-of select="@typeCode"/>"</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:order) &gt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:order is required [min 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:order) &lt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:order appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order
Item: (CDA inFulfillmentOf Teleconsulto)
-->

   <rule fpi="RULC-1"
         context="2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order"
         id="d44e6464-false-d928450e0">
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="string(@classCode) = ('ACT') or not(@classCode)">(CDA inFulfillmentOf Teleconsulto): The value for classCode SHALL be 'ACT'. Found: "<value-of select="@classCode"/>"</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="string(@moodCode) = ('RQO') or not(@moodCode)">(CDA inFulfillmentOf Teleconsulto): The value for moodCode SHALL be 'RQO'. Found: "<value-of select="@moodCode"/>"</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:id) &gt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:id is required [min 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:id) &lt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:id appears too often [max 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:code) &lt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:code appears too often [max 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:priorityCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.16866-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]) &lt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:priorityCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.16866-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor] appears too often [max 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:effectiveTime) &gt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:effectiveTime is required [min 1x].</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="count(hl7:effectiveTime) &lt;= 1">(CDA inFulfillmentOf Teleconsulto): element hl7:effectiveTime appears too often [max 1x].</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order/hl7:id
Item: (CDA inFulfillmentOf Teleconsulto)
-->

   <rule fpi="RULC-1"
         context="2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order/hl7:id"
         id="d44e6470-false-d928497e0">
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="@root">(CDA inFulfillmentOf Teleconsulto): attribute @root SHALL be present.</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.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\-]*$')">(CDA inFulfillmentOf Teleconsulto): Attribute @root SHALL be of data type 'uid'  - '<value-of select="@root"/>'</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="@extension">(CDA inFulfillmentOf Teleconsulto): attribute @extension SHALL be present.</assert>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="not(@extension) or string-length(@extension)&gt;0">(CDA inFulfillmentOf Teleconsulto): 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.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order/hl7:code
Item: (CDA inFulfillmentOf Teleconsulto)
-->

   <!--
Template derived rules for ID: 2.16.840.1.113883.3.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order/hl7:priorityCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.16866-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]
Item: (CDA inFulfillmentOf Teleconsulto)
-->

   <rule fpi="RULC-1"
         context="2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order/hl7:priorityCode[concat(@code, @codeSystem) = doc('include/voc-2.16.840.1.113883.1.11.16866-DYNAMIC.xml')//valueSet[1]/conceptList/concept/concat(@code, @codeSystem) or @nullFlavor]"
         id="d44e6492-false-d928526e0">
      <let name="theCode" value="@code"/>
      <let name="theCodeSystem" value="@codeSystem"/>
      <assert role="error"
              see="https://hl7itig.art-decor.pub/hl7itig-html-20251030T104952/tmp-2.16.840.1.113883.3.1937.777.63.10.687-2025-06-05T115259.html"
              test="@nullFlavor or exists(doc('include/voc-2.16.840.1.113883.1.11.16866-DYNAMIC.xml')//valueSet[1][conceptList/concept[@code = $theCode][@codeSystem = $theCodeSystem]])">(CDA inFulfillmentOf Teleconsulto): The element value SHALL be one of '2.16.840.1.113883.1.11.16866 ActPriority (DYNAMIC)'.</assert>
   </rule>
   <!--
Template derived rules for ID: 2.16.840.1.113883.3.1937.777.63.10.687
Context: 2.16.840.1.113883.3.1937.777.63.10.687/hl7:inFulfillmentOf[hl7:order]/hl7:order/hl7:effectiveTime
Item: (CDA inFulfillmentOf Teleconsulto)
-->
</pattern>
