Skip to main content

Crate octofhir_fhirpath_analyzer

Crate octofhir_fhirpath_analyzer 

Source
Expand description

§FHIRPath Static Analysis and Type-Enriched AST Engine

This crate provides comprehensive static analysis capabilities for FHIRPath expressions with a focus on specification compliance and rich functionality.

§Core Components

§Quick Start

use octofhir_fhirpath_analyzer::{FhirPathAnalyzer};
use octofhir_fhirpath_model::mock_provider::MockModelProvider;
use std::sync::Arc;

let provider = Arc::new(MockModelProvider::new());
let analyzer = FhirPathAnalyzer::new(provider);

let result = analyzer.analyze("Patient.name.given").await?;
println!("Found {} type annotations", result.type_annotations.len());

§Advanced Usage

§Function Registry Integration

use octofhir_fhirpath_analyzer::FhirPathAnalyzer;
use octofhir_fhirpath_registry::create_standard_registry;
use octofhir_fhirpath_model::mock_provider::MockModelProvider;
use std::sync::Arc;

let provider = Arc::new(MockModelProvider::new());
let registry = Arc::new(create_standard_registry().await);
let analyzer = FhirPathAnalyzer::with_function_registry(provider, registry);

// Function signature validation
let result = analyzer.analyze("count()").await?;

§Children() Function Analysis

// Union type analysis for children() function
let result = analyzer.analyze("Patient.children().ofType(HumanName)").await?;

// Check for union type information
if !result.union_types.is_empty() {
    println!("Found union types from children() analysis");
}

§Error Handling

The analyzer provides detailed validation errors with suggestions:

let result = analyzer.analyze("unknownFunction()").await?;

for error in result.validation_errors {
    match error.error_type {
        ValidationErrorType::InvalidFunction => {
            println!("Function error: {}", error.message);
            println!("Suggestions: {:?}", error.suggestions);
        }
        _ => println!("Other error: {}", error.message),
    }
}

§Performance Considerations

The analyzer is designed for high performance:

  • Caching: Aggressive caching of analysis results
  • External Mapping: No AST modifications for zero overhead when disabled
  • Concurrent: Thread-safe operations with DashMap

Typical performance targets:

  • Analysis: <100μs for basic expressions
  • Memory: <10% overhead when enabled
  • Cache hit rate: >90% for repeated expressions

Re-exports§

pub use analyzer::FhirPathAnalyzer;
pub use cache::AnalysisCache;
pub use cache::ExpressionAnalysisMap;
pub use children_analyzer::ChildrenFunctionAnalyzer;
pub use config::AnalyzerConfig;
pub use error::AnalysisError;
pub use error::ValidationError;
pub use error::ValidationErrorType;
pub use field_validator::FieldValidator;
pub use function_analyzer::FunctionAnalyzer;
pub use model_provider_ext::ModelProviderChildrenExt;
pub use types::AnalysisContext;
pub use types::AnalysisResult;
pub use types::AnalysisSettings;
pub use types::SemanticInfo;

Modules§

analyzer
Main analyzer implementation
cache
Caching infrastructure for the FHIRPath analyzer
children_analyzer
Specialized analyzer for children() function with union type support
config
Configuration for the analyzer
error
Error types for the FHIRPath analyzer
field_validator
Field existence validation for FHIRPath expressions using FhirSchema
function_analyzer
Simplified function analyzer that works with the new unified registry system
model_provider_ext
ModelProvider extension for children() function analysis
types
Type definitions for the FHIRPath analyzer