© 2024 IQVIA - All Rights Reserved
Triplicate Reading Average (1 Form)
Summary
This method returns the average of multiple collected item values. A common use case is ECG triplicate readings, but it will apply to any similar use case. It also can be used to average an arbitrary number of values as long as the FormData conforms to the conventions used by this method.
Form Setup
This method requires that the average values are collected in the same form as the three triplicate values. So you’ll want to create an ‘averages’ item group within your triplicate form to house your calculated-average items.
This method returns a ‘float’ datatype value. Therefore, the item you associate it with must also be a float datatype. You can adjust the number of decimal places returned by the method.
Formal Expression
Using this method, the following fields might require editing based on your naming conventions and decimal place precision requirements for averaged results.
Here is an example showing this method applied to ECG Rate values:
var leftItemGroupName = 'ECG 1_V2';
var leftItemName = 'RATE1';
var rightItemGroupName = 'ECG 2_V2';
var rightItemName = 'RATE2';
var middleItemGroupName = 'ECG 3_V2';
var middleItemName = 'RATE3';
var itemGroupRepeatKey = itemJson.item.itemGroupRepeatKey;
// logger('itemGroupRepeatKey='+itemGroupRepeatKey);
var leftVal = parseInt (findFirstItemValueByGroupAndItemName(formJson, leftItemName, leftItemGroupName, itemGroupRepeatKey));
var rightVal = parseInt (findFirstItemValueByGroupAndItemName(formJson, rightItemName, rightItemGroupName, itemGroupRepeatKey));
var middleVal = parseInt (findFirstItemValueByGroupAndItemName(formJson, middleItemName, middleItemGroupName, itemGroupRepeatKey));
result = ((leftVal + rightVal + middleVal) / 3);
result = result.toFixed(2);
return result;
/* Finds the first match of an item from the given form. First search with item name (if provided) then searches with sasFieldName*/
function findFirstItemValueByGroupAndItemName(formJson, itemName, itemGroupName, itemGroupRepeatKey) {
var itemGroups = formJson.form.itemGroups;
if (itemGroups && itemGroups.length) {
for (var i = 0; i < itemGroups.length; i++) {
var itemGroup = itemGroups[i];
if (itemGroupRepeatKey == null || itemGroupRepeatKey == itemGroup.itemGroupRepeatKey) {
if (itemGroupName == itemGroup.name) {
var items = itemGroup.items;
for (var j = 0; j < items.length; j++) {
var item = items[j];
if (item.name == itemName) return item.value;
}
}
}
}
}
return null;
}
Exported and Printed Copies Are Uncontrolled