# FHIR resource

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

{/* Generated by scripts/generate_reference.dart; do not edit. */}

## FhirResource [#fhirresource]

```dart
class FhirResource
```

Generic FHIR R4 on `{baseUrl}/{fhirPath}`; resources are decoded JSON.

Reached through `ovok.fhir`. Every request throws an [`OvokException`](/flutter-sdk/reference/ovok_sdk/ovok-exception#ovokexception)
subclass when it fails.

### Constructors [#constructors]

#### FhirResource.new [#fhirresourcenew]

```dart
FhirResource(HttpClient _http)
```

Built by `Ovok`; use `ovok.fhir` instead.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `_http` | `HttpClient` | positional |  |

### Methods [#methods]

#### FhirResource.read [#fhirresourceread]

```dart
Future<Map<String, dynamic>> read(String type, String id)
```

Reads one resource. Calls `GET {fhirPath}/{type}/{id}`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `type` | `String` | positional |  |
| `id` | `String` | positional |  |

Returns `Future<Map<String, dynamic>>`.

#### FhirResource.search [#fhirresourcesearch]

```dart
Future<Page<Map<String, dynamic>>> search(String type, [QueryParams params = const {}])
```

Searches `type` and returns the first page of matches.

Calls `GET {fhirPath}/{type}?{params}`.
A list value repeats its parameter, which FHIR reads as AND; write `'a,b'` for OR.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `type` | `String` | positional |  |
| `params` | `QueryParams` | optional positional | `const {}` |

Returns `Future<Page<Map<String, dynamic>>>`.

#### FhirResource.searchOne [#fhirresourcesearchone]

```dart
Future<Map<String, dynamic>?> searchOne(String type, [QueryParams params = const {}])
```

Returns the first match of a search with `_count=1`, or null when none matches.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `type` | `String` | positional |  |
| `params` | `QueryParams` | optional positional | `const {}` |

Returns `Future<Map<String, dynamic>?>`.

#### FhirResource.create [#fhirresourcecreate]

```dart
Future<Map<String, dynamic>> create(Map<String, dynamic> resource, {String? ifNoneExist})
```

Creates `resource`. Calls `POST {fhirPath}/{resourceType}`.

`ifNoneExist` is sent as the `If-None-Exist` header.
With `ifNoneExist`, a retry cannot create a duplicate, so the request is safe to repeat.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `resource` | `Map<String, dynamic>` | positional |  |
| `ifNoneExist` | `String?` | named |  |

Returns `Future<Map<String, dynamic>>`.

#### FhirResource.update [#fhirresourceupdate]

```dart
Future<Map<String, dynamic>> update(Map<String, dynamic> resource)
```

Replaces `resource`. Calls `PUT {fhirPath}/{resourceType}/{id}`.

Throws [`OvokValidationException`](/flutter-sdk/reference/ovok_sdk/ovok-exception#ovokvalidationexception) when `resource` has no `id`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `resource` | `Map<String, dynamic>` | positional |  |

Returns `Future<Map<String, dynamic>>`.

#### FhirResource.patch [#fhirresourcepatch]

```dart
Future<Map<String, dynamic>> patch(
  String type,
  String id,
  List<PatchOperation> operations,
)
```

Applies JSON Patch `operations` to one resource.

Calls `PATCH {fhirPath}/{type}/{id}`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `type` | `String` | positional |  |
| `id` | `String` | positional |  |
| `operations` | `List<PatchOperation>` | positional |  |

Returns `Future<Map<String, dynamic>>`.

#### FhirResource.delete [#fhirresourcedelete]

```dart
Future<void> delete(String type, String id)
```

Deletes one resource. Calls `DELETE {fhirPath}/{type}/{id}`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `type` | `String` | positional |  |
| `id` | `String` | positional |  |

Returns `Future<void>`.

#### FhirResource.batch [#fhirresourcebatch]

```dart
Future<Map<String, dynamic>> batch(Map<String, dynamic> bundle)
```

Posts a `batch` or `transaction` `bundle`. Calls `POST {fhirPath}`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `bundle` | `Map<String, dynamic>` | positional |  |

Returns `Future<Map<String, dynamic>>`.
