Operators
Operators are special symbols or keywords that take a left and right operand, returning some sort of result.
Comparison
The following comparison operators are supported:
<=
- Less than or equal to<
- Less than>
- Greater than>=
- Greater than or equal to
Both operands must be singular, the table below shows the valid types and their combinations.
Boolean | String | Integer | Decimal | Date | DateTime | Time | Quantity | |
---|---|---|---|---|---|---|---|---|
Boolean | true | false | false | false | false | false | false | false |
String | false | true | false | false | false | false | false | false |
Integer | false | false | true | true | false | false | false | false |
Decimal | false | false | true | true | false | false | false | false |
Date | false | false | false | false | true | true | false | false |
DateTime | false | false | false | false | true | true | false | false |
Time | false | false | false | false | false | false | true | false |
Quantity | false | false | false | false | false | false | false | true* |
If one or both of the operands is an empty collection, the operator will return an empty collection.
String ordering is strictly lexical and is based on the Unicode value of the individual characters.
All comparison operators return a Boolean value.
The comparability of units within Quantities is defined within UCUM. You can use the NLM Converter Tool to check whether your units are comparable to each other.
See also: Comparison
Equality
The =
operator returns true
if the left operand is equal to the right
operand, and a false
otherwise. The !=
is the inverse of the =
operator.
Both operands must be singular. The valid types and their combinations is the same as for the Comparison operators. In addition to this, Coding types can be compared using the equality operators.
If one or both of the operands is an empty collection, the operator will return an empty collection.
If the operands are Quantity values and are not comparable, an empty collection will be returned.
The comparability of units within Quantities is defined within UCUM. You can use the NLM Converter Tool to check whether your units are comparable to each other.
See also: Equality
Math
The following math operators are supported:
+
- Addition-
- Subtraction*
- Multiplication/
- Divisionmod
- Modulus
Math operators support Integer, Decimal and Quantity operands. The modulus operator is not supported for Quantity types.
Both operands must be singular.
If one or both of the operands is an empty collection, the operator will return an empty collection.
Integer and Decimal types can be mixed, while Quantity types can only be used with other Quantity types.
For Integer and Decimal, +
, -
and *
return the same type as the left
operand, /
returns Decimal and mod
returns Integer.
For Quantity types, math operators return a new Quantity with the canonical unit common to both operands. If the units are not comparable, an empty collection is returned.
See also: Math
Date/time arithmetic
The following operators are supported for date arithmetic:
Date arithmetic always has a DateTime
or Date
on the left-hand side, and a
duration on the right-hand side. The duration operand is a
calendar duration literal. The use of UCUM units
is not supported with these operators.
The Date
or DateTime
operand must be singular. If it is an empty collection,
the operator will return an empty collection.
The use of arithmetic with the Time type is not supported.
Arithmetic involving instant values is limited to a precision of seconds.
See also: Date/Time Arithmetic
Boolean logic
The following Boolean operations are supported:
and
or
xor
- Exclusive ORimplies
- Material implication
Both operands to a Boolean operator must be singular Boolean values.
All Boolean operators return a Boolean value.
See also: Boolean logic
Membership
The following membership operators are supported:
in
([element] in [collection]
)contains
([collection] contains [element]
)
If the element operand is a collection with a single item, the operator
returns true
if the item is in the collection using equality
semantics.
If the element is empty, the result is empty. If the collection is empty, the
result is false
. If the element has multiple items, an error is returned.
See also: Collections
combine
The combine
operator merges the left and right operands into a single
collection, preserving duplicates. The result is not ordered.
The two operands provided to the combine
operator must share the same type.
This implementation has the same semantics as the combine function within the FHIRPath specification, but is implemented as an operator.