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: WeightForAge

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

Related Artifacts

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

Parameters

zscoreindecimal
Ageindecimal
sexindecimal
generateWeightFromAgeoutdecimal
generateZScoreWeightForAgeoutdecimal
ZscoreWeightForAgetables_soutdecimal
ZscoreWeightForAgetables_moutdecimal
ZscoreWeightForAgetables_loutdecimal

Data Requirements

Type: Patient (Patient)

Contents

text/cql


library WeightForAge 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 WeightForAge  Z-Score from the weianthro files
codesystem "administrative-gender": 'http://hl7.org/fhir/administrative-gender'
//code "Female" : 'female' from "administrative-gender"  display 'Female'


define WeightForAgeFemale:
{
	{y:0.0,l:0.3809,s:0.14171,m:3.2322},
	{y:1.0,l:0.3259,s:0.14578,m:3.1957},
	{y:2.0,l:0.3101,s:0.14637,m:3.2104},
	{y:3.0,l:0.2986,s:0.14657,m:3.2315},
	{y:4.0,l:0.2891,s:0.14658,m:3.2558},
	{y:5.0,l:0.281,s:0.14646,m:3.2821},
	{y:6.0,l:0.2737,s:0.14626,m:3.3099},
	{y:7.0,l:0.2671,s:0.146,m:3.3388},
	{y:8.0,l:0.2609,s:0.14569,m:3.3687},
	{y:9.0,l:0.2551,s:0.14534,m:3.3995},
	{y:10.0,l:0.2497,s:0.14498,m:3.4314},
	{y:11.0,l:0.2446,s:0.14459,m:3.4643},
	{y:12.0,l:0.2397,s:0.1442,m:3.4983},
	{y:13.0,l:0.2349,s:0.1438,m:3.5333},
	{y:14.0,l:0.2304,s:0.14339,m:3.5693},
	{y:15.0,l:0.226,s:0.14299,m:3.6063},
	{y:16.0,l:0.2218,s:0.14258,m:3.6438},
	{y:17.0,l:0.2177,s:0.14218,m:3.6818},
	{y:18.0,l:0.2137,s:0.14177,m:3.7201},
	{y:19.0,l:0.2099,s:0.14138,m:3.7584},
	{y:20.0,l:0.2061,s:0.14098,m:3.7968},
	{y:21.0,l:0.2024,s:0.1406,m:3.8352},
	{y:22.0,l:0.1989,s:0.14021,m:3.8735},
	{y:23.0,l:0.1954,s:0.13984,m:3.9116},
	{y:24.0,l:0.1919,s:0.13947,m:3.9495},
	{y:25.0,l:0.1886,s:0.1391,m:3.9872},
	{y:26.0,l:0.1853,s:0.13875,m:4.0247},
	{y:27.0,l:0.1821,s:0.1384,m:4.0618},
	{y:28.0,l:0.1789,s:0.13805,m:4.0987},
	{y:29.0,l:0.1758,s:0.13771,m:4.1353},
	{y:30.0,l:0.1727,s:0.13738,m:4.1716},
	{y:31.0,l:0.1697,s:0.13706,m:4.2075},
	{y:32.0,l:0.1668,s:0.13674,m:4.2431},
	{y:33.0,l:0.1638,s:0.13643,m:4.2783},
	{y:34.0,l:0.161,s:0.13613,m:4.3131},
	{y:35.0,l:0.1582,s:0.13583,m:4.3476},
	{y:36.0,l:0.1554,s:0.13554,m:4.3818},
	{y:37.0,l:0.1526,s:0.13526,m:4.4155},
	{y:38.0,l:0.1499,s:0.13498,m:4.449},
	{y:39.0,l:0.1473,s:0.1347,m:4.482},
	{y:40.0,l:0.1446,s:0.13444,m:4.5148},
	{y:41.0,l:0.142,s:0.13418,m:4.5472},
	{y:42.0,l:0.1395,s:0.13392,m:4.5793},
	{y:43.0,l:0.1369,s:0.13367,m:4.611},
	{y:44.0,l:0.1344,s:0.13342,m:4.6425},
	{y:45.0,l:0.132,s:0.13318,m:4.6736},
	{y:46.0,l:0.1295,s:0.13295,m:4.7044},
	{y:47.0,l:0.1271,s:0.13272,m:4.7349},
	{y:48.0,l:0.1247,s:0.1325,m:4.7651},
	{y:49.0,l:0.1224,s:0.13228,m:4.795},
	{y:50.0,l:0.12,s:0.13206,m:4.8245},
	{y:51.0,l:0.1177,s:0.13185,m:4.8538},
	{y:52.0,l:0.1154,s:0.13165,m:4.8828},
	{y:53.0,l:0.1132,s:0.13145,m:4.9115},
	{y:54.0,l:0.1109,s:0.13125,m:4.9399},
	{y:55.0,l:0.1087,s:0.13106,m:4.968},
	{y:56.0,l:0.1065,s:0.13087,m:4.9959},
	{y:57.0,l:0.1044,s:0.13068,m:5.0235},
	{y:58.0,l:0.1022,s:0.1305,m:5.0509},
	{y:59.0,l:0.1001,s:0.13033,m:5.078},
	{y:60.0,l:0.098,s:0.13015,m:5.1049},
	{y:63.0,l:0.0918,s:0.12966,m:5.1842},
	{y:70.0,l:0.0779,s:0.12861,m:5.3618},
	{y:77.0,l:0.0648,s:0.1277,m:5.5295},
	{y:84.0,l:0.0525,s:0.12691,m:5.6883},
	{y:91.0,l:0.0407,s:0.12622,m:5.8393},
	{y:98.0,l:0.0295,s:0.12561,m:5.9831},
	{y:105.0,l:0.0188,s:0.12507,m:6.1202},
	{y:112.0,l:0.0086,s:0.12459,m:6.2511},
	{y:119.0,l:-0.0013,s:0.12417,m:6.3761},
	{y:126.0,l:-0.0107,s:0.1238,m:6.4956},
	{y:133.0,l:-0.0198,s:0.12346,m:6.6099},
	{y:140.0,l:-0.0285,s:0.12317,m:6.7192},
	{y:147.0,l:-0.0369,s:0.12291,m:6.8238},
	{y:154.0,l:-0.045,s:0.12268,m:6.9241},
	{y:161.0,l:-0.0529,s:0.12248,m:7.0205},
	{y:168.0,l:-0.0605,s:0.12231,m:7.1133},
	{y:175.0,l:-0.0678,s:0.12217,m:7.2029},
	{y:182.0,l:-0.0749,s:0.12205,m:7.2894},
	{y:197.0,l:-0.0894,s:0.12188,m:7.4657},
	{y:227.0,l:-0.1157,s:0.12177,m:7.7867},
	{y:257.0,l:-0.1388,s:0.12187,m:8.0746},
	{y:287.0,l:-0.1593,s:0.12209,m:8.3369},
	{y:317.0,l:-0.1774,s:0.12233,m:8.5808},
	{y:347.0,l:-0.1935,s:0.12256,m:8.8119},
	{y:377.0,l:-0.2077,s:0.12274,m:9.0344},
	{y:407.0,l:-0.2204,s:0.12288,m:9.2511},
	{y:437.0,l:-0.2317,s:0.12296,m:9.4637},
	{y:467.0,l:-0.2418,s:0.12301,m:9.6735},
	{y:497.0,l:-0.2507,s:0.12304,m:9.8816},
	{y:527.0,l:-0.2587,s:0.12307,m:10.0884},
	{y:557.0,l:-0.2658,s:0.12311,m:10.2939},
	{y:587.0,l:-0.2721,s:0.12317,m:10.4985},
	{y:617.0,l:-0.2777,s:0.12326,m:10.7025},
	{y:647.0,l:-0.2827,s:0.12339,m:10.9065},
	{y:677.0,l:-0.2872,s:0.12355,m:11.1111},
	{y:707.0,l:-0.2912,s:0.12373,m:11.3163},
	{y:737.0,l:-0.2948,s:0.12395,m:11.5221},
	{y:767.0,l:-0.2981,s:0.12419,m:11.7279},
	{y:797.0,l:-0.301,s:0.12446,m:11.9331},
	{y:827.0,l:-0.3037,s:0.12477,m:12.1366},
	{y:857.0,l:-0.3061,s:0.12512,m:12.3375},
	{y:887.0,l:-0.3083,s:0.12551,m:12.5356},
	{y:917.0,l:-0.3103,s:0.12593,m:12.7305},
	{y:947.0,l:-0.3122,s:0.12639,m:12.9224},
	{y:977.0,l:-0.314,s:0.12688,m:13.1119},
	{y:1007.0,l:-0.3156,s:0.12741,m:13.2996},
	{y:1037.0,l:-0.3172,s:0.12798,m:13.4863},
	{y:1067.0,l:-0.3187,s:0.12858,m:13.6723},
	{y:1097.0,l:-0.3202,s:0.12922,m:13.858},
	{y:1127.0,l:-0.3216,s:0.12989,m:14.0435},
	{y:1157.0,l:-0.323,s:0.1306,m:14.2288},
	{y:1187.0,l:-0.3243,s:0.13134,m:14.4136},
	{y:1217.0,l:-0.3257,s:0.13211,m:14.5979},
	{y:1247.0,l:-0.327,s:0.13291,m:14.7816},
	{y:1277.0,l:-0.3283,s:0.13372,m:14.9644},
	{y:1307.0,l:-0.3296,s:0.13455,m:15.1463},
	{y:1337.0,l:-0.3308,s:0.13539,m:15.3275},
	{y:1367.0,l:-0.3321,s:0.13623,m:15.5079},
	{y:1397.0,l:-0.3334,s:0.13707,m:15.6877},
	{y:1427.0,l:-0.3347,s:0.1379,m:15.8669},
	{y:1457.0,l:-0.3359,s:0.13873,m:16.0459},
	{y:1487.0,l:-0.3372,s:0.13956,m:16.2246},
	{y:1517.0,l:-0.3385,s:0.14038,m:16.4032},
	{y:1547.0,l:-0.3398,s:0.14118,m:16.5817},
	{y:1577.0,l:-0.3411,s:0.14198,m:16.76},
	{y:1607.0,l:-0.3424,s:0.14277,m:16.9381},
	{y:1637.0,l:-0.3437,s:0.14354,m:17.1159},
	{y:1667.0,l:-0.345,s:0.14431,m:17.2931},
	{y:1697.0,l:-0.3463,s:0.14506,m:17.4696},
	{y:1727.0,l:-0.3476,s:0.14581,m:17.6453},
	{y:1757.0,l:-0.3489,s:0.14654,m:17.82},
	{y:1787.0,l:-0.3502,s:0.14727,m:17.9937},
	{y:1817.0,l:-0.3514,s:0.14799,m:18.1663},
	{y:1847.0,l:-0.3527,s:0.14871,m:18.3378}
}

define WeightForAgeMale:
{
	{y:0.0,l:0.3487,s:0.14602,m:3.3464},
	{y:1.0,l:0.3127,s:0.14693,m:3.3174},
	{y:2.0,l:0.3029,s:0.14676,m:3.337},
	{y:3.0,l:0.2959,s:0.14647,m:3.3627},
	{y:4.0,l:0.2903,s:0.14611,m:3.3915},
	{y:5.0,l:0.2855,s:0.14571,m:3.4223},
	{y:6.0,l:0.2813,s:0.14528,m:3.4545},
	{y:7.0,l:0.2776,s:0.14483,m:3.4879},
	{y:8.0,l:0.2742,s:0.14436,m:3.5222},
	{y:9.0,l:0.2711,s:0.14388,m:3.5576},
	{y:10.0,l:0.2681,s:0.14339,m:3.5941},
	{y:11.0,l:0.2654,s:0.1429,m:3.6319},
	{y:12.0,l:0.2628,s:0.14241,m:3.671},
	{y:13.0,l:0.2604,s:0.14192,m:3.7113},
	{y:14.0,l:0.2581,s:0.14142,m:3.7529},
	{y:15.0,l:0.2558,s:0.14093,m:3.7956},
	{y:16.0,l:0.2537,s:0.14044,m:3.8389},
	{y:17.0,l:0.2517,s:0.13996,m:3.8828},
	{y:18.0,l:0.2497,s:0.13948,m:3.927},
	{y:19.0,l:0.2478,s:0.139,m:3.9714},
	{y:20.0,l:0.246,s:0.13853,m:4.0158},
	{y:21.0,l:0.2442,s:0.13807,m:4.0603},
	{y:22.0,l:0.2425,s:0.13761,m:4.1046},
	{y:23.0,l:0.2408,s:0.13715,m:4.1489},
	{y:24.0,l:0.2392,s:0.1367,m:4.193},
	{y:25.0,l:0.2376,s:0.13626,m:4.2369},
	{y:26.0,l:0.2361,s:0.13582,m:4.2806},
	{y:27.0,l:0.2346,s:0.13539,m:4.324},
	{y:28.0,l:0.2331,s:0.13497,m:4.3671},
	{y:29.0,l:0.2317,s:0.13455,m:4.41},
	{y:30.0,l:0.2303,s:0.13413,m:4.4525},
	{y:31.0,l:0.229,s:0.13372,m:4.4946},
	{y:32.0,l:0.2276,s:0.13332,m:4.5363},
	{y:33.0,l:0.2263,s:0.13292,m:4.5776},
	{y:34.0,l:0.225,s:0.13253,m:4.6185},
	{y:35.0,l:0.2237,s:0.13215,m:4.659},
	{y:36.0,l:0.2225,s:0.13177,m:4.699},
	{y:37.0,l:0.2213,s:0.13139,m:4.7386},
	{y:38.0,l:0.2201,s:0.13102,m:4.7778},
	{y:39.0,l:0.2189,s:0.13066,m:4.8166},
	{y:40.0,l:0.2178,s:0.1303,m:4.8549},
	{y:41.0,l:0.2166,s:0.12994,m:4.8928},
	{y:42.0,l:0.2155,s:0.1296,m:4.9303},
	{y:43.0,l:0.2144,s:0.12925,m:4.9674},
	{y:44.0,l:0.2133,s:0.12891,m:5.0041},
	{y:45.0,l:0.2122,s:0.12858,m:5.0404},
	{y:46.0,l:0.2112,s:0.12825,m:5.0763},
	{y:47.0,l:0.2101,s:0.12792,m:5.1118},
	{y:48.0,l:0.2091,s:0.1276,m:5.1469},
	{y:49.0,l:0.2081,s:0.12729,m:5.1817},
	{y:50.0,l:0.2071,s:0.12698,m:5.2161},
	{y:51.0,l:0.2061,s:0.12667,m:5.2501},
	{y:52.0,l:0.2052,s:0.12637,m:5.2837},
	{y:53.0,l:0.2042,s:0.12607,m:5.3171},
	{y:54.0,l:0.2032,s:0.12577,m:5.35},
	{y:55.0,l:0.2023,s:0.12548,m:5.3826},
	{y:56.0,l:0.2014,s:0.1252,m:5.4149},
	{y:57.0,l:0.2005,s:0.12491,m:5.4468},
	{y:58.0,l:0.1996,s:0.12463,m:5.4784},
	{y:59.0,l:0.1987,s:0.12436,m:5.5097},
	{y:60.0,l:0.1978,s:0.12409,m:5.5407},
	{y:63.0,l:0.1952,s:0.1233,m:5.6319},
	{y:70.0,l:0.1894,s:0.12157,m:5.8346},
	{y:77.0,l:0.184,s:0.12001,m:6.0242},
	{y:84.0,l:0.1789,s:0.1186,m:6.2019},
	{y:91.0,l:0.174,s:0.11732,m:6.369},
	{y:98.0,l:0.1694,s:0.11618,m:6.5265},
	{y:105.0,l:0.1651,s:0.11516,m:6.6755},
	{y:112.0,l:0.1609,s:0.11425,m:6.8168},
	{y:119.0,l:0.1568,s:0.11345,m:6.9513},
	{y:126.0,l:0.1529,s:0.11274,m:7.0794},
	{y:133.0,l:0.1492,s:0.11212,m:7.2018},
	{y:140.0,l:0.1456,s:0.11158,m:7.3187},
	{y:147.0,l:0.1421,s:0.11111,m:7.4307},
	{y:154.0,l:0.1387,s:0.1107,m:7.5379},
	{y:161.0,l:0.1354,s:0.11035,m:7.6406},
	{y:168.0,l:0.1322,s:0.11005,m:7.7394},
	{y:175.0,l:0.129,s:0.1098,m:7.8344},
	{y:182.0,l:0.126,s:0.10959,m:7.926},
	{y:197.0,l:0.1197,s:0.10925,m:8.112},
	{y:227.0,l:0.1081,s:0.1089,m:8.4474},
	{y:257.0,l:0.0974,s:0.1088,m:8.7453},
	{y:287.0,l:0.0875,s:0.10884,m:9.0169},
	{y:317.0,l:0.0782,s:0.10896,m:9.2691},
	{y:347.0,l:0.0695,s:0.10913,m:9.5077},
	{y:377.0,l:0.0613,s:0.10934,m:9.7364},
	{y:407.0,l:0.0534,s:0.10959,m:9.9575},
	{y:437.0,l:0.046,s:0.10987,m:10.1728},
	{y:467.0,l:0.0389,s:0.11019,m:10.3839},
	{y:497.0,l:0.032,s:0.11053,m:10.5918},
	{y:527.0,l:0.0255,s:0.11091,m:10.7971},
	{y:557.0,l:0.0192,s:0.11132,m:11.0},
	{y:587.0,l:0.013,s:0.11177,m:11.2011},
	{y:617.0,l:0.0071,s:0.11224,m:11.4011},
	{y:647.0,l:0.0014,s:0.11275,m:11.6005},
	{y:677.0,l:-0.0041,s:0.11327,m:11.7991},
	{y:707.0,l:-0.0095,s:0.11382,m:11.9971},
	{y:737.0,l:-0.0148,s:0.11439,m:12.1941},
	{y:767.0,l:-0.0199,s:0.11497,m:12.3895},
	{y:797.0,l:-0.0249,s:0.11555,m:12.5826},
	{y:827.0,l:-0.0297,s:0.11614,m:12.7728},
	{y:857.0,l:-0.0345,s:0.11673,m:12.9597},
	{y:887.0,l:-0.0391,s:0.11731,m:13.1431},
	{y:917.0,l:-0.0437,s:0.11788,m:13.3231},
	{y:947.0,l:-0.0481,s:0.11845,m:13.5},
	{y:977.0,l:-0.0525,s:0.11902,m:13.674},
	{y:1007.0,l:-0.0567,s:0.11957,m:13.8455},
	{y:1037.0,l:-0.0609,s:0.12012,m:14.015},
	{y:1067.0,l:-0.065,s:0.12065,m:14.183},
	{y:1097.0,l:-0.0691,s:0.12118,m:14.3498},
	{y:1127.0,l:-0.073,s:0.1217,m:14.5158},
	{y:1157.0,l:-0.0769,s:0.12221,m:14.6811},
	{y:1187.0,l:-0.0808,s:0.12271,m:14.8462},
	{y:1217.0,l:-0.0845,s:0.12321,m:15.0112},
	{y:1247.0,l:-0.0882,s:0.12372,m:15.1761},
	{y:1277.0,l:-0.0919,s:0.12423,m:15.341},
	{y:1307.0,l:-0.0955,s:0.12474,m:15.5058},
	{y:1337.0,l:-0.099,s:0.12527,m:15.6705},
	{y:1367.0,l:-0.1025,s:0.12581,m:15.835},
	{y:1397.0,l:-0.1059,s:0.12637,m:15.9992},
	{y:1427.0,l:-0.1093,s:0.12693,m:16.1632},
	{y:1457.0,l:-0.1127,s:0.12751,m:16.3271},
	{y:1487.0,l:-0.116,s:0.1281,m:16.4908},
	{y:1517.0,l:-0.1192,s:0.12871,m:16.6545},
	{y:1547.0,l:-0.1225,s:0.12932,m:16.8181},
	{y:1577.0,l:-0.1256,s:0.12993,m:16.9818},
	{y:1607.0,l:-0.1288,s:0.13056,m:17.1455},
	{y:1637.0,l:-0.1319,s:0.13119,m:17.3091},
	{y:1667.0,l:-0.1349,s:0.13182,m:17.4726},
	{y:1697.0,l:-0.138,s:0.13245,m:17.636},
	{y:1727.0,l:-0.1409,s:0.13308,m:17.7991},
	{y:1757.0,l:-0.1439,s:0.13372,m:17.9619},
	{y:1787.0,l:-0.1468,s:0.13435,m:18.1245},
	{y:1817.0,l:-0.1497,s:0.13498,m:18.2867},
	{y:1847.0,l:-0.1526,s:0.13561,m:18.4484}
}




define function ZscoreWeightForAgetables(sex String, age Decimal):
	if sex = 'female' then  
        First(WeightForAgeFemale c where c.y = base.AgeToMini(age) )
	else 
        First(WeightForAgeMale c where  c.y = base.AgeToMini(age))
            
define function generateZScoreWeightForAge(sex System.String, age System.Decimal, weight  System.Decimal)  : 
	 generateZScoreWeightForAgedet(ZscoreWeightForAgetables(sex,age), weight )

define function generateZScoreWeightForAgedet(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 generateWeightFromAge(sex System.String, age System.Decimal, zscore  System.Decimal) : 
	 generateWeightFromAgedet(ZscoreWeightForAgetables(sex,age),zscore  )

define function generateWeightFromAgedet(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