Design a Hospital Appointment Booking System

Medium
Real World SystemsSchedulingDoctor AvailabilitySlot ManagementConcurrencyNotifications

Problem Statement

Design a hospital appointment booking system where patients can search for doctors by specialization, view available slots, book appointments, and receive confirmations — while doctors manage their own availability independently.

Requirements

Functional Requirements

  • Doctor profiles: name, specialization, experience, rating, consultation fee
  • Doctors create their own availability slots (date, start time, end time, slot duration)
  • Patients search doctors by specialization, location, availability date
  • Book an available slot — concurrent booking prevention
  • Appointment lifecycle: SCHEDULED → CONFIRMED → COMPLETED / CANCELLED / NO_SHOW
  • Doctors can cancel or reschedule appointments
  • Patients receive confirmation notifications
  • Medical records per patient (view history of appointments)
  • Reminders: automated notifications 24h and 1h before appointment

Non-Functional Requirements

  • Thread-safe slot booking
  • Singleton HospitalSystem

Key Entities

  • Doctor: id, name, specialization, experience, rating, slots
  • Patient: id, name, email, phone, medicalHistory
  • Slot: id, doctor, date, startTime, endTime, available
  • Appointment: id, patient, doctor, slot, status, notes, fee
  • HospitalSystem: Singleton; manages doctors, patients, slots, appointments

Constraints

  • A slot can be booked by exactly one patient
  • Doctors cannot create overlapping slots
  • Cancellation allowed up to 2 hours before appointment
  • Maximum 20 appointments per doctor per day

!Constraints

- One patient per slot — concurrent booking synchronized - Doctors cannot have overlapping slot definitions - Cancellation allowed up to 2 hours before appointment time - Max 20 appointments per doctor per day - No-show after 15 minutes changes status to NO_SHOW automatically
Output

Run or submit your code to see output here.