# ovok.fhir

Canonical page: https://docs.ovok.com/web-sdk/core/namespaces/fhir

Typed FHIR R4 access for any app. The FHIR base path comes from the client's `fhirPath` option (default `fhir`). What a user can see or change is decided by their access policy on the server.

## Read and search [#read-and-search]

```ts
const patient = await ovok.fhir.read('Patient', id);

const page = await ovok.fhir.search('Observation', { patient: `Patient/${id}`, _count: 50 });

for await (const observation of ovok.fhir.search('Observation', { patient: `Patient/${id}` })) {
  // every page, fetched as you go
}

const first = await ovok.fhir.searchOne('Patient', { identifier: 'urn:mrn|123' });
```

- `search` returns a `PagePromise`: await it for `{ data, hasMore, total }`, or `for await` for every item.
- Included resources are left out of `data`.
- A list value repeats its parameter, which FHIR reads as AND: `date: ['ge2026-01-01', 'le2026-02-01']`. For OR, write one comma-separated string.
- `searchOne` returns the first match or `null`.

## Create, update, patch, delete [#create-update-patch-delete]

```ts
await ovok.fhir.create(observation, { ifNoneExist: 'identifier=urn:device|42' });
await ovok.fhir.update(patient);
await ovok.fhir.patch('Patient', id, [{ op: 'replace', path: '/active', value: false }]);
await ovok.fhir.delete('Patient', id);
```

- `update` replaces the resource and throws `OvokValidationError` when it has no `id`.
- `create` with `ifNoneExist` is a conditional create. A retry cannot duplicate it, so it is retried after a network failure. A plain `create` is not.
- `patch` takes JSON Patch operations.

## Batch and transaction bundles [#batch-and-transaction-bundles]

```ts
const result = await ovok.fhir.batch(bundle);
```

- Posts the bundle to the FHIR base and returns the response bundle. Set `bundle.type` to `batch` or `transaction`.
- Check each entry's `response.status` in the result; a batch can succeed in part.

## React [#react]

`useResource`, `useSearch` and `useSubscription` from `@ovok/core/next/react` wrap these calls. See [React](/web-sdk/core/react).

## Reference [#reference]

- [fhir API reference](/web-sdk/core/reference/core/fhir): every method and type.
- [ovok.realtime](/web-sdk/core/namespaces/realtime): subscribe to FHIR changes.
- [ovok.measurements](/web-sdk/core/namespaces/measurements): saving readings safely.
- [Errors and retries](/web-sdk/core/errors-and-retries)
