Title: IMMZCommon Id: IMMZCommon Version: 0.2.0 Url: IMMZCommon Status: draft Type: system: http://terminology.hl7.org/CodeSystem/library-type code: logic-library Date: 2026-03-03 13:07:11+0000 Publisher: WHO Description: This library defines common terminologies and functions used throughout the Immunization CPG Related Artifacts: Dependencies WHOCommon Data Requirements: Type Profile MS Code Filter Medication http://hl7.org/fhir/StructureDefinition/Medication Content: text/cql library IMMZCommon#xD; #xD; using FHIR version '4.0.1'#xD; #xD; include FHIRHelpers version '4.0.1'#xD; include WHOCommon called WC#xD; #xD; /**#xD; * @description Fetches a singleton protocol applied from an immunization#xD; * @comment The protocol list from the immunization#xD; */#xD; define function Only(protocols List<FHIR.Immunization.ProtocolApplied>):#xD; singleton from protocols#xD; #xD; /**#xD; * @description Fetches a singleton protocol applied from an immunization#xD; * @comment The protocol list from the immunization#xD; */#xD; define fluent function only(protocols List<FHIR.Immunization.ProtocolApplied>):#xD; singleton from protocols#xD; #xD; /**#xD; * @description Takes the date choice of a date/string choice (for Immunization date)#xD; */#xD; define function ToDate(choice Choice<FHIR.date, FHIR.string>):#xD; case#xD; when choice is FHIR.date then#xD; choice as FHIR.date#xD; else#xD; Message(null as FHIR.date, true, '1', 'Error', 'Cannot compute a date from a String value')#xD; end#xD; #xD; /**#xD; * @description Takes the date choice of a date/string choice (for Immunization date)#xD; */#xD; define function ToDateTime(choice Choice<FHIR.dateTime, FHIR.string>):#xD; case#xD; when choice is FHIR.dateTime then#xD; choice as FHIR.dateTime#xD; else#xD; Message(null as FHIR.dateTime, true, '1', 'Error', 'Cannot compute a date from a String value')#xD; end#xD; #xD; #xD; /**#xD; * @description Takes a choice of FHIR.string and FHIR.positiveInt and ensures the result is a FHIR.positiveInt#xD; */#xD; define function ToPositiveInt(choice Choice<FHIR.positiveInt, FHIR.string>):#xD; case#xD; when choice is FHIR.positiveInt then#xD; choice as FHIR.positiveInt#xD; else#xD; Message(null as FHIR.positiveInt, true, '1', 'Error', 'Cannot compute a positive from a String value') // TODO: I'm sure that this is supported somehow?#xD; end#xD; #xD; #xD; /**#xD; * @description Takes a choice between a Medication and a CodeableConcept and returns just the code of the medication#xD; */#xD; define function ExtractMedicationCode(choice Choice<FHIR.CodeableConcept, FHIR.Reference>):#xD; case#xD; when choice is FHIR.CodeableConcept then#xD; choice as FHIR.CodeableConcept#xD; when choice is FHIR.Reference then#xD; First([Medication] M #xD; where M.id = Last(Split(choice.reference, '/'))#xD; return M.code as FHIR.CodeableConcept)#xD; else#xD; Message(null as FHIR.CodeableConcept, true, '1', 'Error', 'Cannot compute a medication code') // TODO: I'm sure that this is supported somehow?#xD; end#xD; #xD; #xD; /**#xD; * @description Takes a choice between a Medication and a CodeableConcept and returns just the code of the medication#xD; */#xD; define function ExtractMedicationInitiationDate(choice Choice<FHIR.dateTime, FHIR.Period>):#xD; case#xD; when choice is FHIR.Period then#xD; start of (choice as FHIR.Period)#xD; when choice is FHIR.dateTime then#xD; choice as FHIR.dateTime#xD; else#xD; Message(null as FHIR.dateTime, true, '1', 'Error', 'Cannot compute medication treatment initiation date') // TODO: I'm sure that this is supported somehow?#xD; end#xD; #xD; /**#xD; * @description: Gets the type of antigen dose extension value from an Immunization#xD; */#xD; define fluent function typeOfDose(immz Immunization):#xD; (First(#xD; immz.extension E where E.url = 'http://smart.who.int/immunizations/StructureDefinition/IMMZTypeOfDose'#xD; )).value as FHIR.CodeableConcept#xD; #xD; /**#xD; * @description: Gets the type of antigen dose extension value from an Immunization#xD; */#xD; define fluent function brand(immz Immunization):#xD; (First(#xD; immz.extension E where E.url = 'http://smart.who.int/immunizations/StructureDefinition/IMMZVaccineBrand'#xD; )).value as FHIR.CodeableConcept#xD; #xD; /**#xD; * @description: Gets a given immunization from a list that matches the dose number#xD; */#xD; define fluent function getDose(immunizations List<Immunization>, doseNumber String):#xD; immunizations I where#xD; exists( I.protocolApplied pa where pa.doseNumber = doseNumber )#xD; #xD; /**#xD; * @description: Gets a given immunization from a list that matches the dose number#xD; */#xD; define fluent function getDose(immunization Immunization, doseNumber String):#xD; immunization I where#xD; exists( I.protocolApplied pa where pa.doseNumber = doseNumber )#xD; #xD; /**#xD; * @description: Gets immunizations on or before a date#xD; */#xD; define fluent function onOrBefore(immunizations List<Immunization>, beforeDate Date):#xD; immunizations I where#xD; I.occurrence.toInterval() same day or before beforeDate#xD; #xD; /**#xD; * @description: Gets the series doses from an immunization#xD; */#xD; define fluent function seriesDoses(immunization Immunization):#xD; First(immunization.protocolApplied pa where pa.seriesDoses is not null).seriesDoses#xD; #xD; /**#xD; * @description: Gets observation from an encounter or on or before a date#xD; */#xD; define fluent function encounterOrOnBefore(observations List<Observation>, EncounterId String, beforeDate Date):#xD; observations O where#xD; (O.encounter.references(EncounterId)#xD; or O.effective.toInterval() starts same day or before beforeDate)#xD; #xD; /**#xD; * @description: Gets the doses from the primary series#xD; */#xD; define fluent function seriesPrimary(immunizations List<Immunization>):#xD; immunizations I where#xD; exists( I.protocolApplied pa where pa.series = 'Primary series' )#xD; #xD; /**#xD; * @description: Gets the doses from the dose 0 series#xD; */#xD; define fluent function seriesDose0(immunizations List<Immunization>):#xD; immunizations I where#xD; exists( I.protocolApplied pa where pa.series = 'Dose 0' )#xD; #xD; /**#xD; * @description: Gets the doses from the Booster series#xD; */#xD; define fluent function seriesBooster(immunizations List<Immunization>):#xD; immunizations I where#xD; exists( I.protocolApplied pa where pa.series = 'Booster dose' )#xD; #xD; /**#xD; * @description: Gets the doses from the Supplementary series#xD; */#xD; define fluent function seriesSupplementary(immunizations List<Immunization>):#xD; immunizations I where#xD; exists( I.protocolApplied pa where pa.series = 'Supplementary dose' )#xD; #xD; /**#xD; * @description: Sorts a list and returns the requested index#xD; */#xD; define fluent function sortedIndex(immunizations List<Immunization>, idx Integer):#xD; if exists( immunizations ) then#xD; (immunizations I sort by start of occurrence.toInterval())[idx]#xD; else null#xD; Content: application/elm+xml Encoded data (134572 characters)
This library defines common terminologies and functions used throughout the Immunization CPG