ModelResolver class abstract

The boundary between FHIR-version-specific code and the CQL engine.

Implementations of this interface are the only place in fhir_cql where package:fhir_r4 / package:fhir_r5 / package:fhir_r6 (and the matching _path packages) may be imported. The engine itself works exclusively in CQL System types (see lib/engine/types/) plus raw Map<String, dynamic> FHIR JSON — never typed FHIR classes.

This mirrors the ModelResolver interface from the canonical Java reference implementation cqframework/clinical_quality_language (Src/java/engine/src/commonMain/kotlin/org/opencds/cqf/cql/engine/model/ModelResolver.kt) and the FHIRWrapper pattern from the JavaScript reference cqframework/cql-exec-fhir.

Rules for implementers

  1. Use the modern FHIRPath entry point only: FHIRPathEngine.create(WorkerContext(), hostServices).parse(expr) .evaluateWithContext(...). Never use or reference walkFhirPath / executeFhirPath — these are legacy petitparser-era shims that silently mis-handle host-services and lazy variable scenarios. See feedback_no_walkfhirpath in memory.

  2. Convert FHIR-typed values to CQL System types eagerly at the boundary. Once a value flows into the engine via resolvePath or toCqlSystemType, it must be either a CQL System type, a plain Map<String, dynamic> FHIR JSON, or a primitive String/num/bool. The engine must not see fhir_r4.FhirDateTime etc.

  3. Handle FHIR polymorphic field resolution (effective → effectiveDateTime / effectivePeriod / effectiveTiming / effectiveInstant, value → valueQuantity / valueString / …, onset → onsetDateTime / onsetAge / …, etc.) inside resolvePath. The set of polymorphic prefixes is documented per FHIR version in the model_info files.

Constructors

ModelResolver()

Properties

fhirVersion → String
FHIR version targeted, matching the CQL using FHIR version declaration. Examples: '4.0.1', '5.0.0', '6.0.0-ballot2'.
no setter
hashCode → int
The hash code for this object.
no setterinherited
packageNames → List<String>
Type-system namespace URI(s) this resolver answers for. CQL type specifiers carry a namespace.namespaceURI; the engine dispatches to the resolver whose packageNames includes that URI.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

as_(dynamic value, String typeName, {bool isStrict = false}) → dynamic
Returns value cast to typeName if compatible, otherwise:
createInstance(String typeName) → dynamic
Creates an empty instance of the type named typeName. Used by CQL's instance-construction expression ({ field1: ..., field2: ... } typed to a named type) and by the parameter system.
fromCqlSystemType(dynamic value, [String? fhirTypeName]) → dynamic
Inverse of toCqlSystemType: convert a CQL System value back to a FHIR-typed value (or FHIR JSON Map) for return to user code.
getContextPath(String? contextType, String? targetType) → String?
Returns the path on a resource of targetType that links it to a resource of contextType (the CQL context declaration's anchor).
is_(dynamic value, String typeName) → bool?
Returns true if value is an instance of the FHIR or System type named typeName in this resolver's package(s).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
objectEqual(dynamic left, dynamic right) → bool?
Three-valued deep equality. Returns true/false when comparable; null when either operand is null and the spec demands propagation.
objectEquivalent(dynamic left, dynamic right) → bool?
CQL ~ operator on FHIR-typed values. Type-aware equivalence per the FHIR datatypes specification (e.g. Quantity ignores comparator/unit canonicalization; Period is start-exclusive/end-inclusive).
resolveId(dynamic target) → String?
Returns the resource id of target if it's a FHIR resource, else null.
resolvePath(dynamic source, String path) → Future
Resolves a single property path on a source object.
resolveType(String typeName) → Type?
Resolves typeName (in this resolver's namespace) to a Dart Type suitable for reflection / instance creation. Returns null if unknown.
resolveTypeOf(dynamic value) → String?
Returns the type name for value in this resolver's namespace, e.g. 'Patient' for a FHIR Patient resource, 'DateTime' for a CqlDateTime. Returns null if value doesn't map.
resolveTypePath(String path) → ({bool isList, String type})?
Resolves the static type of a dotted model path such as Observation.value or Patient.name, for return-type inference (used by the engine's Property.getReturnTypes).
setValue(dynamic target, String path, dynamic value) → dynamic
Sets the value at path on target to value, returning the modified target. Used by the engine for set / output-parameter scenarios.
toCqlSystemType(dynamic value) → dynamic
Converts a FHIR-typed value (or raw FHIR JSON Map) to its corresponding CQL System type at the engine boundary.
toElementMap(dynamic value) → Map<String, dynamic>?
Decomposes a model object into its child elements as a FHIR-JSON name → value map, or returns null if value is not a model object.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited