While developing forms, we use JSON to accomplish this. JSON is "self-describing" and easy to understand. Here, we shall look at the basic JSON syntax, their meanings and use case and a detail of the validations we add to the form engine to improve form behaviour.
...
isEmpty(testingLocation)
-isEmpty
is a REACT method that is used to check if a question is empty or values weren’t selected. This hideWhenExpression then would imply that the question with this behaviour in it should not open/display if at all the question with idtestingLocation
is empty or if no value was selected in it. We can also express this behaviour like below:Code Block language js testingLocation == "5995ebd5-11ae-47ca-ac12-bcb8c0117aec";
Meaning that the question should not open if at all the question with id
testingLocation
doesn't have the value with concept5995ebd5-11ae-47ca-ac12-bcb8c0117aec
selected.!includes('vaccineAdministered','5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
-!includes
as well is a REACT method that takes care of the logic of “if a question does not include”. Therefore, for this scenario if the question with idvaccineAdministered
doesn't include a selected value with concept5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
, it should hide the field in which this hideWhenExpression behaviour is.vaccineDose == null
- This means if a question with idvaccineDose
has no values selected/is NULL, the current question in which this hideWhenExpression is should be hidden or not displayed. Instead of Null we can also put in a concept pointing to a given field e.g.Code Block language js vaccineDose == "5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
myValue <= useFieldValue('vaccinationDate')
-useFieldValue
is a REACT method that uses a specified field value for the id provided to a given question. For thisfailsWhenExpression
then means that the current question should fail or throw and error if the value is less than or equal to the value added by the user in the UI for the question with id vaccinationDate i.e. if the user entered the date ‘2021-03-09' for the vaccination Date question, the question in which this validator is should throw an error and fail to save if at all the date value of said question is less than or equal to2021-03-09
.
Form Configuration
You will need to define the form validation rules using JSON expressions for each form element. Behaviors such as conditional visibility, error handling, and action triggers are configurable. Additionally, Test the form using the form-render to ensure validations and behaviors function as expected.
Example Validation Expression:
Code Block |
---|
{
"label": "Date of Birth",
"type": "obs",
"questionOptions": {
"rendering": "date",
"concept": "164802AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"weeksList": ""
},
"id": "birthDate",
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "!isDateEqualTo(myValue, useFieldValue('visit_date'))",
"message": "Child birth date should be the same as the visit date!"
}
]
}
]
}
|
Launching Forms in the RFE
In the RFE, there is function is used to launch and view a form within the patient workspace. It serves the purpose of displaying forms for viewing purposes, such as reviewing previously entered data or accessing read-only versions of forms, in min/max workspace size, and includes associated data like encounterUuid
and patientUuid
. Additionally, it provides callbacks for form save and form mutation actions.
The function has parameters like the OHRIFormSchema
includes essential information about the form's structure, fields, validations, and other configuration settings necessary for rendering and processing the form within the patient workspace.
When launching forms within the patient workspace. The RFE four distinct actions: add
for adding new form entries, view
for read-only form viewing, edit
for modifying existing entries, and embedded-view
specifically designed for viewing embedded forms within another form.
...
The Form Development in the OpenMRS React Form Engine provides a powerful toolset for creating and configuring forms. By leveraging JSON syntax, users can build customized forms tailored to medical record management workflows, improving data collection and usability within the OpenMRS platform.