Leave a comment at the end of this page or email contact@krishagni.com
Defining Data Validation
Data validations are defined using JSON by adding the editChecks section in the System/CP JSON configuration. It is a separate section in JSON.
Whenever the specified records are created or updated, the rules are evaluated, and if a rule fails, the system shows an error message and prevents saving.
Properties Used in Edit Checks
Constraint Level Properties
Property | Required | Description |
|---|---|---|
records | Yes | List of records on which validation should be evaluated. Whenever these records are created or modified, the rules are enforced. Possible values: cpr, visit, specimen, or a combination. |
forms | No | List of form names whose data is used in validation. If not specified, only core fields are validated. |
rules | Yes | List of rules that must be satisfied by the specified records and forms. |
Rule Level Properties
Property | Required | Description |
|---|---|---|
when | No | Specifies when the rule is applicable. For example, apply only for primary specimens. |
expr | Yes | The validation condition that must evaluate to true. If false, the record cannot be saved. |
description | Yes | User-friendly error message displayed when the rule fails. |
Aliases Used in Edit Checks
Record Aliases
Alias | Refers To | Usage |
|---|---|---|
#cpr | Collection Protocol Registration | Access CPR-level core fields in expr |
#visit | Visit record | Access visit-level core fields in expr |
| Specimen record | Access specimen-level core fields in expr |
Form Record Aliases
Alias | Refers To | How It Works |
|---|---|---|
| CPR-level forms | Map indexed by form name |
| Visit-level forms | Map indexed by form name |
| Specimen-level forms | Map indexed by form name |
Accessing Form Data Examples
Example | Description |
|---|---|
| Access the latest SpecimenFrozenEvent form record |
| Access all SpecimenFrozenEvent records for the specimen |
Example:
Visit date should be the same or later than the registration date
For more examples, please refer to the wiki page Data Validation Examples
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
A combination of the core fields, custom fields, and custom form fields
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 validations are added together, it will be difficult to identify the validation in case the above error ‘Cannot index into a null value’ occurs.
Leave a comment at the end of this page or email contact@krishagni.com