> ## 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.

# Prescriptions

> View prescription details via the Management API

# Prescriptions

Retrieve prescription information including doctor data and status.

## Get Prescription Details

```bash theme={null}
GET /v1/management/prescriptions/{prescription_uid}
```

<ParamField path="prescription_uid" type="string" required>
  The prescription UID
</ParamField>

**Required permission:** `prescription:read`

### Example Request

```bash theme={null}
curl -X GET "https://api.rxscale.com/v1/management/prescriptions/px-abc123" \
  -H "X-API-Key: your-api-key-here"
```

### Response

```json theme={null}
{
  "uid": "px-abc123",
  "status": "signed",
  "doctor": {
    "uid": "doc-456",
    "display_name": "Dr. Schmidt"
  },
  "rendered": true
}
```

### Response Fields

| Field                 | Type    | Description                                                                     |
| --------------------- | ------- | ------------------------------------------------------------------------------- |
| `uid`                 | string  | Unique identifier for the prescription                                          |
| `status`              | string  | Current prescription status (e.g. `signed`, `waiting_for_doctor`)               |
| `doctor`              | object  | The prescribing doctor                                                          |
| `doctor.uid`          | string  | Doctor UID                                                                      |
| `doctor.display_name` | string  | Doctor display name                                                             |
| `rendered`            | boolean | `true` when a rendered PDF is available for the prescription, `false` otherwise |

### Error Responses

| Status Code | Description                                               |
| ----------- | --------------------------------------------------------- |
| `403`       | Missing `prescription:read` permission                    |
| `404`       | Prescription not found or belongs to another organisation |

## Externally Signed Prescriptions

Prescriptions whose items were created with `_skip_validation` (or `_rxscale_skip_validation`) on the Shopify line item or in the order-level additional details — i.e. items without an attached anamnesis — can be signed *outside* the rxscale platform and then registered for fulfilment via the Management API. When both levels are present, the line-item value takes precedence over the order-level value.

The flow consists of **two API calls**:

1. `POST /v1/management/prescriptions/{prescription_uid}/render` – asks rxscale to render the unsigned prescription PDF. The endpoint returns immediately; the PDF is produced asynchronously and becomes available as `prescription.file`.
2. `POST /v1/management/prescriptions/{prescription_uid}/external-sign` – once the PDF is available, mark the prescription as `EXTERNALLY_SIGNED`, copy the PDF into the signed bucket, and dispatch it to the pharmacy.

<Note>
  Both endpoints require the `prescription:external_sign` permission.
</Note>

<Warning>
  Only prescriptions where **every** item lacks an `anamnesis_uid` can be externally signed. Mixed prescriptions are rejected with `409 Conflict`.
</Warning>

## Render Prescription PDF

```bash theme={null}
POST /v1/management/prescriptions/{prescription_uid}/render
```

<ParamField path="prescription_uid" type="string" required>
  The prescription UID
</ParamField>

**Required permission:** `prescription:external_sign`

Triggers asynchronous rendering of the unsigned prescription PDF. The endpoint publishes a `prescription.render` event and returns `202 Accepted`. Poll `GET /v1/management/prescriptions/{prescription_uid}` (or wait for a webhook) until `file` is populated before calling external-sign.

### Example Request

```bash theme={null}
curl -X POST "https://api.rxscale.com/v1/management/prescriptions/px-abc123/render" \
  -H "X-API-Key: your-api-key-here"
```

### Response (202 Accepted)

```json theme={null}
{
  "uid": "px-abc123",
  "message": "Prescription rendering triggered"
}
```

### Error Responses

| Status Code | Description                                               |
| ----------- | --------------------------------------------------------- |
| `403`       | Missing `prescription:external_sign` permission           |
| `404`       | Prescription not found or belongs to another organisation |

## External-Sign Prescription

```bash theme={null}
POST /v1/management/prescriptions/{prescription_uid}/external-sign
```

<ParamField path="prescription_uid" type="string" required>
  The prescription UID
</ParamField>

**Required permission:** `prescription:external_sign`

Marks an already-rendered prescription as `EXTERNALLY_SIGNED`. The endpoint:

1. Verifies the prescription is in `WAITING_FOR_DOCTOR` status, all items lack an anamnesis, and the rendered `file` is present.
2. Copies the PDF from the unsigned bucket to the signed-prescription bucket.
3. Updates the prescription status to `EXTERNALLY_SIGNED` and writes a `PrescriptionLog` entry attributed to the calling API key.
4. Publishes a `pharmacy_manager.send_prescription` event so the prescription is dispatched to the pharmacy.

### Example Request

```bash theme={null}
curl -X POST "https://api.rxscale.com/v1/management/prescriptions/px-abc123/external-sign" \
  -H "X-API-Key: your-api-key-here"
```

### Response (200 OK)

```json theme={null}
{
  "uid": "px-abc123",
  "status": "EXTERNALLY_SIGNED"
}
```

### Error Responses

| Status Code | Description                                                                                                             |
| ----------- | ----------------------------------------------------------------------------------------------------------------------- |
| `403`       | Missing `prescription:external_sign` permission                                                                         |
| `404`       | Prescription not found or belongs to another organisation                                                               |
| `409`       | Prescription is not in `WAITING_FOR_DOCTOR` status, has at least one item with an anamnesis, or has no rendered PDF yet |
