# Ccc.Z.Score - WHO FHIR Implementation Guide (IG): Integrated Management of Childhood Illness (IMCI) in emergencies v0.1.0

* [**Table of Contents**](toc.md)
* [**Artifacts Summary**](artifacts.md)
* **Ccc.Z.Score**

## Library: Ccc.Z.Score 

| | |
| :--- | :--- |
| *Official URL*:https://smart.who.int/ccc/Library/Ccczscore | *Version*:0.1.0 |
| Active as of 2026-04-07 | *Computable Name*:Ccczscore |
| *Other Identifiers:*CccZScore (use: official, ) | |

* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: **Id: **
  * ?: Ccczscore
* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: **Version: **
  * ?: 0.1.0
* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: **Url: **
  * ?: [Ccc.Z.Score](Library-Ccczscore.md)
* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: ** Official **
  * ?:  CccZScore 
* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: **Date: **
  * ?: 2026-04-07 13:42:05+0000
* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: **Publisher: **
  * ?: World Health Organization (WHO)
* * **Content: **text/cql: ````/* @author: Patrick Delcroix @description: This library is part of the project EmCare */ library emcarezscore version '1.0.1.rc12.build.156' using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers include emcarebase version '1.0.1.rc12.build.156' called Base include WeightForAge version '1.0.0' called wfa include WeightForLength version '1.0.0' called wfl include WeightForHeight version '1.0.0' called wfh //codesystem "EmCare" : 'https://fhir.dk.swisstph-mis.ch/matchbox/fhir/CodeSystem/emcare-custom-codes' //code "Weight": 'EmCare.B6.DE06' from "EmCare" display 'Weight' //code "Estimated Weight": 'EmCare.B6.DE08' from "EmCare" display 'Estimated Weight' //code "MUAC": 'EmCare.B6.DE17' from "EmCare" display 'MUAC' //code "Length": 'EmCare.B6.DE12' from "EmCare" display 'Length' //code "Height": 'EmCare.B6.DE09' from "EmCare" display 'Height' parameter "encounterid" String context Patient define "Weight": Base.coding('EmCare.B6.DE06') define "Estimated Weight": Base.coding('EmCare.B6.DE08') define "MUAC": Base.coding('EmCare.B6.DE17') define "Length": Base.coding('EmCare.B6.DE12') define "Height": Base.coding('EmCare.B6.DE09') define "Visually assess": Base.coding('EmCare.B6.DE18') define "Underweight": Base.coding('EmCare.B6.DE20') define "Severely Underweight": Base.coding('EmCare.B6.DE21') /* pastweight : Previous Weight*/ define "pastweight": if AgeInMonths()< 4 and Base.HasObsHistory("Weight", 63) is not null then Base.HasObsHistory("Weight", 63) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 94) is not null then Base.HasObsHistory("Weight", 94) as FHIR.Quantity else if AgeInMonths()< 6 and Base.HasObsHistory("Weight", 126) is not null then Base.HasObsHistory("Weight", 126) as FHIR.Quantity else if Base.HasObsHistory("Weight", 201) is not null then Base.HasObsHistory("Weight", 201) as FHIR.Quantity else null /* patientsex : Patient sex*/ define "patientsex": if Patient.gender = 'female' then 'female' else 'male' /* ageatpastweight : Age at Previous Weight*/ define "ageatpastweight": if "pastweight" is not null then (difference in days between Patient.birthDate and ToDate(Last([Observation:"Weight" ] O where O.status in { 'final', 'amended', 'corrected'}).issued) ) * ( 1.0 as System.Decimal ) else null /* pastweightzscore : Z-Score at Previous Weight*/ define "pastweightzscore": if "pastweight" is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ((convert "pastweight" to 'kg').value * ( 1.0 as System.Decimal))) else null /* pastweightactualised : Weight from at Previous Weight*/ define "pastweightactualised": if "pastweightzscore" is not null then System.Quantity { value: Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), "pastweightzscore" ),2), unit: 'Kg'} else null define existingweight: Base.GetObsValue("Weight") define existingestimnatedweight: if existingweight is null then Base.GetObsValue("Estimated Weight") else null define existingheight: Base.GetObsValue("Height") define existinglength: Base.GetObsValue("Length") define existingmuac: Base.GetObsValue("MUAC") define existingvisual: Base.GetObsValue("Visually assess") define zscorefrommuac: if existingmuac is null then 0.0 else if existingmuac < 115 'mnm' then -3.0 else if existingmuac < 125 'mnm' then -2.0 else 0.0 define estimatedweight: case when existingweight is not null then null when existingestimnatedweight is not null then existingestimnatedweight when pastweightactualised is not null then pastweightactualised when AgeInMonths()>24 and existingheight then weightfromheight when AgeInMonths()<=24 and existinglength then weightfromlength else weightfromage end define zscorefromvisual: if existingvisual is not null then case when existingvisual ~ "Severely Underweight" then -3.0 when existingvisual ~ "Underweight" then -2.0 else 0.0 end else null define weightfromlength: System.Quantity { value: Round(wfl.generateWeightFromLength("patientsex",(convert existinglength to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromheight: System.Quantity { value:Round(wfh.generateWeightFromHeight("patientsex",(convert existingheight to 'cm').value * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} define weightfromage: System.Quantity { value:Round(wfa.generateWeightFromAge("patientsex",AgeInDays() * ( 1.0 as System.Decimal ), zscorefrommuac),2), unit: 'Kg'} /* (convert Base.HasObs("Weight") to 'Kg') does not work, so let's assume the weight is in Kg */ define "WAZ": if existingweight is not null then wfa.generateZScoreWeightForAge("patientsex", "ageatpastweight" , ( Base.HasObs("Weight").value * ( 1.0 as System.Decimal ))) else if existingmuac is not null then zscorefrommuac else if existingvisual then zscorefromvisual else null ````: **Jurisdiction: **
  * ?: 001



## Resource Content

```json
{
  "resourceType" : "Library",
  "id" : "Ccczscore",
  "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:42:05+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",
    "data" : " "
  }]
}

```
