# episode.opened

Canonical page: https://docs.ovok.com/signals/standalone/webhooks/episode-opened

An episode opens on the first reading that breaches a trigger. Sent only while your tenant has `episodicAlerts` on; see [Events](/signals/standalone/webhooks#events).

## Payload [#payload]

Every delivery is the envelope `type`, `timestamp`, `sequence` and `data`; the delivery's id is the `webhook-id` header. See [Verify webhooks](/signals/standalone/verify-webhooks).

```json
{
  "type": "episode.opened",
  "timestamp": "2026-10-25T08:00:02.000Z",
  "sequence": 1049,
  "data": {
    "id": "e7a1b2c3-d4e5-4f60-8a9b-0c1d2e3f4a5b",
    "patient": "6f1c2a8e-3b7d-4c55-9a0e-2d4b8f6e1a90",
    "patientRefId": "resident-001",
    "code": "8867-4",
    "system": "http://loinc.org",
    "display": "Heart rate",
    "status": "OPEN",
    "openedAt": "2026-10-25T08:00:00.000Z",
    "closedAt": null,
    "closeReason": null,
    "firstObservationRefId": "reading-0001",
    "lastObservationRefId": "reading-0001",
    "lastAlertId": "0b9d7e52-1f3a-4e8c-b6a2-7c4d9e1f2a35"
  }
}
```

| Field | Meaning |
| --- | --- |
| `id` | The episode. |
| `patient`, `patientRefId` | The patient, by Signals id and by your own `refId`. |
| `code`, `system`, `display` | The code the episode is about. |
| `status` | `OPEN` or `CLOSED`. |
| `openedAt`, `closedAt`, `closeReason` | When it opened and closed, and why. `null` while open. |
| `firstObservationRefId`, `lastObservationRefId` | The first and latest reading in it, by your `refId`. |
| `lastAlertId` | The latest alert in it. |

## Handle the event [#handle-the-event]

Verify the delivery first ([Verify webhooks](/signals/standalone/verify-webhooks)), then act on the verified event as in [Handle an event](/signals/standalone/webhooks#handle-an-event).

<Tabs items={["Node.js", "Python", "Java"]} groupId="language" persist>
<Tab value="Node.js">

```js title="episode-opened.js"
export async function handle(webhookId, event) {
  if (!(await firstTime(webhookId))) return;
  const { data } = event;
  switch (event.type) {
    case 'episode.opened':
      await openEpisode(data.id, data.patientRefId, data.code);
      break;
    default:
      break;
  }
}
```

</Tab>
<Tab value="Python">

```python title="episode_opened.py"
def handle(webhook_id: str, event: dict) -> None:
    if not first_time(webhook_id):
        return
    data = event["data"]
    match event["type"]:
        case "episode.opened":
            open_episode(data["id"], data["patientRefId"], data["code"])
```

</Tab>
<Tab value="Java">

```java title="EpisodeOpenedHandler.java"
void handle(String webhookId, JsonNode event) {
  if (!firstTime(webhookId)) return;
  JsonNode data = event.get("data");
  switch (event.get("type").asText()) {
    case "episode.opened" -> {
      openEpisode(data.get("id").asText(), data.get("patientRefId").asText(), data.get("code").asText());
    }
    default -> {}
  }
}
```

</Tab>
</Tabs>

## Related [#related]

- [Webhooks basics](/signals/standalone/webhooks)
- [Verify webhooks](/signals/standalone/verify-webhooks)
