Skip to main content

Crate ferrobridge_fhirpath

Crate ferrobridge_fhirpath 

Source
Expand description

A FHIRPath evaluator: FHIRPath Normative Release 2.0.0 (https://hl7.org/fhirpath/N1/) with the additions FHIR R4 makes to it (https://hl7.org/fhir/R4/fhirpath.html), over the lexical document model and the generated element table of fhir-types.

expression::Expression::parse parses an expression once; it is then checked against a context type with expression::Expression::check and evaluated any number of times with expression::Expression::evaluate, in an eval::Environment on an eval::Focus.

use ferrobridge_fhirpath::eval::{Environment, Focus};
use ferrobridge_fhirpath::expression::Expression;
use ferrobridge_fhirpath::model::r4::R4;
use ferrobridge_fhirpath::value::Item;
use fhir_types::codec::Value;

let patient: Value = serde_json::from_str(
    r#"{"resourceType": "Patient", "name": [{"given": ["Ada"]}]}"#,
)?;
let expression = Expression::parse("Patient.name.given.first() = 'Ada'")?;
let environment = Environment::new(&R4);
let result = expression.evaluate(&environment, Focus::resource(&patient))?;
assert_eq!(result, vec![Item::Boolean(true)]);

Decimals are exact; dates and times keep the precision they were written to. An evaluation error and an empty result are distinct outcomes. The functions that reach outside the document call seams the caller supplies (seam), and a call without its seam is an error naming the function.

Modules§

ast
The syntax tree a parsed expression holds, one node per production of the N1 grammar (https://hl7.org/fhirpath/N1/grammar.html).
check
A static check of the paths an expression navigates, against the type its context will have (N1 §11).
eval
Evaluating a parsed expression against a document.
expression
A parsed expression: parsed once, then checked and evaluated many times.
model
The FHIR type model an evaluation navigates by.
parse
The parser of the N1 grammar.
quantity
System.Quantity: an exact decimal and a unit, either a UCUM code or a calendar duration keyword (N1 §4.1.8).
seam
What an evaluation calls out to: the caller’s reference resolution, terminology, profile validation and structure definitions.
temporal
System.Date, System.DateTime and System.Time, each with the precision its value was written to (N1 §4.1.5 to §4.1.7).
ucum
Unit conversion by The Unified Code for Units of Measure (https://ucum.org/ucum), version 2.2, over its vendored essence.
value
The items a collection holds: the FHIRPath system values (N1 §4.1), the FHIR elements of the document under evaluation, and the type descriptions type() returns (N1 §10.2).