haste_repository/types/
mod.rs1use haste_fhir_client::request::FHIRRequest;
2use std::fmt::Debug;
3
4pub mod authorization_code;
5pub mod membership;
6pub mod mfa;
7pub mod project;
8pub mod scope;
9pub mod subscription;
10pub mod tenant;
11pub mod user;
12
13pub use haste_jwt::SupportedFHIRVersions;
15
16#[derive(sqlx::Type, Debug, Clone)]
17#[sqlx(type_name = "fhir_method", rename_all = "lowercase")]
18pub enum FHIRMethod {
19 Create,
20 Read,
21 Update,
22 Delete,
23}
24
25impl FHIRMethod {
26 #[must_use]
27 pub fn as_str(&self) -> &'static str {
28 match self {
29 FHIRMethod::Create => "create",
30 FHIRMethod::Read => "read",
31 FHIRMethod::Update => "update",
32 FHIRMethod::Delete => "delete",
33 }
34 }
35}
36
37#[derive(sqlx::Type, Debug, Clone, Copy, PartialEq, Eq, Hash)]
38#[sqlx(type_name = "search_index_backend", rename_all = "lowercase")]
39pub enum SearchIndexBackend {
40 Elasticsearch,
41 Postgres,
42}
43
44impl std::fmt::Display for SearchIndexBackend {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 match self {
47 SearchIndexBackend::Elasticsearch => write!(f, "elasticsearch"),
48 SearchIndexBackend::Postgres => write!(f, "postgres"),
49 }
50 }
51}
52
53impl TryFrom<&str> for FHIRMethod {
54 type Error = String;
55
56 fn try_from(value: &str) -> Result<Self, Self::Error> {
57 match value.to_lowercase().as_str() {
58 "create" => Ok(FHIRMethod::Create),
59 "read" => Ok(FHIRMethod::Read),
60 "update" => Ok(FHIRMethod::Update),
61 "delete" => Ok(FHIRMethod::Delete),
62 _ => Err(format!("Unsupported FHIR method: {value}")),
63 }
64 }
65}
66
67impl TryFrom<&FHIRRequest> for FHIRMethod {
68 type Error = String;
69
70 fn try_from(request: &FHIRRequest) -> Result<Self, Self::Error> {
71 match request {
72 FHIRRequest::Create(_) => Ok(FHIRMethod::Create),
73 FHIRRequest::Read(_) => Ok(FHIRMethod::Read),
74 FHIRRequest::Update(_) => Ok(FHIRMethod::Update),
75 FHIRRequest::Delete(_) => Ok(FHIRMethod::Delete),
76 _ => Err("Unsupported FHIR request".to_string()),
77 }
78 }
79}