{
  "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;\">0.2.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-29 17:23:09+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&lt;FHIR.Immunization.ProtocolApplied&gt;):\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&lt;FHIR.Immunization.ProtocolApplied&gt;):\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&lt;FHIR.date, FHIR.string&gt;):\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&lt;FHIR.dateTime, FHIR.string&gt;):\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&lt;FHIR.positiveInt, FHIR.string&gt;):\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&lt;FHIR.CodeableConcept, FHIR.Reference&gt;):\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&lt;FHIR.dateTime, FHIR.Period&gt;):\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&lt;Immunization&gt;, 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&lt;Immunization&gt;, 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&lt;Observation&gt;, 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&lt;Immunization&gt;):\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&lt;Immunization&gt;):\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&lt;Immunization&gt;):\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&lt;Immunization&gt;):\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&lt;Immunization&gt;, 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        \n        \n        <tr>\n          <td colspan=\"2\">\n            <table>\n              <tr><th><b>Content: </b> application/elm+xml</th></tr>\n              <tr><td><pre><code>Encoded data (134572 characters)</code></pre></td></tr>\n            </table>\n          </td>\n        </tr>\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": "0.2.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-29T17:23:09+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",
      "url": "Library-IMMZCommon.cql"
    },
    {
      "contentType": "application/elm+xml",
      "url": "Library-IMMZCommon.elm.xml"
    }
  ]
}
