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

# Notes and codes

> Regenerate a visit's note, write more notes from it, and draw its ICD codes.

A visit has one **main note**, written when it completes and returned by `GET /visits/{id}`. From there you can do
what a clinician does in the app:

| You want to | Call | Runs |
| - | - | - |
| Rewrite the main note, optionally with another template | `POST /visits/{id}/regenerate` | The visit goes back to `processing`; poll `GET /visits/{id}` |
| Write **another note** from the visit — a progress note, a referral or follow-up letter | `POST /visits/{id}/notes` | A job; poll `GET /jobs/{id}` |
| Draw **ICD-11 codes** from the note | `POST /visits/{id}/icd-codes` | A job; poll `GET /jobs/{id}` |

Each takes as long as writing a note — about a minute — so none of them makes you hold a connection open.

## Regenerate the main note

```bash theme={null}
curl -X POST "$RXNOTE_API/visits/90211/regenerate" \
  -H "Authorization: Bearer $RXNOTE_API_KEY" -H "Content-Type: application/json" \
  -d '{ "template_id": 15 }'
```

The note is written again from the visit's transcript. Omit `template_id` to keep the visit's template. A visit that
is still being processed answers `409`.

## Write another note

```bash theme={null}
curl -X POST "$RXNOTE_API/visits/90211/notes" \
  -H "Authorization: Bearer $RXNOTE_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: letter-appt-0001" \
  -d '{ "template_id": 24 }'
```

```json Response (202) theme={null}
{ "id": "job_4Rt8Vb1Np3Zs7Hc2kQ9xLm", "kind": "note", "visit_id": 90211, "status": "queued", "note": null, "error": null }
```

`source` chooses what it is written from: `note` (the visit's main note), `transcript`, or `auto` (the template's own
choice, as in the app). Poll the job:

```bash theme={null}
curl "$RXNOTE_API/jobs/job_4Rt8Vb1Np3Zs7Hc2kQ9xLm" -H "Authorization: Bearer $RXNOTE_API_KEY"
```

When `status` is `completed`, `note` holds the new note — sections and fields in template order, and `html` — in
the same shape as a visit's main note. `GET /visits/{id}/notes` lists every additional note on the visit.

## ICD codes

```bash theme={null}
curl -X POST "$RXNOTE_API/visits/90211/icd-codes" \
  -H "Authorization: Bearer $RXNOTE_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: icd-appt-0001" -d '{}'
```

When the job completes, `icd_codes` holds the codes, and `GET /visits/{id}` carries them from then on:

```json theme={null}
{ "code_version": "icd11", "generated_at": "…", "codes": [{ "code": "8A81", "name": "Tension-type headache", "confidence": "high" }] }
```

Codes are drawn from the main note, so generate them after it completes — and again after a regenerate.

## Jobs

| Status | Meaning |
| - | - |
| `queued` | Waiting to start. |
| `running` | Being written. |
| `completed` | Done; `note` or `icd_codes` is set. |
| `failed` | See `error.code`: `NOTE_FAILED`, `ICD_FAILED`, `NOTHING_TO_WRITE_FROM` or `TIMED_OUT`. Retry with a new `Idempotency-Key`. |

Repeating a request with the same `Idempotency-Key` returns the same job; the same key with a different body
answers `409`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.