WHO Immunization Implementation Guide
1.0.0 - release
WHO Immunization Implementation Guide, published by WHO. This guide is not an authorized publication; it is the continuous build for version 1.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/WorldHealthOrganization/smart-immunizations/tree/132/merge and changes regularly. See the Directory of published versions
| Draft as of 2026-03-31 |
{
"resourceType" : "Library",
"id" : "IMMZCommon",
"meta" : {
"profile" : [
🔗 "http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-shareablelibrary"🔗 ,
"http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-publishablelibrary"🔗 ,
"http://hl7.org/fhir/uv/cql/StructureDefinition/cql-library"🔗 ,
"http://hl7.org/fhir/uv/cql/StructureDefinition/cql-module"
]
},
"text" : {
"status" : "extensions",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n<div>\n <table class=\"grid dict\">\n \n \n <tr>\n <th scope=\"row\"><b>Title: </b></th>\n <td style=\"padding-left: 4px;\">IMMZCommon</td>\n </tr>\n \n\n \n \n <tr>\n <th scope=\"row\"><b>Id: </b></th>\n <td style=\"padding-left: 4px;\">IMMZCommon</td>\n </tr>\n \n\n \n \n <tr>\n <th scope=\"row\"><b>Version: </b></th>\n <td style=\"padding-left: 4px;\">1.0.0</td>\n </tr>\n \n\n \n <tr>\n <th scope=\"row\"><b>Url: </b></th>\n <td style=\"padding-left: 4px;\"><a href=\"Library-IMMZCommon.html\">IMMZCommon</a></td>\n </tr>\n \n\n \n\n \n\n \n <tr>\n <th scope=\"row\"><b>Status: </b></th>\n <td style=\"padding-left: 4px;\">draft</td>\n </tr>\n \n\n \n\n \n <tr>\n <th scope=\"row\"><b>Type: </b></th>\n <td style=\"padding-left: 4px;\">\n \n \n \n <p style=\"margin-bottom: 5px;\">\n <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>\n </p>\n \n \n <p style=\"margin-bottom: 5px;\">\n <b>code: </b> <span>logic-library</span>\n </p>\n \n \n \n \n \n </td>\n </tr>\n \n\n \n\n \n <tr>\n <th scope=\"row\"><b>Date: </b></th>\n <td style=\"padding-left: 4px;\">2026-03-31 13:54:17+0000</td>\n </tr>\n \n\n \n <tr>\n <th scope=\"row\"><b>Publisher: </b></th>\n <td style=\"padding-left: 4px;\">WHO</td>\n </tr>\n \n\n \n <tr>\n <th scope=\"row\"><b>Description: </b></th>\n <td style=\"padding-left: 4px;\"><div><p>This library defines common terminologies and functions used throughout the Immunization CPG</p>\n</div></td>\n </tr>\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n <tr>\n <th scope=\"row\"><b>Related Artifacts: </b></th>\n <td style=\"padding-left: 4px;\">\n \n \n \n <p><b>Dependencies</b></p>\n <ul>\n \n <li><a href=\"Library-WHOCommon.html\">WHOCommon</a></li>\n \n </ul>\n \n \n \n \n \n </td>\n </tr>\n \n\n \n\n \n <tr>\n <th scope=\"row\"><b>Data Requirements:</b></th>\n <td style=\"padding-left: 4px;\">\n <table class=\"grid-dict\">\n <tr><th><b>Type</b></th><th><b>Profile</b></th><th><b>MS</b></th><th><b>Code Filter</b></th></tr>\n \n <tr>\n <th>Medication</th>\n <th>http://hl7.org/fhir/StructureDefinition/Medication</th>\n <th/>\n <th>\n \n </th>\n </tr>\n \n </table>\n </td>\n </tr>\n \n\n \n \n <tr>\n <td colspan=\"2\">\n <table>\n <tr><th><a id=\"cql-content\"><b>Content: </b></a> text/cql</th></tr>\n <tr><td><pre><code class=\"language-cql\">library IMMZCommon\r\n\r\nusing FHIR version '4.0.1'\r\n\r\ninclude FHIRHelpers version '4.0.1'\r\ninclude WHOCommon called WC\r\n\r\n/**\r\n * @description Fetches a singleton protocol applied from an immunization\r\n * @comment The protocol list from the immunization\r\n */\r\ndefine function Only(protocols List<FHIR.Immunization.ProtocolApplied>):\r\n singleton from protocols\r\n\r\n/**\r\n * @description Fetches a singleton protocol applied from an immunization\r\n * @comment The protocol list from the immunization\r\n */\r\ndefine fluent function only(protocols List<FHIR.Immunization.ProtocolApplied>):\r\n singleton from protocols\r\n\r\n/**\r\n * @description Takes the date choice of a date/string choice (for Immunization date)\r\n */\r\ndefine function ToDate(choice Choice<FHIR.date, FHIR.string>):\r\n case\r\n\t when choice is FHIR.date then\r\n \tchoice as FHIR.date\r\n\t\telse\r\n Message(null as FHIR.date, true, '1', 'Error', 'Cannot compute a date from a String value')\r\n\tend\r\n\r\n/**\r\n * @description Takes the date choice of a date/string choice (for Immunization date)\r\n */\r\ndefine function ToDateTime(choice Choice<FHIR.dateTime, FHIR.string>):\r\n case\r\n\t when choice is FHIR.dateTime then\r\n \tchoice as FHIR.dateTime\r\n\t\telse\r\n Message(null as FHIR.dateTime, true, '1', 'Error', 'Cannot compute a date from a String value')\r\n\tend\r\n\r\n\r\n/**\r\n * @description Takes a choice of FHIR.string and FHIR.positiveInt and ensures the result is a FHIR.positiveInt\r\n */\r\ndefine function ToPositiveInt(choice Choice<FHIR.positiveInt, FHIR.string>):\r\n case\r\n\t when choice is FHIR.positiveInt then\r\n \tchoice as FHIR.positiveInt\r\n\t\telse\r\n 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?\r\n\tend\r\n\r\n\r\n/**\r\n * @description Takes a choice between a Medication and a CodeableConcept and returns just the code of the medication\r\n */\r\ndefine function ExtractMedicationCode(choice Choice<FHIR.CodeableConcept, FHIR.Reference>):\r\n case\r\n\t when choice is FHIR.CodeableConcept then\r\n \tchoice as FHIR.CodeableConcept\r\n when choice is FHIR.Reference then\r\n First([Medication] M \r\n where M.id = Last(Split(choice.reference, '/'))\r\n return M.code as FHIR.CodeableConcept)\r\n\t\telse\r\n Message(null as FHIR.CodeableConcept, true, '1', 'Error', 'Cannot compute a medication code') // TODO: I'm sure that this is supported somehow?\r\n\tend\r\n\r\n\r\n/**\r\n * @description Takes a choice between a Medication and a CodeableConcept and returns just the code of the medication\r\n */\r\ndefine function ExtractMedicationInitiationDate(choice Choice<FHIR.dateTime, FHIR.Period>):\r\n case\r\n\t when choice is FHIR.Period then\r\n \tstart of (choice as FHIR.Period)\r\n when choice is FHIR.dateTime then\r\n choice as FHIR.dateTime\r\n\t\telse\r\n Message(null as FHIR.dateTime, true, '1', 'Error', 'Cannot compute medication treatment initiation date') // TODO: I'm sure that this is supported somehow?\r\n\tend\r\n\r\n/**\r\n * @description: Gets the type of antigen dose extension value from an Immunization\r\n */\r\ndefine fluent function typeOfDose(immz Immunization):\r\n (First(\r\n immz.extension E where E.url = 'http://smart.who.int/immunizations/StructureDefinition/IMMZTypeOfDose'\r\n )).value as FHIR.CodeableConcept\r\n\r\n/**\r\n * @description: Gets the type of antigen dose extension value from an Immunization\r\n */\r\ndefine fluent function brand(immz Immunization):\r\n (First(\r\n immz.extension E where E.url = 'http://smart.who.int/immunizations/StructureDefinition/IMMZVaccineBrand'\r\n )).value as FHIR.CodeableConcept\r\n\r\n/**\r\n * @description: Gets a given immunization from a list that matches the dose number\r\n */\r\ndefine fluent function getDose(immunizations List<Immunization>, doseNumber String):\r\n immunizations I where\r\n exists( I.protocolApplied pa where pa.doseNumber = doseNumber )\r\n\r\n/**\r\n * @description: Gets a given immunization from a list that matches the dose number\r\n */\r\ndefine fluent function getDose(immunization Immunization, doseNumber String):\r\n immunization I where\r\n exists( I.protocolApplied pa where pa.doseNumber = doseNumber )\r\n\r\n/**\r\n * @description: Gets immunizations on or before a date\r\n */\r\ndefine fluent function onOrBefore(immunizations List<Immunization>, beforeDate Date):\r\n immunizations I where\r\n I.occurrence.toInterval() same day or before beforeDate\r\n\r\n/**\r\n * @description: Gets the series doses from an immunization\r\n */\r\ndefine fluent function seriesDoses(immunization Immunization):\r\n First(immunization.protocolApplied pa where pa.seriesDoses is not null).seriesDoses\r\n\r\n/**\r\n * @description: Gets observation from an encounter or on or before a date\r\n */\r\ndefine fluent function encounterOrOnBefore(observations List<Observation>, EncounterId String, beforeDate Date):\r\n observations O where\r\n (O.encounter.references(EncounterId)\r\n or O.effective.toInterval() starts same day or before beforeDate)\r\n\r\n/**\r\n * @description: Gets the doses from the primary series\r\n */\r\ndefine fluent function seriesPrimary(immunizations List<Immunization>):\r\n immunizations I where\r\n exists( I.protocolApplied pa where pa.series = 'Primary series' )\r\n\r\n/**\r\n * @description: Gets the doses from the dose 0 series\r\n */\r\ndefine fluent function seriesDose0(immunizations List<Immunization>):\r\n immunizations I where\r\n exists( I.protocolApplied pa where pa.series = 'Dose 0' )\r\n\r\n/**\r\n * @description: Gets the doses from the Booster series\r\n */\r\ndefine fluent function seriesBooster(immunizations List<Immunization>):\r\n immunizations I where\r\n exists( I.protocolApplied pa where pa.series = 'Booster dose' )\r\n\r\n/**\r\n * @description: Gets the doses from the Supplementary series\r\n */\r\ndefine fluent function seriesSupplementary(immunizations List<Immunization>):\r\n immunizations I where\r\n exists( I.protocolApplied pa where pa.series = 'Supplementary dose' )\r\n\r\n/**\r\n * @description: Sorts a list and returns the requested index\r\n */\r\ndefine fluent function sortedIndex(immunizations List<Immunization>, idx Integer):\r\n if exists( immunizations ) then\r\n (immunizations I sort by start of occurrence.toInterval())[idx]\r\n else null\r\n</code></pre></td></tr>\n </table>\n </td>\n </tr>\n \n \n \n </table>\n</div>\n</div>"
},
"extension" : [
{
"url" : "http://hl7.org/fhir/StructureDefinition/cqf-knowledgeCapability",
"valueCode" : "computable"
}
],
"url" : "http://smart.who.int/immunizations/Library/IMMZCommon",
"version" : "1.0.0",
"name" : "IMMZCommon",
"title" : "IMMZCommon",
"status" : "draft",
"experimental" : false,
"type" : {
"coding" : [
{
"system" : "http://terminology.hl7.org/CodeSystem/library-type",
"code" : "logic-library"
}
]
},
"date" : "2026-03-31T13:54:17+00:00",
"publisher" : "WHO",
"contact" : [
{
"name" : "WHO",
"telecom" : [
{
"system" : "url",
"value" : "http://who.int"
}
]
}
],
"description" : "This library defines common terminologies and functions used throughout the Immunization CPG",
"relatedArtifact" : [
{
"type" : "depends-on",
"display" : "Library WC",
"resource" : "http://smart.who.int/immunizations/Library/WHOCommon"
}
],
"dataRequirement" : [
{
"type" : "Medication",
"profile" : [
🔗 "http://hl7.org/fhir/StructureDefinition/Medication"
]
}
],
"content" : [
{
"contentType" : "text/cql",
"data" : "bGlicmFyeSBJTU1aQ29tbW9uDQoNCnVzaW5nIEZISVIgdmVyc2lvbiAnNC4wLjEnDQoNCmluY2x1ZGUgRkhJUkhlbHBlcnMgdmVyc2lvbiAnNC4wLjEnDQppbmNsdWRlIFdIT0NvbW1vbiBjYWxsZWQgV0MNCg0KLyoqDQogKiBAZGVzY3JpcHRpb24gRmV0Y2hlcyBhIHNpbmdsZXRvbiBwcm90b2NvbCBhcHBsaWVkIGZyb20gYW4gaW1tdW5pemF0aW9uDQogKiBAY29tbWVudCBUaGUgcHJvdG9jb2wgbGlzdCBmcm9tIHRoZSBpbW11bml6YXRpb24NCiAqLw0KZGVmaW5lIGZ1bmN0aW9uIE9ubHkocHJvdG9jb2xzIExpc3Q8RkhJUi5JbW11bml6YXRpb24uUHJvdG9jb2xBcHBsaWVkPik6DQogIHNpbmdsZXRvbiBmcm9tIHByb3RvY29scw0KDQovKioNCiAqIEBkZXNjcmlwdGlvbiBGZXRjaGVzIGEgc2luZ2xldG9uIHByb3RvY29sIGFwcGxpZWQgZnJvbSBhbiBpbW11bml6YXRpb24NCiAqIEBjb21tZW50IFRoZSBwcm90b2NvbCBsaXN0IGZyb20gdGhlIGltbXVuaXphdGlvbg0KICovDQpkZWZpbmUgZmx1ZW50IGZ1bmN0aW9uIG9ubHkocHJvdG9jb2xzIExpc3Q8RkhJUi5JbW11bml6YXRpb24uUHJvdG9jb2xBcHBsaWVkPik6DQogIHNpbmdsZXRvbiBmcm9tIHByb3RvY29scw0KDQovKioNCiAqIEBkZXNjcmlwdGlvbiBUYWtlcyB0aGUgZGF0ZSBjaG9pY2Ugb2YgYSBkYXRlL3N0cmluZyBjaG9pY2UgKGZvciBJbW11bml6YXRpb24gZG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