Skip to content

Commit

Permalink
feat: Implement custom search request
Browse files Browse the repository at this point in the history
  • Loading branch information
Flix authored and FlixCoder committed Aug 18, 2024
1 parent c8e6b47 commit d7dd17f
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions crates/fhir-sdk/src/client/fhir/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>(&self, queries: SearchParameters) -> Result<Page<V, R>, Error>
where
R: AnyResource<V> + TryFrom<V::Resource, Error = WrongResourceType> + 'static,
Expand All @@ -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<R>(
&self,
make_request: impl FnOnce(&reqwest::Client) -> reqwest::RequestBuilder + Send,
) -> Result<Page<V, R>, Error>
where
R: TryFrom<V::Resource> + 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::<V>(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>(
Expand Down

0 comments on commit d7dd17f

Please sign in to comment.