WHO Clinical Care in Crisis Implementation Guide for Children
0.1.0 - ci-build

WHO Clinical Care in Crisis Implementation Guide for Children - Local Development build (v0.1.0). See the Directory of published versions

Library: LengthForAge

Official URL: https://fhir.dk.swisstph-mis.ch/matchbox/fhir/Library/LengthForAge Version: 0.1.0
Active as of 2023-10-04 Computable Name: LengthForAge

Related Artifacts

depends-onanthrobase
depends-onhttp://fhir.org/guides/who/anc-cds/Library/FHIRHelpers

Parameters

zscoreindecimal
Ageindecimal
sexindecimal
generateLengthFromAgeoutdecimal
generateZScoreLengthForAgeoutdecimal
ZscoreLengthForAgetables_soutdecimal
ZscoreLengthForAgetables_moutdecimal
ZscoreLengthForAgetables_loutdecimal

Data Requirements

Type: Patient (Patient)

Contents

text/cql


library LengthForAge version '1.0.4'
using FHIR version '4.0.1'
include anthrobase version '1.0.4' called base
include FHIRHelpers version '4.0.1' called FHIRHelpers

// Antrho library for LengthForAge  Z-Score from the lenanthro files
codesystem "administrative-gender": 'http://hl7.org/fhir/administrative-gender'
//code "Female" : 'female' from "administrative-gender"  display 'Female'


define LengthForAgeFemale:
{
	{y:0.0,l:1.0,s:0.0379,m:49.1477},
	{y:1.0,l:1.0,s:0.03783,m:49.3166},
	{y:2.0,l:1.0,s:0.03776,m:49.4854},
	{y:3.0,l:1.0,s:0.0377,m:49.6543},
	{y:4.0,l:1.0,s:0.03763,m:49.8232},
	{y:5.0,l:1.0,s:0.03756,m:49.9921},
	{y:6.0,l:1.0,s:0.03749,m:50.1609},
	{y:7.0,l:1.0,s:0.03742,m:50.3298},
	{y:8.0,l:1.0,s:0.03735,m:50.4987},
	{y:9.0,l:1.0,s:0.03728,m:50.6676},
	{y:10.0,l:1.0,s:0.03722,m:50.8365},
	{y:11.0,l:1.0,s:0.03715,m:51.0053},
	{y:12.0,l:1.0,s:0.03708,m:51.1742},
	{y:13.0,l:1.0,s:0.03701,m:51.3431},
	{y:14.0,l:1.0,s:0.03694,m:51.512},
	{y:15.0,l:1.0,s:0.0369,m:51.651},
	{y:16.0,l:1.0,s:0.03687,m:51.7895},
	{y:17.0,l:1.0,s:0.03683,m:51.9272},
	{y:18.0,l:1.0,s:0.0368,m:52.0641},
	{y:19.0,l:1.0,s:0.03676,m:52.2002},
	{y:20.0,l:1.0,s:0.03673,m:52.3353},
	{y:21.0,l:1.0,s:0.03669,m:52.4695},
	{y:22.0,l:1.0,s:0.03666,m:52.6027},
	{y:23.0,l:1.0,s:0.03663,m:52.7349},
	{y:24.0,l:1.0,s:0.0366,m:52.8661},
	{y:25.0,l:1.0,s:0.03656,m:52.9963},
	{y:26.0,l:1.0,s:0.03653,m:53.1255},
	{y:27.0,l:1.0,s:0.0365,m:53.2537},
	{y:28.0,l:1.0,s:0.03647,m:53.3809},
	{y:29.0,l:1.0,s:0.03644,m:53.5072},
	{y:30.0,l:1.0,s:0.03641,m:53.6326},
	{y:31.0,l:1.0,s:0.03638,m:53.7571},
	{y:32.0,l:1.0,s:0.03636,m:53.8806},
	{y:33.0,l:1.0,s:0.03633,m:54.0031},
	{y:34.0,l:1.0,s:0.0363,m:54.1247},
	{y:35.0,l:1.0,s:0.03627,m:54.2454},
	{y:36.0,l:1.0,s:0.03625,m:54.3651},
	{y:37.0,l:1.0,s:0.03622,m:54.4839},
	{y:38.0,l:1.0,s:0.03619,m:54.6018},
	{y:39.0,l:1.0,s:0.03617,m:54.7187},
	{y:40.0,l:1.0,s:0.03614,m:54.8348},
	{y:41.0,l:1.0,s:0.03612,m:54.9499},
	{y:42.0,l:1.0,s:0.03609,m:55.0642},
	{y:43.0,l:1.0,s:0.03607,m:55.1777},
	{y:44.0,l:1.0,s:0.03604,m:55.2903},
	{y:45.0,l:1.0,s:0.03602,m:55.4021},
	{y:46.0,l:1.0,s:0.036,m:55.513},
	{y:47.0,l:1.0,s:0.03597,m:55.623},
	{y:48.0,l:1.0,s:0.03595,m:55.7322},
	{y:49.0,l:1.0,s:0.03593,m:55.8406},
	{y:50.0,l:1.0,s:0.03591,m:55.9482},
	{y:51.0,l:1.0,s:0.03588,m:56.0549},
	{y:52.0,l:1.0,s:0.03586,m:56.1609},
	{y:53.0,l:1.0,s:0.03584,m:56.266},
	{y:54.0,l:1.0,s:0.03582,m:56.3704},
	{y:55.0,l:1.0,s:0.0358,m:56.4739},
	{y:56.0,l:1.0,s:0.03578,m:56.5767},
	{y:57.0,l:1.0,s:0.03576,m:56.6788},
	{y:58.0,l:1.0,s:0.03574,m:56.78},
	{y:59.0,l:1.0,s:0.03572,m:56.8806},
	{y:60.0,l:1.0,s:0.0357,m:56.9805},
	{y:63.0,l:1.0,s:0.03564,m:57.2761},
	{y:70.0,l:1.0,s:0.03552,m:57.9436},
	{y:77.0,l:1.0,s:0.0354,m:58.5816},
	{y:84.0,l:1.0,s:0.0353,m:59.1922},
	{y:91.0,l:1.0,s:0.0352,m:59.7773},
	{y:98.0,l:1.0,s:0.03511,m:60.3393},
	{y:105.0,l:1.0,s:0.03503,m:60.8795},
	{y:112.0,l:1.0,s:0.03495,m:61.3991},
	{y:119.0,l:1.0,s:0.03488,m:61.8988},
	{y:126.0,l:1.0,s:0.03482,m:62.3795},
	{y:133.0,l:1.0,s:0.03476,m:62.8423},
	{y:140.0,l:1.0,s:0.03471,m:63.2884},
	{y:147.0,l:1.0,s:0.03466,m:63.7196},
	{y:154.0,l:1.0,s:0.03461,m:64.137},
	{y:161.0,l:1.0,s:0.03457,m:64.5422},
	{y:168.0,l:1.0,s:0.03454,m:64.9366},
	{y:175.0,l:1.0,s:0.03451,m:65.3214},
	{y:182.0,l:1.0,s:0.03448,m:65.6978},
	{y:197.0,l:1.0,s:0.03444,m:66.4802},
	{y:227.0,l:1.0,s:0.0344,m:67.9667},
	{y:257.0,l:1.0,s:0.03441,m:69.3755},
	{y:287.0,l:1.0,s:0.03447,m:70.7241},
	{y:317.0,l:1.0,s:0.03457,m:72.0223},
	{y:347.0,l:1.0,s:0.0347,m:73.2743},
	{y:377.0,l:1.0,s:0.03485,m:74.4839},
	{y:407.0,l:1.0,s:0.03503,m:75.6546},
	{y:437.0,l:1.0,s:0.03521,m:76.7887},
	{y:467.0,l:1.0,s:0.03541,m:77.8891},
	{y:497.0,l:1.0,s:0.03562,m:78.9588},
	{y:527.0,l:1.0,s:0.03583,m:79.9998},
	{y:557.0,l:1.0,s:0.03605,m:81.0135},
	{y:587.0,l:1.0,s:0.03627,m:82.0019},
	{y:617.0,l:1.0,s:0.03649,m:82.9666},
	{y:647.0,l:1.0,s:0.03671,m:83.9085},
	{y:677.0,l:1.0,s:0.03694,m:84.828},
	{y:707.0,l:1.0,s:0.03716,m:85.726},
	{y:737.0,l:1.0,s:0.03769,m:85.9039},
	{y:767.0,l:1.0,s:0.03791,m:86.7624},
	{y:797.0,l:1.0,s:0.03812,m:87.6023},
	{y:827.0,l:1.0,s:0.03834,m:88.4236},
	{y:857.0,l:1.0,s:0.03855,m:89.2263},
	{y:887.0,l:1.0,s:0.03875,m:90.0108},
	{y:917.0,l:1.0,s:0.03895,m:90.7778},
	{y:947.0,l:1.0,s:0.03915,m:91.5282},
	{y:977.0,l:1.0,s:0.03935,m:92.2635},
	{y:1007.0,l:1.0,s:0.03953,m:92.985},
	{y:1037.0,l:1.0,s:0.03972,m:93.6943},
	{y:1067.0,l:1.0,s:0.0399,m:94.3922},
	{y:1097.0,l:1.0,s:0.04007,m:95.0799},
	{y:1127.0,l:1.0,s:0.04024,m:95.7581},
	{y:1157.0,l:1.0,s:0.04041,m:96.427},
	{y:1187.0,l:1.0,s:0.04057,m:97.0871},
	{y:1217.0,l:1.0,s:0.04073,m:97.7385},
	{y:1247.0,l:1.0,s:0.04089,m:98.3815},
	{y:1277.0,l:1.0,s:0.04104,m:99.0159},
	{y:1307.0,l:1.0,s:0.04119,m:99.642},
	{y:1337.0,l:1.0,s:0.04134,m:100.2598},
	{y:1367.0,l:1.0,s:0.04148,m:100.8695},
	{y:1397.0,l:1.0,s:0.04163,m:101.4714},
	{y:1427.0,l:1.0,s:0.04177,m:102.0658},
	{y:1457.0,l:1.0,s:0.04191,m:102.6533},
	{y:1487.0,l:1.0,s:0.04204,m:103.2343},
	{y:1517.0,l:1.0,s:0.04218,m:103.8092},
	{y:1547.0,l:1.0,s:0.04231,m:104.3784},
	{y:1577.0,l:1.0,s:0.04244,m:104.942},
	{y:1607.0,l:1.0,s:0.04257,m:105.5003},
	{y:1637.0,l:1.0,s:0.0427,m:106.0534},
	{y:1667.0,l:1.0,s:0.04282,m:106.6013},
	{y:1697.0,l:1.0,s:0.04294,m:107.144},
	{y:1727.0,l:1.0,s:0.04307,m:107.6814},
	{y:1757.0,l:1.0,s:0.04319,m:108.2137},
	{y:1787.0,l:1.0,s:0.04331,m:108.7409},
	{y:1817.0,l:1.0,s:0.04343,m:109.2632},
	{y:1847.0,l:1.0,s:0.04355,m:109.7808}
}

define LengthForAgeMale:
{
	{y:0.0,l:1.0,s:0.03795,m:49.8842},
	{y:1.0,l:1.0,s:0.03785,m:50.0601},
	{y:2.0,l:1.0,s:0.03775,m:50.2359},
	{y:3.0,l:1.0,s:0.03764,m:50.4118},
	{y:4.0,l:1.0,s:0.03754,m:50.5876},
	{y:5.0,l:1.0,s:0.03744,m:50.7635},
	{y:6.0,l:1.0,s:0.03734,m:50.9393},
	{y:7.0,l:1.0,s:0.03723,m:51.1152},
	{y:8.0,l:1.0,s:0.03713,m:51.291},
	{y:9.0,l:1.0,s:0.03703,m:51.4669},
	{y:10.0,l:1.0,s:0.03693,m:51.6427},
	{y:11.0,l:1.0,s:0.03682,m:51.8186},
	{y:12.0,l:1.0,s:0.03672,m:51.9944},
	{y:13.0,l:1.0,s:0.03662,m:52.1702},
	{y:14.0,l:1.0,s:0.03652,m:52.3461},
	{y:15.0,l:1.0,s:0.03645,m:52.4978},
	{y:16.0,l:1.0,s:0.03639,m:52.6488},
	{y:17.0,l:1.0,s:0.03633,m:52.799},
	{y:18.0,l:1.0,s:0.03627,m:52.9483},
	{y:19.0,l:1.0,s:0.03621,m:53.0967},
	{y:20.0,l:1.0,s:0.03615,m:53.2441},
	{y:21.0,l:1.0,s:0.03609,m:53.3905},
	{y:22.0,l:1.0,s:0.03603,m:53.536},
	{y:23.0,l:1.0,s:0.03597,m:53.6805},
	{y:24.0,l:1.0,s:0.03592,m:53.8239},
	{y:25.0,l:1.0,s:0.03586,m:53.9664},
	{y:26.0,l:1.0,s:0.03581,m:54.1079},
	{y:27.0,l:1.0,s:0.03575,m:54.2485},
	{y:28.0,l:1.0,s:0.0357,m:54.3881},
	{y:29.0,l:1.0,s:0.03565,m:54.5268},
	{y:30.0,l:1.0,s:0.03559,m:54.6645},
	{y:31.0,l:1.0,s:0.03554,m:54.8012},
	{y:32.0,l:1.0,s:0.03549,m:54.9368},
	{y:33.0,l:1.0,s:0.03544,m:55.0714},
	{y:34.0,l:1.0,s:0.03539,m:55.2049},
	{y:35.0,l:1.0,s:0.03534,m:55.3374},
	{y:36.0,l:1.0,s:0.03529,m:55.4688},
	{y:37.0,l:1.0,s:0.03524,m:55.5992},
	{y:38.0,l:1.0,s:0.0352,m:55.7285},
	{y:39.0,l:1.0,s:0.03515,m:55.8568},
	{y:40.0,l:1.0,s:0.0351,m:55.9841},
	{y:41.0,l:1.0,s:0.03506,m:56.1104},
	{y:42.0,l:1.0,s:0.03501,m:56.2357},
	{y:43.0,l:1.0,s:0.03496,m:56.3599},
	{y:44.0,l:1.0,s:0.03492,m:56.4833},
	{y:45.0,l:1.0,s:0.03488,m:56.6056},
	{y:46.0,l:1.0,s:0.03483,m:56.7269},
	{y:47.0,l:1.0,s:0.03479,m:56.8472},
	{y:48.0,l:1.0,s:0.03475,m:56.9666},
	{y:49.0,l:1.0,s:0.0347,m:57.0851},
	{y:50.0,l:1.0,s:0.03466,m:57.2026},
	{y:51.0,l:1.0,s:0.03462,m:57.3192},
	{y:52.0,l:1.0,s:0.03458,m:57.4349},
	{y:53.0,l:1.0,s:0.03454,m:57.5497},
	{y:54.0,l:1.0,s:0.0345,m:57.6637},
	{y:55.0,l:1.0,s:0.03446,m:57.7767},
	{y:56.0,l:1.0,s:0.03442,m:57.8889},
	{y:57.0,l:1.0,s:0.03438,m:58.0003},
	{y:58.0,l:1.0,s:0.03434,m:58.1109},
	{y:59.0,l:1.0,s:0.03431,m:58.2207},
	{y:60.0,l:1.0,s:0.03427,m:58.3299},
	{y:63.0,l:1.0,s:0.03416,m:58.6536},
	{y:70.0,l:1.0,s:0.03392,m:59.3872},
	{y:77.0,l:1.0,s:0.03369,m:60.0894},
	{y:84.0,l:1.0,s:0.03348,m:60.7605},
	{y:91.0,l:1.0,s:0.03329,m:61.4013},
	{y:98.0,l:1.0,s:0.03311,m:62.013},
	{y:105.0,l:1.0,s:0.03294,m:62.5966},
	{y:112.0,l:1.0,s:0.03278,m:63.1533},
	{y:119.0,l:1.0,s:0.03263,m:63.6842},
	{y:126.0,l:1.0,s:0.03249,m:64.1906},
	{y:133.0,l:1.0,s:0.03236,m:64.6744},
	{y:140.0,l:1.0,s:0.03223,m:65.138},
	{y:147.0,l:1.0,s:0.03212,m:65.5834},
	{y:154.0,l:1.0,s:0.03201,m:66.0121},
	{y:161.0,l:1.0,s:0.03191,m:66.4256},
	{y:168.0,l:1.0,s:0.03182,m:66.8254},
	{y:175.0,l:1.0,s:0.03174,m:67.2132},
	{y:182.0,l:1.0,s:0.03166,m:67.5904},
	{y:197.0,l:1.0,s:0.03152,m:68.3685},
	{y:227.0,l:1.0,s:0.03131,m:69.8316},
	{y:257.0,l:1.0,s:0.0312,m:71.2138},
	{y:287.0,l:1.0,s:0.03117,m:72.539},
	{y:317.0,l:1.0,s:0.0312,m:73.8091},
	{y:347.0,l:1.0,s:0.0313,m:75.0285},
	{y:377.0,l:1.0,s:0.03143,m:76.2051},
	{y:407.0,l:1.0,s:0.03161,m:77.3434},
	{y:437.0,l:1.0,s:0.03182,m:78.4451},
	{y:467.0,l:1.0,s:0.03205,m:79.5145},
	{y:497.0,l:1.0,s:0.03231,m:80.5553},
	{y:527.0,l:1.0,s:0.03259,m:81.569},
	{y:557.0,l:1.0,s:0.03288,m:82.5562},
	{y:587.0,l:1.0,s:0.03319,m:83.5176},
	{y:617.0,l:1.0,s:0.03351,m:84.4554},
	{y:647.0,l:1.0,s:0.03384,m:85.3711},
	{y:677.0,l:1.0,s:0.03418,m:86.2659},
	{y:707.0,l:1.0,s:0.03453,m:87.142},
	{y:737.0,l:1.0,s:0.03515,m:87.3006},
	{y:767.0,l:1.0,s:0.03549,m:88.14},
	{y:797.0,l:1.0,s:0.03582,m:88.9584},
	{y:827.0,l:1.0,s:0.03615,m:89.7563},
	{y:857.0,l:1.0,s:0.03647,m:90.5337},
	{y:887.0,l:1.0,s:0.03678,m:91.2903},
	{y:917.0,l:1.0,s:0.03708,m:92.0268},
	{y:947.0,l:1.0,s:0.03736,m:92.7444},
	{y:977.0,l:1.0,s:0.03763,m:93.4446},
	{y:1007.0,l:1.0,s:0.03789,m:94.129},
	{y:1037.0,l:1.0,s:0.03814,m:94.8003},
	{y:1067.0,l:1.0,s:0.03837,m:95.4605},
	{y:1097.0,l:1.0,s:0.03859,m:96.1104},
	{y:1127.0,l:1.0,s:0.0388,m:96.751},
	{y:1157.0,l:1.0,s:0.039,m:97.3827},
	{y:1187.0,l:1.0,s:0.03919,m:98.006},
	{y:1217.0,l:1.0,s:0.03937,m:98.6209},
	{y:1247.0,l:1.0,s:0.03954,m:99.2271},
	{y:1277.0,l:1.0,s:0.0397,m:99.8244},
	{y:1307.0,l:1.0,s:0.03985,m:100.4132},
	{y:1337.0,l:1.0,s:0.04001,m:100.9941},
	{y:1367.0,l:1.0,s:0.04015,m:101.5676},
	{y:1397.0,l:1.0,s:0.0403,m:102.1346},
	{y:1427.0,l:1.0,s:0.04044,m:102.6961},
	{y:1457.0,l:1.0,s:0.04057,m:103.2533},
	{y:1487.0,l:1.0,s:0.04071,m:103.807},
	{y:1517.0,l:1.0,s:0.04084,m:104.358},
	{y:1547.0,l:1.0,s:0.04097,m:104.9071},
	{y:1577.0,l:1.0,s:0.04111,m:105.4547},
	{y:1607.0,l:1.0,s:0.04123,m:106.0012},
	{y:1637.0,l:1.0,s:0.04136,m:106.5465},
	{y:1667.0,l:1.0,s:0.04149,m:107.0908},
	{y:1697.0,l:1.0,s:0.04162,m:107.6341},
	{y:1727.0,l:1.0,s:0.04174,m:108.1764},
	{y:1757.0,l:1.0,s:0.04186,m:108.7179},
	{y:1787.0,l:1.0,s:0.04198,m:109.2584},
	{y:1817.0,l:1.0,s:0.0421,m:109.7978},
	{y:1847.0,l:1.0,s:0.04222,m:110.3358}
}




define function ZscoreLengthForAgetables(sex String, age Decimal):
	if sex = 'female' then  
        First(LengthForAgeFemale c where c.y = base.AgeToMini(age) )
	else 
        First(LengthForAgeMale c where  c.y = base.AgeToMini(age))
            
define function generateZScoreLengthForAge(sex System.String, age System.Decimal, weight  System.Decimal)  : 
	 generateZScoreLengthForAgedet(ZscoreLengthForAgetables(sex,age), weight )

define function generateZScoreLengthForAgedet(row Tuple {y System.Decimal,l System.Decimal,s System.Decimal,m System.Decimal}, weight  System.Decimal):
    if row is not null then 
        base.computeZScore(
            weight,
            row.m , 
            row.l ,
            row.s 
        )
    else null


define function generateLengthFromAge(sex System.String, age System.Decimal, zscore  System.Decimal) : 
	 generateLengthFromAgedet(ZscoreLengthForAgetables(sex,age),zscore  )

define function generateLengthFromAgedet(row Tuple {y System.Decimal,l System.Decimal,s System.Decimal,m System.Decimal},zscore  System.Decimal) : 
    if row is not null then 
        base.computeReverseZScore(
            zscore,
            row.m , 
            row.l ,
            row.s 
        )
    else null