<?xml version='1.0' encoding='UTF-8'?>
<Library xmlns="http://hl7.org/fhir" xmlns:html="http://www.w3.org/1999/xhtml">
  <id value="IMMZD5DTTyphoidContraindicationsLogic" />
  <meta>
    <profile value="http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-shareablelibrary" />
    <profile value="http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-publishablelibrary" />
    <profile value="http://hl7.org/fhir/uv/cql/StructureDefinition/cql-library" />
    <profile value="http://hl7.org/fhir/uv/cql/StructureDefinition/cql-module" />
  </meta>
  <text>
    <status value="extensions" /><html:div>
<html:div>
    <html:table class="grid dict">
        
        
        <html:tr>
            <html:th scope="row"><html:b>Title: </html:b></html:th>
            <html:td style="padding-left: 4px;">IMMZD5DTTyphoidContraindicationsLogic</html:td>
        </html:tr>
        

        
        
        <html:tr>
            <html:th scope="row"><html:b>Id: </html:b></html:th>
            <html:td style="padding-left: 4px;">IMMZD5DTTyphoidContraindicationsLogic</html:td>
        </html:tr>
        

        
        
        <html:tr>
            <html:th scope="row"><html:b>Version: </html:b></html:th>
            <html:td style="padding-left: 4px;">0.2.0</html:td>
        </html:tr>
        

        
        <html:tr>
            <html:th scope="row"><html:b>Url: </html:b></html:th>
            <html:td style="padding-left: 4px;"><html:a href="Library-IMMZD5DTTyphoidContraindicationsLogic.html">IMMZD5DTTyphoidContraindicationsLogic</html:a></html:td>
        </html:tr>
        

        

        

        
        <html:tr>
            <html:th scope="row"><html:b>Status: </html:b></html:th>
            <html:td style="padding-left: 4px;">draft</html:td>
        </html:tr>
        

        

        
        <html:tr>
            <html:th scope="row"><html:b>Type: </html:b></html:th>
            <html:td style="padding-left: 4px;">
                
                    
                        
                        <html:p style="margin-bottom: 5px;">
                            <html:b>system: </html:b> <html:span><html:a href="http://terminology.hl7.org/7.1.0/CodeSystem-library-type.html">http://terminology.hl7.org/CodeSystem/library-type</html:a></html:span>
                        </html:p>
                        
                        
                        <html:p style="margin-bottom: 5px;">
                            <html:b>code: </html:b> <html:span>logic-library</html:span>
                        </html:p>
                        
                        
                    
                
                
            </html:td>
        </html:tr>
        

        

        
        <html:tr>
            <html:th scope="row"><html:b>Date: </html:b></html:th>
            <html:td style="padding-left: 4px;">2026-03-29 17:23:09+0000</html:td>
        </html:tr>
        

        
        <html:tr>
            <html:th scope="row"><html:b>Publisher: </html:b></html:th>
            <html:td style="padding-left: 4px;">WHO</html:td>
        </html:tr>
        

        
        <html:tr>
            <html:th scope="row"><html:b>Description: </html:b></html:th>
            <html:td style="padding-left: 4px;"><html:div><html:p>This library defines decision support logic for the IMMZ.D5.DT.Typhoid contraindications decision table in the Immunization CPG</html:p>
</html:div></html:td>
        </html:tr>
        

        

        

        

        

        

        

        

        

        

        

        
        <html:tr>
            <html:th scope="row"><html:b>Related Artifacts: </html:b></html:th>
            <html:td style="padding-left: 4px;">
                
                
                
                <html:p><html:b>Dependencies</html:b></html:p>
                <html:ul>
                  
                    <html:li><html:a href="Library-IMMZD5DTTyphoidEncounterElements.html">IMMZD5DTTyphoidEncounterElements</html:a></html:li>
                  
                </html:ul>
                
                
                
                
                
            </html:td>
        </html:tr>
        

        
        <html:tr>
          <html:th scope="row"><html:b>Parameters: </html:b></html:th>
          <html:td style="padding-left: 4px;">
            <html:table class="grid-dict">
              <html:tr><html:th><html:b>Name</html:b></html:th><html:th><html:b>Type</html:b></html:th><html:th><html:b>Min</html:b></html:th><html:th><html:b>Max</html:b></html:th><html:th><html:b>In/Out</html:b></html:th></html:tr>
              
                <html:tr><html:th>Today</html:th><html:th>date</html:th><html:th>0</html:th><html:th>1</html:th><html:th>In</html:th></html:tr>
              
                <html:tr><html:th>Patient</html:th><html:th>Patient</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Draft Medication Request ID for Typhoid dose</html:th><html:th>id</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note.</html:th><html:th>boolean</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note. Guidance</html:th><html:th>string</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note</html:th><html:th>boolean</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note Guidance</html:th><html:th>string</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1</html:th><html:th>boolean</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2</html:th><html:th>boolean</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination is contraindicated for Ty21a vaccine.</html:th><html:th>boolean</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Typhoid vaccination is contraindicated for Ty21a vaccine. Guidance</html:th><html:th>string</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Guidance</html:th><html:th>string</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Has Guidance</html:th><html:th>boolean</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
                <html:tr><html:th>Test Validation</html:th><html:th>Resource</html:th><html:th>0</html:th><html:th>1</html:th><html:th>Out</html:th></html:tr>
              
            </html:table>
          </html:td>
        </html:tr>
        

        

        
        
        <html:tr>
          <html:td colspan="2">
            <html:table>
              <html:tr><html:th><html:a id="cql-content"><html:b>Content: </html:b></html:a> text/cql</html:th></html:tr>
              <html:tr><html:td><html:pre><html:code class="language-cql">/*
 * Library: IMMZD5DTTyphoidContraindicationsLogic (IMMZ.D5.DT.Typhoid contraindications)
 * Rule: Check for contraindications before administering the vaccine(s) due
 * Decision Table: IMMZ.D5.DT.Typhoid contraindications
 * Trigger: IMMZ.D5 Determine vaccine(s) to be administered based on contraindications
 */
library IMMZD5DTTyphoidContraindicationsLogic

using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1'

include IMMZD5DTTyphoidEncounterElements called Encounter

parameter Today Date default Today()

context Patient

/*
  @dynamicValue: Draft Medication Request ID for Typhoid dose
  */
  define "Draft Medication Request ID for Typhoid dose":
    First(Encounter."Draft Medication Request for Typhoid dose").id


/*
@dynamicValue: Guidance
*/
define "Guidance":
  case 
    when "Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note." then "Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note. Guidance"
    when "Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note" then "Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note Guidance"
    when "Typhoid vaccination is contraindicated for Ty21a vaccine." then "Typhoid vaccination is contraindicated for Ty21a vaccine. Guidance" 
    else ''
  end
  
define "Has Guidance":
  "Guidance" is not null and "Guidance" != ''

/*
@output: Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note.
@pseudocode: "Immunization recommendation status" = "Further evaluation needed"
*/
define "Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note.":
  Encounter."The client has hypersensitivity to any component of the vaccine"

/*
@output: Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note. Guidance
@guidance: Do not vaccinate client with typhoid if client has known hypersensitivity to any component of the vaccine.
*/
define "Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note. Guidance":
  'Do not vaccinate client with typhoid if client has known hypersensitivity to any component of the vaccine.'

/*
@output: Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note
@pseudocode: "Immunization recommendation status" = "Contraindicated" (where "Type of typhoid dose" = "Ty21a") AND "Immunization recommendation status" = "Further evaluation needed" (where "Type of typhoid dose" = "Typbar-TCV" OR "ViPS")
*/
define "Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note":
  Encounter."The client is currently pregnant"

/*
@output: Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note Guidance
@guidance: Do not vaccinate client with Ty21a vaccine as live attenuated Ty21a vaccine is contraindicated for pregnant clients. For Typbar-TCV or ViPS vaccine, check if an alternative typhoid vaccine is appropriate for the client, consider risks of vaccination and make a clinical judgement.
*/
define "Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note Guidance":
  'Do not vaccinate client with Ty21a vaccine as live attenuated Ty21a vaccine is contraindicated for pregnant clients. For Typbar-TCV or ViPS vaccine, check if an alternative typhoid vaccine is appropriate for the client, consider risks of vaccination and make a clinical judgement.'

/*
@output: Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1
@pseudocode: "Immunization recommendation status" = "Contraindicated" (where "Type of typhoid dose" = "Ty21a")
*/
define "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1":
  Encounter."The client is currently taking antibiotics"

/*
@output: Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2
@pseudocode: "Immunization recommendation status" = "Contraindicated" (where "Type of typhoid dose" = "Ty21a")
*/
define "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2":
  Encounter."The client's HIV status is positive"
    and Encounter."The client is not immunologically stable"

/*
@output: Typhoid vaccination is contraindicated for Ty21a vaccine.
@pseudocode: "Immunization recommendation status" = "Contraindicated" (where "Type of typhoid dose" = "Ty21a")
*/
define "Typhoid vaccination is contraindicated for Ty21a vaccine.":
  "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1"
    or "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2"

/*
@output: Typhoid vaccination is contraindicated for Ty21a vaccine. Guidance
@guidance = Do not vaccinate client with Ty21a vaccine as Ty21a vaccine is contraindicated for clients who are taking antibiotics. Evaluate if other types of typhoid vacccines can be administered.
@guidance = Do not vaccinate client with Ty21a vaccine as Ty21a vaccine is contraindicated for HIV-infected client who are not immunologically stable.
*/
define "Typhoid vaccination is contraindicated for Ty21a vaccine. Guidance":
  case
    when "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1" then 'Do not vaccinate client with Ty21a vaccine as Ty21a vaccine is contraindicated for clients who are taking antibiotics. Evaluate if other types of typhoid vacccines can be administered.'
    when "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2" then 'Do not vaccinate client with Ty21a vaccine as Ty21a vaccine is contraindicated for HIV-infected client who are not immunologically stable.'
    else ''
  end


/*
@test: Test expected results based on example patients
*/
define "Test Validation":
  case
    when Patient.id = 'Typhoid41.1' then "Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note." and "Guidance" = 'Do not vaccinate client with typhoid if client has known hypersensitivity to any component of the vaccine.'
    when Patient.id = 'Typhoid42.1' then "Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note" and "Guidance" = 'Do not vaccinate client with Ty21a vaccine as live attenuated Ty21a vaccine is contraindicated for pregnant clients. For Typbar-TCV or ViPS vaccine, check if an alternative typhoid vaccine is appropriate for the client, consider risks of vaccination and make a clinical judgement.'
    when Patient.id = 'Typhoid43.1' then "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1" and "Guidance" = 'Do not vaccinate client with Ty21a vaccine as Ty21a vaccine is contraindicated for clients who are taking antibiotics. Evaluate if other types of typhoid vacccines can be administered.'
    when Patient.id = 'Typhoid44.2' then "Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2" and "Guidance" = 'Do not vaccinate client with Ty21a vaccine as Ty21a vaccine is contraindicated for HIV-infected client who are not immunologically stable.'
    else 'No test case set'
  end
</html:code></html:pre></html:td></html:tr>
            </html:table>
          </html:td>
        </html:tr>
        
        
        
        
        
        <html:tr>
          <html:td colspan="2">
            <html:table>
              <html:tr><html:th><html:b>Content: </html:b> application/elm+xml</html:th></html:tr>
              <html:tr><html:td><html:pre><html:code>Encoded data (60184 characters)</html:code></html:pre></html:td></html:tr>
            </html:table>
          </html:td>
        </html:tr>
        
        
    </html:table>
</html:div>
</html:div>
  </text>
  <extension url="http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability">
    <valueCode value="computable" />
  </extension>
  <url value="http://smart.who.int/immunizations/Library/IMMZD5DTTyphoidContraindicationsLogic" />
  <version value="0.2.0" />
  <name value="IMMZD5DTTyphoidContraindicationsLogic" />
  <title value="IMMZD5DTTyphoidContraindicationsLogic" />
  <status value="draft" />
  <experimental value="false" />
  <type>
    <coding>
      <system value="http://terminology.hl7.org/CodeSystem/library-type" />
      <code value="logic-library" />
    </coding>
  </type>
  <date value="2026-03-29T17:23:09+00:00" />
  <publisher value="WHO" />
  <contact>
    <name value="WHO" />
    <telecom>
      <system value="url" />
      <value value="http://who.int" />
    </telecom>
  </contact>
  <description value="This library defines decision support logic for the IMMZ.D5.DT.Typhoid contraindications decision table in the Immunization CPG" />
  <relatedArtifact>
    <type value="depends-on" />
    <display value="Library Encounter" />
    <resource value="http://smart.who.int/immunizations/Library/IMMZD5DTTyphoidEncounterElements" />
  </relatedArtifact>
  <parameter>
    <name value="Today" />
    <use value="in" />
    <min value="0" />
    <max value="1" />
    <type value="date" />
  </parameter>
  <parameter>
    <name value="Patient" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="Patient" />
  </parameter>
  <parameter>
    <name value="Draft Medication Request ID for Typhoid dose" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="id" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note." />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination could be contraindicated. Clinical judgement is required. Create a clinical note. Guidance" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination is contraindicated for Ty21a vaccine. Clinical judgement is required for Typbar-TCV or ViPS vaccine. Create a clinical note Guidance" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination is contraindicated for Ty21a vaccine. Case 1" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination is contraindicated for Ty21a vaccine. Case 2" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination is contraindicated for Ty21a vaccine." />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Typhoid vaccination is contraindicated for Ty21a vaccine. Guidance" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Guidance" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Has Guidance" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Test Validation" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="Resource" />
  </parameter>
  <content>
    <contentType value="text/cql" />
    <url value="Library-IMMZD5DTTyphoidContraindicationsLogic.cql" /></content>
  <content>
    <contentType value="application/elm+xml" />
    <url value="Library-IMMZD5DTTyphoidContraindicationsLogic.elm.xml" /></content>
</Library>