Design appointment scheduling data model and APIs
Company: Cloverhealth
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
## Scenario
You are extending an existing healthcare system that already has **User** and **Patient** management APIs.
- **Doctors** and **Staff** are **Users**.
- **Patients are not Users** (they are separate entities managed via Patient APIs).
- You must add an **Appointment Scheduling** capability between **Doctors** and **Patients** at **Hospitals**.
- Implementation context: **Django** (data model design + REST API design).
## Definitions & Business Rules
### Hospital operating hours
- Each **Hospital** has operating hours (e.g., 09:00–19:00).
- The schedule UI only displays hours when the hospital is open.
### Doctor Availability
- An **Availability** is a time range when a **Doctor** can see patients **at a specific Hospital**.
- A Doctor can only have Availabilities **within the Hospital operating hours**.
- Users (staff) can create Availabilities for doctors.
### Appointment
- An **Appointment** is a time when a **Patient** is scheduled to see a **Doctor** at a **Hospital**.
- Appointments are:
- exactly **1 hour** long
- must **start on the hour** (e.g., 10:00, 11:00)
- An Appointment can only be scheduled **within an Availability**.
- Users (staff) can create Appointments between Doctors and Patients.
## UX-driven behavior
- Clicking an **empty time slot** prompts the user to schedule an **Availability**.
- Clicking an **Availability** prompts the user to schedule an **Appointment**.
## Required API capabilities (Gherkin-style)
1. **View** Availabilities and Appointments filtered by:
- date
- doctor(s)
- hospital
2. **Create** a Doctor’s Availability for a given date and hospital.
3. **Create** an Appointment within an Availability.
## Your task
Design:
1. A Django-friendly **data model** (entities, key fields, relationships, constraints).
2. The **REST APIs** (endpoints, request/response shapes, validation rules, error cases).
3. The core logic to enforce constraints (operating hours, no invalid times, appointment-within-availability, conflict handling).
Quick Answer: This question evaluates backend data modeling, REST API design, and enforcement of domain constraints within a web framework, focusing on scheduling, time-window validation, and resource relationships.