Skip to content

Correct interval extraction from FHIR Range and Period - #130

Open
bryantaustin13 wants to merge 1 commit into
mainfrom
interval-fhir-type-extraction
Open

bryantaustin13 wants to merge 1 commit into
mainfrom
interval-fhir-type-extraction

Conversation

@bryantaustin13

Copy link
Copy Markdown
Contributor

The extractors that map FHIR.Range and FHIR.Period back to CQL intervals — the representation the "Using CQL with FHIR" IG specifies for Interval in Conformance Requirement 4.3 — had four defects:

  • DateTimeIntervalExtractor hardcoded highClosed: true, so a Period with no end extracted as {highClosed: true, high: null}. An absent boundary is unbounded and therefore open; NumericIntervalExtractor already treated it that way, so the two disagreed on the same shape.
  • A null valuePeriod, a null valueRange, or a null Range boundary each threw a TypeError out of the extractor, which turns a test into an error rather than a comparison.
  • A Range boundary carrying unit but no code lost its unit, silently reducing a dimensioned boundary to a unitless one.

Adds tests covering all seven interval point types the IG maps (Integer, Long, Decimal and Quantity onto Range; Date, DateTime and Time onto Period) plus the boundary and null cases above.

One behaviour is pinned deliberately rather than changed: a Period carrying no cqf-cqlType is read as Interval. The point type cannot be recovered in that case — a boundary of 2012-01-01T00:00:00-07:00 is indistinguishable from a DateTime interval starting at midnight — and the IG states that a value without cqf-cqlType is the FHIR type. Inferring a Date would be a guess, so the test asserts the mismatch instead, keeping the missing extension visible as a server defect.

The extractors that map FHIR.Range and FHIR.Period back to CQL intervals — the
representation the "Using CQL with FHIR" IG specifies for Interval in
Conformance Requirement 4.3 — had four defects:

- DateTimeIntervalExtractor hardcoded `highClosed: true`, so a Period with no
  `end` extracted as `{highClosed: true, high: null}`. An absent boundary is
  unbounded and therefore open; NumericIntervalExtractor already treated it that
  way, so the two disagreed on the same shape.
- A null `valuePeriod`, a null `valueRange`, or a null Range boundary each threw
  a TypeError out of the extractor, which turns a test into an error rather than
  a comparison.
- A Range boundary carrying `unit` but no `code` lost its unit, silently
  reducing a dimensioned boundary to a unitless one.

Adds tests covering all seven interval point types the IG maps (Integer, Long,
Decimal and Quantity onto Range; Date, DateTime and Time onto Period) plus the
boundary and null cases above.

One behaviour is pinned deliberately rather than changed: a Period carrying no
cqf-cqlType is read as Interval<DateTime>. The point type cannot be recovered in
that case — a boundary of 2012-01-01T00:00:00-07:00 is indistinguishable from a
DateTime interval starting at midnight — and the IG states that a value without
cqf-cqlType is the FHIR type. Inferring a Date would be a guess, so the test
asserts the mismatch instead, keeping the missing extension visible as a server
defect.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant