---
title: "Find or Get Patient"
description: "Find an existing patient and choose the correct patient_id for appointments, notes, and documents."
canonical_url: "http://localhost/api/quickstart/find-patient"
---
# Find or Get Patient
> Find an existing patient and choose the correct patient_id for appointments, notes, and documents.
Use this guide to find an existing patient and choose the correct `patient_id` for follow-up requests like appointments, medical notes, and documents.
This guide requires `care_unit_id` from step 1 in [Show Doctor's Availability](http://localhost/api/quickstart/show-availability) before running patient lookup requests.
## Flow Overview

## Code Example
```python
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"
# 1. Lookup patients by demographics
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients",
headers=headers,
params={
"first_name": "Tolvan",
"last_name": "Tolvansson"
}
)
patients = response.json()
patient = patients[0]
print(f"Found patient Leyr ID: {patient['id']}")
print(f"EHR ID: {patient.get('emr_id')}")
# 2. Get one patient using patient_id
patient_id = f"emr_id:{patient['emr_id']}"
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients/{patient_id}",
headers=headers
)
patient_details = response.json()
print("✓ Patient loaded")
print(f"Name: {patient_details.get('first_name')} {patient_details.get('last_name')}")
print(f"Care Unit ID: {patient_details.get('care_unit_id')}")
```
```javascript
const CLIENT_ID = "your-client-id";
const CLIENT_SECRET = "your-client-secret";
const BASE_URL = "https://api.leyr.io/api";
const EMR = "webdoc";
const headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
};
const careUnitId = "L0_1";
// 1. Lookup patients by demographics
let response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients?first_name=Tolvan&last_name=Tolvansson`,
{ headers }
);
const patients = await response.json();
const patient = patients[0];
console.log(`Found patient Leyr ID: ${patient.id}`);
console.log(`EHR ID: ${patient.emr_id}`);
// 2. Get one patient using patient_id
const patientId = `emr_id:${patient.emr_id}`;
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients/${patientId}`,
{ headers }
);
const patientDetails = await response.json();
console.log("✓ Patient loaded");
console.log(`Name: ${patientDetails.first_name} ${patientDetails.last_name}`);
console.log(`Care Unit ID: ${patientDetails.care_unit_id}`);
```
### Shared setup
```python
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"
```
```javascript
const CLIENT_ID = "your-client-id";
const CLIENT_SECRET = "your-client-secret";
const BASE_URL = "https://api.leyr.io/api";
const EMR = "webdoc";
const headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
};
const careUnitId = "L0_1";
```
#### 1. Lookup patients by demographics
```python
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients",
headers=headers,
params={
"first_name": "Tolvan",
"last_name": "Tolvansson"
}
)
patients = response.json()
patient = patients[0]
print(f"Found patient Leyr ID: {patient['id']}")
print(f"EHR ID: {patient.get('emr_id')}")
```
```javascript
let response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients?first_name=Tolvan&last_name=Tolvansson`,
{ headers }
);
const patients = await response.json();
const patient = patients[0];
console.log(`Found patient Leyr ID: ${patient.id}`);
console.log(`EHR ID: ${patient.emr_id}`);
```
#### 2. Get one patient using `patient_id`
```python
patient_id = f"emr_id:{patient['emr_id']}"
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients/{patient_id}",
headers=headers
)
patient_details = response.json()
print("✓ Patient loaded")
print(f"Name: {patient_details.get('first_name')} {patient_details.get('last_name')}")
print(f"Care Unit ID: {patient_details.get('care_unit_id')}")
```
```javascript
const patientId = `emr_id:${patient.emr_id}`;
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients/${patientId}`,
{ headers }
);
const patientDetails = await response.json();
console.log("✓ Patient loaded");
console.log(`Name: ${patientDetails.first_name} ${patientDetails.last_name}`);
console.log(`Care Unit ID: ${patientDetails.care_unit_id}`);
```
## patient_id formats
The `patient_id` path parameter supports multiple formats:
- `abc_12345` (treated as EHR ID)
- `emr_id:abc_12345`
- `se_personal_number:191212121212`
- `no_personal_number:26258605879`
- `nhs_number:9434765919`
For full details, see [Patient IDs](http://localhost/api/guides/patient-id).
## Key Insights
- For patient-specific endpoints, use supported `patient_id` formats (`emr_id:*`, `se_personal_number:*`, etc.).
- Keep both `id` (Leyr) and `emr_id` (EHR) for traceability and support workflows.
- Use the Patients OpenAPI tag for request/response schema details when building UI mappings.
## Next steps
Create or upsert a patient record.
Create appointments using a found timeslot and a patient.
## 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.