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

# Sync patients

> Keep patient files the same in both systems.

## Your system to Docistra

When a patient is created or changed in your system, send it:

```bash theme={null}
curl -X POST https://docistra.com/api/v1/patients \
  -H "Authorization: Bearer $DOCISTRA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: patient-P-10293-v1" \
  -d '{
    "external_id": "P-10293",
    "name": "Mona Samy",
    "phone": "01012345678",
    "gender": "female",
    "date_of_birth": "1990-04-12",
    "nationality": "EG"
  }'
```

`POST /patients` never makes a second copy of a person. It finds the patient in this order:

1. already linked to this `external_id`
2. the same phone and the same name. Arabic and English spellings of the same name match ("منى سامي" and "Mona Samy")
3. the same phone with a different name: a family member who uses that phone. They're created under the phone's holder (`holder_id`), so messages still reach that phone

A matched patient is updated with what you sent and linked to your `external_id`; you get `200` with `"created": false`. A new patient is `201` with `"created": true`.

For later changes, use `PATCH /patients/ext:P-10293` with only the fields that changed. `null` clears a field.

### Phones

Egyptian mobiles are accepted in any spelling (`01012345678`, `+201012345678`, `201012345678`) and returned as `+201012345678`. International numbers must start with `+` or `00`.

### Family members

To add a child under a parent explicitly, send `holder_id` (the parent, as an id or `ext:`) and `relationship` (`son`, `daughter`, `wife`, `husband`, `father`, `mother`, `brother`, `sister`, `grandson`, `granddaughter`, `grandfather`, `grandmother`, `other`).

## Docistra to your system

Patients also appear in Docistra without you: the AI agent registers new patients from WhatsApp, and patients book on the clinic's page. Listen to `patient.created` and `patient.updated`:

1. If `data.object.external_id` is set, it's a patient you already have: update it.
2. If not, create it in your system, then link it back: `PATCH /patients/{id}` with `{"external_id": "<your new id>"}`.

That `PATCH` doesn't come back to you as a webhook.


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