View raw Markdown
type: fhirpath-operatoroperator: =category: Equalitysection: 6.1.1source: fhirpath/operations.json

FHIRPath Operator: = (equals)

Returns true if the left collection is equal to the right collection:

As noted above, if either operand is an empty collection, the result is an empty collection. Otherwise:

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

If both operands are collections with multiple items, check the equality of each pair of items in order:

Note that this implies that if the collections have a different number of items to compare, the result will be false.

Typically, this operator is used with single fixed values as operands. This means that Patient.telecom.system = 'phone'{:.fhirpath} will result in an error if there is more than one telecom with a use. Typically, you'd want Patient.telecom.where(system = 'phone'){:.fhirpath}

If one or both of the operands is the empty collection, this operation returns an empty collection.

Quantity Equality

When comparing quantities for equality, 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 empty ({ }).

For time-valued quantities, note that calendar durations and definite quantity durations above days (and weeks) are considered un-comparable:

1 year = 1 'a' // {} an empty collection
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 Equality

For Date, DateTime and Time equality, the comparison is performed by considering each precision in order, beginning with years (or hours for time values), and respecting timezone offsets. If the values are the same, comparison proceeds to the next precision; if the values are different, the comparison stops and the result is false. If one input has a value for the precision and the other does not, the comparison stops and the result is empty ({ }); if neither input has a value for the precision, or the last precision has been reached, the comparison stops and the result is true. For the purposes of comparison, seconds and milliseconds are considered a single precision using a decimal, with decimal equality semantics.

For example:

@2012 = @2012 // returns true
@2012 = @2013 // returns false
@2012-01 = @2012 // returns empty ({ })
@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 empty ({ })
@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

For DateTime values that do not have a timezone offsets, whether or not to provide a default timezone offset is a policy decision. In the simplest case, no default timezone offset is provided, but some implementations may use the client's or the evaluating system's timezone offset.

To support comparison of DateTime values, either both values have no timezone offset specified, or both values are converted to a common timezone offset. The timezone offset to use is an implementation decision. In the simplest case, it's the timezone offset of the local server. The following examples illustrate expected behavior:

@2017-11-05T01:30:00.0-04:00 > @2017-11-05T01:15:00.0-05:00 // false
@2017-11-05T01:30:00.0-04:00 < @2017-11-05T01:15:00.0-05:00 // true
@2017-11-05T01:30:00.0-04:00 = @2017-11-05T01:15:00.0-05:00 // false
@2017-11-05T01:30:00.0-04:00 = @2017-11-05T00:30:00.0-05:00 // true

Additional functions to support more sophisticated timezone offset comparison (such as .toUTC()) may be defined in a future version.

Summary

Description

Returns true if the left collection is equal to the right collection. For single items, they must be of the same type (or implicitly convertible). For primitives: String comparison is based on Unicode values, Integer values must be exactly equal, Decimal values must be equal (trailing zeroes ignored), Boolean values must be the same, Date/DateTime/Time must be exactly the same (respecting timezone offset). For complex types, all child properties must be equal recursively. For collections with multiple items, each item must be equal and comparison is order dependent. Returns false if collections have different number of items.

Type Mapping