Expression Helpers Reference

OpenMRS forms provide a number expression helper functions that are useful for evaluating more complex expressions.

isEmpty

Determines whether a value is nullish or a blank string or an empty array.

{ "failsWhenExpression": "!isEmpty(myValue) && isEmpty(`referredToPreventionServices`)" }

NB: myValue is a runtime variable that resolves to the current field’s value.

today

Returns now or today's date.

{ "failsWhenExpression": "myValue > today()" }

includes

Determines whether an array of items includes a given value.

includes(questionId: string, value: any)

Example usage:

{ "failsWhenExpression": "!includes('reasonsForCovidTest','5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')" }

isDateBefore

Date comparator.

isDateBefore(left: Date, right: Date | string, format?: string)

Determines whether left date value is before right date value. Optionally accepts a custom date format for date string values. If not provided, YYYY-MM-DD will be used.

Example usage:

useFieldValue

Returns a field value by field ID.

Example usage:

calcBMI

Takes the height and weight field values and returns the BMI (Body Mass Index) value

Example usage:

calcEDD

Takes the last menstruation date value and returns the expected date of delivery (EDD)

Example usage:

calcBSA

Takes the height and weight field values and returns the BSA (Body Surface Area) value

Example usage:

calcHeightForAgeZscore

Takes the height and weight and returns the zscore based on the age of the patients for both Male and Female patients less than 5 years or greater than or equal to 5 years but less than 18 years of age

Example usage:

calcBMIForAgeZscore

Takes the patient's height and weight and automatically calculates the BMI and returns the zscore for both Male and Female patients greater than or equal to 5 years but less than 18 years of age

Example usage:

calcWeightForHeightZscore

Takes the patient's height and weight and returns the zscore for both Male and Female patients less than 5 years

Example usage:

arrayContains

Takes in values in an array and returns true if the values are contained in the source array

Example usage:

This evaluation means that the question will be hidden if the Specify other reason is not selected amongst the answers to the preceding question.

arrayContainsAny

Tests whether the source array contains members (or the values contained in members if it is an Array). Returns true if members is/are in array, and false otherwise.

arrayContainsAny(array, members)

calcMonthsOnART

Takes in the art start date and retuns the months the patient has been on art

Example usage:

calcAgeBasedOnDate

Takes in the birth date and returns a patients age

Example usage:

formatDate

formatDate(value, format, offset)

Takes in a date value, preferred format and offset value and returns the preferred date format

calcGravida

Takes in the parity term and parity aborting numerical values and returns the patients gravida

Example usage:

calcTimeDifference

Takes in a date and returns the difference in days, weeks, months or years from the current date

Example usage:

Time difference in days :

Time difference in weeks :

Time difference in months :

Time difference in years :