haste_operation_executor/
lib.rs1pub mod providers;
2pub mod structs;
3pub mod traits;
4
5use haste_fhir_model::r4::generated::resources::OperationDefinition;
6use haste_fhir_model::r4::generated::types::{Extension, ExtensionValueTypeChoice};
7
8const CUSTOM_CODE_EXTENSION_URL: &str = "https://haste.health/Extension/custom-code";
9const CUSTOM_CODE_TYPE_EXTENSION_URL: &str = "https://haste.health/Extension/custom-code-type";
10
11pub(crate) fn extract_code_from_operation_definition(
12 operation: &OperationDefinition,
13) -> Option<(&str, &str)> {
14 let code_extension = operation.extension.as_ref()?.iter().find(|extension| {
15 extension.url == CUSTOM_CODE_EXTENSION_URL
16 && extension_value_as_string(extension.as_ref()).is_some()
17 })?;
18
19 let code = extension_value_as_string(code_extension.as_ref())?;
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.as_ref()))?;
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}