{
  "resourceType": "Library",
  "id": "Ccczscore",
  "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;\">Ccc.Z.Score</td>\n        </tr>\n        \n\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Id: </b></th>\n            <td style=\"padding-left: 4px;\">Ccczscore</td>\n        </tr>\n        \n\n        \n        \n        <tr>\n            <th scope=\"row\"><b>Version: </b></th>\n            <td style=\"padding-left: 4px;\">0.1.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-Ccczscore.html\">Ccc.Z.Score</a></td>\n        </tr>\n        \n\n        \n        <tr>\n            <th scope=\"row\">\n                <b>\n                    \n                        Official\n                    \n                </b>\n            </th>\n            <td style=\"padding-left: 4px;\">\n                \n                <p style=\"margin-bottom: 5px;\">\n                    <span>CccZScore</span>\n                </p>\n                \n            </td>\n        </tr>\n        \n\n        \n\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://hl7.org/fhir/R4/valueset-library-type.html\">http://hl7.org/fhir/ValueSet/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-04-07 13:36:32+0000</td>\n        </tr>\n        \n\n        \n        <tr>\n            <th scope=\"row\"><b>Publisher: </b></th>\n            <td style=\"padding-left: 4px;\">World Health Organization (WHO)</td>\n        </tr>\n        \n\n        \n\n        \n\n        \n\n        \n\n        \n        <tr>\n            <th scope=\"row\"><b>Jurisdiction: </b></th>\n            <td style=\"padding-left: 4px;\">001</td>\n        </tr>\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><code>http://fhir.org/guides/who/anc-cds/Library/FHIRHelpers</code></li>\n                  \n                    <li><a href=\"Library-Cccbase.html\">CccBase</a></li>\n                  \n                    <li><code>https://smart.who.int/ccc/Library/weightforage</code></li>\n                  \n                    <li><code>https://smart.who.int/ccc/Library/anthrobase</code></li>\n                  \n                    <li><code>https://smart.who.int/ccc/Library/weightforlength</code></li>\n                  \n                    <li><code>https://smart.who.int/ccc/Library/weightforheight</code></li>\n                  \n                </ul>\n                \n                \n                \n                \n                \n            </td>\n        </tr>\n        \n\n        \n        <tr>\n          <th scope=\"row\"><b>Parameters: </b></th>\n          <td style=\"padding-left: 4px;\">\n            <table class=\"grid-dict\">\n              <tr><th><b>Name</b></th><th><b>Type</b></th><th><b>Min</b></th><th><b>Max</b></th><th><b>In/Out</b></th></tr>\n              \n                <tr><th>encounter</th><th>Encounter</th><th/><th/><th>In</th></tr>\n              \n                <tr><th>pastweight</th><th>decimal</th><th/><th/><th>Out</th></tr>\n              \n                <tr><th>patientsex</th><th>string</th><th/><th/><th>Out</th></tr>\n              \n                <tr><th>ageatpastweight</th><th>integer</th><th/><th/><th>Out</th></tr>\n              \n                <tr><th>pastweightzscore</th><th>decimal</th><th/><th/><th>Out</th></tr>\n              \n                <tr><th>pastweightactualised</th><th>decimal</th><th/><th/><th>Out</th></tr>\n              \n                <tr><th>WAZ</th><th>decimal</th><th/><th/><th>Out</th></tr>\n              \n            </table>\n          </td>\n        </tr>\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>Patient</th>\n                  <th>http://hl7.org/fhir/StructureDefinition/Patient</th>\n                  <th/>\n                  <th>\n                    \n                  </th>\n                </tr>\n              \n                <tr>\n                  <th>Encounter</th>\n                  <th>http://hl7.org/fhir/StructureDefinition/Encounter</th>\n                  <th/>\n                  <th>\n                    \n                  </th>\n                </tr>\n              \n                <tr>\n                  <th>Observation</th>\n                  <th>http://hl7.org/fhir/StructureDefinition/Observation</th>\n                  <th>;;;;;</th>\n                  <th>\n                    \n                      <b>code filter: </b>\n                      \n                      <br/>\n                      \n                      \n                      <span style=\"padding-left: 4px;\">\n                          <b>path: </b><span>code</span>\n                      </span>\n                      \n                      <br/>\n                      \n                      \n                      \n                      \n                          \n                          \n                          <p style=\"margin-bottom: 5px;\">\n                              <b>code: </b> <span>Ccc.B6.DE06</span>\n                          </p>\n                          \n                          \n                      \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\">/*\n@author: Patrick Delcroix\n@description: This library is part of the project EmCare\n*/\nlibrary emcarezscore version '1.0.1.rc12.build.156'\nusing FHIR version '4.0.1'\ninclude FHIRHelpers version '4.0.1' called FHIRHelpers \ninclude emcarebase version '1.0.1.rc12.build.156' called Base\ninclude WeightForAge version '1.0.0' called wfa\ninclude WeightForLength version '1.0.0' called wfl\ninclude WeightForHeight version '1.0.0' called wfh\n\n\n\n//codesystem &quot;EmCare&quot; : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes'\n\n\n\n//code &quot;Weight&quot;: 'EmCare.B6.DE06' from &quot;EmCare&quot; display 'Weight'\n//code &quot;Estimated Weight&quot;: 'EmCare.B6.DE08' from &quot;EmCare&quot; display 'Estimated Weight'\n//code &quot;MUAC&quot;: 'EmCare.B6.DE17' from &quot;EmCare&quot; display 'MUAC'\n//code &quot;Length&quot;: 'EmCare.B6.DE12' from &quot;EmCare&quot; display 'Length'\n//code &quot;Height&quot;: 'EmCare.B6.DE09' from &quot;EmCare&quot; display 'Height'\n\nparameter &quot;encounterid&quot; String\n\ncontext Patient\n\ndefine &quot;Weight&quot;:\n  Base.coding('EmCare.B6.DE06')\ndefine &quot;Estimated Weight&quot;:\n  Base.coding('EmCare.B6.DE08')\ndefine &quot;MUAC&quot;:\n  Base.coding('EmCare.B6.DE17')\ndefine &quot;Length&quot;:\n  Base.coding('EmCare.B6.DE12')\ndefine &quot;Height&quot;:\n  Base.coding('EmCare.B6.DE09')\ndefine &quot;Visually assess&quot;:\n  Base.coding('EmCare.B6.DE18')\ndefine &quot;Underweight&quot;:\n  Base.coding('EmCare.B6.DE20') \ndefine &quot;Severely Underweight&quot;:\n  Base.coding('EmCare.B6.DE21') \n\n/* pastweight : Previous Weight*/\ndefine &quot;pastweight&quot;:\n    if AgeInMonths()&lt; 4 and Base.HasObsHistory(&quot;Weight&quot;, 63) is not null then\n      Base.HasObsHistory(&quot;Weight&quot;, 63)  as FHIR.Quantity\n    else  if AgeInMonths()&lt; 6 and Base.HasObsHistory(&quot;Weight&quot;, 94)   is not null then\n      Base.HasObsHistory(&quot;Weight&quot;, 94)  as  FHIR.Quantity\n    else if AgeInMonths()&lt; 6 and Base.HasObsHistory(&quot;Weight&quot;, 126)   is not null then\n       Base.HasObsHistory(&quot;Weight&quot;, 126)  as FHIR.Quantity\n    else if Base.HasObsHistory(&quot;Weight&quot;, 201)  is not null then\n       Base.HasObsHistory(&quot;Weight&quot;, 201)  as FHIR.Quantity\n    else\n      null\n\n\n/* patientsex : Patient sex*/\ndefine &quot;patientsex&quot;:\n    if Patient.gender = 'female' then 'female' else 'male'\n\n/* ageatpastweight : Age at Previous Weight*/\ndefine &quot;ageatpastweight&quot;:\n    if &quot;pastweight&quot; is not null  then\n      (difference in days between Patient.birthDate and ToDate(Last([Observation:&quot;Weight&quot; ] O where  O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal )\n    else\n     null\n\n/* pastweightzscore : Z-Score at Previous Weight*/\ndefine &quot;pastweightzscore&quot;:\n    if &quot;pastweight&quot; is not null  then\n      wfa.generateZScoreWeightForAge(&quot;patientsex&quot;, &quot;ageatpastweight&quot; , ((convert &quot;pastweight&quot; to 'kg').value * ( 1.0 as System.Decimal)))\n    else\n      null\n\n/* pastweightactualised : Weight from  at Previous Weight*/\ndefine &quot;pastweightactualised&quot;:\n    if &quot;pastweightzscore&quot; is not null then\n      System.Quantity { value: Round(wfa.generateWeightFromAge(&quot;patientsex&quot;,AgeInDays() * ( 1.0 as System.Decimal ),  &quot;pastweightzscore&quot; ),2), unit: 'Kg'} \n    else \n       null\n\ndefine existingweight:\n  Base.GetObsValue(&quot;Weight&quot;)\n\ndefine existingestimnatedweight:\n  if existingweight is null then  \n    Base.GetObsValue(&quot;Estimated Weight&quot;)\n  else \n    null\n\ndefine existingheight:\n  Base.GetObsValue(&quot;Height&quot;)\n\ndefine existinglength:\n  Base.GetObsValue(&quot;Length&quot;)\n\ndefine existingmuac:\n  Base.GetObsValue(&quot;MUAC&quot;)\n\ndefine existingvisual:\n  Base.GetObsValue(&quot;Visually assess&quot;)\n\ndefine zscorefrommuac:\n  if existingmuac is null then 0.0\n  else if existingmuac &lt; 115 'mnm' then -3.0\n  else if existingmuac &lt; 125 'mnm' then -2.0\n  else 0.0\n\ndefine estimatedweight:\n  case  \n  when existingweight is not null then null\n  when existingestimnatedweight is not null then existingestimnatedweight\n  when pastweightactualised is not null then pastweightactualised\n  when AgeInMonths()&gt;24 and existingheight then weightfromheight\n  when AgeInMonths()&lt;=24 and existinglength then weightfromlength\n  else weightfromage\n  end\n\ndefine zscorefromvisual:\n    if existingvisual is not null then\n      case  \n        when existingvisual ~ &quot;Severely Underweight&quot; then -3.0\n        when existingvisual ~ &quot;Underweight&quot; then -2.0\n        else 0.0\n      end\n    else  null\n\n\ndefine weightfromlength:\n    System.Quantity { value: Round(wfl.generateWeightFromLength(&quot;patientsex&quot;,(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'}\n\ndefine weightfromheight:\n    System.Quantity { value:Round(wfh.generateWeightFromHeight(&quot;patientsex&quot;,(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'}\n\ndefine weightfromage:\n    System.Quantity { value:Round(wfa.generateWeightFromAge(&quot;patientsex&quot;,AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'}\n/*\n(convert Base.HasObs(&quot;Weight&quot;) to 'Kg') does not work, so let's assume the weight is in Kg\n*/\ndefine &quot;WAZ&quot;:\n    if existingweight is not null then\n         wfa.generateZScoreWeightForAge(&quot;patientsex&quot;, &quot;ageatpastweight&quot; , ( Base.HasObs(&quot;Weight&quot;).value * ( 1.0 as System.Decimal )))\n    else if existingmuac is not null then\n        zscorefrommuac\n    else if existingvisual then\n        zscorefromvisual\n    else null\n\n</code></pre></td></tr>\n            </table>\n          </td>\n        </tr>\n        \n        \n        \n    </table>\n</div>\n</div>"
  },
  "url": "https://smart.who.int/ccc/Library/Ccczscore",
  "identifier": [
    {
      "use": "official",
      "value": "CccZScore"
    }
  ],
  "version": "0.1.0",
  "name": "Ccczscore",
  "title": "Ccc.Z.Score",
  "status": "active",
  "type": {
    "coding": [
      {
        "system": "http://hl7.org/fhir/ValueSet/library-type",
        "code": "logic-library"
      }
    ]
  },
  "date": "2026-04-07T13:36:32+00:00",
  "publisher": "World Health Organization (WHO)",
  "contact": [
    {
      "name": "World Health Organization (WHO)",
      "telecom": [
        {
          "system": "url",
          "value": "https://www.who.int"
        }
      ]
    },
    {
      "telecom": [
        {
          "system": "url",
          "value": "https://www.who.int"
        }
      ]
    }
  ],
  "jurisdiction": [
    {
      "coding": [
        {
          "system": "http://unstats.un.org/unsd/methods/m49/m49.htm",
          "code": "001"
        }
      ]
    }
  ],
  "relatedArtifact": [
    {
      "type": "depends-on",
      "resource": "http://fhir.org/guides/who/anc-cds/Library/FHIRHelpers"
    },
    {
      "type": "depends-on",
      "resource": "https://smart.who.int/ccc/Library/Cccbase"
    },
    {
      "type": "depends-on",
      "resource": "https://smart.who.int/ccc/Library/weightforage"
    },
    {
      "type": "depends-on",
      "resource": "https://smart.who.int/ccc/Library/anthrobase"
    },
    {
      "type": "depends-on",
      "resource": "https://smart.who.int/ccc/Library/weightforlength"
    },
    {
      "type": "depends-on",
      "resource": "https://smart.who.int/ccc/Library/weightforheight"
    }
  ],
  "parameter": [
    {
      "name": "encounter",
      "use": "in",
      "type": "Encounter"
    },
    {
      "name": "pastweight",
      "use": "out",
      "type": "decimal"
    },
    {
      "name": "patientsex",
      "use": "out",
      "type": "string"
    },
    {
      "name": "ageatpastweight",
      "use": "out",
      "type": "integer"
    },
    {
      "name": "pastweightzscore",
      "use": "out",
      "type": "decimal"
    },
    {
      "name": "pastweightactualised",
      "use": "out",
      "type": "decimal"
    },
    {
      "name": "WAZ",
      "use": "out",
      "type": "decimal"
    }
  ],
  "dataRequirement": [
    {
      "type": "Patient",
      "profile": [
        "http://hl7.org/fhir/StructureDefinition/Patient"
      ]
    },
    {
      "type": "Encounter",
      "profile": [
        "http://hl7.org/fhir/StructureDefinition/Encounter"
      ]
    },
    {
      "type": "Observation",
      "profile": [
        "http://hl7.org/fhir/StructureDefinition/Observation"
      ],
      "mustSupport": [
        "code",
        "encounter.reference",
        "encounter",
        "value",
        "status"
      ],
      "codeFilter": [
        {
          "path": "code",
          "code": [
            {
              "code": "Ccc.B6.DE06"
            }
          ]
        }
      ]
    }
  ],
  "content": [
    {
      "id": "ig-loader-Ccczscore.cql",
      "contentType": "text/cql",
      "url": "Library-Ccczscore.cql"
    }
  ]
}
