Skip to main content

haste_fhir_client/
lib.rs

1use haste_fhir_model::r4::generated::resources::{
2    Bundle, CapabilityStatement, Parameters, Resource, ResourceType,
3};
4use haste_fhir_operation_error::OperationOutcomeError;
5use json_patch::Patch;
6
7use crate::{
8    request::{FHIRRequest, FHIRResponse},
9    url::ParsedParameters,
10};
11
12#[cfg(feature = "axum")]
13pub mod axum;
14pub mod canonical_resolver;
15#[cfg(feature = "http")]
16pub mod http;
17pub mod middleware;
18pub mod request;
19pub mod url;
20
21/// Redacts the value of a string when printed, for use in debug implementations of request types that may contain sensitive information.
22fn redact<V>(_: &V, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23    write!(f, "***")
24}
25
26pub trait FHIRClient<CTX, Error>: Send + Sync {
27    fn request(
28        &self,
29        ctx: CTX,
30        request: FHIRRequest,
31    ) -> impl Future<Output = Result<FHIRResponse, Error>> + Send;
32
33    fn capabilities(
34        &self,
35        ctx: CTX,
36    ) -> impl Future<Output = Result<CapabilityStatement, OperationOutcomeError>> + Send;
37
38    fn search_system(
39        &self,
40        ctx: CTX,
41        parameters: ParsedParameters,
42    ) -> impl Future<Output = Result<Bundle, Error>> + Send;
43    fn search_type(
44        &self,
45        ctx: CTX,
46        resource_type: ResourceType,
47        parameters: ParsedParameters,
48    ) -> impl Future<Output = Result<Bundle, Error>> + Send;
49
50    fn create(
51        &self,
52        ctx: CTX,
53        resource_type: ResourceType,
54        resource: Resource,
55    ) -> impl Future<Output = Result<Resource, Error>> + Send;
56
57    fn update(
58        &self,
59        ctx: CTX,
60        resource_type: ResourceType,
61        id: String,
62        resource: Resource,
63    ) -> impl Future<Output = Result<Resource, Error>> + Send;
64
65    fn conditional_update(
66        &self,
67        ctx: CTX,
68        resource_type: ResourceType,
69        parameters: ParsedParameters,
70        resource: Resource,
71    ) -> impl Future<Output = Result<Resource, Error>> + Send;
72
73    fn patch(
74        &self,
75        ctx: CTX,
76        resource_type: ResourceType,
77        id: String,
78        patches: Patch,
79    ) -> impl Future<Output = Result<Resource, Error>> + Send;
80
81    fn read(
82        &self,
83        ctx: CTX,
84        resource_type: ResourceType,
85        id: String,
86    ) -> impl Future<Output = Result<Option<Resource>, Error>> + Send;
87
88    fn vread(
89        &self,
90        ctx: CTX,
91        resource_type: ResourceType,
92        id: String,
93        version_id: String,
94    ) -> impl Future<Output = Result<Option<Resource>, Error>> + Send;
95
96    fn delete_instance(
97        &self,
98        ctx: CTX,
99        resource_type: ResourceType,
100        id: String,
101    ) -> impl Future<Output = Result<(), Error>> + Send;
102
103    fn delete_type(
104        &self,
105        ctx: CTX,
106        resource_type: ResourceType,
107        parameters: ParsedParameters,
108    ) -> impl Future<Output = Result<(), Error>> + Send;
109
110    fn delete_system(
111        &self,
112        ctx: CTX,
113        parameters: ParsedParameters,
114    ) -> impl Future<Output = Result<(), Error>> + Send;
115
116    fn history_system(
117        &self,
118        ctx: CTX,
119        parameters: ParsedParameters,
120    ) -> impl Future<Output = Result<Bundle, Error>> + Send;
121
122    fn history_type(
123        &self,
124        ctx: CTX,
125        resource_type: ResourceType,
126        parameters: ParsedParameters,
127    ) -> impl Future<Output = Result<Bundle, Error>> + Send;
128
129    fn history_instance(
130        &self,
131        ctx: CTX,
132        resource_type: ResourceType,
133        id: String,
134        parameters: ParsedParameters,
135    ) -> impl Future<Output = Result<Bundle, Error>> + Send;
136
137    fn invoke_instance(
138        &self,
139        ctx: CTX,
140        resource_type: ResourceType,
141        id: String,
142        operation: String,
143        parameters: Parameters,
144    ) -> impl Future<Output = Result<Resource, Error>> + Send;
145
146    fn invoke_type(
147        &self,
148        ctx: CTX,
149        resource_type: ResourceType,
150        operation: String,
151        parameters: Parameters,
152    ) -> impl Future<Output = Result<Resource, Error>> + Send;
153
154    fn invoke_system(
155        &self,
156        ctx: CTX,
157        operation: String,
158        parameters: Parameters,
159    ) -> impl Future<Output = Result<Resource, Error>> + Send;
160
161    fn transaction(
162        &self,
163        ctx: CTX,
164        bundle: Bundle,
165    ) -> impl Future<Output = Result<Bundle, Error>> + Send;
166
167    fn batch(&self, ctx: CTX, bundle: Bundle)
168    -> impl Future<Output = Result<Bundle, Error>> + Send;
169}