rumtk_web/utils/
mod.rs

1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025  Luis M. Santos, M.D.
5 * Copyright (C) 2025  Nick Stephenson
6 * Copyright (C) 2025  Ethan Dixon
7 * Copyright (C) 2025  MedicalMasses L.L.C.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 */
23pub mod app;
24pub mod conf;
25pub mod defaults;
26pub mod matcher;
27pub mod packaging;
28pub mod render;
29pub mod types;
30
31pub use render::*;
32pub use types::*;
33
34#[macro_export]
35macro_rules! rumtk_web_get_text_item {
36    ( $store:expr, $item:expr, $default:expr) => {{
37        match $store.get($item) {
38            Some(x) => x,
39            None => $default,
40        }
41    }};
42}
43
44#[macro_export]
45macro_rules! rumtk_web_get_param_eq {
46    ( $params:expr, $indx:expr, $comparison:expr, $default:expr ) => {{
47        match $params.get($indx) {
48            Some(x) => *x == $comparison,
49            None => $default,
50        }
51    }};
52}
53
54#[macro_export]
55macro_rules! rumtk_web_get_param {
56    ( $params:expr, $indx:expr, $default:expr ) => {{
57        match $params.get($indx) {
58            Some(x) => x.parse().unwrap_or($default),
59            None => $default,
60        }
61    }};
62}
63
64#[macro_export]
65macro_rules! rumtk_web_params_map {
66    ( $params:expr ) => {{
67        use std::collections::HashMap;
68        let mut params = HashMap::<RUMString, RUMString>::with_capacity($params.len());
69
70        for (k, v) in $params.iter() {
71            params.insert(
72                RUMString::from(k.to_string()),
73                RUMString::from(v.to_string()),
74            );
75        }
76        params
77    }};
78}
79
80#[macro_export]
81macro_rules! rumtk_web_fetch {
82    ( $matcher:expr ) => {{
83        use axum::extract::{Path, Query, State};
84        use axum::response::Html;
85        use $crate::utils::types::{RouterAppConf, RouterComponents, RouterParams};
86
87        async |Path(path_params): RouterComponents,
88               Query(params): RouterParams,
89               State(state): RouterAppConf|
90               -> Html<String> {
91            match $matcher(path_params, params, state).await {
92                Ok(res) => res,
93                Err(e) => {
94                    error!("{}", e);
95                    return Html(String::default());
96                }
97            }
98        }
99    }};
100}