Skip to content

New CQL value type for structured types in engine runtime#1713

Open
antvaset wants to merge 21 commits intomainfrom
engine-structured-types
Open

New CQL value type for structured types in engine runtime#1713
antvaset wants to merge 21 commits intomainfrom
engine-structured-types

Conversation

@antvaset
Copy link
Copy Markdown
Contributor

@antvaset antvaset commented Mar 25, 2026

  • Non-system structured types (e.g. instances of FHIR.Patient, FHIR.string, etc.) are now represented in the engine as CqlClassInstances. A CqlClassInstance can be thought of as a named tuple type (a tuple with a QName type tag like {http://hl7.org/fhir}Patient). As a result:
    • the engine only operates on a fixed set of Kotlin types, and HAPI FHIR structures and other custom types do not bleed into the runtime,
    • resolvePath(), as(), setValue(), objectEqual(), objectEquivalent(), resolveType() are no longer needed in the ModelResolver interface.
  • Java Class<T> references are replaced with type specifiers and type QNames (both multiplatform) in the engine. As a result:
    • packageName(s) is no longer needed in ModelResolver and is(value: Any?, type: Class<*>?): Boolean? changed to is(valueType: String, type: QName): Boolean?,
    • type testing is improved so e.g. Interval[1,2] is Interval<Integer> returns true and Interval[1,2] is Interval<Time> returns false,
    • function resolution is more robust when function refs are compiled without signatures.
  • In FhirModelResolver : ModelResolver, the is(valueType: String, type: QName): Boolean? method now returns true only if {http://hl7.org/fhir}_valueType_ extends type or is the same as type. As a result, expressions like FHIR.integer { ... } is FHIR.positiveInt and FHIR.Quantity { ... } is FHIR.Age return false because FHIR.integer is a supertype of FHIR.positiveInt and FHIR.Quantity is a supertype of FHIR.Age.
  • Fix DescendentsEvaluator.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2026

Related Issues

The following open issues may be related to this PR:

Issue Title Score Matched Terms
#867 Runtime type behavior of FHIR types is not polymorphic 23 "returns false", "false because", "fhir string", "because fhir", true, returns, string, return, types, false, because, expressions, runtime (path), type (path), provider (path), fhir (path), state (path), value (path)
#1273 Contexts should have type specifiers 22 "type specifiers", "org fhir", "hl7 org", "http hl7", "fhir patient", specifiers, string, patient, http, type (path), context (path), fhir (path), org (path), cql (path), hl7 (path)
#895 Integrate code generation into the cql-engine build 21.5 "hapi fhir", structures, string, modelresolver, fhirmodelresolver, return, types, resolvetype, instances, hapi, runtime (path), resources (path), java (path), src (path), caching (path), opencds (path), engine (path), function (path), context (path), fhir (path), main (path), org (path), cql (path), cqf (path), model (path), reflection (path), hl7 (path), data (path), class (path)
#1718 Includes operation returns false instead of null if either operand is null 20.5 "returns false", "hl7 org", "http hl7", "interval interval", result, returns, false, http, fhirpath (path), operators (path), interval (path), org (path), cql (path), instance (path), hl7 (path), list (path), test (path)
#1133 ToList is not implemented according to the spec 20 "org fhir", "hl7 org", returns, types, because, expressions, set, type (path), java (path), src (path), opencds (path), engine (path), property (path), retrieve (path), fhir (path), main (path), org (path), cql (path), cqf (path), elm (path), execution (path), hl7 (path), value (path), list (path), test (path)

Tip: If this PR addresses any of these issues, please link them using Closes #NNN or Refs #NNN in the PR description.

@github-actions
Copy link
Copy Markdown

Formatting check succeeded!

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 80.76923% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.74%. Comparing base (5bb1ece) to head (55cfb3f).

Files with missing lines Patch % Lines
...cds/cqf/cql/engine/fhir/model/FhirModelResolver.kt 80.00% 3 Missing and 9 partials ⚠️
...cql/engine/fhir/converter/BaseFhirTypeConverter.kt 75.00% 0 Missing and 1 partial ⚠️
...f/cql/engine/fhir/converter/R4FhirTypeConverter.kt 66.66% 0 Missing and 1 partial ⚠️
...e/fhir/retrieve/SearchParamFhirRetrieveProvider.kt 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1713      +/-   ##
============================================
+ Coverage     62.00%   62.74%   +0.74%     
+ Complexity     3944     3889      -55     
============================================
  Files           210      210              
  Lines         20374    19946     -428     
  Branches       3882     3767     -115     
============================================
- Hits          12632    12516     -116     
+ Misses         6131     5870     -261     
+ Partials       1611     1560      -51     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antvaset antvaset marked this pull request as ready for review March 27, 2026 06:35
) {
return operand
return when (target) {
is Quantity -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: This is most of the ModelProvider functionality, but now written against the internal CQL types. Might make sense to factor that out as a class and test it independently rather than rolling it into the Environment, which manages cache, library loading, etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possibility would be a specialized kind of "Evaluator" class in the engine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I moved is(), as(), etc. into repsective evaluators, so now it looks better.

@Zylox
Copy link
Copy Markdown
Contributor

Zylox commented Apr 1, 2026

We are currently using a custom modelinfo and a custom modelresolver to implement cql over internal data types that are not fhir related. This is well supported currently. These changes to modelresolver seem to make that impossible now. Is this engine only going to support FHIR, specifically hapi fhir, or is there some other avenue to get existing behavior that i am missing.

Fully extracting every record into a CqlClassInstance would be prohibitively poorly performing for us. Right now, the fact that we can retrieve objects at request time with resolvePath is very useful.

If CqlClassInstance were an interface that allowed similar behavior we could make this work, maybe. You could even then implement the interface by something identical to the current implementation if for some reason that is performant for you, where cqlClassInstanceImpl.resolvePath("value") performs a get on elements, and others like my team can back it with our existing data structures. This approach still wouldnt be ideal as we would have to wrap every object in an adapter, but its preferable to having to fork off the engine.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
70.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

3 participants