# Open a chat thread

Canonical page: https://docs.ovok.com/api/chat/open-a-chat-thread

`POST /v1/chat/threads`

Opens a chat thread about one patient between you and the people you name, or answers the one they already have. A thread is a FHIR `Communication` in the patient's compartment, so whoever may see the patient may see the thread.

**Scope:** the caller's project (from the token). A Patient, Practitioner or RelatedPerson session, in a project with `CHAT_ENABLED` on.

## Behaviour

- `patient` is `Patient/<id>`; you must be able to read it, else **404** `CHAT_PATIENT_NOT_FOUND`.
- `participants` are `Patient/<id>`, `Practitioner/<id>` or `RelatedPerson/<id>`; you are added yourself. Each one's own access policy must let them read the patient, else **403** `CHAT_PARTICIPANT_NOT_ALLOWED` naming them.
- Your own access policy must let you create a `Communication` about the patient, else **403** `CHAT_WRITE_NOT_ALLOWED`.
- A patient may open a thread about another patient who shares readings with them, between the two of them only (anyone else is **403** `CHAT_PARTICIPANT_NOT_ALLOWED`); the share lets them read that chat, and ovok writes it.
- A new thread answers **201** with `Location: /v1/chat/threads/<id>`, and everyone in it hears `chat.thread` on the `chat` socket topic.
- The same patient and people again answer **200** with the thread they have, in any order of `participants`.

## Example

```bash
curl -X POST 'https://api.sandbox.ovok.com/v1/chat/threads' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk' \
  -H 'Content-Type: application/json' \
  -d '{ "patient": "Patient/123", "participants": ["Practitioner/456"], "title": null }'
```
