Versions Compared

Key

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

...

This edit check verifies that for a medical history form, the chosen value of ongoing is consistent with end date.<iframe width="640" height="336" src="

...

Formal Expression

Code Block
var ONGOING_SAS_FIELD_NAME = 'MHONGO';
var endDate = itemJson.item.value;
var repeatKey = itemJson.item.itemGroupRepeatKey;
logger('endDate '+endDate);
logger('repeatKey '+repeatKey);
var ongoingItem = findFirstItemByName(formJson, null, ONGOING_SAS_FIELD_NAME, repeatKey);
var ongoing = ongoingItem.value;
logger('ongoing '+ongoing);

var valid = true;
if (ongoing.equalsIgnoreCase('true')) {
    if (endDate) {
        customErrorMessage('There can not be an end date if ongoing is true');
        valid = false;
    }
} else if (ongoing.equalsIgnoreCase('false')) {
    if (!endDate) {
        customErrorMessage('There must be an end date if ongoing is false');
        valid = false;
    }
} else {
    logger('unexpected ongoing value of ['+ongoing+']');
}
return valid;

...