# PatientBillingResource

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

```java
public final class PatientBillingResource
```

Patients' health insurance, plans, billing accounts and invoices, as FHIR Coverage, Account and Invoice, under `/v1/patient-billing`; the project's `PATIENT_BILLING_ENABLED` setting must be on. Get it from [`Ovok.patientBilling()`](/java-sdk/reference/ovok#patientbilling).

## Methods [#methods]

### insurers [#insurers]

```java
public PatientBillingResource.Insurers insurers()
```

Returns the health insurer directory.

**Returns:** the insurer routes

### coverages [#coverages]

```java
public PatientBillingResource.Coverages coverages()
```

Returns patients' health insurances.

**Returns:** the coverage routes

### plans [#plans]

```java
public PatientBillingResource.Plans plans()
```

Returns the plan each patient pays for.

**Returns:** the plan routes

### accounts [#accounts]

```java
public PatientBillingResource.Accounts accounts()
```

Returns patients' billing accounts.

**Returns:** the account routes

### invoices [#invoices]

```java
public PatientBillingResource.Invoices invoices()
```

Returns patients' invoices.

**Returns:** the invoice routes

## PatientBillingResource.Insurers [#patientbillingresourceinsurers]

```java
public static final class Insurers
```

Ovok's directory of health insurers.

### Insurers.list [#insurerslist]

```java
public List<JsonNode> list(
        Map<String, ?> params,
        RequestOptions options) throws IOException, InterruptedException
```

Lists the insurers that match, by kind and name (`GET /v1/patient-billing/insurers`).

**Parameters:**

- `params`: optional `country`, `kind` (`statutory` or `private`) and `query`
- `options`: per-request options, such as the timeout

**Returns:** the insurers

**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

## PatientBillingResource.Coverages [#patientbillingresourcecoverages]

```java
public static final class Coverages
```

Patients' health insurances.

### Coverages.list [#coverageslist]

```java
public List<JsonNode> list(
        String patientId,
        RequestOptions options) throws IOException, InterruptedException
```

Lists a patient's active coverages, in the order they apply (`GET /v1/patient-billing/patients/{patientId}/coverages`).

**Parameters:**

- `patientId`: the patient id
- `options`: per-request options, such as the timeout

**Returns:** the coverages

**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

### Coverages.create [#coveragescreate]

```java
public JsonNode create(
        String patientId,
        Object coverage,
        RequestOptions options) throws IOException, InterruptedException
```

Adds a coverage; the insurer must be in the directory and the member number must be valid (`POST /v1/patient-billing/patients/{patientId}/coverages`).

**Parameters:**

- `patientId`: the patient id
- `coverage`: the coverage to add
- `options`: per-request options, such as the timeout

**Returns:** the coverage

**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
- [`OvokConflictException`](/java-sdk/reference/ovok-conflict-exception): if another statutory coverage runs in that period
- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if the member number, insurer, period or country is invalid

### Coverages.update [#coveragesupdate]

```java
public JsonNode update(
        String coverageId,
        Object changes,
        RequestOptions options) throws IOException, InterruptedException
```

Changes a coverage (`PATCH /v1/patient-billing/coverages/{coverageId}`).

**Parameters:**

- `coverageId`: the coverage id
- `changes`: the fields to change
- `options`: per-request options, such as the timeout

**Returns:** the coverage

**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
- [`OvokConflictException`](/java-sdk/reference/ovok-conflict-exception): if another statutory coverage runs in that period

```java
public JsonNode update(
        String coverageId,
        Object changes,
        String ifVersion,
        RequestOptions options) throws IOException, InterruptedException
```

Changes a coverage only if it is still at the version you read (`PATCH /v1/patient-billing/coverages/{coverageId}` with `If-Match`).

**Parameters:**

- `coverageId`: the coverage id
- `changes`: the fields to change
- `ifVersion`: the version you read
- `options`: per-request options, such as the timeout

**Returns:** the coverage

**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
- [`OvokConflictException`](/java-sdk/reference/ovok-conflict-exception): if the coverage changed since `ifVersion`, or another statutory coverage runs in that period

### Coverages.remove [#coveragesremove]

```java
public void remove(
        String coverageId,
        RequestOptions options) throws IOException, InterruptedException
```

Removes a coverage: deletes it, or cancels it when a billing account names it (`DELETE /v1/patient-billing/coverages/{coverageId}`).

**Parameters:**

- `coverageId`: the coverage 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

## PatientBillingResource.Plans [#patientbillingresourceplans]

```java
public static final class Plans
```

The plan each patient pays for; setting it is for project admins and admin client applications.

### Plans.retrieve [#plansretrieve]

```java
public JsonNode retrieve(
        String patientId,
        RequestOptions options) throws IOException, InterruptedException
```

Reads a patient's plan, running or ended (`GET /v1/patient-billing/patients/{patientId}/plan`).

**Parameters:**

- `patientId`: the patient id
- `options`: per-request options, such as the timeout

**Returns:** the plan

**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
- [`OvokNotFoundException`](/java-sdk/reference/ovok-not-found-exception): if the patient has no plan

### Plans.set [#plansset]

```java
public JsonNode set(
        String patientId,
        Object plan,
        RequestOptions options) throws IOException, InterruptedException
```

Sets a patient's plan, or ends it with `{"plan": null}` (`PUT /v1/patient-billing/patients/{patientId}/plan`).

**Parameters:**

- `patientId`: the patient id
- `plan`: the plan to set, or `{"plan": null}` to end it
- `options`: per-request options, such as the timeout

**Returns:** the plan as set or ended, or `null` when there was no plan to end

**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

## PatientBillingResource.Accounts [#patientbillingresourceaccounts]

```java
public static final class Accounts
```

Patients' billing accounts.

### Accounts.list [#accountslist]

```java
public List<JsonNode> list(
        String patientId,
        RequestOptions options) throws IOException, InterruptedException
```

Lists a patient's billing accounts (`GET /v1/patient-billing/patients/{patientId}/accounts`).

**Parameters:**

- `patientId`: the patient id
- `options`: per-request options, such as the timeout

**Returns:** the accounts

**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

### Accounts.retrieve [#accountsretrieve]

```java
public JsonNode retrieve(
        String accountId,
        RequestOptions options) throws IOException, InterruptedException
```

Reads one billing account (`GET /v1/patient-billing/accounts/{accountId}`).

**Parameters:**

- `accountId`: the account id
- `options`: per-request options, such as the timeout

**Returns:** the account

**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

## PatientBillingResource.Invoices [#patientbillingresourceinvoices]

```java
public static final class Invoices
```

Patients' invoices; recording them is for project admins and admin client applications.

### Invoices.list [#invoiceslist]

```java
public Page<JsonNode> list(
        String patientId,
        Map<String, ?> params,
        RequestOptions options) throws IOException, InterruptedException
```

Lists a patient's invoices, latest first (`GET /v1/patient-billing/patients/{patientId}/invoices`).

**Parameters:**

- `patientId`: the patient id
- `params`: optional filters and `limit`
- `options`: per-request options, such as the timeout

**Returns:** the first page; iterating it loads the next pages

**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

### Invoices.retrieve [#invoicesretrieve]

```java
public JsonNode retrieve(
        String invoiceId,
        RequestOptions options) throws IOException, InterruptedException
```

Reads one invoice (`GET /v1/patient-billing/invoices/{invoiceId}`).

**Parameters:**

- `invoiceId`: the invoice id
- `options`: per-request options, such as the timeout

**Returns:** the invoice

**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

### Invoices.record [#invoicesrecord]

```java
public JsonNode record(
        String patientId,
        Object invoice,
        RequestOptions options) throws IOException, InterruptedException
```

Records an invoice, or updates the one recorded with the same identifier, so a retry is safe (`POST /v1/patient-billing/patients/{patientId}/invoices`).

**Parameters:**

- `patientId`: the patient id
- `invoice`: the invoice to record
- `options`: per-request options, such as the timeout

**Returns:** the invoice

**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
