---
title: "Show Doctor's Availability"
description: "Find available timeslots for booking by listing care units, resources, healthcare services, and open time windows."
canonical_url: "http://localhost/api/quickstart/show-availability"
---
# Show Doctor's Availability
> Find available timeslots for booking by listing care units, resources, healthcare services, and open time windows.
Learn how to discover available timeslots for booking appointments. This guide walks through the complete flow from finding care units to checking doctor availability.
Start with this guide in all quickstart flows. `care_unit_id` from step 1 is required in all subsequent API calls. You will also reuse `resource_id`, `healthcare_service_id`, and `timeslots` in later guides.
## Flow Overview

## Understanding the Concepts
Before diving into code, let's understand the key concepts:
- **Care Units**: Physical locations where healthcare is provided (e.g., "Main Clinic", "Downtown Office")
- **Resources**: People or equipment that can be scheduled (e.g., "Dr. Smith", "MRI Machine")
- **Healthcare Services**: Types of appointments offered (e.g., "General Consultation", "Follow-up Visit")
- **Timeslots**: Available time windows when a resource can be booked
## Code Example
```python
import requests
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
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"
}
# 1. Get care units
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units",
headers=headers
)
care_units = response.json()
care_unit = care_units[0]
care_unit_id = care_unit["id"]
# 2. Get resources
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/resources",
headers=headers
)
resources = response.json()
doctor = resources[0]
resource_id = doctor["id"]
# 3. Get healthcare services
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/healthcare-services",
headers=headers
)
services = response.json()
service = services[0]
service_id = service["id"]
# 4. Get available timeslots
start = datetime.now(tz=ZoneInfo("Europe/Stockholm")).isoformat()
end = (datetime.now(tz=ZoneInfo("Europe/Stockholm")) + timedelta(days=30)).isoformat()
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/timeslots",
headers=headers,
params={
"start": start,
"end": end,
# "resource_id": resource_id, # Add filters as needed
# "healthcare_service_id": service_id # Add filters as needed
}
)
timeslots = response.json()
# 5. Display a few results
print(f"Found {len(timeslots)} timeslots. First 5:")
for slot in timeslots[:5]:
print(f"- {slot['start']}")
```
```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"
};
// 1. Get care units
let response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units`,
{ headers }
);
const careUnits = await response.json();
const careUnit = careUnits[0];
const careUnitId = careUnit.id;
// 2. Get resources
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/resources`,
{ headers }
);
const resources = await response.json();
const doctor = resources[0];
const resourceId = doctor.id;
// 3. Get healthcare services
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/healthcare-services`,
{ headers }
);
const services = await response.json();
const service = services[0];
const serviceId = service.id;
// 4. Get available timeslots
const start = new Date().toISOString();
const end = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString();
const params = new URLSearchParams({
start,
end,
// resource_id: resourceId, // Add filters as needed
// healthcare_service_id: serviceId // Add filters as needed
});
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/timeslots?${params}`,
{ headers }
);
const timeslots = await response.json();
// 5. Display a few results
console.log(`Found ${timeslots.length} timeslots. First 5:`);
timeslots.slice(0, 5).forEach(slot => {
console.log(`- ${slot.start}`);
});
```
### Shared setup
```python
import requests
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
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"
}
```
```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"
};
```
#### 1. Get care units
```python
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units",
headers=headers
)
care_units = response.json()
care_unit = care_units[0]
care_unit_id = care_unit["id"]
```
```javascript
let response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units`,
{ headers }
);
const careUnits = await response.json();
const careUnit = careUnits[0];
const careUnitId = careUnit.id;
```
#### 2. Get resources
```python
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/resources",
headers=headers
)
resources = response.json()
doctor = resources[0]
resource_id = doctor["id"]
```
```javascript
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/resources`,
{ headers }
);
const resources = await response.json();
const doctor = resources[0];
const resourceId = doctor.id;
```
#### 3. Get healthcare services
```python
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/healthcare-services",
headers=headers
)
services = response.json()
service = services[0]
service_id = service["id"]
```
```javascript
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/healthcare-services`,
{ headers }
);
const services = await response.json();
const service = services[0];
const serviceId = service.id;
```
#### 4. Get available timeslots
```python
start = datetime.now(tz=ZoneInfo("Europe/Stockholm")).isoformat()
end = (datetime.now(tz=ZoneInfo("Europe/Stockholm")) + timedelta(days=30)).isoformat()
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/timeslots",
headers=headers,
params={
"start": start,
"end": end,
# "resource_id": resource_id, # Add filters as needed
# "healthcare_service_id": service_id # Add filters as needed
}
)
timeslots = response.json()
```
```javascript
const start = new Date().toISOString();
const end = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString();
const params = new URLSearchParams({
start,
end,
// resource_id: resourceId, // Add filters as needed
// healthcare_service_id: serviceId // Add filters as needed
});
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/timeslots?${params}`,
{ headers }
);
const timeslots = await response.json();
```
#### 5. Display a few results
```python
print(f"Found {len(timeslots)} timeslots. First 5:")
for slot in timeslots[:5]:
print(f"- {slot['start']}")
```
```javascript
console.log(`Found ${timeslots.length} timeslots. First 5:`);
timeslots.slice(0, 5).forEach(slot => {
console.log(`- ${slot.start}`);
});
```
## Key Insights
### Working with IDs
Leyr uses two types of identifiers throughout the API:
- **id** - Leyr's internal identifier. **Always use this for API requests** (booking appointments, filtering timeslots, etc.)
- **emr_id** - The original EHR system's identifier. This is provided for informational purposes and debugging with the EHR, but should not be used in Leyr API calls
For example, when booking an appointment, use `resource.id` and `service.id`, not `resource.emr_id`.
**Date Format:** All datetime values use ISO 8601 format (e.g., `2024-03-22T14:30:00+01:00`). Make sure to URL-encode these values when passing as query parameters.
## Filtering Results
You can filter timeslots by resource, service, or both:
```python
# Get timeslots for a specific doctor only
params = {
"start": start,
"end": end,
"resource_id": resource_id # Filter by doctor
}
# Get timeslots for a specific service only
params = {
"start": start,
"end": end,
"healthcare_service_id": service_id # Filter by service type
}
# Get timeslots for specific doctor AND service
params = {
"start": start,
"end": end,
"resource_id": resource_id,
"healthcare_service_id": service_id
}
```
```javascript
// Get timeslots for a specific doctor only
const params = new URLSearchParams({
start,
end,
resource_id: resourceId // Filter by doctor
});
// Get timeslots for a specific service only
const params = new URLSearchParams({
start,
end,
healthcare_service_id: serviceId // Filter by service type
});
// Get timeslots for specific doctor AND service
const params = new URLSearchParams({
start,
end,
resource_id: resourceId,
healthcare_service_id: serviceId
});
```
## Next steps
Create appointments using a found timeslot and a patient.
## API Reference
For detailed API documentation, see:
- [Care Units API](https://api.leyr.io/docs#tag/Care-Units)
- [Resources API](https://api.leyr.io/docs#tag/Resources)
- [Healthcare Services API](https://api.leyr.io/docs#tag/Healthcare-Services)
- [Timeslots API](https://api.leyr.io/docs#tag/Timeslots)
## Sitemap
See the full [sitemap](http://localhost/sitemap.md) for all pages.