FHIRClient - v3.0.0
    Preparing search index...

    Class default

    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 (View Summary)

    Index
    api: Record<string, any> | undefined

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

    encounter: { id: string | null; 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: string | null

      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.

      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
    fhirBaseUrl: string

    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.

    patient: {
        api?: Record<string, any>;
        id: string | null;
        read: RequestFunction<Patient>;
        request: <R = FetchResult>(
            requestOptions: string | URL | fhirclient.RequestOptions,
            fhirOptions?: FhirOptions,
        ) => Promise<R>;
    }

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

    Type Declaration

    • Optionalapi?: Record<string, any>

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

    • id: string | null

      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.

      Any options to pass to the fetch call.

    • request: <R = FetchResult>(
          requestOptions: string | URL | fhirclient.RequestOptions,
          fhirOptions?: FhirOptions,
      ) => Promise<R>

      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.

    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: string | null;
        id: string | null;
        read: RequestFunction<Patient | Practitioner | RelatedPerson>;
        resourceType: string | null;
    }

    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: string | null

      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.

      client.getFhirUser()

    • id: string | null

      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.

      Any options to pass to the fetch call.

    • resourceType: string | null

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

      client.getUserType()

    • Parameters

      • resource: Resource
      • references: string[]
      • graph: boolean
      • cache: Record<string, any> = {}
      • requestOptions: Omit<fhirclient.RequestOptions, "url"> = {}

      Returns Promise<Record<string, any>>

    • Builds and returns the value of the Authorization header that can be sent to the FHIR server

      Returns string | null

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

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

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

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

    • Returns the ID of the selected patient or null. You should have requested "launch/patient" scope. Otherwise this will return null.

      Returns string | null

    • Fetches all references in the given resource, ignoring duplicates

      Parameters

      Returns Promise<Record<string, Resource>>

    • 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

    • Returns the user ID or null.

      Returns string | null

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

      Returns string | null

    • Given a FHIR Bundle or a URL pointing to a bundle, iterates over all pages. Note that this will automatically crawl through further pages (if any) but it will not detect previous pages. It is designed to be called on the first page and fetch any followup pages.

      Parameters

      • bundleOrUrl: string | URL | Bundle<FhirResource>
      • OptionalrequestOptions: RequestOptions

      Returns AsyncGenerator<Bundle<FhirResource>, void, unknown>

    • Fetches all references in the given resource, ignoring duplicates, and then modifies the resource by "mounting" the resolved references in place

      Parameters

      Returns Promise<void>

    • Given a FHIR Bundle or a URL pointing to a bundle, iterates over all entry resources. Note that this will also automatically crawl through further pages (if any)

      Parameters

      • bundleOrUrl: string | URL | Bundle<FhirResource>
      • Optionaloptions: RequestOptions

      Returns AsyncGenerator<FhirResource | undefined, void, unknown>

    • Makes a JSON Patch to the given resource

      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>

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

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

    units: {
        any(pq: CodeValue): number;
        cm(__namedParameters: CodeValue): number;
        kg(__namedParameters: CodeValue): number;
    } = units
    • 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 ]
      // }

      Parameters

      • observations: Observation | Observation[]

        Array of observations

      • property: string

        The name of a CodeableConcept property to group by

      Returns ObservationMap

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

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

      Parameters

      • observations: Observation | Observation[]

        Array of observations

      • property: string

        The name of a CodeableConcept property to group by

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

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

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

      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

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