FHIRKit Client - v2.0.0
    Preparing search index...

    Class Client

    FHIR REST client. Provides typed methods for all FHIR interactions.

    import { Client } from 'fhir-kit-client';

    const client = new Client({ baseUrl: 'https://r4.smarthealthit.org' });
    const patient = await client.read({ resourceType: 'Patient', id: '123' });
    Index

    Constructors

    Properties

    httpClient: HttpClient

    Underlying HTTP client — exposed for advanced use cases.

    pagination: Pagination

    Pagination helper.

    Accessors

    • get baseUrl(): string

      FHIR server base URL.

      Returns string

    • set baseUrl(url: string): void

      Parameters

      • url: string

      Returns void

    • set bearerToken(token: string): void

      Set the OAuth2 bearer token used for Authorization headers.

      Parameters

      • token: string

      Returns void

    • get customHeaders(): Record<string, string>

      Custom headers sent with every request.

      Returns Record<string, string>

    • set customHeaders(headers: Record<string, string>): void

      Parameters

      • headers: Record<string, string>

      Returns void

    Methods

    • Submit a batch Bundle (FHIR batch interaction).

      The body.type field must be 'batch'. Each entry is processed independently; partial failures are reported per-entry in the response.

      Parameters

      Returns Promise<FhirResource>

      The batch response Bundle.

    • Delete a resource by type and id (FHIR delete interaction).

      Parameters

      Returns Promise<FhirResource>

      The server's response (often an OperationOutcome).

      If resourceType is invalid or the server returns an error.

    • Patch a resource using JSON Patch (RFC 6902) (FHIR patch interaction).

      Sends Content-Type: application/json-patch+json.

      Parameters

      Returns Promise<FhirResource>

      The patched resource.

      If resourceType is invalid or the server returns an error.

    • Execute a raw request against the FHIR server. Useful for endpoints not covered by higher-level methods.

      Parameters

      • requestUrl: string

        Path or absolute URL to request.

      • __namedParameters: RawRequestParams = {}

      Returns Promise<FhirResource>

      The parsed FHIR response.

      client.request('Patient/123')
      client.request('Patient/123', { method: 'DELETE' })
      client.request('Patient', { method: 'POST', body: newPatient })
    • Resolve a FHIR reference to a resource.

      • Absolute URL (http://...): fetches directly or creates a new client for a foreign base URL.
      • Relative URL (Patient/123): fetches from this client's baseUrl.
      • Contained reference (#id): resolved from context.contained[].
      • Bundle-scoped reference: resolved from context.entry[].fullUrl.

      Parameters

      Returns Promise<FhirResource>

      The resolved FHIR resource.

    • Instance-level history for a specific resource.

      Parameters

      • __namedParameters: { id: string; options?: RequestOptions; resourceType: string }

      Returns Promise<FhirResource>

      A history Bundle.

    • Search for resources. Dispatches to the appropriate search variant based on parameters:

      • compartment + resourceType → compartment search
      • resourceType only → type-level search
      • searchParams only → system-wide search

      Parameters

      Returns Promise<FhirResource>

      A search result Bundle.

      If resourceType is invalid or insufficient parameters are provided.

    • Fetch SMART OAuth 2.0 authorization metadata from the server.

      Races three sources simultaneously and resolves with the first successful response: .well-known/smart-configuration, metadata (CapabilityStatement), and .well-known/openid-configuration. Rejects only if all three fail.

      Parameters

      Returns Promise<SmartAuthMetadata>

      SMART auth metadata containing authorizeUrl, tokenUrl, etc.

    • Submit a transaction Bundle (FHIR transaction interaction).

      The body.type field must be 'transaction'. All entries succeed or fail together (atomic).

      Parameters

      Returns Promise<FhirResource>

      The transaction response Bundle.

    • Update a resource (FHIR update interaction).

      Supports conditional update via searchParams (sets the If-Match criteria). Provide either id or searchParams, not both.

      Parameters

      Returns Promise<FhirResource>

      The updated resource.

      If resourceType is invalid, both or neither of id/searchParams are provided, or the server returns an error.

    • Read a specific version of a resource (FHIR vread interaction).

      Parameters

      Returns Promise<FhirResource>

      The specified version of the resource.

      If resourceType is invalid or the server returns an error.

    • Return the raw Request and Response objects attached to a FHIR response value by the HTTP layer.

      Parameters

      • requestResponse: FhirResource

        A FHIR resource returned by any client method.

      Returns { request: Request | undefined; response: Response | undefined }

      { request, response } — either may be undefined for synthetic responses.