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