...
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 ret = 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
ret = ((Number(thisFormSum) - Number(baselineSum)) / Number(baselineSum))*100; //perform the calculation... ((current - baseline)/baseline)*100
}
}
return ret; |
...