fhir_r5_path 0.6.0
fhir_r5_path: ^0.6.0 copied to clipboard
FHIRPath for FHIR R5: the version binding for the model-independent fhirpath engine, with terminology support.
// Query FHIR R5 resources with FHIRPath using fhir_r5_path.
//
// fhir_r5_path is the R5 binding over the model-independent `fhirpath`
// engine: build a FHIRPathEngine (model-aware via WorkerContext), parse an
// expression once, then evaluate it against any resource. Each evaluation
// returns a List<FhirBase> — FHIRPath always yields a collection.
//
// Run: dart run example/main.dart
// ignore_for_file: avoid_print
import 'package:fhir_r5/fhir_r5.dart';
import 'package:fhir_r5_path/fhir_r5_path.dart';
Future<void> main() async {
// Create the engine once; parse-once / evaluate-many is the intended use.
final engine = await FHIRPathEngine.create(WorkerContext());
final patient = Patient(
id: 'example'.toFhirString,
active: true.toFhirBoolean,
name: [
HumanName(
family: 'Rossi'.toFhirString,
given: ['Mario'.toFhirString],
),
],
telecom: [
ContactPoint(
system: ContactPointSystem.email,
use: ContactPointUse.mobile,
rank: FhirPositiveInt(3),
),
],
);
// Evaluate a handful of expressions against the patient.
for (final expression in <String>[
'Patient.active',
'name.given.first()',
"name.family = 'Rossi'",
'telecom.rank > 1',
"'abcdefg'.endsWith('efg')",
]) {
final result = await engine.evaluate(patient, engine.parse(expression));
print('$expression => $result');
}
}