Date Time comparison - dynamic query
Compare two date questions that also have time elements and display a dynamic query if the dates are not as expected.
Rule description: Collection Date and Time must be on or prior to the Study Vaccine Administration Date and Time of Injection.
Rule expression
//to meet the rule description criteria colldt-vaccdt should be a negative value or 0 (<=0)
if(timeDiffInMinutes(colldt,vaccdt)<=0)
{
return true;
}
else
{
var dt1=getDateDMYFormat(colldt,"HH:mm");
var dt2=getDateDMYFormat(vaccdt,"HH:mm");
var qtstr="Potential Protocol Deviation: Blood sample "+dt1+" was obtained post-injection "+dt2+".Please reconcile or complete Protocol Deviation CRF."
setQueryMessage(qtstr); //query message set dynamically
return false; //System sends query when return false condition is met
}
Query message: Potential Protocol Deviation: Blood sample {SampleDate} was obtained post-injection {injectiondate}. Please reconcile or complete Protocol Deviation CRF.
Definitions
- colldt
-
Corresponds to the Collection Date and Time from the rule description.
- vaccdt
-
Corresponds to the Study Vaccine Administration Date and Time from rule description.
- <=
-
Less Than or Equal To operator. Update operator based on the rule description.
- timeDiffInMinutes( )
-
Calculates difference between date1 (colldt), date2 (vaccdt) (date1-date2) in minutes.
- getDateDMYFormat( )
- Returns a date or datetime in DD-Mon-YYYY format, including time elements if applicable.
-
"HH:mm"
- Time format passed as a parameter for the
getDateDMYFormat()
helper function to define the output format of the time elements present. - setQueryMessage( )
-
Specify dynamic query text using the setQueryMessage( ) function.
Return value
Usage tips
- Always use the relevant date helper function to compare dates rather than comparing the variables directly using comparison operators.
- Use this when comparison should be performed for full dates with time.
Verification steps
- Using a subject for testing, go to the given visit and form containing the
date items to compare, in this example the sample collection date
<
colldt
> and study vaccine administration date <vaccdt
>. - Update the form items
colldt
andvaccdt
as in the following table and verify the result is as listed:colldt
vaccdt
Result 10-May-2021 10:00 Null
No query 10-May-2021 10:00 10-May-2021 10:00 No query 10-May-2021 10:01 10-May-2021 10:00 Query. Verify correct date values are populated in the Query Text.
10-May-2021 09:59 10-May-2021 10:00 No query 11-Jun-2021 10:00 10-May-2021 10:00 Query. Verify correct date values are populated in the Query Text.
11-Apr-2021 07:01 10-May-2021 10:00 No query Null
10-May-2021 10:00 No query
Other examples
Example 4-23 ECG Date [and Time Performed] must be on or prior to either 'Date of Study Completion'
if(dateDiffInDays(ecgdt,compdt)<=0)
{
return true;
}
var dt1=getDateDMYFormat(ecgdt,"HH:mm");
var dt2=getDateDMYFormat(compdt);
var qtstr="Date is "+dt1+" after Date of Study Completion or Discontinuation "+dt2+". Please correct or confirm date(s).";
setQueryMessage(qtstr);
return false;
}
Query message: Date is after Date of Study Completion or Discontinuation. Please correct or confirm date(s).
Parent topic: Dates with Dynamic Query Text