Data validations can be defined using JSON. The ‘editChecks’ section of the code must be inserted after the ‘dictionary’ section in the workflow JSON.
The code has three parts - records, forms and rules
records - Whenever any of these specified records are modified; the constraint rules should be evaluated/enforced. Refers to the fields at the data entry level for which the validation is to be applied. The value for records can be cpr, specimen, visit or a combination of these.
forms - Optional field. If present, specifies the list of forms whose data is used to enforce the constraints.
rules - List of integrity rules that should be satisfied by the records and forms.
A ‘rule’ is made up of three attributes when, expr, and description.
when: The attribute 'when' is optional and specifies when the rule is applicable. For example, the rule is applicable only for primary specimens
expr: The attribute 'expr' specifies the check constraint that should be satisfied.
description: The attribute 'description' describes the constraint in user-friendly language. This is also used in error messages when the rule is broken or not satisfied.
Aliases for rules are - “cpr, visit, primarySpecimen, specimen”, which are self-explanator.
Aliases for accessing the form records are cprForms, visitForms, primarySpecimenForms, specimenForms. These are maps that can be indexed by the form name to access the relevant form data. For example, specimenForms['SpecimenFrozenEvent'] can be used to access the latest frozen event. Similarly, specimenForms['SpecimenFrozenEvent$Array'] can be used to access the list of all the frozen events for the specimen in question.
Example: Visit date should be same or later than the registration date
{
"name" : "editChecks",
"data" : {
"constraints" : [
{
"records" : [ "cpr", "visit" ],
"rules" : [
{
"expr" : "#cpr.registrationDate != null && #visit.visitDate != null && !#cpr.registrationDate.after(#visit.visitDate)",
"description" : "Visit date should be same or later than the registration date!"
}
]
}
]
}
}
Data Validation Fields
We can set up data validation on these 3 types of fields and their combinations:
Core fields
Custom fields
Custom form fields
Combination of the core fields, custom fields, custom form fields
Level
Field Name
Field Expression
Level
Field Name
Field Expression
Participant
PPID
#cpr.ppid
Participant
First Name
#cpr.participant.firstName
Participant
Middle Name
Participant
Last Name
Participant
Registration Date
Participant
External Subject ID
Participant
Registration Site
Participant
Birth Date
Participant
Social Security Number
Participant
eMPI
Participant
Gender
Participant
Vital Status
Participant
Death Date
Participant
Races
Participant
Ethnicity
Participant
MRN
Visit
Name
Visit
Name
Visit
Status
Visit
Missed By
Visit
Missed Reason
Visit
Visit Date
Visit
Visit Site
Visit
Clinical Diagnosis
Visit
Clinical Status
Visit
SPR
Visit
Visit Comments
Specimen
Label
Specimen
Barcode
Specimen
Lineage
Specimen
Collection Status
Specimen
Type
Specimen
Anatomic Site
Specimen
Laterality
Specimen
Pathology Status
Specimen
Initial Qty
Specimen
Available Qty
Specimen
Concentration
Specimen
Parent Specimen Label
Specimen
Biohazard
Specimen
Location
Specimen
Created On
Specimen
Freezer Thaw Cycle
Specimen
Increment Freeze Thaw Cycle
Specimen
Comments
Specimen
Collection Date
Specimen
Collector
Specimen
Received Date
Specimen
Receiver
Specimen
Collection Container
Specimen
Collection Procedure
Specimen
Received Quality
Specimen
Frozen Time
Specimen
Frozen Method
Specimen
Frozen Comments
Adding Multiple Data Validations
In case there are many data validations to be performed, here is a tip that could help in avoiding errors:
Check and test the data entry workflow after adding each validation. This will allow you to identify if any validation fails and will be useful in rectifying the failed one. If all the validation are added together, it will be difficult to identify the validation in case the above error ‘Cannot index into a null value’ occurs.