| Crates.io | helios-fhirpath-support |
| lib.rs | helios-fhirpath-support |
| version | 0.1.16 |
| created_at | 2025-08-22 15:09:20.815695+00 |
| updated_at | 2025-09-11 12:50:07.098377+00 |
| description | The helios-fhirpath-support crate serves as a bridge module that provides essential types and traits for integration between the FHIRPath evaluator, it's associated functions, and also the FHIR model code in the fhir module, and it's generated code that is created by fhir_macro. |
| homepage | https://github.com/HeliosSoftware/hfs/tree/main/crates/fhirpath-support |
| repository | https://github.com/HeliosSoftware/hfs |
| max_upload_size | |
| id | 1806486 |
| size | 84,519 |
The helios-fhirpath-support crate serves as a bridge module that provides essential types and traits for integration between the FHIRPath evaluator, it's associated functions, and also the FHIR model code in the fhir module, and it's generated code that is created by fhir_macro.
helios-fhirpath-support acts as a communication layer that allows:
The crate provides the shared vocabulary that all other components use when working with FHIRPath expressions and FHIR data.
As a bridge module, fhirpath_support:
EvaluationResult and EvaluationError that serve as the universal data exchange formatIntoEvaluationResult trait for converting FHIR types to FHIRPath resultsEvaluationResultThe central data type representing any value that can result from FHIRPath expression evaluation:
pub enum EvaluationResult {
Empty, // FHIRPath empty result
Boolean(bool), // true/false values
String(String), // Text values
Decimal(Decimal), // High-precision numbers
Integer(i64), // Whole numbers
Date(String), // Date values (ISO format)
DateTime(String), // DateTime values (ISO format)
Time(String), // Time values (ISO format)
Quantity(Decimal, String), // Value with unit (e.g., "5.4 mg")
Collection { // Arrays/lists of values
items: Vec<EvaluationResult>,
has_undefined_order: bool,
},
Object(HashMap<String, EvaluationResult>), // Key-value structures
}
EvaluationErrorComprehensive error handling for FHIRPath evaluation failures:
pub enum EvaluationError {
TypeError(String), // Type mismatch errors
InvalidArgument(String), // Function argument errors
UndefinedVariable(String), // Variable resolution errors
InvalidOperation(String), // Operation errors
InvalidArity(String), // Function arity errors
InvalidIndex(String), // Array indexing errors
DivisionByZero, // Math errors
ArithmeticOverflow, // Overflow errors
InvalidRegex(String), // Regex compilation errors
InvalidTypeSpecifier(String), // Type specifier errors
SingletonEvaluationError(String), // Collection cardinality errors
SemanticError(String), // Semantic validation errors
Other(String), // Generic errors
}
IntoEvaluationResult TraitThe universal conversion interface that enables any FHIR type to become a FHIRPath result:
pub trait IntoEvaluationResult {
fn to_evaluation_result(&self) -> EvaluationResult;
}
crates/fhirpath)Primary Consumer: The fhirpath crate is the main consumer of fhirpath_support, importing it in virtually every module:
// Used in all FHIRPath function modules
use helios_fhirpath_support::{EvaluationError, EvaluationResult};
Modules using fhirpath_support:
evaluator.rs - Core expression evaluation engineaggregate_function.rs - aggregate() function implementationboolean_functions.rs - Boolean logic operationscollection_functions.rs - Collection manipulation functionsconversion_functions.rs - Type conversion functionsdate_arithmetic.rs - Date/time arithmetic operationsextension_function.rs - FHIR extension accesspolymorphic_access.rs - Choice element handlingtrace_function.rs - Debug tracing functionalitytruncate_function.rs - Decimal truncationtype_function.rs - Type reflection operationsPublic Re-export: The fhirpath crate re-exports EvaluationResult for external consumers:
pub use helios_fhirpath_support::EvaluationResult;
crates/fhir)FHIR Type Conversion: The main fhir crate imports fhirpath_support to enable FHIR data structures to work with FHIRPath:
use helios_fhirpath_support::{EvaluationResult, IntoEvaluationResult};
Purpose: Enables FHIR resources, data types, and elements to be seamlessly converted into FHIRPath-compatible formats for expression evaluation.
crates/fhir_macro)Macro-Generated Implementations: The fhir_macro crate uses fhirpath_support extensively to generate FHIRPath-aware code:
/// Derives the `fhirpath_support::IntoEvaluationResult` trait.
impl fhirpath_support::IntoEvaluationResult for GeneratedType {
fn to_evaluation_result(&self) -> fhirpath_support::EvaluationResult {
// Generated conversion logic
}
}
Generated Code Features:
IntoEvaluationResult implementations for all FHIR typesEvaluationResult::ObjectFHIRPath Type Mapping: Maps FHIR primitive types to appropriate FHIRPath representations:
boolean → EvaluationResult::Booleanstring/code/uri → EvaluationResult::Stringinteger → EvaluationResult::Integerdecimal → EvaluationResult::Decimal (high-precision)date/dateTime/time → EvaluationResult::Date/DateTime/TimeEvaluationResult::CollectionEvaluationResult::ObjectBuilt-in Conversions: Provides implementations for Rust standard types:
impl IntoEvaluationResult for String { /* ... */ }
impl IntoEvaluationResult for bool { /* ... */ }
impl IntoEvaluationResult for i32 { /* ... */ }
impl IntoEvaluationResult for i64 { /* ... */ }
impl IntoEvaluationResult for f64 { /* ... */ }
impl IntoEvaluationResult for Decimal { /* ... */ }
impl<T> IntoEvaluationResult for Option<T> { /* ... */ }
impl<T> IntoEvaluationResult for Vec<T> { /* ... */ }
impl<T> IntoEvaluationResult for Box<T> { /* ... */ }
Equality and Ordering: Implements proper comparison semantics for FHIRPath:
Boolean Conversion: Sophisticated boolean logic handling:
Utility Methods: Rich API for working with evaluation results:
count() - FHIRPath-compliant item countingto_boolean() - FHIRPath boolean conversion rulesto_string_value() - String representationtype_name() - Runtime type identificationis_collection() - Type checking utilitiesMinimal and Focused: The crate maintains a lean dependency profile:
rust_decimal - High-precision decimal arithmetic required for FHIR's precise numeric requirementsNo FHIR Dependencies: Intentionally avoids depending on FHIR types to prevent circular dependencies and maintain clean separation of concerns.
The crate exemplifies the bridge pattern by:
New Type Support: Adding support for new FHIRPath types requires:
EvaluationResultNew Conversion Sources: Supporting new FHIR types requires:
IntoEvaluationResult for the typeThe crate's types implement comprehensive trait support:
All implementations follow FHIRPath specification requirements for type behavior and conversion rules.
fhirpath_support is a mature, stable component that successfully bridges the FHIRPath evaluator with the FHIR type system. As the foundation for data exchange in the FHIRPath ecosystem, it maintains:
Future enhancements focus on:
The crate serves as the essential foundation that enables the entire FHIRPath implementation to function as a cohesive, interoperable system.