Repository navigation
Correct interval extraction from FHIR Range and Period - #130
Open
bryantaustin13 wants to merge 2 commits into
Open
bryantaustin13 wants to merge 2 commits into
bryantaustin13 wants to merge 2 commits into
Conversation
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>
Resolves the conflict in datetime-interval-extractor.ts, which arose because this branch predates #129 and #135 and carried an older copy of the whole file. Taking either side alone would have lost work: - main's side drops this branch's null guards and its `highClosed: high !== null`, leaving an absent Period boundary reported as closed. - this branch's side drops #135's applyDeclaredTimePrecision on the `_start`/`_end` companion elements and #129's List<...> unwrapping in declaredPointType, which would have reverted time-precision support and lists of temporal intervals. The resolution keeps all of it: this branch's early-return guards and derived highClosed, wrapping main's precision-aware boundary extraction, with #129's List unwrapping untouched above. Verified after resolution: 247 tests pass, and each behaviour checked directly — a Period with hour time-precision extracts as @T10/@t12, List<Interval<System.Date>> still resolves to Date literals, an absent end yields highClosed:false, and null valuePeriod / valueRange / boundary no longer throw. tsc reports only the two pre-existing rest-routes.ts errors present on main. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
DateTimeIntervalExtractorhardcodedhighClosed: true, so a Period with noendextracted as{highClosed: true, high: null}. An absent boundary is unbounded and therefore open;NumericIntervalExtractoralready treated it that way, so the two disagreed on the same shape.valuePeriod, a nullvalueRange, or a null Range boundary each threw a TypeError out ofthe extractor, which turns a test into an error rather than a comparison.
unitbut nocodelost its unit, silently reducing a dimensionedboundary 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-cqlTypeis readas
Interval<DateTime>. The point type cannot be recovered in that case — a boundary of2012-01-01T00:00:00-07:00is indistinguishable from a DateTime interval starting at midnight — andthe IG states that a value without
cqf-cqlTypeis the FHIR type. Inferring a Date would be aguess, so the test asserts the mismatch instead, keeping the missing extension visible as a server
defect.
Rebased on main (#129 and #135)
This branch was opened before #129 and #135 merged, both of which rewrote
datetime-interval-extractor.ts.mainhas since been merged in and the resulting conflictresolved so that all three changes survive:
applyDeclaredTimePrecisionon the_start/_endcompanion elementsList<...>unwrapping indeclaredPointTypehighClosed: high !== nullTaking either side of the conflict wholesale would have lost work — this branch's copy of the file
predated both merged PRs, so accepting it would have reverted time-precision support and lists of
temporal intervals. Each behaviour was re-checked individually after resolving:
time-precisionextracts as@T10/@T12(Honour the time-precision extension on dateTime, time and Period boundaries #135)List<Interval<System.Date>>still resolves to Date literals (Support numeric uncertainty ranges, lists of numeric intervals, and lists of temporal intervals #129)endyieldshighClosed: false(this PR)valuePeriod, nullvalueRangeand a null boundary no longer throw (this PR)unitbut nocodekeeps its unit (this PR)The effective diff against
mainis now this PR's own work only — two extractors and one new testfile.
Verification
tsc --noEmit: no new errors. The twosrc/server/rest-routes.tserrors it reports arepre-existing on
main(Express 5 typesreq.params.idasstring | string[]under TypeScript7.0.2) and are untouched by this PR.
main, plus this PR's 12).cql-testssuite against the reference engine (HAPI FHIR 8.10.0 / CQF engine 4.1.0,$cql,CQL 1.5, Node 26): 1639 pass / 170 fail / 14 skip / 0 error — identical to
main, with zerostatus changes across all 1823 records.
That last point is the important one for review: no test changes status on this engine. The four
defects fixed here need inputs this engine does not produce — it never returns a Period without an
end, never a null boundary, and always includescodeon Range quantities. The fixes aredemonstrated by the unit tests rather than by the integration run, and the integration run's role is
to confirm the merge resolution introduced no regression.