Skip to main content

haste_operation_executor/
lib.rs

1pub mod providers;
2pub mod structs;
3pub mod traits;
4pub mod validate;
5
6use haste_fhir_model::r4::generated::resources::OperationDefinition;
7use haste_fhir_model::r4::generated::types::{Extension, ExtensionValueTypeChoice};
8
9pub const CUSTOM_CODE_EXTENSION_URL: &str = "https://haste.health/Extension/custom-code";
10pub const CUSTOM_CODE_TYPE_EXTENSION_URL: &str = "https://haste.health/Extension/custom-code-type";
11
12pub(crate) fn extract_code_from_operation_definition(
13    operation: &OperationDefinition,
14) -> Option<(&str, &str)> {
15    let code_extension = operation.extension.as_ref()?.iter().find(|extension| {
16        extension.url == CUSTOM_CODE_EXTENSION_URL && extension_value_as_string(extension).is_some()
17    })?;
18
19    let code = extension_value_as_string(code_extension)?;
20
21    let media_type = code_extension
22        .extension
23        .as_ref()?
24        .iter()
25        .find(|extension| extension.url == CUSTOM_CODE_TYPE_EXTENSION_URL)
26        .and_then(|extension| extension_value_as_string(extension))?;
27
28    Some((code, media_type))
29}
30
31fn extension_value_as_string(extension: &Extension) -> Option<&str> {
32    match extension.value.as_ref()? {
33        ExtensionValueTypeChoice::String(value) => value.value.as_deref(),
34        _ => None,
35    }
36}