Docs
Expression Helpers Reference

Expression Helpers Reference

RFE forms provides 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:

{
  "failsWhenExpression": "isDateBefore(myValue, '2020-12-01')"
}

useFieldValue

Returns a field value by field ID.

Example usage:

{
  "failsWhenExpression": "isDateBefore(myValue,'2020-01-01') || myValue <= useFieldValue('vaccinationDate')"
}

calcBMI

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

Example usage:

{
  "calculate": {
    "calculateExpression": "calcBMI('height','weight')"
  }
}

calcEDD

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

Example usage:

{
  "calculate": {
    "calculateExpression": "calcEDD('LMP')"
  }
}

calcBSA

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

Example usage:

{
  "calculate": {
    "calculateExpression": "calcBSA('height','weight')"
  }
}

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:

{
"calculate": {
  "calculateExpression":"calcHeightForAgeZscore( 'height', 'weight')"
    },
}

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:

{
"calculate": {
  "calculateExpression":"calcBMIForAgeZscore( 'height', 'weight')"
    },
}

calcWeightForHeightZscore

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

Example usage:

{
"calculate": {
  "calculateExpression":"calcWeightForHeightZscore( 'height', 'weight')"
    },
}

arrayContains

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

Example usage:

{
  "hide": {
    "hideWhenExpression": "!arrayContains(referralReason,'5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')"
  }
}

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:

{
  "calculate": {
    "calculateExpression": "calcMonthsOnART('artStartDate')"
  }
}

calcAgeBasedOnDate

Takes in the birth date and returns a patients age

Example usage:

{
  "calculate": {
    "calculateExpression": "calcAgeBasedOnDate('dateValue')"
  }
}

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:

{
  "calculate": {
    "calculateExpression": "calcGravida('parityTerm', 'parityAbortion')"
  }
}

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 :

{
  "calculate": {
    "calculateExpression": "calcTimeDifference('dateValue', 'd')"
  }
}

Time difference in weeks :

{
  "calculate": {
    "calculateExpression": "calcTimeDifference('dateValue', 'w')"
  }
}

Time difference in months :

{
  "calculate": {
    "calculateExpression": "calcTimeDifference('dateValue', 'm')"
  }
}

Time difference in years :

{
  "calculate": {
    "calculateExpression": "calcTimeDifference('dateValue', 'y')"
  }
}