# FhirResource

Canonical page: https://docs.ovok.com/java-sdk/reference/fhir-resource

```java
public final class FhirResource
```

Reads and writes FHIR R4 resources under the configured FHIR path. Get it from [`Ovok.fhir()`](/java-sdk/reference/ovok#fhir).

## Methods [#methods]

### read [#read]

```java
public JsonNode read(String resourceType, String id) throws IOException, InterruptedException
```

Reads one resource (`GET /fhir/{resourceType}/{id}`).

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Patient`
- `id`: the resource id

**Returns:** the resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode read(
        String resourceType,
        String id,
        RequestOptions options) throws IOException, InterruptedException
```

Reads one resource (`GET /fhir/{resourceType}/{id}`).

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Patient`
- `id`: the resource id
- `options`: per-request options, such as the timeout

**Returns:** the resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### search [#search]

```java
public Page<JsonNode> search(
        String resourceType,
        Map<String, ?> parameters) throws IOException, InterruptedException
```

Searches resources of one type (`GET /fhir/{resourceType}?...`); iterating the page follows the bundle's next links.

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Observation`
- `parameters`: FHIR search parameters

**Returns:** the matching resources, without included or outcome entries

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public Page<JsonNode> search(String resourceType) throws IOException, InterruptedException
```

Searches all resources of one type (`GET /fhir/{resourceType}`).

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Observation`

**Returns:** the matching resources, without included or outcome entries

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public Page<JsonNode> search(
        String resourceType,
        Map<String, ?> parameters,
        RequestOptions options) throws IOException, InterruptedException
```

Searches resources of one type (`GET /fhir/{resourceType}?...`); iterating the page follows the bundle's next links.

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Observation`
- `parameters`: FHIR search parameters
- `options`: per-request options, such as the timeout

**Returns:** the matching resources, without included or outcome entries

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### searchOne [#searchone]

```java
public JsonNode searchOne(
        String resourceType,
        Map<String, ?> parameters) throws IOException, InterruptedException
```

Returns the first resource matching a search, requested with `_count=1`.

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Patient`
- `parameters`: FHIR search parameters

**Returns:** the first match, or `null` when nothing matches

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode searchOne(String resourceType) throws IOException, InterruptedException
```

Returns the first resource of one type, requested with `_count=1`.

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Patient`

**Returns:** the first match, or `null` when there is none

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode searchOne(
        String resourceType,
        Map<String, ?> parameters,
        RequestOptions options) throws IOException, InterruptedException
```

Returns the first resource matching a search, requested with `_count=1`.

**Parameters:**

- `resourceType`: the FHIR resource type, such as `Patient`
- `parameters`: FHIR search parameters
- `options`: per-request options, such as the timeout

**Returns:** the first match, or `null` when nothing matches

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### create [#create]

```java
public JsonNode create(JsonNode resource) throws IOException, InterruptedException
```

Creates a resource (`POST /fhir/{resourceType}`).

**Parameters:**

- `resource`: the resource to create; it must have `resourceType`

**Returns:** the created resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the resource has no `resourceType`

```java
public JsonNode create(
        JsonNode resource,
        String ifNoneExist) throws IOException, InterruptedException
```

Creates a resource unless one matches the `If-None-Exist` search (`POST /fhir/{resourceType}`).

**Parameters:**

- `resource`: the resource to create; it must have `resourceType`
- `ifNoneExist`: the conditional-create search, such as `identifier=x|y`, or `null`

**Returns:** the created or matching resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the resource has no `resourceType`

```java
public JsonNode create(
        JsonNode resource,
        String ifNoneExist,
        RequestOptions options) throws IOException, InterruptedException
```

Creates a resource unless one matches the `If-None-Exist` search (`POST /fhir/{resourceType}`).

**Parameters:**

- `resource`: the resource to create; it must have `resourceType`
- `ifNoneExist`: the conditional-create search, such as `identifier=x|y`, or `null`
- `options`: per-request options, such as the timeout

**Returns:** the created or matching resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the resource has no `resourceType`

### update [#update]

```java
public JsonNode update(JsonNode resource) throws IOException, InterruptedException
```

Replaces a resource (`PUT /fhir/{resourceType}/{id}`).

**Parameters:**

- `resource`: the full resource; it must have `resourceType` and `id`

**Returns:** the updated resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the resource has no `resourceType` or `id`

```java
public JsonNode update(
        JsonNode resource,
        RequestOptions options) throws IOException, InterruptedException
```

Replaces a resource (`PUT /fhir/{resourceType}/{id}`).

**Parameters:**

- `resource`: the full resource; it must have `resourceType` and `id`
- `options`: per-request options, such as the timeout

**Returns:** the updated resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the resource has no `resourceType` or `id`

### patch [#patch]

```java
public JsonNode patch(
        String resourceType,
        String id,
        List<? extends Map<String, ?>> operations,
        RequestOptions options) throws IOException, InterruptedException
```

Applies a JSON Patch to a resource (`PATCH /fhir/{resourceType}/{id}`).

**Parameters:**

- `resourceType`: the FHIR resource type
- `id`: the resource id
- `operations`: the JSON Patch operations, such as `{op: replace, path: /status, value: final}`
- `options`: per-request options, such as the timeout

**Returns:** the patched resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode patch(
        String resourceType,
        String id,
        List<? extends Map<String, ?>> operations) throws IOException, InterruptedException
```

Applies a JSON Patch to a resource (`PATCH /fhir/{resourceType}/{id}`).

**Parameters:**

- `resourceType`: the FHIR resource type
- `id`: the resource id
- `operations`: the JSON Patch operations

**Returns:** the patched resource

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### delete [#delete]

```java
public void delete(String resourceType, String id) throws IOException, InterruptedException
```

Deletes a resource (`DELETE /fhir/{resourceType}/{id}`).

**Parameters:**

- `resourceType`: the FHIR resource type
- `id`: the resource id

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public void delete(
        String resourceType,
        String id,
        RequestOptions options) throws IOException, InterruptedException
```

Deletes a resource (`DELETE /fhir/{resourceType}/{id}`).

**Parameters:**

- `resourceType`: the FHIR resource type
- `id`: the resource id
- `options`: per-request options, such as the timeout

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### batch [#batch]

```java
public JsonNode batch(JsonNode bundle) throws IOException, InterruptedException
```

Runs a batch or transaction bundle (`POST /fhir`).

**Parameters:**

- `bundle`: a `Bundle` of type `batch` or `transaction`

**Returns:** the response bundle

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode batch(
        JsonNode bundle,
        RequestOptions options) throws IOException, InterruptedException
```

Runs a batch or transaction bundle (`POST /fhir`).

**Parameters:**

- `bundle`: a `Bundle` of type `batch` or `transaction`
- `options`: per-request options, such as the timeout

**Returns:** the response bundle

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
