...
BASELINE_STUDY_EVENT
BASELINE_FORM
BASELINE_ITEM_NAME
THIS_ITEM_NAME
Note also that the number in line 16 can be modified to adjust the decimal place precision of the percentage increase or decrease.
Code Block | ||
---|---|---|
| ||
//calculates percent increase or decrease compared to BASELINE_STUDY_EVENT //adjust the first four variables var BASELINE_STUDY_EVENT = 'Screening'; //study event name associated with the baseline form var BASELINE_FORM = "Baseline Form"; //baseline form name var BASE_ITEM_NAME = 'AverageSys'; //baseline item name to be compared var THIS_ITEM_NAME = 'AverageSys'; //the name of the current item var retpercent = null; var baseForms = findFormData(BASELINE_STUDY_EVENT, BASELINE_FORM); //find the baseline form if (baseForms !== null && baseForms.length === 1) { //if the form exists perform the following var baselineSum = findFirstItemValueByName(baseForms[0], BASE_ITEM_NAME); //find the baseline item value var thisFormSum = findFirstItemValueByName(formJson, THIS_ITEM_NAME); //find the value of the current item if (!isNaN(baselineSum) && !isNaN(thisFormSum)) { //ensure neither value is null retpercent = Math.round(((Number(thisFormSum) - Number(baselineSum)) / Number(baselineSum))*100); //perform the calculation... ((current - baseline)/baseline)*100 var percentTruncate = percent.toFixed(1); //specify decimal place precision } } return retpercentTruncate; |