© 2024 IQVIA - All Rights Reserved

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Summary

This document shows two patterns of edit checks. The first shows an example of how to work with simple Date string inputs. The second shows how to work with ClinSpark’s native Item DataTypes which include partial datatime types.

Common String Dates

This Edit Check relies on various date conversions to convert date string values such as 01Feb2019 and 1992-06-27 to javascript dates that can be used for comparison.

In the below example, this edit check ensures that some item date is after the volunteer DOB as recorded in the volunteer record.

// Medical history start date should be after or equal to date of birth
var dob = formJson.form.subject.volunteer.dateOfBirth;
var startDate = findFirstItemByName(formJson, 'MH Start Date').value;
logger('dob = '+dob);
logger('parseDate2(dob) '+parseDate2(dob));
return parseDate1(startDate).getTime() > parseDate2(dob).getTime();

ClinSpark Date DataTypes

This edit check is designed to be attached to an item of type DateTime. It marks an itemData as nonconformant if it is before another itemData in the same form, which also must be of type DateTime.

This Edit Check relies on clinsparkDateToMilliseconds to convert relevant date/time values to milliseconds. Once the values are in milliseconds, the comparison can be made as required.

Form Setup

This Edit Check example expects that both dates are contained within the same Form. Though of course any of the dates could also be retrieved using findFormData to look up previously-collected data for the same subject.

This is meant to be an example, and will likely require modification for your use case. Easy modifications can change the comparison operator, supporting >=, <=, etc.

Here is a walkthrough showing how to use the method:

Formal Expression

  • First = item that is expected to be first

  • Second = item that is expected to be first

var first = findFirstItemByName(formJson, 'incomplete DateTime 1');
var second = findFirstItemByName(formJson, 'incomplete DateTime 2');

return clinsparkDatesToMilliseconds(first) >= clinsparkDatesToMilliseconds(second);

/* Extracts the time in milliseconds for ClinSpark item DataTypes including DateTime, Date, Time and the 
incomplete versions of each of these.  Expects that the dataType has a date component.  May not be meaningful 
if the DateTypes do not match.
*/
function clinsparkDatesToMilliseconds(itemData) {
    var dateFields = toDateFields(itemData);
    var timeFields = toTimeFields(itemData);
    // logger('input value '+itemData.value);
    // logger('Date fields '+dateFields);
    // logger('Time fields '+timeFields);

    var date = new Date(dateFields[0],dateFields[1],dateFields[2],timeFields[0],timeFields[1],timeFields[2]);
    // logger('ms: '+date.getTime()+' '+date);
    return date.getTime();
}

/* Extracts the date fields from an itemData which contains them.  For incomplete
type blank fields are replaced with 1
*/
function toDateFields(item) {
    var value = item.value;
    var d = [0,1,1];
    if (item.dataType.toLowerCase().indexOf('datetime') != -1) {
      d = value.split('T')[0].split('-');
    } else if (item.dataType.toLowerCase().indexOf('date') != -1) {
      d = value.split('-');
    }
    
    d = defautBlankArrayElements(d, 1);
    d[1] = d[1] -1; // // date field is 0 based
    return d;
}

/* Extracts the time fields from an itemData which contains them.  For incomplete
type blank fields are replaced with 0
*/
function toTimeFields(item) {
    var value = item.value;
    var d = [0,0,0];
    if (item.dataType.toLowerCase().indexOf('datetime') != -1) {
      d = value.split('T')[1].split(':');
    } else if (item.dataType.toLowerCase().indexOf('time') != -1) {
      d = value.split(':');
    }
    d = defautBlankArrayElements(d, 0);

    return d;
}

function defautBlankArrayElements(array, defaultInt, isDate) {
    for (var i=0; i < array.length; i++) {
        if (typeof array[i] === 'undefined' || (typeof array[i] == 'string' && array[i].trim().length == 0)) { 
            array[i] = defaultInt; 
        } 
    }
    return array;
} 

© 20

  • No labels