# FHIR

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

`ovok.fhir` is a generic FHIR R4 client for any resource type. Resources are plain
dictionaries in FHIR JSON shape. Use it when no dedicated namespace covers the resource.

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

`search` returns a `Page`. A list value repeats its parameter, which FHIR reads as AND.

```python
from ovok_sdk import Ovok

ovok = Ovok("https://api.sandbox.ovok.com", "your-tenant")

patient = ovok.fhir.read("Patient", "patient-id")
page = ovok.fhir.search("Observation", {"patient": "Patient/patient-id", "_count": 50})
for observation in page.auto_paging_iter():
    print(observation["id"])

first = ovok.fhir.search_one("Patient", {"identifier": "https://example.com/mrn|123"})
```

## Create without duplicates [#create-without-duplicates]

With `if_none_exist`, the server returns the existing match instead of creating a second
resource, so the request is safe to retry.

```python
ovok.fhir.create(
    {
        "resourceType": "Patient",
        "identifier": [{"system": "https://example.com/mrn", "value": "123"}],
    },
    if_none_exist="identifier=https://example.com/mrn|123",
)
```

## Update, patch and delete [#update-patch-and-delete]

```python
patient["active"] = False
ovok.fhir.update(patient)
ovok.fhir.patch("Patient", "patient-id", [{"op": "replace", "path": "/active", "value": True}])
ovok.fhir.delete("Patient", "patient-id")
```

## Send a transaction [#send-a-transaction]

```python
ovok.fhir.batch({
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [
        {"request": {"method": "POST", "url": "Observation"}, "resource": observation},
    ],
})
```

## API reference [#api-reference]

See [`ovok_sdk.resources.fhir`](/python-sdk/reference/resources/fhir)
for every method, parameter and error.
