Skip to main content

ViewDefinitionConstantTrait

Trait ViewDefinitionConstantTrait 

Source
pub trait ViewDefinitionConstantTrait {
    // Required methods
    fn name(&self) -> Option<&str>;
    fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError>;
}
Expand description

Trait for abstracting ViewDefinitionConstant across FHIR versions.

This trait provides version-agnostic access to constant definitions, which define reusable values that can be referenced in FHIRPath expressions throughout the ViewDefinition. Constants improve maintainability and readability of complex transformations.

§Constant Usage

Constants are referenced in FHIRPath expressions using the % prefix:

// Define constant: name="baseUrl", valueString="http://example.org"
// Use in path: "identifier.where(system = %baseUrl)"

§Supported Types

Constants can hold various FHIR primitive types:

  • String values
  • Boolean values
  • Integer and decimal numbers
  • Date, dateTime, and time values
  • Coded values and URIs

§Examples

use helios_sof::traits::ViewDefinitionConstantTrait;
use helios_fhirpath::EvaluationResult;

fn process_constant<T: ViewDefinitionConstantTrait>(constant: &T) -> Result<(), Box<dyn std::error::Error>> {
    if let Some(name) = constant.name() {
        let eval_result = constant.to_evaluation_result()?;
         
        match eval_result {
            EvaluationResult::String(s, _) => {
                println!("String constant '{}' = '{}'", name, s);
            },
            EvaluationResult::Integer(i, _) => {
                println!("Integer constant '{}' = {}", name, i);
            },
            EvaluationResult::Boolean(b, _) => {
                println!("Boolean constant '{}' = {}", name, b);
            },
            _ => {
                println!("Other constant '{}'", name);
            }
        }
    }
    Ok(())
}

Required Methods§

Source

fn name(&self) -> Option<&str>

Returns the name of this constant for use in FHIRPath expressions (referenced as %name)

Source

fn to_evaluation_result(&self) -> Result<EvaluationResult, SofError>

Converts this constant to an EvaluationResult for use in FHIRPath evaluation

Implementations on Foreign Types§

Source§

impl ViewDefinitionConstantTrait for ViewDefinitionConstant

Implementors§