fhir_r5_cql 0.7.0 copy "fhir_r5_cql: ^0.7.0" to clipboard
fhir_r5_cql: ^0.7.0 copied to clipboard

FHIR R5 binding for the model-independent `cql` engine: the R5 ModelResolver and TerminologyProvider implementations that let the CQL engine execute against FHIR R5 data.

example/main.dart

// Translate and execute CQL (Clinical Quality Language) with fhir_r5_cql.
//
// fhir_r5_cql is a thin R5 binding over the model-independent `cql` engine:
// `libraryFromCql` (CQL -> ELM) and `execute` come from `cql`, while
// `R5ModelResolver` supplies FHIR R5 data access for retrieves.
//
// Run: dart run example/main.dart
// ignore_for_file: avoid_print
import 'package:fhir_r5_cql/fhir_r5_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 R5ModelResolver wires in FHIR R5 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 R5ModelResolver(),
  ) 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 R5 binding for the model-independent `cql` engine: the R5 ModelResolver and TerminologyProvider implementations that let the CQL engine execute against FHIR R5 data.

Homepage
Repository (GitHub)
View/report issues

Topics

#fhir #hl7 #healthcare #cql #interoperability

License

MIT (license)

Dependencies

cql, fhir_r5, fhir_r5_path, ucum

More

Packages that depend on fhir_r5_cql