View raw Markdown
type: fhirpath-operatoroperator: impliescategory: Boolean Logicsection: 6.5.5source: fhirpath/operations.json

FHIRPath Operator: implies (implies)

If the left operand evaluates to true, this operator returns the boolean evaluation of the right operand. If the left operand evaluates to false, this operator returns true. Otherwise, this operator returns true if the right operand evaluates to true, and the empty collection ({ }) otherwise.

impliestruefalseempty
truetruefalseempty ({ })
falsetruetruetrue
emptytrueempty ({ })empty ({ })
{:.grid}

The implies operator is useful for testing conditionals. For example, if a given name is present, then a family name must be as well:

Patient.name.given.exists() implies Patient.name.family.exists()
CareTeam.onBehalfOf.exists() implies (CareTeam.member.resolve() is Practitioner)
StructureDefinition.contextInvariant.exists() implies StructureDefinition.type = 'Extension'

Note carefully that if the left side of an implies evaluates to empty, the result of the operation is the right side. This is often not the intended result, so the use of operators that ensure a value (such as ~, instead of =) is recommended for testing boolean conditions, as illustrated in the following examples:

Medication.status ~ 'active' implies form.exists()

// if using the following expression in a constraint, it won't have the expected behavior of only requiring form if status was active.
// (using equal '=' would evaluate and return the right argument if the left argument (status) is missing from the input)
Medication.status = 'active' implies form.exists() // bad constraint expression

// More complex conditions
(type ~ 'incident' and severity ~ 'high') implies reviewDate.exists()

// Works with boolean too, but not special-cased
wasNotGiven ~ true implies reasonNotGiven.exists()

Note that implies may use short-circuit evaluation in the case that the first operand evaluates to false.

Summary

Description

If the left operand evaluates to true, returns the boolean evaluation of the right operand. If the left operand evaluates to false, returns true. Otherwise, returns true if the right operand evaluates to true, and empty collection otherwise.

Type Mapping