Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A client for one FHIR terminology server.

The client is cheap to clone: the HTTP stack and the configuration are shared, so a clone carries the same connection pool.

Implementations§

Source§

impl Client

Source

pub fn new(config: Config) -> Result<Self, Error>

Returns a client for the server config describes.

This constructor is the only way to obtain a client, so a deployment that configures no terminology server holds no Client at all and the absence is a compile-time Option<Client> rather than a runtime fallback.

§Errors

Returns Error::BaseUrl when the base URL cannot carry a path, and Error::ClientBuild when the HTTP stack refuses the configuration.

Source

pub fn config(&self) -> &Config

Returns the configuration this client was built from.

Source

pub fn check(&self, request: &Request) -> Result<(), Error>

Checks that the configured release can carry request, sending nothing.

A caller that sends several requests uses this to set aside one the release cannot carry, since a batch holding it is refused whole.

§Errors

Returns Error::UnsupportedParameter when request names a parameter the configured release does not declare: a concept map url or a value set version on an STU3 client.

Source

pub async fn reachability(&self) -> Result<StatusCode, Error>

Returns the status the server answers GET [base]/metadata with.

Every FHIR REST server states its capabilities at that path (https://hl7.org/fhir/R4/http.html#capabilities), so a reachability question needs no terminology operation. The call is not retried, and every status is returned as it stands, 401 and 404 included; under Credentials::OAuth a refused token is renewed once first.

§Errors

Returns Error::BaseUrl when the base URL cannot carry a path, Error::Token when no token could be obtained, Error::Timeout when the server did not answer inside the configured budget, and Error::Transport when the request never reached it.

Source

pub async fn lookup( &self, system: &str, code: &str, version: Option<&str>, ) -> Result<LookupOutcome, Error>

Resolves the display of code in system.

A server that does not know the code answers LookupOutcome::NotFound carrying its OperationOutcome; the display is never an empty string.

§Errors

Returns Error::Refused when the server refused the operation for another reason, and Error otherwise when the call did not reach an answer or the answer could not be decoded.

Source

pub async fn translate( &self, translation: &Translation, ) -> Result<TranslateOutcome, Error>

Translates the code translation names, through the concept map, into the target system and in the direction it names.

url, targetsystem and reverse are each sent only when the translation sets them, as R4 declares each 0..1 (https://hl7.org/fhir/R4/conceptmap-operation-translate.html). Every match the server returned is carried with its equivalence, so the caller decides which ones count; TranslateOutcome::accepted yields the equivalent and equal ones.

§Examples

A deployment with no terminology server holds no client, and a translation it cannot make is a refusal:

use ferrobridge_term::client::Client;
use ferrobridge_term::outcome::Translation;

let Some(client) = terminology.as_ref() else {
    return Err("no terminology server is configured".into());
};
let translation = Translation::new("http://example.org/source", "alpha")
    .with_concept_map("http://example.org/ConceptMap/source-to-target");
let outcome = client.translate(&translation).await?;
let Some(translated) = outcome.accepted().next() else {
    return Err("no equivalent translation".into());
};
let code = translated.concept.as_ref().and_then(|concept| concept.code.as_deref());
assert!(code.is_some(), "an accepted match names its target code");
§Errors

Returns Error::Refused when the server refused the operation, for example because it serves no such concept map, and Error otherwise when the call did not reach an answer or the answer could not be decoded. A refusal is never a missing translation. Returns Error::UnsupportedParameter when the translation names a concept map on an STU3 client, whose $translate has no url; nothing is sent.

Source

pub async fn validate_code( &self, value_set_url: &str, system: &str, code: &str, ) -> Result<ValidateOutcome, Error>

Validates that code from system is a member of value_set_url.

§Errors

Returns Error::Refused when the server refused the operation, for example because it serves no such value set, and Error otherwise when the call did not reach an answer or the answer could not be decoded. A refusal is never an invalid code.

Source

pub async fn validate( &self, validation: &Validation, ) -> Result<ValidateOutcome, Error>

Validates that the coded value of validation is a member of its value set, in any of the three forms the operation accepts: a code with its system, version and display, a Coding, or a CodeableConcept (https://hl7.org/fhir/R4/valueset-operation-validate-code.html).

§Errors

Returns Error::Refused when the server refused the operation, and Error otherwise when the call did not reach an answer or the answer could not be decoded. A refusal is never an invalid code. Returns Error::UnsupportedParameter when the validation names a value set version on an STU3 client, whose $validate-code has no valueSetVersion; nothing is sent.

Source

pub async fn validate_all( &self, validations: &[Validation], ) -> Result<Vec<Result<ValidateOutcome, Error>>, Error>

Validates every one of validations, answering them by position: one call for one validation, one batch Bundle for several.

An entry the server refused is that entry’s own typed error and leaves the others alone, as in Client::batch.

§Errors

Returns Error::BatchArity when a batch answer holds a different number of entries than were sent, and Error otherwise when the batch itself did not reach an answer or its Bundle could not be decoded. Returns Error::UnsupportedParameter when one of several validations names a parameter the configured release does not declare, and then no entry is sent.

Source

pub async fn batch( &self, requests: &[Request], ) -> Result<Vec<Result<BatchOutcome, Error>>, Error>

Sends requests as one batch Bundle and answers them by position.

“The server processes each entry independently” and answers a batch-response whose entries are “in the same order as the request” (https://hl7.org/fhir/R4/http.html#transaction), so entry n is the answer to request n. An entry the server refused is that entry’s own typed error and leaves the others alone.

§Errors

Returns Error::BatchArity when the answer holds a different number of entries than were sent, and Error otherwise when the batch itself did not reach an answer or its Bundle could not be decoded. Returns Error::UnsupportedParameter when a request names a parameter the configured release does not declare, and then no entry is sent.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more