<?xml version='1.0' encoding='UTF-8'?>
<Library xmlns="http://hl7.org/fhir" xmlns:html="http://www.w3.org/1999/xhtml">
  <id value="IMMZD18SDTPPregnancyStartingWith3DosesLogic" />
  <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:p><html:b style="color: maroon">Exception parsing generated Narrative (see /tmp/liquid-8c60c021-f1dc-4716-a92f-0d9ce32b5632.html): Unable to Parse HTML - node 'code' has unexpected content ' ' (last text = '/*
 * Library: IMMZD18SDTPPregnancyStartingWith3DosesLogic (IMMZ.D18.S.DTP.Pregnancy starting with 3 doses schedule)
 * Schedule Table: Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood diphtheria–tetanus–pertussis (DTP) doses
 */
library IMMZD18SDTPPregnancyStartingWith3DosesLogic

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

include WHOCommon called WC

include IMMZCommon called Common
include IMMZConcepts called Concepts

include IMMZEncounterElements called IE
include IMMZD2DTDTPEncounterElements called Encounter

parameter Today Date default Today()


context Patient


/*
@output: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)
@description: Provision of tetanus and diphtheria booster dose 1 for pregnant women who received only 3 doses of DTP during childhood without booster doses
@trigger: The primary DTP series has been completed and client is currently pregnant
@pseudo: "Completed the primary vaccination series" = TRUE (where "Vaccine type" = "DTP-containing vaccines") AND "Currently pregnant" = TRUE
@triggerDate: "Contact date" WHEN "ANC contact number" = 1
*/
define "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)":
  Encounter."Three DTP primary series doses were administered"
  and Encounter."Client is currently pregnant"
  and not("First tetanus and diphtheria booster dose was administered")


/*
@output: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Create
@create: Pregnant women who have received only 3 doses of tetanus-containing vaccines during childhood without booster doses should receive 2 doses of tetanus-containing vaccines at the earliest opportunity during pregnancy with a minimal interval of 4 weeks between doses and the second dose at least 2 weeks before giving birth.
*/
define "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Create":
  if "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)"
  then 'Pregnant women who have received only 3 doses of tetanus-containing vaccines during childhood without booster doses should receive 2 doses of tetanus-containing vaccines at the earliest opportunity during pregnancy with a minimal interval of 4 weeks between doses and the second dose at least 2 weeks before giving birth.' + '
Due Date: ' + ToString("Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Due Date") + '
Overdue: ' + ToString("Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Overdue") + '
Expiration: ' + "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Expiration"
  else ''


/*
@dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Due Date
@pseudocode: "Contact date" WHEN "ANC contact number" = 1
*/
define "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Due Date":
  if "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)" then Today
  else null


/*
@dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Overdue
@pseudocode: Every subsequent contact until 38 weeks
*/
define "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Overdue":
  if "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)" then Today
  else null


/*
@dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Expiration
@pseudocode: Two weeks before birth for the pregnancy; however, individuals remain eligible to be vaccinated.
"Gestational age" ' at line 278 column 20</html:b></html:p></html:div>
  </text>
  <extension url="http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability">
    <valueCode value="computable" />
  </extension>
  <url value="http://smart.who.int/immunizations/Library/IMMZD18SDTPPregnancyStartingWith3DosesLogic" />
  <version value="1.0.0" />
  <name value="IMMZD18SDTPPregnancyStartingWith3DosesLogic" />
  <title value="IMMZD18SDTPPregnancyStartingWith3DosesLogic" />
  <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-10-02T09:24:37+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.D18.S.DTP.Pregnancy starting with 3 doses schedule table in the Immunization CPG" />
  <relatedArtifact>
    <type value="depends-on" />
    <display value="Library WC" />
    <resource value="http://smart.who.int/immunizations/Library/WHOCommon" />
  </relatedArtifact>
  <relatedArtifact>
    <type value="depends-on" />
    <display value="Library Common" />
    <resource value="http://smart.who.int/immunizations/Library/IMMZCommon" />
  </relatedArtifact>
  <relatedArtifact>
    <type value="depends-on" />
    <display value="Library Concepts" />
    <resource value="http://smart.who.int/immunizations/Library/IMMZConcepts" />
  </relatedArtifact>
  <relatedArtifact>
    <type value="depends-on" />
    <display value="Library IE" />
    <resource value="http://smart.who.int/immunizations/Library/IMMZEncounterElements" />
  </relatedArtifact>
  <relatedArtifact>
    <type value="depends-on" />
    <display value="Library Encounter" />
    <resource value="http://smart.who.int/immunizations/Library/IMMZD2DTDTPEncounterElements" />
  </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="First tetanus and diphtheria booster dose was administered" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Due Date" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="date" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Overdue" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="date" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Expiration" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Create" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Second tetanus and diphtheria booster dose was administered" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Due Date" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="date" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Overdue" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="date" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Expiration" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Create" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Third tetanus and diphtheria-containing booster dose was administered. Tetanus and diphtheria immunization schedule has been completed" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 3" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="boolean" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 3 Due Date" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="date" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 3 Create" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="string" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 3 Overdue" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="Resource" />
  </parameter>
  <parameter>
    <name value="Tetanus and diphtheria-containing vaccine booster dose 3 Expiration" />
    <use value="out" />
    <min value="0" />
    <max value="1" />
    <type value="Resource" />
  </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-IMMZD18SDTPPregnancyStartingWith3DosesLogic.cql" /></content>
  <content>
    <contentType value="application/elm+xml" />
    <url value="Library-IMMZD18SDTPPregnancyStartingWith3DosesLogic.elm.xml" /></content>
</Library>