1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! # FHIR Type Hierarchy
//!
//! Implements FHIR type system navigation and inheritance checking for FHIRPath type operations.
use helios_fhir::{FhirPrimitiveTypeProvider, FhirVersion};
/// FHIR Type Hierarchy module
///
/// This module provides utility functions for FHIR type checking and string manipulation.
/// It includes primitive type checking and string capitalization utilities.
///
/// Checks if a type is a FHIR primitive type in the given FHIR version.
///
/// Delegates to the macro-generated [`FhirPrimitiveTypeProvider`] implementation,
/// which is derived from the FHIR specification (StructureDefinitions of kind
/// `primitive-type`), rather than a hand-maintained list.
pub fn is_fhir_primitive_type_for_version(type_name: &str, fhir_version: &FhirVersion) -> bool {
match fhir_version {
#[cfg(feature = "R4")]
FhirVersion::R4 => helios_fhir::r4::PrimitiveTypes::is_primitive_type(type_name),
#[cfg(feature = "R4B")]
FhirVersion::R4B => helios_fhir::r4b::PrimitiveTypes::is_primitive_type(type_name),
#[cfg(feature = "R5")]
FhirVersion::R5 => helios_fhir::r5::PrimitiveTypes::is_primitive_type(type_name),
#[cfg(feature = "R6")]
FhirVersion::R6 => helios_fhir::r6::PrimitiveTypes::is_primitive_type(type_name),
#[allow(unreachable_patterns)]
_ => false, // For versions not enabled by feature flags
}
}
/// Checks if a type is a FHIR primitive type.
///
/// Version-agnostic convenience wrapper around [`is_fhir_primitive_type_for_version`]:
/// returns `true` if the type is a primitive in any enabled FHIR version.
pub fn is_fhir_primitive_type(type_name: &str) -> bool {
FhirVersion::enabled_versions()
.iter()
.any(|version| is_fhir_primitive_type_for_version(type_name, version))
}
/// Utility function to capitalize the first letter of a string
///
/// # Arguments
///
/// * `s` - The string to capitalize
///
/// # Returns
///
/// * A new string with the first letter capitalized
pub fn capitalize_first_letter(s: &str) -> String {
let mut chars = s.chars();
match chars.next() {
None => String::new(),
Some(c) => {
let cap = c.to_uppercase().collect::<String>();
cap + chars.as_str()
}
}
}