fhir_r6_cql 0.7.0
fhir_r6_cql: ^0.7.0 copied to clipboard
FHIR R6 binding for the model-independent `cql` engine: the R6 ModelResolver and TerminologyProvider implementations that let the CQL engine execute against FHIR R6 data.
fhir_r6_cql #
The FHIR R6 binding for the model-independent
cql engine.
The cql package translates
Clinical Quality Language source into ELM and
executes it, but it is deliberately FHIR-free: all access to FHIR data goes
through its ModelResolver / TerminologyProvider boundary interfaces. This
package supplies the FHIR R6 implementations of those interfaces — the
analogue of cqframework's engine.fhir / cql-exec-fhir:
R6ModelResolver— type checks (is/as), FHIRPath-based property navigation, and the boundary conversions between FHIR R6 types and CQL System types (FhirBoolean↔Boolean,Coding→Code,CodeableConcept→Concept,Quantity→System.Quantity,Period→Interval<DateTime>,Range→Interval<Quantity>, …).R6TerminologyProvider— resolves value-set membership by fetching the FHIRValueSetresource (throughfhir_r6_path's canonical-resource cache) and checking codes with itsValueSetChecker.
The package re-exports package:cql/cql.dart, so this single import gives
you the whole engine plus the R6 wiring.
Installation #
dependencies:
fhir_r6_cql: ^0.6.0
Usage #
import 'package:fhir_r6_cql/fhir_r6_cql.dart';
Future<void> main() async {
const source = '''
library Example version '1.0.0'
define "Greeting": 'Hello, CQL'
define "Sum": 1 + 2 + 3
define "IsAdult": 21 >= 18
define "Evens": (List{1, 2, 3, 4, 5, 6}) X where X mod 2 = 0
''';
// 1. Translate CQL source to an executable ELM library. Translation
// problems are recorded on `library.annotation` (mirroring the
// reference translator) rather than thrown.
final library = libraryFromCql(source);
// 2. Execute. The R6ModelResolver wires in FHIR R6 data access;
// expressions that retrieve (e.g. [Patient], [Observation]) resolve
// through it. `execute` returns the run context, keyed by define name.
final results = await library.execute(
<String, dynamic>{},
const R6ModelResolver(),
) as Map<String, dynamic>;
print(results['Sum']); // 6
}
A runnable version of this demo is in example/main.dart. Translated
libraries round-trip through ELM JSON (library.toJson() /
CqlLibrary.fromJson(...)), so they can be stored and reloaded without
re-translating.
Terminology #
R6TerminologyProvider resolves in "MyValueSet" membership tests. By
default it fetches ValueSet resources over the network; pass a
pre-populated CanonicalResourceCache to resolve offline:
final terminology = R6TerminologyProvider();
Libraries that only use locally-supplied expansions can instead place them
directly in the execution context under _valueSets and need no provider.
The fhir_fli CQL family #
| Package | Role |
|---|---|
cql |
Model-independent CQL→ELM translator + engine |
fhir_r4_cql |
The FHIR R4 binding |
fhir_r5_cql |
The FHIR R5 binding |
fhir_r6_cql |
This package — the FHIR R6 binding |
License #
MIT — see LICENSE.