...
Specific Dropdowns and Their Needs
...
Trigger Component
The Trigger Component dropdown specifies the form field that the validation rule will apply to. This is the field whose value or state will be monitored to determine if the condition is met.
...
The Trigger Condition dropdown lets users define the specific condition to be checked on the Trigger Component. This could include options like "is empty", "not empty", "equals", “not equals”, "greater than or equal to", "less than or equal to", etc.
Conditional Value
The Conditional Value ( or target value ) dropdown is used to select or enter the value to be checked against the Trigger Condition. The Target Value component will only be visible if the conditions are "equals," "not equals," "greater than or equal to," or "less than or equal to."
Target Action
The Target Action dropdown specifies what action should be taken when the Trigger Condition is met. Examples: include hiding a field or custom validation logic.
...
Ensure that users do not skip mandatory fields in your form. With a simple toggle button, you can make any field required.
Example:
In a form, if you want to ensure that the "Name" field is mandatory, simply toggle the "Required" option for the "Name" field to enforce this validation.
...
Control whether date fields can accept future dates. This is particularly useful for fields like "Date of Birth" where future dates should be restricted.
Example:
For a "Date of Birth" field, toggle the "Disallow Future Dates" option to ensure users cannot select a date in the future.
...
Enable fields to decline decimal values when necessary. For example, age cannot be in decimal values.
Example:
For an "Age" field, toggle the "Disallow Decimal Values" option to decline entries like 12.2.
...
Check if a Field is Empty or Not Empty
Example:
Build a condition to check if the "Name" field is empty and trigger a corresponding action if it is.
...
Check if a Field is Equal to a Target Value
Example:
Check if the "Sex" field value is equal to "F" and display relevant fields accordingly.
...
Check if a Field's Value is Greater Than or Less Than a Target Value
Example:
Ensure the "Age" field value is greater than 18 to display additional fields for adult users.
...
Combine conditions using logical operators (&&, ||) to build comprehensive validation rules.
Example:
Check if the Name and Age fields are not empty, then show relevant fields accordingly.
...
Actions
hideWhenExpression
i ) Hiding the form field
The hideWhenExpression
action allows you to control the visibility of form fields based on specified conditions. This is particularly useful when you want certain fields to appear only when certain criteria are met, enhancing the user experience by showing only relevant fields.
Example Scenario
Consider a scenario where you are building a form that has two fields: Are you currently in HIV care or under ART?
and Reason for being in HIV care or on ART
. You want the Reason for being in HIV care or on the ART
field to be visible only if Are you currently in HIV care or under ART?
is equal to Yes
.
...
Define the Expression: Create a condition that checks if the
Are you currently in HIV care or under ART?
equals 'No'.Apply the Expression: Use
hideWhenExpression
to make theReason for being in HIV care or on the ART
field hidden unless the condition is met.
...
In this example, the Reason for being in HIV care or in the ART
field will only be shown when the Are you currently in HIV care or under ART?
is equal to Yes.
...
ii ) Hiding the specified page
...
iii ) Hiding the specified section
...
Failing a field:
The failsWhenExpression
action is used to define custom validation logic that determines when a form input should fail validation. This is useful for scenarios where default validation rules are not sufficient and you need to create more complex, condition-based validations.
...
Code Block | ||
---|---|---|
| ||
"validators": [ { "type": "js_expression", "failsWhenExpression": "isEmpty(guardianRelationship) || ageheight <= 140", "message": "PatientHeight should isbe eithergreater pediatricthan or aequal student. Please provide guardian relationship information.to zero" } ] |
In this example, the guardianRelationship
height
field will fail validation if it is empty and the age is 14 or youngerheight is lesser than zero. When the condition evaluates to true, the provided message will be displayed, indicating the validation error.
...
Expression: The logical condition that must be met for the validation to fail.
Message: The error message displayed to the user when the validation fails.
...
Calculation Expression:
The purpose of the calculation expression
is to automatically calculate values without requiring any manual effort.
i) Body Mass Index (BMI)
Example Scenario:
Consider a scenario where a doctor wants to calculate a patient's BMI using their height and weight as inputs. Typically, the doctor would need to perform the mathematical calculation manually each time, increasing their workload. It would be more efficient if the doctor could simply enter the patient's height and weight, and the patient's BMI would be automatically calculated and displayed in the BMI field.
Code Example
Code Block | ||
---|---|---|
| ||
"calculate": {
"calculateExpression": "calcBMI('height', 'weight')"
} |
ii) Body Surface Area (BSA) Calculation:
This function takes the height and weight values and returns the Body Surface Area (BSA).
Example Scenario:
Consider a scenario where a doctor needs to determine a patient's Body Surface Area (BSA) for medical dosing or treatment plans. By inputting the patient's height and weight, the function can automatically calculate and provide the BSA value, reducing the need for manual calculation and ensuring precision.
Code Example
Code Block |
---|
{
"calculate": {
"calculateExpression": "calcBSA('height','weight')"
}
} |
iii) Calculate Gravida :
The calcGravida
function calculates the total number of pregnancies (gravida) based on the number of term pregnancies and abortions/miscarriages. This function ensures that the inputs are valid numbers and returns the sum of the term pregnancies and abortions.
Code Example
Code Block |
---|
{
"calculate": {
"calculateExpression": "calcGravida('parityTerm','parityAbortion')"
}
} |
...
Does not Match Expression
This helper allows users to validate fields against regular expressions eg. in the failsWhenExpression as below
...
Time Calculation
Calculate Time Difference in days/weeks/months/years
...
Date Calculation:
i) Expected Date of Delivery (EDD) Calculation:
This function takes the last menstruation date and returns the expected date of delivery (EDD).
Example Scenario:
Consider a scenario where a doctor needs to determine the expected date of delivery (EDD) for a pregnant patient. By inputting the patient's last menstruation date, the function can automatically calculate and provide the EDD, eliminating the need for manual calculation and ensuring accuracy.
Code Example
Code Block | ||
---|---|---|
| ||
{
"calculate": {
"calculateExpression": "calcEDD('LMP')"
}
} |
...
ii) Next Visit Date Calculation :
In a healthcare setting, particularly in the management of HIV patients, it is crucial to ensure that patients adhere to their antiretroviral (ARV) therapy. Patients are typically dispensed a specific number of days' worth of ARV medication, and their next clinic visit is scheduled based on the dispensed medication duration. The calcNextVisitDate
function helps calculate the next visit date based on the follow-up date and the number of days for which ARV medication is dispensed.
Example Scenario
A patient visits a clinic on July 10, 2024, for their routine follow-up. During this visit, they are given a supply of ARV medication for the next 10 days. The healthcare provider needs to schedule the patient's next visit based on this information.
Code Example
Code Block | ||
---|---|---|
| ||
{
"calculate": {
"calculateExpression": "calcNextVisitDate('followUpDate', 'arvDispensedInDays')"
}
} |
...
iii) Treatment End Date Calculation:
For instance, a patient with a particular medical condition (indicated by a specific status code) might be given additional days beyond the regular ARV dispensed days to ensure better health outcomes.
Example Scenario
A patient visits a clinic on July 10, 2024, for their routine follow-up. They are given a supply of ARV medication for the next 10 days. The patient has a status code '160429AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', indicating a need for extended treatment.
Code Example
Code Block | ||
---|---|---|
| ||
{
"calculate": {
"calculateExpression": "calcTreatmentEndDate('followUpDate', 'arvDispensedInDays', 'patientStatus')"
}
} |
...
Date Validation
This helper function ( isDateBefore, isDateAfter )
allows users to validate the date field by checking whether the selected date is in the past or future by comparing it with a base date.
Example:
Consider a scenario where a patient wishes to book an appointment with a doctor. The appointment date should be in the future and not in the past. If the patient mistakenly books an appointment for a past date, it leads to an invalid appointment. To prevent this, the date field should be validated to ensure the selected date is not in the past, thereby guiding the patient to choose a valid appointment date.
Code Example
Code Block | ||
---|---|---|
| ||
"validators": [
{
"type": "js_expression",
"failsWhenExpression": "isDateBefore(appointment, '2024-07-13')",
"message": "Appointment cannot be in the past"
}
] |
Historical Expression
The historical Expression gives ability to retrieve the patient’s most recent data, and copy the same into another form field.
Example
Consider a patient who needs to calculate the weight difference between the most recent visit and the current visit. In this scenario, a historical expression will be helpful as it retrieves the patient's previous visit details, including the patient's biometric data. This allows us to fetch the patient's weight and compare the weight difference.
References:
i) Expression helper functions
ii) Date validation
iii) Hiding fields