# 4.2 release date and extension-libs

**URL:** <https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702>\
**Category:** Development\
**Tags:** forms\
**Created:** [May 2, 2023, 2:03pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702 "2023-05-02T14:03:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![delcroip](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/delcroip/32/1568_2.png) [@delcroip](https://forum.communityhealthtoolkit.org/u/delcroip)\
**Post date:** [May 2, 2023, 2:03pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/1 "2023-05-02T14:03:40Z")

</div>

@jkuester point me the [extension-libs](https://docs.communityhealthtoolkit.org/apps/reference/extension-libs/) and I’d really like to test it but it says that it will come with version 4.2 so I am wondering when it will be out

Here a first draft (I didn’t try it, it is just for the idea) on how it might help us: Drug calculation can be difficult to read in XLSForms, having them in function will really help

```auto
const {isDate} = require('../stph-extra.js')

/*
result format : https://docs.communityhealthtoolkit.org/apps/reference/extension-libs/
{
  "t": <type>,
  "v": <value>
}

 “bool”, “num”, “str”, “date”, or “arr”

*/

const getValue = function(obj) {
    let val;
    if (obj.t === 'arr') {
      val = obj.v && obj.v.length && obj.v[0];
    } else {
      val = obj.v;
    }
    return val
}

const getDateValue = function(obj) {
    val = getValue(obj)
    if (!val || !isDate(val.textContent)) {
        return null;
    }
    return Date(val.textContent);
}

const getStrValue = function(obj) {
    val = getValue(obj)
    if (!val) {
        return null;
    }
    return val.textContent;
}

const getDecimalValue = function(obj) {
    val = getValue(obj)
    if (!val) {
        return null;
    }
    const parsed = parseFloat(val.textContent);
    return isNaN(parsed) ? 0 : parsed;
}
/*
field_dob date
field_sex String f or m
field_weight decimal in KG

*/

const result_null = { 't':'str','v':''}
return function(field_dob, field_sex, field_weight, str_treatment) {
    //collect data
    let dob = getDateValue(field_dob);
    let sex = getStrValue(field_sex);
    let weight = getDecimalValue(field_weight);
    if (dob === null || sex === null || weight === null || !str_treatment || str_treatment === '' ){
        return result_null;
    }
    //swich treatement

    return TREATMENTS[str_treatment](dob,sex,weigh);
}

const TREATMENTS = [

]

const PARACETAMOLE_ML = {
     6: 3,
     10:5,
     15:8,
     100:10
    } 

function getSlice(DICT,int_val){
    DICT.forEach(([key,value]) => {
        if (int_val < key){
            return value;
        }
    }
    )
    return null
}

function getAgeInMonth(dob){
    ageInMs = new Date(Date.now() - dob.getTime());
    return (Math.abs(ageInMs.getFullYear() - 1970) * 12) + ageInMs.getMonth();

}

function fct_paracetamole_sirop(dob,sex,weigh){
    let rate = 40; // 40 mg per kg
    let concentration = 250 ; // 250 mg / ml
    if (weigh>0){
        return {'t':'num', 'v': Math.round(rate * weigh / concentration) };
    }
    ml = getSlice(PARACETAMOLE_ML,getAgeInMonth(dob));
    if (ml === null){
        return {'t':'str', 'v':''};
    }
    return {'t':'num', 'v':ml};

}

TREATMENTS['paracetamole_sirop'] = fct_paracetamole_sirop;

```

---

<div class="post-metadata">

**Author:** ![gareth](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/gareth/32/62_2.png) [@gareth](https://forum.communityhealthtoolkit.org/u/gareth)\
**Post date:** [May 2, 2023, 9:31pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/2 "2023-05-02T21:31:50Z")

</div>

@delcroip Great to hear you’re as excited about this feature as we are!

The 4.2.0 release is very close with three high priority bug fixes being tested now. You can follow along here: [4.2.0 Milestone · GitHub](https://github.com/medic/cht-core/milestone/109)

After those fixes are merged and assuming no further blocking issues are found I’d expect to get the release out in the next couple of weeks.

---

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [May 3, 2023, 6:48am UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/3 "2023-05-03T06:48:37Z")

</div>

So, as I understand it, this gives us the ability to write our own “XForm User-Defined Functions”?

---

<div class="post-metadata">

**Author:** ![jkuester](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/jkuester/32/806_2.png) [@jkuester](https://forum.communityhealthtoolkit.org/u/jkuester)\
**Post date:** [May 3, 2023, 1:46pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/4 "2023-05-03T13:46:29Z")

</div>

@delcroip since you have already been drafting up a potential extension-lib, I wanted to make sure you saw that we are making a small [last-minute change](https://github.com/medic/cht-core/pull/8211) to how the extension-lib code will need to be formatted (using `module.exports` instead of returning a function). This will be easier to test and more consistent with how we already load code for things like the contact-summary. (See the [docs PR](https://github.com/medic/cht-docs/pull/1052) for a quick summary of the changes!)

And @bamatic, yes, that is correct! The custom functions will be accessible from XForm evaluations as well as tasks/targets configuration code!

---

<div class="post-metadata">

**Author:** ![delcroip](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/delcroip/32/1568_2.png) [@delcroip](https://forum.communityhealthtoolkit.org/u/delcroip)\
**Post date:** [May 25, 2023, 2:39pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/6 "2023-05-25T14:39:20Z")

</div>

Thanks

I could upload the libs after resintalling CHT-CONF with the global option

---

<div class="post-metadata">

**Author:** ![delcroip](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/delcroip/32/1568_2.png) [@delcroip](https://forum.communityhealthtoolkit.org/u/delcroip)\
**Post date:** [June 1, 2023, 12:08pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/7 "2023-06-01T12:08:05Z")

</div>

Thanks it works

I made a z-score function that use WHO anthro data to calculate exact z.scores (daily point up to 60 days, weekly up to 182 days, then monthly)

```auto
const getValue = function(obj) {
    let val;
    if (obj.t === 'arr') {
      val = obj.v && obj.v.length && obj.v[0];
    } else {
      val = obj.v;
    }
    return val;
};

const getDateValue = function(obj) {
    val = getValue(obj);
    if (!val || !isDate(val.textContent)) {
        return null;
    }
    return new Date(val.textContent);
};

const getStrValue = function(obj) {
    val = getValue(obj);
    if (!val) {
        return null;
    }
    return val.textContent;
};
const getDecimalValue = function(obj) {
    val = getValue(obj);
    if (!val) {
        return null;
    }
    const parsed = parseFloat(val.textContent);
    return isNaN(parsed) ? 0 : parsed;
};

const getIntValue = function(obj) {
    val = getValue(obj);
    if (!val) {
        return null;
    }
    console.log('getIntValue '+val.textContent)
    const parsed = parseInt(val.textContent);
    return isNaN(parsed) ? 0 : parsed;
};

let WeightForAgeFemale ={
	0:{'l':0.3809,'s':0.14171,'m':3.2322},
	1:{'l':0.3259,'s':0.14578,'m':3.1957},
	2:{'l':0.3101,'s':0.14637,'m':3.2104},
	3:{'l':0.2986,'s':0.14657,'m':3.2315},
	4:{'l':0.2891,'s':0.14658,'m':3.2558},
	5:{'l':0.281,'s':0.14646,'m':3.2821},
	6:{'l':0.2737,'s':0.14626,'m':3.3099},
	7:{'l':0.2671,'s':0.146,'m':3.3388},
	8:{'l':0.2609,'s':0.14569,'m':3.3687},
	9:{'l':0.2551,'s':0.14534,'m':3.3995},
	10:{'l':0.2497,'s':0.14498,'m':3.4314},
	11:{'l':0.2446,'s':0.14459,'m':3.4643},
	12:{'l':0.2397,'s':0.1442,'m':3.4983},
	13:{'l':0.2349,'s':0.1438,'m':3.5333},
	14:{'l':0.2304,'s':0.14339,'m':3.5693},
	15:{'l':0.226,'s':0.14299,'m':3.6063},
	16:{'l':0.2218,'s':0.14258,'m':3.6438},
	17:{'l':0.2177,'s':0.14218,'m':3.6818},
	18:{'l':0.2137,'s':0.14177,'m':3.7201},
	19:{'l':0.2099,'s':0.14138,'m':3.7584},
	20:{'l':0.2061,'s':0.14098,'m':3.7968},
	21:{'l':0.2024,'s':0.1406,'m':3.8352},
	22:{'l':0.1989,'s':0.14021,'m':3.8735},
	23:{'l':0.1954,'s':0.13984,'m':3.9116},
	24:{'l':0.1919,'s':0.13947,'m':3.9495},
	25:{'l':0.1886,'s':0.1391,'m':3.9872},
	26:{'l':0.1853,'s':0.13875,'m':4.0247},
	27:{'l':0.1821,'s':0.1384,'m':4.0618},
	28:{'l':0.1789,'s':0.13805,'m':4.0987},
	29:{'l':0.1758,'s':0.13771,'m':4.1353},
	30:{'l':0.1727,'s':0.13738,'m':4.1716},
	31:{'l':0.1697,'s':0.13706,'m':4.2075},
	32:{'l':0.1668,'s':0.13674,'m':4.2431},
	33:{'l':0.1638,'s':0.13643,'m':4.2783},
	34:{'l':0.161,'s':0.13613,'m':4.3131},
	35:{'l':0.1582,'s':0.13583,'m':4.3476},
	36:{'l':0.1554,'s':0.13554,'m':4.3818},
	37:{'l':0.1526,'s':0.13526,'m':4.4155},
	38:{'l':0.1499,'s':0.13498,'m':4.449},
	39:{'l':0.1473,'s':0.1347,'m':4.482},
	40:{'l':0.1446,'s':0.13444,'m':4.5148},
	41:{'l':0.142,'s':0.13418,'m':4.5472},
	42:{'l':0.1395,'s':0.13392,'m':4.5793},
	43:{'l':0.1369,'s':0.13367,'m':4.611},
	44:{'l':0.1344,'s':0.13342,'m':4.6425},
	45:{'l':0.132,'s':0.13318,'m':4.6736},
	46:{'l':0.1295,'s':0.13295,'m':4.7044},
	47:{'l':0.1271,'s':0.13272,'m':4.7349},
	48:{'l':0.1247,'s':0.1325,'m':4.7651},
	49:{'l':0.1224,'s':0.13228,'m':4.795},
	50:{'l':0.12,'s':0.13206,'m':4.8245},
	51:{'l':0.1177,'s':0.13185,'m':4.8538},
	52:{'l':0.1154,'s':0.13165,'m':4.8828},
	53:{'l':0.1132,'s':0.13145,'m':4.9115},
	54:{'l':0.1109,'s':0.13125,'m':4.9399},
	55:{'l':0.1087,'s':0.13106,'m':4.968},
	56:{'l':0.1065,'s':0.13087,'m':4.9959},
	57:{'l':0.1044,'s':0.13068,'m':5.0235},
	58:{'l':0.1022,'s':0.1305,'m':5.0509},
	59:{'l':0.1001,'s':0.13033,'m':5.078},
	60:{'l':0.098,'s':0.13015,'m':5.1049},
	63:{'l':0.0918,'s':0.12966,'m':5.1842},
	70:{'l':0.0779,'s':0.12861,'m':5.3618},
	77:{'l':0.0648,'s':0.1277,'m':5.5295},
	84:{'l':0.0525,'s':0.12691,'m':5.6883},
	91:{'l':0.0407,'s':0.12622,'m':5.8393},
	98:{'l':0.0295,'s':0.12561,'m':5.9831},
	105:{'l':0.0188,'s':0.12507,'m':6.1202},
	112:{'l':0.0086,'s':0.12459,'m':6.2511},
	119:{'l':-0.0013,'s':0.12417,'m':6.3761},
	126:{'l':-0.0107,'s':0.1238,'m':6.4956},
	133:{'l':-0.0198,'s':0.12346,'m':6.6099},
	140:{'l':-0.0285,'s':0.12317,'m':6.7192},
	147:{'l':-0.0369,'s':0.12291,'m':6.8238},
	154:{'l':-0.045,'s':0.12268,'m':6.9241},
	161:{'l':-0.0529,'s':0.12248,'m':7.0205},
	168:{'l':-0.0605,'s':0.12231,'m':7.1133},
	175:{'l':-0.0678,'s':0.12217,'m':7.2029},
	182:{'l':-0.0749,'s':0.12205,'m':7.2894},
	197:{'l':-0.0894,'s':0.12188,'m':7.4657},
	227:{'l':-0.1157,'s':0.12177,'m':7.7867},
	257:{'l':-0.1388,'s':0.12187,'m':8.0746},
	287:{'l':-0.1593,'s':0.12209,'m':8.3369},
	317:{'l':-0.1774,'s':0.12233,'m':8.5808},
	347:{'l':-0.1935,'s':0.12256,'m':8.8119},
	377:{'l':-0.2077,'s':0.12274,'m':9.0344},
	407:{'l':-0.2204,'s':0.12288,'m':9.2511},
	437:{'l':-0.2317,'s':0.12296,'m':9.4637},
	467:{'l':-0.2418,'s':0.12301,'m':9.6735},
	497:{'l':-0.2507,'s':0.12304,'m':9.8816},
	527:{'l':-0.2587,'s':0.12307,'m':10.0884},
	557:{'l':-0.2658,'s':0.12311,'m':10.2939},
	587:{'l':-0.2721,'s':0.12317,'m':10.4985},
	617:{'l':-0.2777,'s':0.12326,'m':10.7025},
	647:{'l':-0.2827,'s':0.12339,'m':10.9065},
	677:{'l':-0.2872,'s':0.12355,'m':11.1111},
	707:{'l':-0.2912,'s':0.12373,'m':11.3163},
	737:{'l':-0.2948,'s':0.12395,'m':11.5221},
	767:{'l':-0.2981,'s':0.12419,'m':11.7279},
	797:{'l':-0.301,'s':0.12446,'m':11.9331},
	827:{'l':-0.3037,'s':0.12477,'m':12.1366},
	857:{'l':-0.3061,'s':0.12512,'m':12.3375},
	887:{'l':-0.3083,'s':0.12551,'m':12.5356},
	917:{'l':-0.3103,'s':0.12593,'m':12.7305},
	947:{'l':-0.3122,'s':0.12639,'m':12.9224},
	977:{'l':-0.314,'s':0.12688,'m':13.1119},
	1007:{'l':-0.3156,'s':0.12741,'m':13.2996},
	1037:{'l':-0.3172,'s':0.12798,'m':13.4863},
	1067:{'l':-0.3187,'s':0.12858,'m':13.6723},
	1097:{'l':-0.3202,'s':0.12922,'m':13.858},
	1127:{'l':-0.3216,'s':0.12989,'m':14.0435},
	1157:{'l':-0.323,'s':0.1306,'m':14.2288},
	1187:{'l':-0.3243,'s':0.13134,'m':14.4136},
	1217:{'l':-0.3257,'s':0.13211,'m':14.5979},
	1247:{'l':-0.327,'s':0.13291,'m':14.7816},
	1277:{'l':-0.3283,'s':0.13372,'m':14.9644},
	1307:{'l':-0.3296,'s':0.13455,'m':15.1463},
	1337:{'l':-0.3308,'s':0.13539,'m':15.3275},
	1367:{'l':-0.3321,'s':0.13623,'m':15.5079},
	1397:{'l':-0.3334,'s':0.13707,'m':15.6877},
	1427:{'l':-0.3347,'s':0.1379,'m':15.8669},
	1457:{'l':-0.3359,'s':0.13873,'m':16.0459},
	1487:{'l':-0.3372,'s':0.13956,'m':16.2246},
	1517:{'l':-0.3385,'s':0.14038,'m':16.4032},
	1547:{'l':-0.3398,'s':0.14118,'m':16.5817},
	1577:{'l':-0.3411,'s':0.14198,'m':16.76},
	1607:{'l':-0.3424,'s':0.14277,'m':16.9381},
	1637:{'l':-0.3437,'s':0.14354,'m':17.1159},
	1667:{'l':-0.345,'s':0.14431,'m':17.2931},
	1697:{'l':-0.3463,'s':0.14506,'m':17.4696},
	1727:{'l':-0.3476,'s':0.14581,'m':17.6453},
	1757:{'l':-0.3489,'s':0.14654,'m':17.82},
	1787:{'l':-0.3502,'s':0.14727,'m':17.9937},
	1817:{'l':-0.3514,'s':0.14799,'m':18.1663},
	1847:{'l':-0.3527,'s':0.14871,'m':18.3378}
}

let WeightForAgeMale = {
	0:{'l':0.3487,'s':0.14602,'m':3.3464},
	1:{'l':0.3127,'s':0.14693,'m':3.3174},
	2:{'l':0.3029,'s':0.14676,'m':3.337},
	3:{'l':0.2959,'s':0.14647,'m':3.3627},
	4:{'l':0.2903,'s':0.14611,'m':3.3915},
	5:{'l':0.2855,'s':0.14571,'m':3.4223},
	6:{'l':0.2813,'s':0.14528,'m':3.4545},
	7:{'l':0.2776,'s':0.14483,'m':3.4879},
	8:{'l':0.2742,'s':0.14436,'m':3.5222},
	9:{'l':0.2711,'s':0.14388,'m':3.5576},
	10:{'l':0.2681,'s':0.14339,'m':3.5941},
	11:{'l':0.2654,'s':0.1429,'m':3.6319},
	12:{'l':0.2628,'s':0.14241,'m':3.671},
	13:{'l':0.2604,'s':0.14192,'m':3.7113},
	14:{'l':0.2581,'s':0.14142,'m':3.7529},
	15:{'l':0.2558,'s':0.14093,'m':3.7956},
	16:{'l':0.2537,'s':0.14044,'m':3.8389},
	17:{'l':0.2517,'s':0.13996,'m':3.8828},
	18:{'l':0.2497,'s':0.13948,'m':3.927},
	19:{'l':0.2478,'s':0.139,'m':3.9714},
	20:{'l':0.246,'s':0.13853,'m':4.0158},
	21:{'l':0.2442,'s':0.13807,'m':4.0603},
	22:{'l':0.2425,'s':0.13761,'m':4.1046},
	23:{'l':0.2408,'s':0.13715,'m':4.1489},
	24:{'l':0.2392,'s':0.1367,'m':4.193},
	25:{'l':0.2376,'s':0.13626,'m':4.2369},
	26:{'l':0.2361,'s':0.13582,'m':4.2806},
	27:{'l':0.2346,'s':0.13539,'m':4.324},
	28:{'l':0.2331,'s':0.13497,'m':4.3671},
	29:{'l':0.2317,'s':0.13455,'m':4.41},
	30:{'l':0.2303,'s':0.13413,'m':4.4525},
	31:{'l':0.229,'s':0.13372,'m':4.4946},
	32:{'l':0.2276,'s':0.13332,'m':4.5363},
	33:{'l':0.2263,'s':0.13292,'m':4.5776},
	34:{'l':0.225,'s':0.13253,'m':4.6185},
	35:{'l':0.2237,'s':0.13215,'m':4.659},
	36:{'l':0.2225,'s':0.13177,'m':4.699},
	37:{'l':0.2213,'s':0.13139,'m':4.7386},
	38:{'l':0.2201,'s':0.13102,'m':4.7778},
	39:{'l':0.2189,'s':0.13066,'m':4.8166},
	40:{'l':0.2178,'s':0.1303,'m':4.8549},
	41:{'l':0.2166,'s':0.12994,'m':4.8928},
	42:{'l':0.2155,'s':0.1296,'m':4.9303},
	43:{'l':0.2144,'s':0.12925,'m':4.9674},
	44:{'l':0.2133,'s':0.12891,'m':5.0041},
	45:{'l':0.2122,'s':0.12858,'m':5.0404},
	46:{'l':0.2112,'s':0.12825,'m':5.0763},
	47:{'l':0.2101,'s':0.12792,'m':5.1118},
	48:{'l':0.2091,'s':0.1276,'m':5.1469},
	49:{'l':0.2081,'s':0.12729,'m':5.1817},
	50:{'l':0.2071,'s':0.12698,'m':5.2161},
	51:{'l':0.2061,'s':0.12667,'m':5.2501},
	52:{'l':0.2052,'s':0.12637,'m':5.2837},
	53:{'l':0.2042,'s':0.12607,'m':5.3171},
	54:{'l':0.2032,'s':0.12577,'m':5.35},
	55:{'l':0.2023,'s':0.12548,'m':5.3826},
	56:{'l':0.2014,'s':0.1252,'m':5.4149},
	57:{'l':0.2005,'s':0.12491,'m':5.4468},
	58:{'l':0.1996,'s':0.12463,'m':5.4784},
	59:{'l':0.1987,'s':0.12436,'m':5.5097},
	60:{'l':0.1978,'s':0.12409,'m':5.5407},
	63:{'l':0.1952,'s':0.1233,'m':5.6319},
	70:{'l':0.1894,'s':0.12157,'m':5.8346},
	77:{'l':0.184,'s':0.12001,'m':6.0242},
	84:{'l':0.1789,'s':0.1186,'m':6.2019},
	91:{'l':0.174,'s':0.11732,'m':6.369},
	98:{'l':0.1694,'s':0.11618,'m':6.5265},
	105:{'l':0.1651,'s':0.11516,'m':6.6755},
	112:{'l':0.1609,'s':0.11425,'m':6.8168},
	119:{'l':0.1568,'s':0.11345,'m':6.9513},
	126:{'l':0.1529,'s':0.11274,'m':7.0794},
	133:{'l':0.1492,'s':0.11212,'m':7.2018},
	140:{'l':0.1456,'s':0.11158,'m':7.3187},
	147:{'l':0.1421,'s':0.11111,'m':7.4307},
	154:{'l':0.1387,'s':0.1107,'m':7.5379},
	161:{'l':0.1354,'s':0.11035,'m':7.6406},
	168:{'l':0.1322,'s':0.11005,'m':7.7394},
	175:{'l':0.129,'s':0.1098,'m':7.8344},
	182:{'l':0.126,'s':0.10959,'m':7.926},
	197:{'l':0.1197,'s':0.10925,'m':8.112},
	227:{'l':0.1081,'s':0.1089,'m':8.4474},
	257:{'l':0.0974,'s':0.1088,'m':8.7453},
	287:{'l':0.0875,'s':0.10884,'m':9.0169},
	317:{'l':0.0782,'s':0.10896,'m':9.2691},
	347:{'l':0.0695,'s':0.10913,'m':9.5077},
	377:{'l':0.0613,'s':0.10934,'m':9.7364},
	407:{'l':0.0534,'s':0.10959,'m':9.9575},
	437:{'l':0.046,'s':0.10987,'m':10.1728},
	467:{'l':0.0389,'s':0.11019,'m':10.3839},
	497:{'l':0.032,'s':0.11053,'m':10.5918},
	527:{'l':0.0255,'s':0.11091,'m':10.7971},
	557:{'l':0.0192,'s':0.11132,'m':11.0},
	587:{'l':0.013,'s':0.11177,'m':11.2011},
	617:{'l':0.0071,'s':0.11224,'m':11.4011},
	647:{'l':0.0014,'s':0.11275,'m':11.6005},
	677:{'l':-0.0041,'s':0.11327,'m':11.7991},
	707:{'l':-0.0095,'s':0.11382,'m':11.9971},
	737:{'l':-0.0148,'s':0.11439,'m':12.1941},
	767:{'l':-0.0199,'s':0.11497,'m':12.3895},
	797:{'l':-0.0249,'s':0.11555,'m':12.5826},
	827:{'l':-0.0297,'s':0.11614,'m':12.7728},
	857:{'l':-0.0345,'s':0.11673,'m':12.9597},
	887:{'l':-0.0391,'s':0.11731,'m':13.1431},
	917:{'l':-0.0437,'s':0.11788,'m':13.3231},
	947:{'l':-0.0481,'s':0.11845,'m':13.5},
	977:{'l':-0.0525,'s':0.11902,'m':13.674},
	1007:{'l':-0.0567,'s':0.11957,'m':13.8455},
	1037:{'l':-0.0609,'s':0.12012,'m':14.015},
	1067:{'l':-0.065,'s':0.12065,'m':14.183},
	1097:{'l':-0.0691,'s':0.12118,'m':14.3498},
	1127:{'l':-0.073,'s':0.1217,'m':14.5158},
	1157:{'l':-0.0769,'s':0.12221,'m':14.6811},
	1187:{'l':-0.0808,'s':0.12271,'m':14.8462},
	1217:{'l':-0.0845,'s':0.12321,'m':15.0112},
	1247:{'l':-0.0882,'s':0.12372,'m':15.1761},
	1277:{'l':-0.0919,'s':0.12423,'m':15.341},
	1307:{'l':-0.0955,'s':0.12474,'m':15.5058},
	1337:{'l':-0.099,'s':0.12527,'m':15.6705},
	1367:{'l':-0.1025,'s':0.12581,'m':15.835},
	1397:{'l':-0.1059,'s':0.12637,'m':15.9992},
	1427:{'l':-0.1093,'s':0.12693,'m':16.1632},
	1457:{'l':-0.1127,'s':0.12751,'m':16.3271},
	1487:{'l':-0.116,'s':0.1281,'m':16.4908},
	1517:{'l':-0.1192,'s':0.12871,'m':16.6545},
	1547:{'l':-0.1225,'s':0.12932,'m':16.8181},
	1577:{'l':-0.1256,'s':0.12993,'m':16.9818},
	1607:{'l':-0.1288,'s':0.13056,'m':17.1455},
	1637:{'l':-0.1319,'s':0.13119,'m':17.3091},
	1667:{'l':-0.1349,'s':0.13182,'m':17.4726},
	1697:{'l':-0.138,'s':0.13245,'m':17.636},
	1727:{'l':-0.1409,'s':0.13308,'m':17.7991},
	1757:{'l':-0.1439,'s':0.13372,'m':17.9619},
	1787:{'l':-0.1468,'s':0.13435,'m':18.1245},
	1817:{'l':-0.1497,'s':0.13498,'m':18.2867},
	1847:{'l':-0.1526,'s':0.13561,'m':18.4484}
}

const result_null = { 't':'str','v':''};

function ageToMini(y){

    if (y >= 182){
        return ( y - ((y - 182) % 30) + 15)
    }else if (y >= 60){
        return (y - ((y - 60) % 7) + 3)
    }else {
        return y;
    }
}

function computeZScore(y, m ,l,s){

    return ((Math.pow((y / m), l) - 1) / (s * l));

}

function computeReverseZScore(y, m ,l,s){
    return (m * Math.pow((z*s*l+1),(1/l)));
}

module.exports = function(field_sex, field_age_in_day, field_weight ) {
    //collect data
    let sex = getStrValue(field_sex);
    let age = getDecimalValue(field_age_in_day); //getAgeInMonth(getDateValue(field_dob))
    let weight = getDecimalValue(field_weight);
    if (age === null || sex === null || weight === null ){
        return result_null;
    }
    let row = null;
    age_min = (ageToMini(age));
    if (sex === 'female'){
        row = WeightForAgeFemale[age_min]
    }else{
        row = WeightForAgeMale[age_min]
    }

    //swich treatement
    let value = computeZScore(
        weight,
        row['m'], 
        row['l'] ,
        row['s']
    )    
    //console.log('treatment for '+str_treatment.v + ': age '+ age+', sex' + sex +', weight ' +weight + ' -> ' + obj.t +': '+ obj.v )
    return { 't':'num','v':value};
}

```

---

<div class="post-metadata">

**Author:** ![delcroip](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/delcroip/32/1568_2.png) [@delcroip](https://forum.communityhealthtoolkit.org/u/delcroip)\
**Post date:** [June 2, 2023, 2:30pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/8 "2023-06-02T14:30:05Z")

</div>

I fixed a error on the wfa.js

the function call look like this

```auto
cht:extension-lib('wfa.js',${p_sel_gender}, ${p_age_day},${p_weight}) 

```

and here are the sources [GitHub - WorldHealthOrganization/anthro: Computation of the WHO Child Growth Standards](https://github.com/WorldHealthOrganization/anthro)

---

<div class="post-metadata">

**Author:** ![bamatic](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/bamatic/32/1318_2.png) [@bamatic](https://forum.communityhealthtoolkit.org/u/bamatic)\
**Post date:** [January 7, 2025, 12:24pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/9 "2025-01-07T12:24:36Z")

</div>

Hi there,  
I’ve an use case that I think can be resolved with this feauture, at this moment I’ve just no experience with the CHT v4 so I would want to get your confirmation if possible

From an assessment app form I need to generate a code from the name of the patient and the current date and show this code in a note to the community health worker, so the CHW can give this code to the patient.

So with the latest CHTv4, that we plan to install in production this month, I think that we will be able to write an external function that returns the encoded string, taking as parameter the name of the patient and that we’ll be able to execute this function from the assessment app form.

could you, if possible, confirm this ?  
thank you

---

<div class="post-metadata">

**Author:** ![jkuester](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/jkuester/32/806_2.png) [@jkuester](https://forum.communityhealthtoolkit.org/u/jkuester)\
**Post date:** [January 7, 2025, 3:13pm UTC](https://forum.communityhealthtoolkit.org/t/4-2-release-date-and-extension-libs/2702/10 "2025-01-07T15:13:34Z")

</div>

In short, yes, this sounds like a very good use case for an extension-lib function! 👍
