Use this guide to create or upsert a patient before booking appointments, writing medical notes, or attaching documents.
care_unit_id from step 1 in Show Doctor's Availability before creating or upserting patients.
import requests
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
BASE_URL = "https://api.leyr.io/api"
EMR = "webdoc"
headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
}
care_unit_id = "L0_1"
patient_payload = {
"first_name": "Tolvan",
"last_name": "Tolvansson",
"external_id": "191212121212",
"phones": ["+46001234567"],
"emails": ["Tolvan.Tolvansson@example.com"]
}
response = requests.post(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients",
headers=headers,
json=patient_payload
)
patient = response.json()
print("✓ Patient created or updated")
print(f"Leyr ID: {patient['id']}")
print(f"EHR ID: {patient.get('emr_id')}")
patient_id formats like emr_id:* or se_personal_number:*.emr_id is useful for EHR-side tracing and support.se_personal_number:{value}.