ferrobridge_fhirpath/lib.rs
1// SPDX-FileCopyrightText: Cadasto B.V.
2// SPDX-License-Identifier: BUSL-1.1
3
4//! A FHIRPath evaluator: FHIRPath Normative Release 2.0.0
5//! (<https://hl7.org/fhirpath/N1/>) with the additions FHIR R4 makes to it
6//! (<https://hl7.org/fhir/R4/fhirpath.html>), over the lexical document model
7//! and the generated element table of `fhir-types`.
8//!
9//! [`expression::Expression::parse`] parses an expression once; it is then
10//! checked against a context type with [`expression::Expression::check`] and
11//! evaluated any number of times with
12//! [`expression::Expression::evaluate`], in an [`eval::Environment`] on an
13//! [`eval::Focus`].
14//!
15//! ```
16//! use ferrobridge_fhirpath::eval::{Environment, Focus};
17//! use ferrobridge_fhirpath::expression::Expression;
18//! use ferrobridge_fhirpath::model::r4::R4;
19//! use ferrobridge_fhirpath::value::Item;
20//! use fhir_types::codec::Value;
21//!
22//! let patient: Value = serde_json::from_str(
23//! r#"{"resourceType": "Patient", "name": [{"given": ["Ada"]}]}"#,
24//! )?;
25//! let expression = Expression::parse("Patient.name.given.first() = 'Ada'")?;
26//! let environment = Environment::new(&R4);
27//! let result = expression.evaluate(&environment, Focus::resource(&patient))?;
28//! assert_eq!(result, vec![Item::Boolean(true)]);
29//! # Ok::<(), Box<dyn std::error::Error>>(())
30//! ```
31//!
32//! Decimals are exact; dates and times keep the precision they were written
33//! to. An evaluation error and an empty result are distinct outcomes. The
34//! functions that reach outside the document call seams the caller supplies
35//! ([`seam`]), and a call without its seam is an error naming the function.
36
37#![doc(test(attr(deny(warnings))))]
38
39pub mod ast;
40pub mod check;
41pub mod eval;
42pub mod expression;
43mod html;
44mod lex;
45pub mod model;
46pub mod parse;
47pub mod quantity;
48pub mod seam;
49pub mod temporal;
50pub mod ucum;
51pub mod value;