Id: IMMZD18SDTPPregnancyStartingWith3Doses Url: IMMZ.D18.S.DTP.Pregnancy starting with 3 doses schedule Version: 1.0.0 Title: IMMZ.D18.S.DTP.Pregnancy starting with 3 doses schedule Status: draft Type: system: http://terminology.hl7.org/CodeSystem/plan-definition-type code: eca-rule Date: 2026-03-31 13:54:17+0000 Publisher: WHO Description: IMMZ.D18.S.DTP.Pregnancy starting with 3 doses schedule Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood diphtheria–tetanus–pertussis (DTP) doses Knowledge Capability: computable Related Artifacts: References WHO recommendations for routine immunization - summary tables (January 2025) Libraries: IMMZD18SDTPPregnancyStartingWith3DosesLogic Actions: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy): Provision of tetanus and diphtheria booster dose 1 for pregnant women who received only 3 doses of DTP during childhood without booster doses Trigger event: The primary DTP series has been completed and client is currently pregnant Trigger pseudo: "Completed the primary vaccination series" = TRUE (where "Vaccine type" = "DTP-containing vaccines") AND "Currently pregnant" = TRUE Trigger date: "Contact date" WHEN "ANC contact number" = 1 Create condition: 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. If: Applicability: Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) (Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)) Then: Definition: IMMZ.D2.DT.CR Dynamic Values: status: ('active') payload.contentString: (Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Create) category.coding: (Code { system: 'http://terminology.hl7.org/CodeSystem/communication-category', code: 'alert' }) priority: (Code { system: 'http://hl7.org/fhir/request-priority', code: 'routine' }) Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy): Provision of tetanus and diphtheria booster dose 2 for pregnant women who received only 3 doses of DTP during childhood without booster doses Trigger event: First tetanus and diphtheria booster dose was administered Trigger pseudo: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 1 Trigger date: Latest "Date and time of vaccination" where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" Create condition: 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. If: Applicability: Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) (Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)) Then: Definition: IMMZ.D2.DT.CR Dynamic Values: status: ('active') payload.contentString: (Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Create) category.coding: (Code { system: 'http://terminology.hl7.org/CodeSystem/communication-category', code: 'alert' }) priority: (Code { system: 'http://hl7.org/fhir/request-priority', code: 'routine' }) Tetanus and diphtheria-containing vaccine booster dose 3: Provision of tetanus and diphtheria booster dose 3 for pregnant women who received only 3 doses of DTP during childhood without booster doses Trigger event: Second tetanus and diphtheria booster dose was administered Trigger pseudo: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 2 Trigger date: Latest "Date and time of vaccination" where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" Create condition: A sixth dose would be needed at least 1 year after the fifth dose, or during the next pregnancy. If: Applicability: Tetanus and diphtheria-containing vaccine booster dose 3 (Tetanus and diphtheria-containing vaccine booster dose 3) Then: Definition: IMMZ.D2.DT.CR Dynamic Values: status: ('active') payload.contentString: (Tetanus and diphtheria-containing vaccine booster dose 3 Create) category.coding: (Code { system: 'http://terminology.hl7.org/CodeSystem/communication-category', code: 'alert' }) priority: (Code { system: 'http://hl7.org/fhir/request-priority', code: 'routine' })
/** * @dataElement All Doses Administered to Patient */ define "Doses Administered to Patient": [Immunization] I where I.status = 'completed' and I.isSubpotent is not true
/* @internal: Td Doses Administered to Patient */ define "Td Doses Administered to Patient": Elements."Doses Administered to Patient" I where I.vaccineCode in Concepts."Tetanus and diphtheria-containing vaccines"
Td Booster Series Doses Administered to Patient
/* @internal: Td Booster Series Doses Administered to Patient */ define "Td Booster Series Doses Administered to Patient": "Td Doses Administered to Patient".seriesBooster()
/* @internal: Td Booster Series Doses Administered to Patient */ define "Td Booster Series Doses Administered to Patient": DTPElements."Td Booster Series Doses Administered to Patient".onOrBefore(Today)
Number of Td Booster Series Doses Administered
/* @internal: Number of Td Booster Series Doses Administered */ define "Number of Td Booster Series Doses Administered": Count("Td Booster Series Doses Administered to Patient")
Two tetanus and diphtheria booster doses were administered
/* @input: Two tetanus and diphtheria booster doses were administered @pseudocode: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 2 @code: Two tetanus and diphtheria booster doses were administered-140 @decision: IMMZ.D2.DT.DTP.On-time start: DTP vaccination schedule, on-time start (at ≤ 12 months of age) @decision: IMMZ.D2.DT.DTP.Delayed or interrupted series: DTP vaccination schedule for the following groups: children ≥ 1 year of age with no previous immunization, adolescents and adults with no previous immunization (including pregnant women) and supplementary immunization activities in high-risk areas, for women of reproductive age @decision: IMMZ.D2.DT.DTP.Pregnancy: Determine whether DTP-containing vaccines are needed for pregnant women @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 3 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood DTP doses @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 4 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 4 childhood DTP doses */ define "Two tetanus and diphtheria booster doses were administered": "Number of Td Booster Series Doses Administered" = 2
Second tetanus and diphtheria booster dose was administered
/* @complete: Second tetanus and diphtheria booster dose was administered @pseudocode: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 2 */ define "Second tetanus and diphtheria booster dose was administered": Encounter."Two tetanus and diphtheria booster doses were administered"
Three tetanus and diphtheria booster doses were administered
/* @input: Three tetanus and diphtheria booster doses were administered @pseudocode: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 3 @code: Three tetanus and diphtheria booster doses were administered-140 @decision: IMMZ.D2.DT.DTP.On-time start: DTP vaccination schedule, on-time start (at ≤ 12 months of age) @decision: IMMZ.D2.DT.DTP.Pregnancy: Determine whether DTP-containing vaccines are needed for pregnant women @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 3 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood DTP doses @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 4 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 4 childhood DTP doses */ define "Three tetanus and diphtheria booster doses were administered": "Number of Td Booster Series Doses Administered" = 3
Third tetanus and diphtheria-containing booster dose was administered. Tetanus and diphtheria immunization schedule has been completed
/* @complete: Third tetanus and diphtheria-containing booster dose was administered. Tetanus and diphtheria immunization schedule has been completed @pseudocode: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 3 "Immunization recommendation status" = "Complete" (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines") */ define "Third tetanus and diphtheria-containing booster dose was administered. Tetanus and diphtheria immunization schedule has been completed": Encounter."Three tetanus and diphtheria booster doses were administered"
Tetanus and diphtheria-containing vaccine booster dose 3
/* @output: Tetanus and diphtheria-containing vaccine booster dose 3 @description: Provision of tetanus and diphtheria booster dose 3 for pregnant women who received only 3 doses of DTP during childhood without booster doses @trigger: Second tetanus and diphtheria booster dose was administered @pseudo: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 2 @triggerDate: Latest "Date and time of vaccination" where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" */ define "Tetanus and diphtheria-containing vaccine booster dose 3": "Second tetanus and diphtheria booster dose was administered" and not "Third tetanus and diphtheria-containing booster dose was administered. Tetanus and diphtheria immunization schedule has been completed"
/* @internal: DTP containing Doses Administered to Patient */ define "DTP Doses Administered to Patient": Elements."Doses Administered to Patient" I where I.vaccineCode in Concepts."DTP-containing vaccines"
DTP Primary Series Doses Administered to Patient
/* @internal: DTP containing Doses Administered to Patient that are in the Primary series */ define "DTP Primary Series Doses Administered to Patient": "DTP Doses Administered to Patient".seriesPrimary()
/* @internal: DTP containing Doses Administered to Patient that are in the Primary series */ define "DTP Primary Series Doses Administered to Patient": DTPElements."DTP Primary Series Doses Administered to Patient".onOrBefore(Today)
Number of DTP Primary Series Doses Administered
/* @internal: Number of DTP Primary Series doses */ define "Number of DTP Primary Series Doses Administered": Count("DTP Primary Series Doses Administered to Patient")
Three DTP primary series doses were administered
/* @input: Three DTP primary series doses were administered @pseudocode: Count of vaccines administered (where "Vaccine type" = "DTP-containing vaccines" and "Type of dose" = "Primary series") = 3 @code: Three DTP primary series doses were administered-123 @decision: IMMZ.D2.DT.DTP.On-time start: DTP vaccination schedule, on-time start (at ≤ 12 months of age) @decision: IMMZ.D2.DT.DTP.Delayed or interrupted series: DTP vaccination schedule for the following groups: children ≥ 1 year of age with no previous immunization, adolescents and adults with no previous immunization (including pregnant women) and supplementary immunization activities in high-risk areas, for women of reproductive age @decision: IMMZ.D2.DT.DTP.Pregnancy: Determine whether DTP-containing vaccines are needed for pregnant women @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 3 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood DTP doses @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 4 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 4 childhood DTP doses */ define "Three DTP primary series doses were administered": "Number of DTP Primary Series Doses Administered" = 3
/* @internal: Potential contraindications observations */ define "Potential contraindications": ([Observation: Concepts."Potential contraindications"]).complete()
/* @internal: Observation for currently pregnant */ define "CI Currently pregnant Observation": "Potential contraindications" O where O.value ~ Concepts."CI-Currently pregnant"
/* @internal: Observation for currently pregnant */ define "CI Currently pregnant Observation": Elements."CI Currently pregnant Observation" O where O.encounter.references(EncounterId) or O.effective.toInterval() starts same day or after Today - 9 months
/* @internal: Condition for currently pregnant */ define "CI Currently pregnant Condition": [Condition: Concepts."CI-Currently pregnant"]
/* @internal: Condition for currently pregnant */ define "CI Currently pregnant Condition": Elements."CI Currently pregnant Condition" C where C.prevalenceInterval() includes Today
define "Pregnancy Status Observation": [Observation: Concepts."Pregnancy status"] O where O.status in { 'final', 'amended', 'corrected' }
define "Pregnant Observation": "Pregnancy Status Observation" O where O.value ~ Concepts."Pregnant"
define "Pregnant Observation": Elements."Pregnant Observation" O where O.encounter.references(EncounterId) or O.effective.toInterval() starts same day or after AsOf - 9 months
/* @input: The client is pregnant @pseudocode: "Potential contraindications" = "Currently pregnant" */ define "The client is pregnant": exists "CI Currently pregnant Observation" or exists "CI Currently pregnant Condition" or exists WE."Pregnant Observation"
/* @input: Client is currently pregnant @pseudocode: "Currently pregnant" = TRUE @code: Client is currently pregnant-27 @decision: IMMZ.D2.DT.DTP.Pregnancy: Determine whether DTP-containing vaccines are needed for pregnant women @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 3 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood DTP doses @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 4 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 4 childhood DTP doses */ define "Client is currently pregnant": Encounter."The client is pregnant"
One tetanus and diphtheria booster dose was administered
/* @input: One tetanus and diphtheria booster dose was administered @pseudocode: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 1 @code: One tetanus and diphtheria booster dose was administered-140 @decision: IMMZ.D2.DT.DTP.On-time start: DTP vaccination schedule, on-time start (at ≤ 12 months of age) @decision: IMMZ.D2.DT.DTP.Delayed or interrupted series: DTP vaccination schedule for the following groups: children ≥ 1 year of age with no previous immunization, adolescents and adults with no previous immunization (including pregnant women) and supplementary immunization activities in high-risk areas, for women of reproductive age @decision: IMMZ.D2.DT.DTP.Pregnancy: Determine whether DTP-containing vaccines are needed for pregnant women @decision: IMMZ.D2.DT.DTP.Pregnancy starting with 4 doses: Diphtheria and tetanus vaccination schedule in pregnant women who received 4 childhood DTP doses */ define "One tetanus and diphtheria booster dose was administered": "Number of Td Booster Series Doses Administered" = 1
First tetanus and diphtheria booster dose was administered
/* @complete: First tetanus and diphtheria booster dose was administered @pseudocode: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 1 */ define "First tetanus and diphtheria booster dose was administered": Encounter."One tetanus and diphtheria booster dose was administered"
Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)
/* @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")
Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Due Date
/* @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
Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Overdue
/* @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
Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Expiration
/* @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" < 38 weeks */ define "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Expiration": if "Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy)" then 'Two weeks before birth' else null
Tetanus and diphtheria-containing vaccine booster dose 1 (during pregnancy) Create
/* @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 ''
Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)
/* @output: Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) @description: Provision of tetanus and diphtheria booster dose 2 for pregnant women who received only 3 doses of DTP during childhood without booster doses @trigger: First tetanus and diphtheria booster dose was administered @pseudo: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 1 @triggerDate: Latest "Date and time of vaccination" where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" */ define "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)": "First tetanus and diphtheria booster dose was administered" and Encounter."Client is currently pregnant" and not "Second tetanus and diphtheria booster dose was administered"
/* @internal: Td Doses Administered to Patient */ define "Td Doses Administered to Patient": DTPElements."Td Doses Administered to Patient".onOrBefore(Today)
/* @internal: Date of Latest Td Dose */ define "Date of Latest Td Dose": date from start of "Td Doses Administered to Patient".mostRecent().occurrence.toInterval()
Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Due Date
/* @dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Due Date @pseudocode: Latest "Date and time of vaccination" (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines") + 4 'week' */ define "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Due Date": if "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)" then Encounter."Date of Latest Td Dose" + 4 weeks else null
Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Overdue
/* @dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Overdue @pseudocode: Every subsequent contact until 38 weeks */ define "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Overdue": if "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)" then Encounter."Date of Latest Td Dose" + 4 weeks else null
Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Expiration
/* @dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Expiration @pseudocode: Two weeks before birth for the pregnancy; however, individuals remain eligible to be vaccinated after giving birth. "Gestational age" < 38 weeks */ define "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Expiration": if "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy)" then 'Two weeks before birth' else null
Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Create
/* @output: Tetanus and diphtheria-containing vaccine booster dose 2 (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 2 (during pregnancy) Create": if "Tetanus and diphtheria-containing vaccine booster dose 2 (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 2 (during pregnancy) Due Date") + ' Overdue: ' + ToString("Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Overdue") + ' Expiration: ' + "Tetanus and diphtheria-containing vaccine booster dose 2 (during pregnancy) Expiration" else ''
Tetanus and diphtheria-containing vaccine booster dose 3 Due Date
/* @dynamicValue: Tetanus and diphtheria-containing vaccine booster dose 3 Due Date @pseudocode: Latest "Date and time of vaccination" (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines") + 1 year or during next pregnancy */ define "Tetanus and diphtheria-containing vaccine booster dose 3 Due Date": if "Tetanus and diphtheria-containing vaccine booster dose 3" then Encounter."Date of Latest Td Dose" + 1 year else null
Tetanus and diphtheria-containing vaccine booster dose 3 Create
/* @output: Tetanus and diphtheria-containing vaccine booster dose 3 Create @create: A sixth dose would be needed at least 1 year after the fifth dose, or during the next pregnancy. */ define "Tetanus and diphtheria-containing vaccine booster dose 3 Create": if "Tetanus and diphtheria-containing vaccine booster dose 3" then 'A sixth dose would be needed at least 1 year after the fifth dose, or during the next pregnancy.' + ' Due Date: ' + ToString("Tetanus and diphtheria-containing vaccine booster dose 3 Due Date") else ''
/** * @description: Gets immunizations on or before a date */ define fluent function onOrBefore(immunizations List<Immunization>, beforeDate Date): immunizations I where I.occurrence.toInterval() same day or before beforeDate
/* From FHIRCommon 4.1.0: */ /* @description: Normalizes a value that is a choice of timing-valued types to an equivalent interval @comment: Normalizes a choice type of FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instance, FHIR.string, FHIR.Age, or FHIR.Range types to an equivalent interval. This selection of choice types is a superset of the majority of choice types that are used as possible representations for timing-valued elements in FHIR, allowing this function to be used across any resource. The input can be provided as a dateTime, Period, Timing, instant, string, Age, or Range. The intent of this function is to provide a clear and concise mechanism to treat single elements that have multiple possible representations as intervals so that logic doesn't have to account for the variability. More complex calculations (such as medication request period or dispense period calculation) need specific guidance and consideration. That guidance may make use of this function, but the focus of this function is on single element calculations where the semantics are unambiguous. If the input is a dateTime, the result a DateTime Interval beginning and ending on that dateTime. If the input is a Period, the result is a DateTime Interval. If the input is a Timing, an error is raised indicating a single interval cannot be computed from a Timing. If the input is an instant, the result is a DateTime Interval beginning and ending on that instant. If the input is a string, an error is raised indicating a single interval cannot be computed from a string. If the input is an Age, the result is a DateTime Interval beginning when the patient was the given Age, and ending immediately prior to when the patient was the given Age plus one year. If the input is a Range, the result is a DateTime Interval beginning when the patient was the Age given by the low end of the Range, and ending immediately prior to when the patient was the Age given by the high end of the Range plus one year. NOTE: Due to the complexity of determining a single interval from a Timing or String type, this function will throw a run-time exception if it is used with a Timing or String. */ define fluent function toInterval(choice Choice<FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instant, FHIR.string, FHIR.Age, FHIR.Range>): case when choice is FHIR.dateTime then Interval[FHIRHelpers.ToDateTime(choice as FHIR.dateTime), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)] when choice is FHIR.Period then FHIRHelpers.ToInterval(choice as FHIR.Period) when choice is FHIR.instant then Interval[FHIRHelpers.ToDateTime(choice as FHIR.instant), FHIRHelpers.ToDateTime(choice as FHIR.instant)] when choice is FHIR.Age then Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age), FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age) + 1 year) when choice is FHIR.Range then Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).low), FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).high) + 1 year) when choice is FHIR.Timing then Message(null as Interval<DateTime>, true, 'NOT_IMPLEMENTED', 'Error', 'Calculation of an interval from a Timing value is not supported') when choice is FHIR.string then Message(null as Interval<DateTime>, true, 'NOT_IMPLEMENTED', 'Error', 'Calculation of an interval from a String value is not supported') else null as Interval<DateTime> end
define function ToDateTime(value dateTime): value.value
define function ToInterval(period FHIR.Period): if period is null then null else if period."start" is null then Interval(period."start".value, period."end".value] else Interval[period."start".value, period."end".value]
define function ToDateTime(value instant): value.value
define function ToDate(value date): value.value
define function ToQuantity(quantity FHIR.Quantity): case when quantity is null then null when quantity.value is null then null when quantity.comparator is not null then Message(null, true, 'FHIRHelpers.ToQuantity.ComparatorQuantityNotSupported', 'Error', 'FHIR Quantity value has a comparator and cannot be converted to a System.Quantity value.') when quantity.system is null or quantity.system.value = 'http://unitsofmeasure.org' or quantity.system.value = 'http://hl7.org/fhirpath/CodeSystem/calendar-units' then System.Quantity { value: quantity.value.value, unit: ToCalendarUnit(Coalesce(quantity.code.value, quantity.unit.value, '1')) } else Message(null, true, 'FHIRHelpers.ToQuantity.InvalidFHIRQuantity', 'Error', 'Invalid FHIR Quantity code: ' & quantity.unit.value & ' (' & quantity.system.value & '|' & quantity.code.value & ')') end
define function ToCalendarUnit(unit System.String): case unit when 'ms' then 'millisecond' when 's' then 'second' when 'min' then 'minute' when 'h' then 'hour' when 'd' then 'day' when 'wk' then 'week' when 'mo' then 'month' when 'a' then 'year' else unit end
/** * @description: Gets the doses from the Booster series */ define fluent function seriesBooster(immunizations List<Immunization>): immunizations I where exists( I.protocolApplied pa where pa.series = 'Booster dose' )
define function ToString(value string): value.value
define function ToString(value ImmunizationStatus): value.value
define function ToBoolean(value boolean): value.value
define function ToConcept(concept FHIR.CodeableConcept): if concept is null then null else System.Concept { codes: concept.coding C return ToCode(C), display: concept.text.value }
define function ToCode(coding FHIR.Coding): if coding is null then null else System.Code { code: coding.code.value, system: coding.system.value, version: coding.version.value, display: coding.display.value }
/** * @description: Gets the doses from the primary series */ define fluent function seriesPrimary(immunizations List<Immunization>): immunizations I where exists( I.protocolApplied pa where pa.series = 'Primary series' )
define fluent function complete(observations List<Observation>): observations O where O.status in { 'final', 'amended', 'corrected' }
define function ToString(value ObservationStatus): value.value
/* @description: Returns true if the given reference is to the given resourceId @comment: Returns true if the `resourceId` parameter exactly equals the tail of the given reference. NOTE: This function assumes resources from the same source server. */ define fluent function references(reference FHIR.Reference, resourceId String): resourceId = Last(Split(reference.reference, '/'))
/* @description: Returns an interval representing the normalized prevalence period of a given Condition resource. @comment: Uses the toInterval and toAbatementInterval functions to determine the widest potential interval from onset to abatement as specified in the given Condition. */ define fluent function prevalenceInterval(condition Condition): if condition.clinicalStatus ~ "active" or condition.clinicalStatus ~ "recurrence" or condition.clinicalStatus ~ "relapse" then Interval[start of condition.onset.toInterval(), end of condition.abatementInterval()] else (end of condition.abatementInterval()) abatementDate return if abatementDate is null then Interval[start of condition.onset.toInterval(), abatementDate) else Interval[start of condition.onset.toInterval(), abatementDate]
// Was getting error on this for this particular choice set not being found /* @description: Returns an interval representing the normalized Abatement of a given Condition resource. @comment: NOTE: Due to the complexity of determining an interval from a String, this function will throw a run-time exception if used with a Condition instance that has a String as the abatement value. */ define fluent function abatementInterval(condition Condition): if condition.abatement is FHIR.dateTime then Interval[FHIRHelpers.ToDateTime(condition.abatement as FHIR.dateTime), FHIRHelpers.ToDateTime(condition.abatement as FHIR.dateTime)] else if condition.abatement is FHIR.Period then FHIRHelpers.ToInterval(condition.abatement as FHIR.Period) else if condition.abatement is FHIR.string then Message(null as Interval<DateTime>, true, 'NOT_IMPLEMENTED', 'Error', 'Calculation of an interval from a String value is not supported') else if condition.abatement is FHIR.Age then Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(condition.abatement as FHIR.Age), FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(condition.abatement as FHIR.Age) + 1 year) else if condition.abatement is FHIR.Range then Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((condition.abatement as FHIR.Range).low), FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((condition.abatement as FHIR.Range).high) + 1 year) else if condition.abatement is FHIR.boolean then Interval[end of condition.onset.toInterval(), condition.recordedDate) else null
define fluent function mostRecent(immunizations List<Immunization>): Last( immunizations I sort by start of occurrence.toInterval() )
Code system ConditionClinicalStatusCodes
Value set Tetanus and diphtheria-containing vaccines
IMMZ.D18.S.DTP.Pregnancy starting with 3 doses schedule
IMMZ.D18.S.DTP.Pregnancy starting with 3 doses schedule Diphtheria and tetanus vaccination schedule in pregnant women who received 3 childhood diphtheria–tetanus–pertussis (DTP) doses
WHO recommendations for routine immunization - summary tables (January 2025)
Provision of tetanus and diphtheria booster dose 1 for pregnant women who received only 3 doses of DTP during childhood without booster doses Trigger event: The primary DTP series has been completed and client is currently pregnant Trigger pseudo: "Completed the primary vaccination series" = TRUE (where "Vaccine type" = "DTP-containing vaccines") AND "Currently pregnant" = TRUE Trigger date: "Contact date" WHEN "ANC contact number" = 1 Create condition: 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.
Code { system: 'http://terminology.hl7.org/CodeSystem/communication-category', code: 'alert' }
Code { system: 'http://hl7.org/fhir/request-priority', code: 'routine' }
Provision of tetanus and diphtheria booster dose 2 for pregnant women who received only 3 doses of DTP during childhood without booster doses Trigger event: First tetanus and diphtheria booster dose was administered Trigger pseudo: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 1 Trigger date: Latest "Date and time of vaccination" where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" Create condition: 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.
Provision of tetanus and diphtheria booster dose 3 for pregnant women who received only 3 doses of DTP during childhood without booster doses Trigger event: Second tetanus and diphtheria booster dose was administered Trigger pseudo: Count of vaccines administered (where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" and "Type of dose" = "Booster dose") = 2 Trigger date: Latest "Date and time of vaccination" where "Vaccine type" = "Tetanus and diphtheria-containing vaccines" Create condition: A sixth dose would be needed at least 1 year after the fifth dose, or during the next pregnancy.