--- title: "Create Patient" description: "Create or upsert a patient record before booking appointments, writing notes, or attaching documents." canonical_url: "http://localhost/api/quickstart/create-patient" --- # Create Patient > Create or upsert a patient record before booking appointments, writing notes, or attaching documents. Use this guide to create or upsert a patient before booking appointments, writing medical notes, or attaching documents. ## Flow Overview ![Create Patient Flow](http://localhost/images/quickstart/create-patient.png) ## Code Example ### Shared setup #### 1. Prepare patient payload #### 2. Create or upsert the patient #### 3. Read key values from the response ## Key Insights - Leyr applies idempotent behavior here: if the patient already exists in the EHR, create requests will return the existing patient instead of creating a duplicate. - For patient path parameters, use supported `patient_id` formats like `emr_id:*` or `se_personal_number:*`. - Use [Find or Get Patient](http://localhost/api/quickstart/find-patient) to determine the right identifier for downstream flows. - `emr_id` is useful for EHR-side tracing and support. - Some EHRs allow direct national identifier lookup in path parameters, for example `se_personal_number:{value}`. ## Next steps Advanced topics and best practices. Understand Leyr error codes and how to respond to them. ## API Reference - [Patients API](https://api.leyr.io/docs#tag/Patients) - [Patient ID Guide](http://localhost/api/guides/patient-id) ## Sitemap See the full [sitemap](http://localhost/sitemap.md) for all pages.