<?xml version="1.0" encoding="UTF-8"?>

<Library xmlns="http://hl7.org/fhir">
  <id value="IMMZD2DTHepatitisBBirthDoseLogic"/>
  <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"/><div xmlns="http://www.w3.org/1999/xhtml">
<div>
    <table class="grid dict">
        
        
        <tr>
            <th scope="row"><b>Title: </b></th>
            <td style="padding-left: 4px;">IMMZD2DTHepatitisBBirthDoseLogic</td>
        </tr>
        

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

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

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

        

        

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

        

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

        

        
        <tr>
            <th scope="row"><b>Date: </b></th>
            <td style="padding-left: 4px;">2026-03-31 13:54:17+0000</td>
        </tr>
        

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

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

        

        

        

        

        

        

        

        

        

        

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

        
        <tr>
          <th scope="row"><b>Parameters: </b></th>
          <td style="padding-left: 4px;">
            <table class="grid-dict">
              <tr><th><b>Name</b></th><th><b>Type</b></th><th><b>Min</b></th><th><b>Max</b></th><th><b>In/Out</b></th></tr>
              
                <tr><th>Today</th><th>date</th><th>0</th><th>1</th><th>In</th></tr>
              
                <tr><th>Patient</th><th>Patient</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Client is due for hepatitis B monovalent vaccine</th><th>boolean</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Client is due for hepatitis B monovalent vaccine Guidance</th><th>string</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Client should follow delayed-start decision logic</th><th>boolean</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Client should follow delayed-start decision logic Guidance</th><th>string</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Client is not due for the hepatitis B birth dose</th><th>boolean</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Client is not due for the hepatitis B birth dose Guidance</th><th>string</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Guidance</th><th>string</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Has Guidance</th><th>boolean</th><th>0</th><th>1</th><th>Out</th></tr>
              
                <tr><th>Test Validation</th><th>Resource</th><th>0</th><th>1</th><th>Out</th></tr>
              
            </table>
          </td>
        </tr>
        

        

        
        
        <tr>
          <td colspan="2">
            <table>
              <tr><th><a id="cql-content"><b>Content: </b></a> text/cql</th></tr>
              <tr><td><pre><code class="language-cql">/*
 * Library: IMMZD2DTHepatitisBBirthDoseLogic (IMMZ.D2.DT.Hepatitis B.Birth dose)
 * Rule: Determine if the client is due for a hepatitis B vaccination according to the national immunization schedule
 * Decision Table: Birth dose administration
 * Trigger: IMMZ.D2 Determine required vaccination(s) if any
 */
library IMMZD2DTHepatitisBBirthDoseLogic

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

include IMMZD2DTHepatitisBEncounterElements called Encounter

parameter Today Date default Today()

context Patient


/*
@dynamicValue: Guidance
*/
define &quot;Guidance&quot;:
  case 
    when &quot;Client is due for hepatitis B monovalent vaccine&quot; then &quot;Client is due for hepatitis B monovalent vaccine Guidance&quot;
    when &quot;Client should follow delayed-start decision logic&quot; then &quot;Client should follow delayed-start decision logic Guidance&quot;
    when &quot;Client is not due for the hepatitis B birth dose&quot; then &quot;Client is not due for the hepatitis B birth dose Guidance&quot; 
    else ''
  end
  
define &quot;Has Guidance&quot;:
  &quot;Guidance&quot; is not null and &quot;Guidance&quot; != ''

/*
@output: Client is due for hepatitis B monovalent vaccine
@pseudocode: &quot;Immunization recommendation status&quot; = &quot;Due&quot; (where &quot;Type of hepatitis B dose&quot; = &quot;Hepatitis B monovalent vaccine&quot;)
*/
define &quot;Client is due for hepatitis B monovalent vaccine&quot;:
  Encounter.&quot;Hepatitis B birth dose was not administered&quot;
    and Encounter.&quot;Client's age is less than {Member States defined upper limit}&quot;

/*
@output: Client is due for hepatitis B monovalent vaccine Guidance
@guidance: Should vaccinate client with hepatitis B birth dose, as a monovalent dose. Check for contraindications.
*/
define &quot;Client is due for hepatitis B monovalent vaccine Guidance&quot;:
  'Should vaccinate client with hepatitis B birth dose, as a monovalent dose. Check for contraindications.'

/*
@output: Client should follow delayed-start decision logic
@pseudocode: 
*/
define &quot;Client should follow delayed-start decision logic&quot;:
  Encounter.&quot;Hepatitis B birth dose was not administered&quot;
    and Encounter.&quot;Client's age is more than {Member States defined upper limit}&quot;

/*
@output: Client should follow delayed-start decision logic Guidance
@guidance: The client has a delayed start. Please follow the delayed start schedule.
*/
define &quot;Client should follow delayed-start decision logic Guidance&quot;:
  'The client has a delayed start. Please follow the delayed start schedule.'

/*
@output: Client is not due for the hepatitis B birth dose
@pseudocode: &quot;Immunization recommendation status&quot; = &quot;Not due&quot;
*/
define &quot;Client is not due for the hepatitis B birth dose&quot;:
  Encounter.&quot;Hepatitis B birth dose was administered&quot;

/*
@output: Client is not due for the hepatitis B birth dose Guidance
@guidance: Hepatitis B birth dose was already administered. Check hepatitis B immunization schedule.
*/
define &quot;Client is not due for the hepatitis B birth dose Guidance&quot;:
  'Hepatitis B birth dose was already administered. Check hepatitis B immunization schedule.'


/*
@test: Test expected results based on example patients
*/
define &quot;Test Validation&quot;:
  case
    when Patient.id = 'HepatitisB08.2' then &quot;Client is due for hepatitis B monovalent vaccine&quot; and &quot;Guidance&quot; = 'Should vaccinate client with hepatitis B birth dose, as a monovalent dose. Check for contraindications.'
    when Patient.id = 'HepatitisB09.2' then &quot;Client should follow delayed-start decision logic&quot; and &quot;Guidance&quot; = 'The client has a delayed start. Please follow the delayed start schedule.'
    when Patient.id = 'HepatitisB10.1' then &quot;Client is not due for the hepatitis B birth dose&quot; and &quot;Guidance&quot; = 'Hepatitis B birth dose was already administered. Check hepatitis B immunization schedule.'
    else 'No test case set'
  end
</code></pre></td></tr>
            </table>
          </td>
        </tr>
        
        
        
    </table>
</div>
</div>
  </text>
  <extension url="http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability">
    <valueCode value="computable"/>
  </extension>
  <url value="http://smart.who.int/immunizations/Library/IMMZD2DTHepatitisBBirthDoseLogic"/>
  <version value="1.0.0"/>
  <name value="IMMZD2DTHepatitisBBirthDoseLogic"/>
  <title value="IMMZD2DTHepatitisBBirthDoseLogic"/>
  <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-31T13:54:17+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.D2.DT.Hepatitis B.Birth dose decision table in the Immunization CPG"/>
  <relatedArtifact>
    <type value="depends-on"/>
    <display value="Library Encounter"/>
    <resource value="http://smart.who.int/immunizations/Library/IMMZD2DTHepatitisBEncounterElements"/>
  </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="Client is due for hepatitis B monovalent vaccine"/>
    <use value="out"/>
    <min value="0"/>
    <max value="1"/>
    <type value="boolean"/>
  </parameter>
  <parameter>
    <name value="Client is due for hepatitis B monovalent vaccine Guidance"/>
    <use value="out"/>
    <min value="0"/>
    <max value="1"/>
    <type value="string"/>
  </parameter>
  <parameter>
    <name value="Client should follow delayed-start decision logic"/>
    <use value="out"/>
    <min value="0"/>
    <max value="1"/>
    <type value="boolean"/>
  </parameter>
  <parameter>
    <name value="Client should follow delayed-start decision logic Guidance"/>
    <use value="out"/>
    <min value="0"/>
    <max value="1"/>
    <type value="string"/>
  </parameter>
  <parameter>
    <name value="Client is not due for the hepatitis B birth dose"/>
    <use value="out"/>
    <min value="0"/>
    <max value="1"/>
    <type value="boolean"/>
  </parameter>
  <parameter>
    <name value="Client is not due for the hepatitis B birth dose 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"/>
    <data value="LyoKICogTGlicmFyeTogSU1NWkQyRFRIZXBhdGl0aXNCQmlydGhEb3NlTG9naWMgKElNTVouRDIuRFQuSGVwYXRpdGlzIEIuQmlydGggZG9zZSkKICogUnVsZTogRGV0ZXJtaW5lIGlmIHRoZSBjbGllbnQgaXMgZHVlIGZvciBhIGhlcGF0aXRpcyBCIHZhY2NpbmF0aW9uIGFjY29yZGluZyB0byB0aGUgbmF0aW9uYWwgaW1tdW5pemF0aW9uIHNjaGVkdWxlCiAqIERlY2lzaW9uIFRhYmxlOiBCaXJ0aCBkb3NlIGFkbWluaXN0cmF0aW9uCiAqIFRyaWdnZXI6IElNTVouRDIgRGV0ZXJtaW5lIHJlcXVpcmVkIHZhY2NpbmF0aW9uKHMpIGlmIGFueQogKi8KbGlicmFyeSBJTU1aRDJEVEhlcGF0aXRpc0JCaXJ0aERvc2VMb2dpYwoKdXNpbmcgRkhJUiB2ZXJzaW9uICc0LjAuMScKaW5jbHVkZSBGSElSSGVscGVycyB2ZXJzaW9uICc0LjAuMScKCmluY2x1ZGUgSU1NWkQyRFRIZXBhdGl0aXNCRW5jb3VudGVyRWxlbWVudHMgY2FsbGVkIEVuY291bnRlcgoKcGFyYW1ldGVyIFRvZGF5IERhdGUgZGVmYXVsdCBUb2RheSgpCgpjb250ZXh0IFBhdGllbnQKCgovKgpAZHluYW1pY1ZhbHVlOiBHdWlkYW5jZQoqLwpkZWZpbmUgIkd1aWRhbmNlIjoKICBjYXNlIAogICAgd2hlbiAiQ2xpZW50IGlzIGR1ZSBmb3IgaGVwYXRpd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