Skip to content

Choice-type overloads missing on Exists / Empty / Count; is on absent choice field returns empty and propagates #1799

Description

@c-schuler

Two coupled defects around FHIR choice types (e.g. Observation.effective = choice<dateTime, Period>):

  1. Standard FHIRPath emptiness checks fail to compile because the operators have no overload for FHIR choice types or individual FHIR primitives:
    • effective.exists().not() - Could not resolve call to operator Exists with signature (choice<FHIR.Period, FHIR.dateTime>)
    • exists(effective as FHIR.dateTime) - Could not resolve call to operator Exists with signature (FHIR.dateTime)
    • effective.count() = 0 - Could not resolve call to operator Count with signature (choice<...>)
  2. (effective is FHIR.dateTime).not() compiles, but when effective is absent, is returns empty (per FHIRPath spec is semantics on empty input). Empty propagates through .not(), the surrounding or chain, .where(), and .exists(). So an Observation with no effective field never triggers even when the surrounding predicate would otherwise let it through.

Repro (part 1- resolution failures):

library Repro
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
context Patient

define A: [Observation] O where O.effective.exists().not()
define B: [Observation] O where exists(O.effective as FHIR.dateTime)
define C: [Observation] O where O.effective.count() = 0

All three fail to translate.

Repro (part 2 - empty propagation):

define D:
  [Observation] O
    where ((O.effective is FHIR.dateTime).not()
           or (O.effective as FHIR.dateTime) >= @2025-01-01)

An Observation with no effective field is filtered out because both OR operands evaluate empty.

Expected: Exists, Empty, and Count should have overloads for FHIR choice types (choice<...>) and for individual FHIR primitives (FHIR.dateTime, FHIR.Period, etc.). is on empty should be safe to compose with .not() and boolean logic without dropping the containing collection.

Workaround: wrap in CQL Coalesce:
Coalesce((O.effective is FHIR.dateTime).not(), true)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions