fhir_r6_cql 0.7.0 copy "fhir_r6_cql: ^0.7.0" to clipboard
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.

example/main.dart

// Translate and execute CQL (Clinical Quality Language) with fhir_r6_cql.
//
// fhir_r6_cql is a thin R6 binding over the model-independent `cql` engine:
// `libraryFromCql` (CQL -> ELM) and `execute` come from `cql`, while
// `R6ModelResolver` supplies FHIR R6 data access for retrieves.
//
// Run: dart run example/main.dart
// ignore_for_file: avoid_print
import 'package:fhir_r6_cql/fhir_r6_cql.dart';

Future<void> main() async {
  // A small library of pure expressions — no FHIR retrieves, so it runs with
  // an empty execution context.
  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 — inspect it before executing if you
  //    need to surface errors.
  final library = libraryFromCql(source);

  // 2. Execute the library. The R6ModelResolver wires in FHIR R6 data access;
  //    expressions that retrieve (e.g. [Patient], [Observation]) resolve
  //    through it. Pure expressions ignore it. `execute` returns the run
  //    context, keyed by define name (alongside internal engine keys).
  final results = await library.execute(
    <String, dynamic>{},
    const R6ModelResolver(),
  ) as Map<String, dynamic>;

  // 3. Read each define's result by name.
  for (final name in ['Greeting', 'Sum', 'IsAdult', 'Evens']) {
    print('$name: ${results[name]}');
  }
}
0
likes
160
points
134
downloads

Documentation

API reference

Publisher

verified publisherfhirfli.dev

Weekly Downloads

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.

Homepage
Repository (GitHub)
View/report issues

Topics

#fhir #hl7 #healthcare #cql #interoperability

License

MIT (license)

Dependencies

cql, fhir_r6, fhir_r6_path, ucum

More

Packages that depend on fhir_r6_cql