1. Design a doctor booking system

Through this blog, we will do a low level design of a simple doctor booking system. We will cover the requirements first, then we will start with how we should approach the problem. Then, we discuss the major classes involved. Then finally we code with a all the test cases.

By Shamir
04/07/2024

1. Requirements

We are required to build an app that lets patients connect to doctors and book appointments. The day is divided into time slots of 30 mins each, starting from 9 am to 9 pm. Doctors can login to the portal and declare their availability for the given day in terms of slots. Patients can login and book appointments/cancel existing appointments. For simplicity you can assume that the doctors’ availability is declared for that particular day only. For this app, we have been asked to implement these features.

  1. A new doctor should be able to register, and mention his/her speciality among (Cardiologist, Dermatologist, Orthopedic, General Physician)
  2. A doctor should be able to declare his/her availability in each slot for the day. For example, the slots will be of 30 mins like 9am-9.30am, 9.30am-10am.
  3. Patients should be able to login, and search available slots based on speciality.
  4. The slots should be displayed in a ranked fashion. Default ranking strategy should be to rank by start time. But we should be able to plugin more strategies like Doctor’s rating etc in future.
  5. Patients should be able to book appointments with a doctor for an available slot.A patient can book multiple appointments in a day. A patient cannot book two appointments with two different doctors in the same time slot.
  6. Patients can also cancel an appointment, in which case that slot becomes available for someone else to book.
  7. Build a waitlist feature.If the patient wishes to book a slot for a particular doctor that is already booked, then add this patient to the waitlist. If the patient with whom the appointment is booked originally, cancels the appointment, then the first in the waitlist gets the appointment.
  8. A patient/doctor should be able to view his/her booked appointments for the day.
  9. Trending Doctor: Maintain at any point of time which doctor has the most appointments.

2. Approach

There are n number of ways to do things and get the same results. However, let me share with you how i think and approach this problem. This helps me solve it easily. Do let me know, if there is a better way to think. I beleive rhe way of thinking is the most important part than the solution itself. With a way of thinking, you would be able to figure out solutions for multiple problems rather than a single one. Without further ado lets get to the business.

The first question I will ask will be. Who all the parties involved here? Lets try to think.

Obviously doctor should be there. And patients would be there to book. Assume always doctor know only to consult and he have delegated all his other admin work. Think like a small clinic, how is the booking done there. You call the clinic, you ask the receptionist to book a slot for you. Same way, there would be an intermediarry booking manager who would help with the booking. So far great going.

The above settings work for a small clinic in a village. Lets make shift the doctor to a bit more big hospital. First he needs to register himself at the hospital so that he gets his office and his own patients. The one who handles the registration at office, lets call them the Registration Manager. He takes care of all the registration of doctors. Now our doctor went and registered. He got himself a consulting room at the hospital. We have also moved our Booking Manager to the new hospital. Now, she takes care of different doctors who are available. Now since there are lot of doctors, she doesnt know the working hours of each doctor. So the management had asked the doctors to give their availability slots for each day to the Booking Manager. So, first Doctor will call the Booking Manager two days before. He gives schedule. Then, Booking Manager books each slots for the patients on a first come first serve basis. And she also maintains a waiting list. Further, Doctors can call Booking Manager to ask whats his consultation booking for a particular day to know how is day look like. The hospital had come different mechanisms to assess the performance of the doctors. One among them is Trending Doctor. They hired a specialist to do this job. Lets call them AnalyticsManager. Now, the booking app have all the people who needs to be there.

To summarise, this is the list which we came up. A doctor, patient, booking manager, and an analytics manager. We will add more people if there is a need. This is a good place to start.

The second question I will ask would be what are the duties of each person involved. The hospital has clear set of rules on who should do what. Lets define those now.