View raw Markdown
type: fhirpath-operatoroperator: ~category: Equalitysection: 6.1.2source: fhirpath/operations.json

FHIRPath Operator: ~ (equivalent)

Returns true if the collections are the same. In particular, comparing empty collections for equivalence { } ~ { }{:.fhirpath} will result in true.

If both operands are collections with a single item, they must be of the same type (or implicitly convertible to the same type), and:

If both operands are collections with multiple items:

Note that this implies that if the collections have a different number of items to compare, or if one input is a value and the other is empty ({ }), the result will be false.

Quantity Equivalence

When comparing quantities for equivalence, the dimensions of each quantity must be the same, but not necessarily the unit. For example, units of 'cm' and 'm' can be compared, but units of 'cm2' and 'cm' cannot. The comparison will be made using the most granular unit of either input. Attempting to operate on quantities with invalid units will result in false.

For time-valued quantities, calendar durations and definite quantity durations are considered equivalent:

1 year ~ 1 'a' // true
1 second ~ 1 's' // true

Implementations are not required to fully support operations on units, but they must at least respect units, recognizing when units differ.

Implementations that do support units shall do so as specified by [UCUM] as well as the calendar durations as defined in the toQuantity function.

Date/Time Equivalence

For Date, DateTime and Time equivalence, the comparison is the same as for equality, with the exception that if the input values have different levels of precision, the result is false, rather than empty ({ }). As with equality, the second and millisecond precisions are considered a single precision using a decimal, with decimal equivalence semantics.

For example:

@2012 ~ @2012 // returns true
@2012 ~ @2013 // returns false
@2012-01 ~ @2012 // returns false as well
@2012-01-01T10:30 ~ @2012-01-01T10:30 // returns true
@2012-01-01T10:30 ~ @2012-01-01T10:31 // returns false
@2012-01-01T10:30:31 ~ @2012-01-01T10:30 // returns false as well
@2012-01-01T10:30:31.0 ~ @2012-01-01T10:30:31 // returns true
@2012-01-01T10:30:31.1 ~ @2012-01-01T10:30:31 // returns false

String Equivalence

For strings, equivalence returns true if the strings are the same value while ignoring case and locale, and normalizing whitespace. Normalizing whitespace means that all whitespace characters are treated as equivalent, with whitespace characters as defined in the Whitespace lexical category.

Summary

Description

Returns true if the collections are equivalent. Similar to equals but with different semantics: String comparison ignores case and normalizes whitespace, Decimal comparison uses precision of least precise operand, Date/DateTime/Time comparison returns false (not empty) for different precisions. For collections with multiple items, comparison is not order dependent.

Type Mapping