> ## Documentation Index
> Fetch the complete documentation index at: https://docs.haau3.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use your own FHIR client

> The FHIR base is standard FHIR R4: MedplumClient, fhir-kit-client and fhirpy work with it, pointed at the base with the API key as a Bearer token.

Plan Benefits, MedList, Terminology, the provider directory and Questionnaires share one FHIR R4
base, `https://api.haau3.com/v1/fhir/r4`, so a FHIR client you already use works with them. Point
it at the base and send your API key as a Bearer token. Every example below was run against the
API with the client version it names. Scheduling is not on the FHIR base: call it with an
[SDK](/sdks) or plain HTTP.

## MedplumClient (TypeScript)

```bash theme={null}
npm install @medplum/core @medplum/fhirtypes
```

Checked with `@medplum/core` 5.2.5. `baseUrl` is the API's host and `fhirUrlPath` the
base's path:

```ts theme={null}
import { MedplumClient } from "@medplum/core";

const medplum = new MedplumClient({
  baseUrl: "https://api.haau3.com/",
  fhirUrlPath: "v1/fhir/r4",
  accessToken: process.env.HAAU3_API_KEY,
});
```

Read a resource, and search across every page of an answer:

```ts theme={null}
const plan = await medplum.readResource("InsurancePlan", "H2406-013-000");
console.log(plan.name);
```

```ts theme={null}
for await (const page of medplum.searchResourcePages("PractitionerRole", {
  practitioner: "Practitioner-1093209884",
  _count: 1,
})) {
  for (const role of page) console.log(role.id);
}
```

An operation is a request to its address, and a batch is a `Bundle`:

```ts theme={null}
const lookup = await medplum.get(medplum.fhirUrl("CodeSystem", "$lookup") + "?system=http://loinc.org&code=2345-7");
console.log(lookup.parameter.find((p: { name: string }) => p.name === "display").valueString);
```

```ts theme={null}
const answers = await medplum.executeBatch({
  resourceType: "Bundle",
  type: "batch",
  entry: [
    { request: { method: "GET", url: "InsurancePlan/H2406-013-000" } },
    { request: { method: "GET", url: "Practitioner/Practitioner-1093209884" } },
  ],
});
for (const entry of answers.entry ?? []) console.log(entry.response?.status, entry.resource?.resourceType);
```

## fhir-kit-client (JavaScript)

```bash theme={null}
npm install fhir-kit-client
```

Checked with `fhir-kit-client` 2.0.3:

```js theme={null}
import { Client } from "fhir-kit-client";

const client = new Client({
  baseUrl: "https://api.haau3.com/v1/fhir/r4",
  bearerToken: process.env.HAAU3_API_KEY,
});
```

```js theme={null}
const plan = await client.read({ resourceType: "InsurancePlan", id: "H2406-013-000" });
console.log(plan.name);
```

```js theme={null}
let bundle = await client.search({
  resourceType: "PractitionerRole",
  searchParams: { practitioner: "Practitioner-1093209884", _count: 1 },
});
while (bundle) {
  for (const entry of bundle.entry ?? []) console.log(entry.resource.id);
  bundle = await client.nextPage({ bundle });
}
```

```js theme={null}
const lookup = await client.operation({
  resourceType: "CodeSystem",
  name: "$lookup",
  method: "GET",
  input: { system: "http://loinc.org", code: "2345-7" },
});
console.log(lookup.parameter.find((p) => p.name === "display").valueString);
```

```js theme={null}
const answers = await client.batch({
  body: {
    resourceType: "Bundle",
    type: "batch",
    entry: [
      { request: { method: "GET", url: "InsurancePlan/H2406-013-000" } },
      { request: { method: "GET", url: "Practitioner/Practitioner-1093209884" } },
    ],
  },
});
for (const entry of answers.entry ?? []) console.log(entry.response?.status, entry.resource?.resourceType);
```

## fhirpy (Python)

```bash theme={null}
pip install fhirpy
```

Checked with `fhirpy` 2.3.1:

```python theme={null}
import os

from fhirpy import SyncFHIRClient

client = SyncFHIRClient(
    "https://api.haau3.com/v1/fhir/r4",
    authorization=f"Bearer {os.environ['HAAU3_API_KEY']}",
)
```

```python theme={null}
plan = client.reference("InsurancePlan", "H2406-013-000").to_resource()
print(plan["name"])
```

```python theme={null}
roles = client.resources("PractitionerRole").search(practitioner="Practitioner-1093209884").limit(1).fetch_all()
for role in roles:
    print(role.id)
```

```python theme={null}
lookup = client.execute("CodeSystem/$lookup", method="get", params={"system": "http://loinc.org", "code": "2345-7"})
print(next(p["valueString"] for p in lookup["parameter"] if p["name"] == "display"))
```

## Go

The [Go SDK](/sdks) calls every operation on the FHIR base, with FHIR R4 types generated from HL7's
own schema in its `fhir` package.

## What every client meets

* Every answer is FHIR JSON, and every error an `OperationOutcome`. [Errors](/errors) lists each
  status and whether to retry it.
* A search answers one page at a time, with a `next` link to the following page. Each client above
  follows it.
* A batch `Bundle` sent to the base carries several requests, each answered in the order sent.
  Every operation on the base can go in one except `$reconcile-medications`.
* An API key belongs on a server. Call the API from your backend, never from a browser.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.