Options
All
  • Public
  • Public/Protected
  • All
Menu

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:

// BROWSER
const client = FHIR.client("https://r4.smarthealthit.org");

// SERVER
const client = smart(req, res).client("https://r4.smarthealthit.org");

Hierarchy

  • default

Index

Constructors

  • Validates the parameters, creates an instance and tries to connect it to FhirJS, if one is available globally.

    Parameters

    Returns default

Other Properties

_refreshTask: null | Promise<any>

Refers to the refresh task while it is being performed.

see

refresh

api: undefined | Record<string, any>

The FhirJS API. NOTE: This will only be available if fhir.js is used. Otherwise it will be undefined.

encounter: { id: null | string; read: RequestFunction<Encounter> }

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.

Type declaration

  • id: null | string

    The ID of the current encounter or null if there is no current encounter

  • read: RequestFunction<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.

    param Any

    options to pass to the fetch call.

environment: Adapter

The adapter to use to connect to the current environment. Currently we have:

  • BrowserAdapter - for browsers
  • NodeAdapter - for Express or vanilla NodeJS servers
  • HapiAdapter - for HAPI NodeJS servers
patient: { api?: Record<string, any>; id: null | string; read: RequestFunction<Patient>; request: any }

A SMART app is typically associated with a patient. This is a namespace for the patient-related functionality of the client.

Type declaration

  • Optional api?: Record<string, any>

    This is the FhirJS Patient API. It will ONLY exist if the Client instance is "connected" to FhirJS.

  • id: null | string

    The ID of the current patient or null if there is no current patient

  • read: RequestFunction<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.

    param [requestOptions]

    Any options to pass to the fetch call.

  • request:function
    • 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.includeResponses has been set to true.

      Type Parameters

      Parameters

      Returns Promise<R>

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.

user: { fhirUser: null | string; id: null | string; read: RequestFunction<Patient | Practitioner | RelatedPerson>; resourceType: null | string }

The client may be associated with a specific user, if the scopes permit that. This is a namespace for user-related functionality.

Type declaration

  • fhirUser: null | string

    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.

    alias

    client.getFhirUser()

  • id: null | string

    The ID of the current user or null if there is no current user

  • read: RequestFunction<Patient | Practitioner | RelatedPerson>

    A method to fetch the current user resource from the FHIR server. If there is no user context, it will reject with an error.

    param Any

    options to pass to the fetch call.

  • resourceType: null | string

    Returns the type of the logged-in user or null. The result can be Practitioner, Patient or RelatedPerson.

    alias

    client.getUserType()

Utility Properties

units: { any: any; cm: any; kg: any } = units

Type declaration

Other Methods

  • _clearState(): Promise<void>
  • Used internally to clear the state of the instance and the state in the associated storage.

    Returns Promise<void>

  • connect(fhirJs?: ((options: Record<string, any>) => Record<string, any>)): default
  • 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.

    Parameters

    • Optional fhirJs: ((options: Record<string, any>) => Record<string, any>)
        • (options: Record<string, any>): Record<string, any>
        • Parameters

          • options: Record<string, any>

          Returns Record<string, any>

    Returns default

  • getAuthorizationHeader(): null | string
  • Builds and returns the value of the Authorization header that can be sent to the FHIR server

    Returns null | string

  • getEncounterId(): null | string
  • 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 null | string

  • getFhirRelease(): Promise<number>
  • Returns a promise that will be resolved with the numeric fhir version

    • 2 for DSTU2
    • 3 for STU3
    • 4 for R4
    • 0 if the version is not known

    Returns Promise<number>

  • getFhirUser(): null | string
  • 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 null | string

  • getFhirVersion(): Promise<string>
  • Returns a promise that will be resolved with the fhir version as defined in the CapabilityStatement.

    Returns Promise<string>

  • 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 null | IDToken

  • getPatientId(): null | string
  • Returns the ID of the selected patient or null. You should have requested "launch/patient" scope. Otherwise this will return null.

    Returns null | string

  • getState(path?: string): any
  • 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)

    Parameters

    • path: string = ""

      The path (eg. "a.b.4.c")

    Returns any

    Whatever is found in the path or undefined

  • getUserId(): null | string
  • getUserType(): null | string
  • Returns the type of the logged-in user or null. The result can be "Practitioner", "Patient" or "RelatedPerson".

    Returns null | string

Request Methods

  • delete<R>(url: string, requestOptions?: FetchOptions): Promise<R>
  • Removes an existing resource.

    see

    http://hl7.org/fhir/http.html#delete

    Type Parameters

    • R = unknown

    Parameters

    • url: string

      Relative URI of the FHIR resource to be deleted (format: resourceType/id)

    • requestOptions: FetchOptions = {}

      Any options (except method which will be fixed to DELETE) to be passed to the fetch call.

    Returns Promise<R>

  • Makes a JSON Patch to the given resource

    see

    http://hl7.org/fhir/http.html#patch

    since

    2.4.0

    Type Parameters

    • ResolveType = 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.

    Parameters

    • url: string

      Relative URI of the FHIR resource to be patched (format: resourceType/id)

    • patch: JsonPatch

      A JSON Patch array to send to the server, For details see https://datatracker.ietf.org/doc/html/rfc6902

    • requestOptions: FetchOptions = {}

      Any options to be passed to the fetch call, except for method, url and body which cannot be overridden.

    Returns Promise<ResolveType>

  • refresh(requestOptions?: RequestInit): Promise<ClientState>
  • 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.

    Parameters

    • requestOptions: RequestInit = {}

      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.

    Returns Promise<ClientState>

  • refreshIfNeeded(requestOptions?: RequestInit): Promise<ClientState>
  • 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.

    Parameters

    • requestOptions: RequestInit = {}

      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.

    Returns Promise<ClientState>

  • Type Parameters

    • T = any

    Parameters

    • requestOptions: string | URL | RequestOptions

      Can be a string URL (relative to the serviceUrl), or an object which will be passed to fetch()

    • fhirOptions: FhirOptions = {}

      Additional options to control the behavior

    • _resolvedRefs: JsonObject = {}

      DO NOT USE! Used internally.

    Returns Promise<T>

  • Creates a new current version for an existing resource or creates an initial version if no resource already exists for the given id.

    see

    http://hl7.org/fhir/http.html#update

    Type Parameters

    Parameters

    • resource: Resource

      A FHIR resource to be updated

    • Optional requestOptions: O

      Any options to be passed to the fetch call. Note that method and body will be ignored.

    Returns Promise<O["includeResponse"] extends true ? CombinedFetchResult<R> : R>

Utility Methods

  • 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 ]
    // }
    todo

    This should be deprecated and moved elsewhere. One should not have to obtain an instance of Client just to use utility functions like this.

    deprecated

    Parameters

    • observations: Observation | Observation[]

      Array of observations

    • property: string

      The name of a CodeableConcept property to group by

    Returns ObservationMap

  • 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 ]
    todo

    This should be deprecated and moved elsewhere. One should not have to obtain an instance of Client just to use utility functions like this.

    deprecated

    Parameters

    • observations: Observation | Observation[]

      Array of observations

    • property: string

      The name of a CodeableConcept property to group by

    Returns ((...codes: string[]) => any[])

      • (...codes: string[]): any[]
      • 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 ]
        todo

        This should be deprecated and moved elsewhere. One should not have to obtain an instance of Client just to use utility functions like this.

        deprecated
        category

        Utility

        Parameters

        • Rest ...codes: string[]

        Returns any[]

  • getPath(obj: Record<string, any>, path?: string): any
  • 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.

    todo

    This should be deprecated and moved elsewhere. One should not have to obtain an instance of Client just to use utility functions like this.

    deprecated

    Parameters

    • obj: Record<string, any>

      The object (or Array) to walk through

    • path: string = ""

      The path (eg. "a.b.4.c")

    Returns any

    Whatever is found in the path or undefined

Generated using TypeDoc