# Set accounts for a Patient

Canonical page: https://docs.ovok.com/primitives/set-accounts-patient

Set the accounts associated with a Patient. With `propagate=true`, Ovok also applies account changes to resources in the Patient compartment. This operation is restricted to project administrators.

| Method | Path |
| --- | --- |
| `POST` | `/fhir/R4/Patient/:id/$set-accounts` |

## Request [#request]

The body is a FHIR `Parameters` resource. Include one `accounts` parameter per Account reference. `propagate` is optional.

```bash
curl --request POST \
  --url "https://api.sandbox.ovok.com/fhir/R4/Patient/${PATIENT_ID}/\$set-accounts" \
  --header "Authorization: Bearer ${OVOK_TOKEN}" \
  --header 'Content-Type: application/fhir+json' \
  --data "{\"resourceType\":\"Parameters\",\"parameter\":[{\"name\":\"accounts\",\"valueReference\":{\"reference\":\"Account/${ACCOUNT_ID}\"}},{\"name\":\"propagate\",\"valueBoolean\":true}]}"
```

| Parameter | Type | Description |
| --- | --- | --- |
| `accounts` | Reference, repeated | Account references to set on the Patient. An empty list clears the account association. |
| `propagate` | boolean | When true, propagate account differences to resources in the Patient compartment. |

Propagation is capped by the server's compartment update limit. For an asynchronous propagation request, send `Prefer: respond-async` and follow the returned job location.

## Successful response [#successful-response]

The synchronous response is a FHIR `Parameters` resource containing `resourcesUpdated`.

| Response parameter | Type | Description |
| --- | --- | --- |
| `resourcesUpdated` | integer | Number of resources updated, including the Patient. |

The server may return `202 Accepted` for an asynchronous propagation request. A caller without administrative access receives an authorization error.
