Validates the parameters, creates an instance and tries to connect it to FhirJS, if one is available globally.
Refers to the refresh task while it is being performed.
The FhirJS API.
NOTE: This will only be available if fhir.js
is used. Otherwise it
will be undefined
.
The client may be associated with a specific encounter, if the scopes permit that and if the back-end server supports that. This is a namespace for encounter-related functionality.
The ID of the current encounter or null
if there is no current
encounter
A method to fetch the current encounter resource from the FHIR server. If there is no encounter context, it will reject with an error.
The adapter to use to connect to the current environment. Currently we have:
A SMART app is typically associated with a patient. This is a namespace for the patient-related functionality of the client.
This is the FhirJS Patient API. It will ONLY exist if the Client
instance is "connected" to FhirJS.
The ID of the current patient or null
if there is no current patient
A method to fetch the current patient resource from the FHIR server. If there is no patient context, it will reject with an error.
This is similar to request but it makes requests in the context of the current patient. For example, instead of doing
client.request("Observation?patient=" + client.patient.id)
you can do
client.patient.request("Observation")
The return type depends on the arguments. Typically it will be the
response payload JSON object. Can also be a string or the Response
object itself if we have received a non-json result, which allows us
to handle even binary responses. Can also be a CombinedFetchResult
object if the requestOptions.includeResponse
s has been set to true.
The state of the client instance is an object with various properties.
It contains some details about how the client has been authorized and
determines the behavior of the client instance. This state is persisted
in SessionStorage
in browsers or in request session on the servers.
The client may be associated with a specific user, if the scopes permit that. This is a namespace for user-related functionality.
Returns the profile of the logged_in user (if any), or null if the
user is not available. This is a string having the shape
{user type}/{user id}
. For example Practitioner/abc
or
Patient/xyz
.
The ID of the current user or null
if there is no current user
A method to fetch the current user resource from the FHIR server. If there is no user context, it will reject with an error.
Returns the type of the logged-in user or null. The result can be
Practitioner
, Patient
or RelatedPerson
.
Used internally to clear the state of the instance and the state in the associated storage.
This method is used to make the "link" between the fhirclient
and the
fhir.js
, if one is available.
Note: This is called by the constructor. If fhir.js is available in
the global scope as fhir
, it will automatically be linked to any Client
instance. You should only use this method to connect to fhir.js
which
is not global.
Builds and returns the value of the Authorization
header that can be
sent to the FHIR server
Returns the ID of the selected encounter or null. You should have requested "launch/encounter" scope. Otherwise this will return null. Note that not all servers support the "launch/encounter" scope so this will be null if they don't.
Returns a promise that will be resolved with the numeric fhir version
Returns the profile of the logged_in user (if any). This is a string
having the following shape "{user type}/{user id}"
. For example:
"Practitioner/abc"
or "Patient/xyz"
.
Returns a promise that will be resolved with the fhir version as defined in the CapabilityStatement.
Returns the (decoded) id_token if any. You need to request "openid" and "profile" scopes if you need to receive an id_token (if you need to know who the logged-in user is).
Returns the ID of the selected patient or null. You should have requested "launch/patient" scope. Otherwise this will return null.
Returns a copy of the client state. Accepts a dot-separated path argument
(same as for getPath
) to allow for selecting specific properties.
Examples:
client.getState(); // -> the entire state object
client.getState("serverUrl"); // -> the URL we are connected to
client.getState("tokenResponse.patient"); // -> The selected patient ID (if any)
The path (eg. "a.b.4.c")
Whatever is found in the path or undefined
Returns the user ID or null.
Returns the type of the logged-in user or null. The result can be "Practitioner", "Patient" or "RelatedPerson".
Creates a new resource in a server-assigned location
A FHIR resource to be created
Removes an existing resource.
Relative URI of the FHIR resource to be deleted
(format: resourceType/id
)
Any options (except method
which will be fixed
to DELETE
) to be passed to the fetch call.
Makes a JSON Patch to the given resource
This method would typically resolve with the patched resource or reject with an OperationOutcome. However, this may depend on the server implementation or even on the request headers. For that reason, if the default resolve type (which is fhirclient.FHIR.Resource) does not work for you, you can pass in your own resolve type parameter.
Relative URI of the FHIR resource to be patched
(format: resourceType/id
)
A JSON Patch array to send to the server, For details see https://datatracker.ietf.org/doc/html/rfc6902
Any options to be passed to the fetch call,
except for method
, url
and body
which cannot be overridden.
Use the refresh token to obtain new access token. If the refresh token is expired (or this fails for any other reason) it will be deleted from the state, so that we don't enter into loops trying to re-authorize.
This method is typically called internally from request if certain request fails with 401.
Any options to pass to the fetch call. Most of them will be overridden, bit it might still be useful for passing additional request options or an abort signal.
Checks if access token and refresh token are present. If they are, and if
the access token is expired or is about to expire in the next 10 seconds,
calls this.refresh()
to obtain new access token.
Any options to pass to the fetch call. Most of them will be overridden, bit it might still be useful for passing additional request options or an abort signal.
Can be a string URL (relative to the serviceUrl), or an object which will be passed to fetch()
Additional options to control the behavior
DO NOT USE! Used internally.
Creates a new current version for an existing resource or creates an initial version if no resource already exists for the given id.
A FHIR resource to be updated
Any options to be passed to the fetch call.
Note that method
and body
will be ignored.
Groups the observations by code. Returns a map that will look like:
const map = client.byCodes(observations, "code");
// map = {
// "55284-4": [ observation1, observation2 ],
// "6082-2": [ observation3 ]
// }
Array of observations
The name of a CodeableConcept property to group by
First groups the observations by code using byCode
. Then returns a function
that accepts codes as arguments and will return a flat array of observations
having that codes. Example:
const filter = client.byCodes(observations, "category");
filter("laboratory") // => [ observation1, observation2 ]
filter("vital-signs") // => [ observation3 ]
filter("laboratory", "vital-signs") // => [ observation1, observation2, observation3 ]
Array of observations
The name of a CodeableConcept property to group by
First groups the observations by code using byCode
. Then returns a function
that accepts codes as arguments and will return a flat array of observations
having that codes. Example:
const filter = client.byCodes(observations, "category");
filter("laboratory") // => [ observation1, observation2 ]
filter("vital-signs") // => [ observation3 ]
filter("laboratory", "vital-signs") // => [ observation1, observation2, observation3 ]
Walks through an object (or array) and returns the value found at the provided path. This function is very simple so it intentionally does not support any argument polymorphism, meaning that the path can only be a dot-separated string. If the path is invalid returns undefined.
The object (or Array) to walk through
The path (eg. "a.b.4.c")
Whatever is found in the path or undefined
Generated using TypeDoc
This is a FHIR client that is returned to you from the
ready()
call of the SMART API. You can also create it yourself if needed: