From 665acb1256efad1d2eb87802907fcd1ba9e11513 Mon Sep 17 00:00:00 2001 From: Flix Date: Sun, 18 Aug 2024 14:51:16 +0200 Subject: [PATCH] feat: Implement custom search request --- crates/fhir-sdk/src/client/fhir/crud.rs | 31 +++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/fhir-sdk/src/client/fhir/crud.rs b/crates/fhir-sdk/src/client/fhir/crud.rs index ed8c0291..0ef06517 100644 --- a/crates/fhir-sdk/src/client/fhir/crud.rs +++ b/crates/fhir-sdk/src/client/fhir/crud.rs @@ -251,8 +251,6 @@ where } /// Search for FHIR resources of a given type given the query parameters. - /// This simply ignores resources of the wrong type, e.g. an additional - /// OperationOutcome. pub async fn search(&self, queries: SearchParameters) -> Result, Error> where R: AnyResource + TryFrom + 'static, @@ -277,6 +275,35 @@ where } } + /// Search for FHIR resources via a custom request. This allows sending POST requests instead of + /// GET when necessary. You can construct the request yourself to any URL and send any data. + /// The endpoint is expected to send a FHIR-conform bundle. + /// + /// You can specify the expected search entry type via the type parameter. This can be either + /// the generic resource or a specific resource. + /// + /// Keep in mind that mismatching origins to the base URL are rejected if not explicitly allowed + /// via the flag in the builder ([ClientBuilder::allow_origin_mismatch]). Similarly, if the + /// server responds with a different major FHIR version than the client is configured for, the + /// response is rejected if not explicitly allowed via the flag in the builder + /// ([ClientBuilder::allow_version_mismatch]). + pub async fn search_custom( + &self, + make_request: impl FnOnce(&reqwest::Client) -> reqwest::RequestBuilder + Send, + ) -> Result, Error> + where + R: TryFrom + Send + Sync + 'static, + for<'a> &'a R: TryFrom<&'a V::Resource>, + { + let response = self.send_custom_request(make_request).await?; + if response.status().is_success() { + let bundle: V::Bundle = response.json().await?; + Ok(Page::new(self.clone(), bundle)) + } else { + Err(Error::from_response::(response).await) + } + } + /// Begin building a patch request for a FHIR resource on the server via the /// `FHIRPath Patch` method. pub fn patch_via_fhir<'a>(