> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rxscale.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Anamnesis

> Connect an anamnesis to a patient

# Anamnesis

An anamnesis is a completed questionnaire submission. It is often collected before you know
which customer it belongs to -- for example when a patient fills in a form before an order
exists. This endpoint attaches one to a patient.

## Connect an Anamnesis to a Patient

Requires an API key with the `anamnesis:connect_patient` permission.

```bash theme={null}
curl -X POST "https://api.rxscale.com/v1/management/anamnesis/patient-connections" \
  -H "X-API-Key: {api_key}" \
  -H "Content-Type: application/json" \
  -d '{
    "shop_identifier": "my-shop",
    "shop_customer_id": "cust-123",
    "anamnesis_uid": "an-abc123"
  }'
```

**Response** (`200 OK`):

```json theme={null}
{
  "status": "success"
}
```

### Identifying the patient

`shop_identifier` and `shop_customer_id` are always required. Together they name the customer
in your shop, the same pair used by the wallet pass and patient endpoints. The shop must
belong to your organisation.

### Identifying the anamnesis

Supply **exactly one** of the three addressing modes below. The last one is a pair: both
halves are required together, and supplying only one is an error rather than a third way of
asking.

| Mode                   | Fields                                              | Use when                                                          |
| ---------------------- | --------------------------------------------------- | ----------------------------------------------------------------- |
| Internal               | `anamnesis_uid`                                     | You already have the anamnesis UID from RxScale                   |
| External by UID        | `external_submission_uid`                           | You submitted through the Anamnesis API and kept the returned UID |
| External by identifier | `external_identifier` **and** `provider_identifier` | You track submissions under your own identifier                   |

Both external modes convert the submission into an internal anamnesis first, then attach the
patient to it. Converting is repeatable: calling again reuses the anamnesis created the first
time rather than making a second one.

```bash theme={null}
curl -X POST "https://api.rxscale.com/v1/management/anamnesis/patient-connections" \
  -H "X-API-Key: {api_key}" \
  -H "Content-Type: application/json" \
  -d '{
    "shop_identifier": "my-shop",
    "shop_customer_id": "cust-123",
    "external_identifier": "your-submission-id",
    "provider_identifier": "your-provider-id"
  }'
```

<Info>
  Connecting the **same** patient again returns `200` and changes nothing, so it is safe to
  retry a request whose response you did not receive.
</Info>

<Warning>
  An anamnesis can only be connected once. Connecting a **different** patient to an anamnesis
  that is already attached returns `409` and leaves the original connection untouched.
</Warning>

### Error Responses

| Code  | Meaning                                                                                                                                 |
| ----- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `400` | Validation error -- including no addressing mode, more than one, or only half of the `external_identifier` / `provider_identifier` pair |
| `401` | Missing or invalid API key                                                                                                              |
| `403` | The API key lacks `anamnesis:connect_patient`                                                                                           |
| `404` | Shop, patient, anamnesis, external submission or provider not found, or not part of your organisation                                   |
| `409` | The anamnesis is already connected to a different patient                                                                               |

A `400` reports the offending fields:

```json theme={null}
{
  "error": {
    "_schema": [
      "Supply exactly one of: anamnesis_uid, external_submission_uid, or external_identifier together with provider_identifier."
    ]
  }
}
```

<Note>
  Anything belonging to another organisation returns `404`, exactly like something that does not
  exist, so the response never confirms whether a record is real.
</Note>

### After connecting

Once connected, the questionnaire answers are used to fill the patient's profile fields. The
anamnesis also appears on the patient in the RxScale interface.
