Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Summary

This method retrieves a value from another collected form in the same study event. It filters the forms returned to find only Complete data.INSERT VIDEO HERE

Iframe
srchttps://player.vimeo.com/video/626541824?h=6b8f60ad50&
width650
frameborderhide
alignmiddle
height450

Formal Expression

Code Block
// set the name of the item which contains the desired value
var DATE_OF_VISIT_ITEM_NAME = 'SV_DATE'
var studyEventName = formJson.form.studyEventName;
logger('studyEventName '+studyEventName);
var allVisitData = findFormData(studyEventName,'Date of Visit');
var completedVisitData = collectCompleted(allVisitData);

var visitDataForm = null
if (completedVisitData.length == 0) {
    logger('no completedVisitData found');
} else if (completedVisitData.length == 1) {
    visitDataForm = completedVisitData[0];
} else if (completedVisitData.length > 1) {
    logger('multiple values of completedVisitData found.  Picking the first');
    visitDataForm = completedVisitData[0];
}

var value = null;
if (visitDataForm != null) {
    value = findFirstItemValueByName(visitDataForm, DATE_OF_VISIT_ITEM_NAME);
}
return value;

function collectCompleted(formDataArray) {
    if (formDataArray == null) { return []; }
    var keepers = [];
    for (var i = formDataArray.length - 1; i >= 0; i--) {
        var formData = formDataArray[i];
        if (formData.form.canceled == false && formData.form.itemGroups[0].canceled == false && (formData.form.dataCollectionStatus == 'Complete'
        )) {
            keepers.push(formData);
        }
    }
    return keepers;
}

...