IntoEvaluationResult

Trait IntoEvaluationResult 

Source
pub trait IntoEvaluationResult {
    // Required method
    fn to_evaluation_result(&self) -> EvaluationResult;
}
Expand description

Universal conversion trait for transforming values into FHIRPath evaluation results.

This trait provides the bridge between FHIR data types and the FHIRPath evaluation system. It allows any type to be converted into an EvaluationResult that can be processed by FHIRPath expressions.

§Implementation Guidelines

When implementing this trait:

  • Return EvaluationResult::Empty for None or missing values
  • Use appropriate variant types (Boolean, String, Integer, etc.)
  • For complex types, use EvaluationResult::Object with field mappings
  • For arrays/collections, use EvaluationResult::Collection

§Examples

use helios_fhirpath_support::{EvaluationResult, IntoEvaluationResult};

struct CustomType {
    value: String,
    active: bool,
}

impl IntoEvaluationResult for CustomType {
    fn to_evaluation_result(&self) -> EvaluationResult {
        let mut map = std::collections::HashMap::new();
        map.insert("value".to_string(), self.value.to_evaluation_result());
        map.insert("active".to_string(), self.active.to_evaluation_result());
        EvaluationResult::Object { map, type_info: None }
    }
}

Required Methods§

Source

fn to_evaluation_result(&self) -> EvaluationResult

Converts this value into a FHIRPath evaluation result.

This method should transform the implementing type into the most appropriate EvaluationResult variant that represents the value’s semantics in FHIRPath.

Implementations on Foreign Types§

Source§

impl IntoEvaluationResult for bool

Converts a bool to EvaluationResult::Boolean.

Enables direct use of Rust boolean values in FHIRPath expressions.

Source§

impl IntoEvaluationResult for f64

Converts an f64 to EvaluationResult::Decimal with error handling.

Uses high-precision Decimal type to avoid floating-point errors. Returns Empty for invalid values like NaN or Infinity.

Source§

impl IntoEvaluationResult for i32

Converts an i32 to EvaluationResult::Integer.

Automatically promotes to i64 for consistent integer handling.

Source§

impl IntoEvaluationResult for i64

Converts an i64 to EvaluationResult::Integer.

This is the primary integer type used in FHIRPath evaluation.

Source§

impl IntoEvaluationResult for String

Converts a String to EvaluationResult::String.

This is the most direct conversion for text values in the FHIRPath system.

Source§

impl IntoEvaluationResult for Decimal

Converts a rust_decimal::Decimal to EvaluationResult::Decimal.

This is the preferred conversion for precise decimal values in FHIR.

Source§

impl<T> IntoEvaluationResult for Option<T>

Converts Option<T> to either the inner value’s result or Empty.

This is fundamental for handling FHIR’s optional fields and nullable values. Some(value) converts the inner value, None becomes Empty.

Source§

impl<T> IntoEvaluationResult for Box<T>

Converts Box<T> to the result of the boxed value.

This enables use of boxed values (often used to break circular references in FHIR data structures) directly in FHIRPath evaluation.

Source§

impl<T> IntoEvaluationResult for Vec<T>

Converts Vec<T> to EvaluationResult::Collection.

Each item in the vector is converted to an EvaluationResult. The resulting collection is marked as having defined order (FHIRPath collections maintain order).

Implementors§