View raw Markdown
type: fhirpath-functionfunction: comparablecategory: Comparisonsection: 6.2.5source: fhirpath/functions.json

FHIRPath Function: comparable

{:.stu}

Note: The contents of this section are Standard for Trial Use (STU) {: .stu-note }

Returns true if the input Quantity can be compared with the other Quantity and their relationship to each other determined. Comparable means that both have values, and the units are the same (irrespective of the system), or both have code and system values, and the system is recognized by the FHIRPath implementation, and the codes are comparable within that system (e.g. 'd' (days) and 'h' (hours), or '[in_i]' (inches) and 'cm' (centimeters)). {:.stu}

If either or both inputs are empty, or either input is not a single Quantity value, the result is empty ({ }). {:.stu}

1 'mg'.comparable(2 'mg') // true - these types are comparable
1 'm'.comparable(20 'cm') // true - these types are both metric distance measures
2 '1'.comparable(3) // true - the integer will implicitly convert to a Quantity with unit `'1'` which is the same system/code so is comparable
1.comparable(2) // true - these will both convert to quantities with the same system/code, hence are comparable

{:.stu}

This function can be used to guard comparison operations to prevent returning empty results when the quantities are not comparable: {:.stu}

iif(Observation.value.comparable(2 'mg'), Observation.value < 2 'mg', {})

{:.stu}

Summary

Description

Returns true if the input Quantity can be compared with the other Quantity and their relationship to each other determined. Comparable means that both have values, and the units are the same (irrespective of the system), or both have code and system values, and the system is recognized by the FHIRPath implementation, and the codes are comparable within that system.

Arguments

Type Mapping

Example

1 'mg'.comparable(2 'mg') // true - these types are comparable
1 'm'.comparable(20 'cm') // true - these types are both metric distance measures
iif(Observation.value.comparable(2 'mg'), Observation.value < 2 'mg', {})