<?xml version="1.0" encoding="UTF-8"?>
<library xmlns="urn:hl7-org:elm:r1" xmlns:t="urn:hl7-org:elm-types:r1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fhir="http://hl7.org/fhir" xmlns:qdm43="urn:healthit-gov:qdm:v4_3" xmlns:qdm53="urn:healthit-gov:qdm:v5_3" xmlns:a="urn:hl7-org:cql-annotations:r1" localId="0">
   <annotation translatorOptions="EnableAnnotations,EnableLocators,DisableListDemotion,DisableListPromotion" signatureLevel="Overloads" xsi:type="a:CqlToElmInfo"/>
   <annotation message="An operand identifier reference is hiding another identifier of the same name." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
   <annotation message="An operand identifier reference is hiding another identifier of the same name." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
   <annotation message="An operand identifier reference is hiding another identifier of the same name." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
   <annotation xsi:type="a:Annotation">
      <a:s r="266">
         <a:s>/*
 * Library: IMMZD5DTRabiesContraindicationsLogic (IMMZ.D5.DT.Rabies contraindications)
 * Rule: Check for contraindications before administering the vaccine(s) due
 * Decision Table: IMMZ.D5.DT.Rabies contraindications
 * Trigger: IMMZ.D5 Determine vaccine(s) to be administered based on contraindications
 */
library IMMZD5DTRabiesContraindicationsLogic</a:s>
      </a:s>
   </annotation>
   <identifier id="IMMZD5DTRabiesContraindicationsLogic" system="http://smart.who.int/immunizations"/>
   <schemaIdentifier id="urn:hl7-org:elm" version="r1"/>
   <usings>
      <def localId="1" localIdentifier="System" uri="urn:hl7-org:elm-types:r1" version="1.0.0"/>
      <def localId="206" locator="9:1-9:26" localIdentifier="FHIR" uri="http://hl7.org/fhir" version="4.0.1">
         <annotation xsi:type="a:Annotation">
            <a:s r="206">
               <a:s>using </a:s>
               <a:s>
                  <a:s>FHIR</a:s>
               </a:s>
               <a:s> version '4.0.1'</a:s>
            </a:s>
         </annotation>
      </def>
   </usings>
   <includes>
      <def localId="208" locator="10:1-10:35" localIdentifier="FHIRHelpers" path="http://hl7.org/fhir/FHIRHelpers" version="4.0.1">
         <annotation xsi:type="a:Annotation">
            <a:s r="208">
               <a:s>include </a:s>
               <a:s>
                  <a:s>FHIRHelpers</a:s>
               </a:s>
               <a:s> version '4.0.1'</a:s>
            </a:s>
         </annotation>
      </def>
      <def localId="210" locator="12:1-12:56" localIdentifier="Encounter" path="http://smart.who.int/immunizations/IMMZD5DTRabiesEncounterElements">
         <annotation xsi:type="a:Annotation">
            <a:s r="210">
               <a:s>include </a:s>
               <a:s>
                  <a:s>IMMZD5DTRabiesEncounterElements</a:s>
               </a:s>
               <a:s> called Encounter</a:s>
            </a:s>
         </annotation>
      </def>
   </includes>
   <parameters>
      <def localId="212" locator="14:1-14:36" name="Today" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:s r="212">
               <a:s>parameter Today </a:s>
               <a:s r="216">
                  <a:s>Date</a:s>
               </a:s>
               <a:s> default </a:s>
               <a:s r="215">
                  <a:s>Today()</a:s>
               </a:s>
            </a:s>
         </annotation>
         <default localId="215" locator="14:30-14:36" xsi:type="Today"/>
         <parameterTypeSpecifier localId="216" locator="14:17-14:20" name="t:Date" xsi:type="NamedTypeSpecifier"/>
      </def>
   </parameters>
   <contexts>
      <def localId="221" locator="16:1-16:15" name="Patient"/>
   </contexts>
   <statements>
      <def localId="219" locator="16:1-16:15" name="Patient" context="Patient">
         <expression localId="220" xsi:type="SingletonFrom">
            <operand localId="218" locator="16:1-16:15" dataType="fhir:Patient" templateId="http://hl7.org/fhir/StructureDefinition/Patient" xsi:type="Retrieve"/>
         </expression>
      </def>
      <def localId="224" locator="21:3-22:66" name="Draft Medication Request ID for Rabies dose" context="Patient" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:t name="dynamicValue" value="Draft Medication Request ID for Rabies dose"/>
            <a:s r="224">
               <a:s>/*
  @dynamicValue: Draft Medication Request ID for Rabies dose
  */
  define &quot;Draft Medication Request ID for Rabies dose&quot;:
    </a:s>
               <a:s r="230">
                  <a:s r="229">
                     <a:s>First(</a:s>
                     <a:s r="226">
                        <a:s r="225">
                           <a:s>Encounter</a:s>
                        </a:s>
                        <a:s>.</a:s>
                        <a:s r="226">
                           <a:s>&quot;Draft Medication Request for Rabies dose&quot;</a:s>
                        </a:s>
                     </a:s>
                     <a:s>)</a:s>
                  </a:s>
                  <a:s>.</a:s>
                  <a:s r="230">
                     <a:s>id</a:s>
                  </a:s>
               </a:s>
            </a:s>
         </annotation>
         <expression localId="230" locator="22:5-22:66" path="id" xsi:type="Property">
            <source localId="229" locator="22:5-22:63" xsi:type="First">
               <source localId="226" locator="22:11-22:62" name="Draft Medication Request for Rabies dose" libraryName="Encounter" xsi:type="ExpressionRef"/>
            </source>
         </expression>
      </def>
      <def localId="238" locator="41:1-42:65" name="Clinical judgement is required. Create a clinical note" context="Patient" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:t name="output" value="Clinical judgement is required. Create a clinical note"/>
            <a:t name="pseudocode" value="&quot;Immunization recommendation status&quot; = &quot;Further evaluation needed&quot;"/>
            <a:s r="238">
               <a:s>/*
@output: Clinical judgement is required. Create a clinical note
@pseudocode: &quot;Immunization recommendation status&quot; = &quot;Further evaluation needed&quot;
*/
define &quot;Clinical judgement is required. Create a clinical note&quot;:
  </a:s>
               <a:s r="240">
                  <a:s r="239">
                     <a:s>Encounter</a:s>
                  </a:s>
                  <a:s>.</a:s>
                  <a:s r="240">
                     <a:s>&quot;The client has history of severe allergic reactions&quot;</a:s>
                  </a:s>
               </a:s>
            </a:s>
         </annotation>
         <expression localId="240" locator="42:3-42:65" name="The client has history of severe allergic reactions" libraryName="Encounter" xsi:type="ExpressionRef"/>
      </def>
      <def localId="244" locator="48:1-49:205" name="Clinical judgement is required. Create a clinical note Guidance" context="Patient" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:t name="output" value="Clinical judgement is required. Create a clinical note Guidance"/>
            <a:t name="guidance" value="Check if the client has a history of severe hypersensitivity to any of the components or to excipients listed by the vaccine manufacturer. If so, provide an alternative rabies vaccine product for PreP."/>
            <a:s r="244">
               <a:s>/*
@output: Clinical judgement is required. Create a clinical note Guidance
@guidance: Check if the client has a history of severe hypersensitivity to any of the components or to excipients listed by the vaccine manufacturer. If so, provide an alternative rabies vaccine product for PreP.
*/
define &quot;Clinical judgement is required. Create a clinical note Guidance&quot;:
  </a:s>
               <a:s r="245">
                  <a:s>'Check if the client has a history of severe hypersensitivity to any of the components or to excipients listed by the vaccine manufacturer. If so, provide an alternative rabies vaccine product for PreP.'</a:s>
               </a:s>
            </a:s>
         </annotation>
         <expression localId="245" locator="49:3-49:205" valueType="t:String" value="Check if the client has a history of severe hypersensitivity to any of the components or to excipients listed by the vaccine manufacturer. If so, provide an alternative rabies vaccine product for PreP." xsi:type="Literal"/>
      </def>
      <def localId="233" locator="28:1-32:5" name="Guidance" context="Patient" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:t name="dynamicValue" value="Guidance"/>
            <a:s r="233">
               <a:s>/*
@dynamicValue: Guidance
*/
define &quot;Guidance&quot;:
  </a:s>
               <a:s r="234">
                  <a:s>case 
    </a:s>
                  <a:s r="235">
                     <a:s>when </a:s>
                     <a:s r="241">
                        <a:s>&quot;Clinical judgement is required. Create a clinical note&quot;</a:s>
                     </a:s>
                     <a:s> then </a:s>
                     <a:s r="247">
                        <a:s>&quot;Clinical judgement is required. Create a clinical note Guidance&quot;</a:s>
                     </a:s>
                  </a:s>
                  <a:s> 
    else </a:s>
                  <a:s r="248">
                     <a:s>''</a:s>
                  </a:s>
                  <a:s>
  end</a:s>
               </a:s>
            </a:s>
         </annotation>
         <expression localId="234" locator="29:3-32:5" xsi:type="Case">
            <caseItem localId="235" locator="30:5-30:136">
               <when localId="241" locator="30:10-30:65" name="Clinical judgement is required. Create a clinical note" xsi:type="ExpressionRef"/>
               <then localId="247" locator="30:72-30:136" name="Clinical judgement is required. Create a clinical note Guidance" xsi:type="ExpressionRef"/>
            </caseItem>
            <else localId="248" locator="31:10-31:11" valueType="t:String" value="" xsi:type="Literal"/>
         </expression>
      </def>
      <def localId="252" locator="34:1-35:45" name="Has Guidance" context="Patient" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:s r="252">
               <a:s>define &quot;Has Guidance&quot;:
  </a:s>
               <a:s r="253">
                  <a:s r="256">
                     <a:s r="254">
                        <a:s>&quot;Guidance&quot;</a:s>
                     </a:s>
                     <a:s> is not null</a:s>
                  </a:s>
                  <a:s> and </a:s>
                  <a:s r="263">
                     <a:s r="258">
                        <a:s>&quot;Guidance&quot;</a:s>
                     </a:s>
                     <a:s> != </a:s>
                     <a:s r="259">
                        <a:s>''</a:s>
                     </a:s>
                  </a:s>
               </a:s>
            </a:s>
         </annotation>
         <expression localId="253" locator="35:3-35:45" xsi:type="And">
            <operand localId="256" locator="35:3-35:24" xsi:type="Not">
               <operand localId="255" locator="35:3-35:24" xsi:type="IsNull">
                  <operand localId="254" locator="35:3-35:12" name="Guidance" xsi:type="ExpressionRef"/>
               </operand>
            </operand>
            <operand localId="263" locator="35:30-35:45" xsi:type="Not">
               <operand localId="257" locator="35:30-35:45" xsi:type="Equal">
                  <signature localId="261" name="t:String" xsi:type="NamedTypeSpecifier"/>
                  <signature localId="262" name="t:String" xsi:type="NamedTypeSpecifier"/>
                  <operand localId="258" locator="35:30-35:39" name="Guidance" xsi:type="ExpressionRef"/>
                  <operand localId="259" locator="35:44-35:45" valueType="t:String" value="" xsi:type="Literal"/>
               </operand>
            </operand>
         </expression>
      </def>
      <def localId="266" locator="55:1-59:5" name="Test Validation" context="Patient" accessLevel="Public">
         <annotation xsi:type="a:Annotation">
            <a:t name="test" value="Test expected results based on example patients"/>
            <a:s r="266">
               <a:s>/*
@test: Test expected results based on example patients
*/
define &quot;Test Validation&quot;:
  </a:s>
               <a:s r="267">
                  <a:s>case
    </a:s>
                  <a:s r="268">
                     <a:s>when </a:s>
                     <a:s r="269">
                        <a:s r="271">
                           <a:s r="270">
                              <a:s>Patient</a:s>
                           </a:s>
                           <a:s>.</a:s>
                           <a:s r="271">
                              <a:s>id</a:s>
                           </a:s>
                        </a:s>
                        <a:s> = </a:s>
                        <a:s r="272">
                           <a:s>'Rabies17.1'</a:s>
                        </a:s>
                     </a:s>
                     <a:s> then </a:s>
                     <a:s r="278">
                        <a:s r="279">
                           <a:s>&quot;Clinical judgement is required. Create a clinical note&quot;</a:s>
                        </a:s>
                        <a:s> and </a:s>
                        <a:s r="280">
                           <a:s r="281">
                              <a:s>&quot;Guidance&quot;</a:s>
                           </a:s>
                           <a:s> = </a:s>
                           <a:s r="282">
                              <a:s>'Check if the client has a history of severe hypersensitivity to any of the components or to excipients listed by the vaccine manufacturer. If so, provide an alternative rabies vaccine product for PreP.'</a:s>
                           </a:s>
                        </a:s>
                     </a:s>
                  </a:s>
                  <a:s>
    else </a:s>
                  <a:s r="286">
                     <a:s>'No test case set'</a:s>
                  </a:s>
                  <a:s>
  end</a:s>
               </a:s>
            </a:s>
         </annotation>
         <expression localId="267" locator="56:3-59:5" xsi:type="Case">
            <caseItem localId="268" locator="57:5-57:317">
               <when localId="269" locator="57:10-57:34" xsi:type="Equal">
                  <signature localId="276" name="t:String" xsi:type="NamedTypeSpecifier"/>
                  <signature localId="277" name="t:String" xsi:type="NamedTypeSpecifier"/>
                  <operand localId="274" name="ToString" libraryName="FHIRHelpers" xsi:type="FunctionRef">
                     <signature localId="275" name="fhir:string" xsi:type="NamedTypeSpecifier"/>
                     <operand localId="271" locator="57:10-57:19" path="id" xsi:type="Property">
                        <source localId="270" locator="57:10-57:16" name="Patient" xsi:type="ExpressionRef"/>
                     </operand>
                  </operand>
                  <operand localId="272" locator="57:23-57:34" valueType="t:String" value="Rabies17.1" xsi:type="Literal"/>
               </when>
               <then localId="288" xsi:type="As">
                  <operand localId="278" locator="57:41-57:317" xsi:type="And">
                     <operand localId="279" locator="57:41-57:96" name="Clinical judgement is required. Create a clinical note" xsi:type="ExpressionRef"/>
                     <operand localId="280" locator="57:102-57:317" xsi:type="Equal">
                        <signature localId="284" name="t:String" xsi:type="NamedTypeSpecifier"/>
                        <signature localId="285" name="t:String" xsi:type="NamedTypeSpecifier"/>
                        <operand localId="281" locator="57:102-57:111" name="Guidance" xsi:type="ExpressionRef"/>
                        <operand localId="282" locator="57:115-57:317" valueType="t:String" value="Check if the client has a history of severe hypersensitivity to any of the components or to excipients listed by the vaccine manufacturer. If so, provide an alternative rabies vaccine product for PreP." xsi:type="Literal"/>
                     </operand>
                  </operand>
                  <asTypeSpecifier localId="289" xsi:type="ChoiceTypeSpecifier">
                     <choice localId="290" name="t:Boolean" xsi:type="NamedTypeSpecifier"/>
                     <choice localId="291" name="t:String" xsi:type="NamedTypeSpecifier"/>
                  </asTypeSpecifier>
               </then>
            </caseItem>
            <else localId="292" xsi:type="As">
               <operand localId="286" locator="58:10-58:27" valueType="t:String" value="No test case set" xsi:type="Literal"/>
               <asTypeSpecifier localId="293" xsi:type="ChoiceTypeSpecifier">
                  <choice localId="294" name="t:Boolean" xsi:type="NamedTypeSpecifier"/>
                  <choice localId="295" name="t:String" xsi:type="NamedTypeSpecifier"/>
               </asTypeSpecifier>
            </else>
         </expression>
      </def>
   </statements>
</library>
