Appointment Management with Dynamic Drop Down

Appointment Management with Dynamic Drop Down

Requirement  

Allow patients to book appointments with their doctors.

Use Case  

A clinic wants to digitize its booking system. There are multiple specialists and different dates/times for appointments. Each appointment lasts for 30 minutes. There are two forms: the Doctor form, to add the details of specialization and availability of the doctors who visit, and the Appointment form to book an appointment.
 
See how it works

Steps to follow  

1. Create the forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Doctor
Doctor
Name
Doctor Name
Doctor_Name
Drop Down
Specialization
Specialization
Time
From
From
Time
To
To
Appointment
Appointment
Name
Patient Name
Patient_Name
Phone
Phone
Phone_Number
Lookup (Doctor)
Doctor Name
Doctor_Name
Drop Down
Date of Appointment
Date_of_Appointment
Drop Down
Appointment Slot
Appointment_Slot

Add a few fields of specialization to the Specialization choices -> (General, Gynacology, Obstetrics, Neonatalogy, Pediatrics, Dermatology, Ophthalmology, Cardiology, Pulmonology).
 
2. Insert a few records to the Doctor form.
 
3. Let us now create a workflow to populate dates in the Date of Appointment field in the Appointment form. A patient is allowed to book appointments for the next five days. We shall create a workflow to execute during the load of the Appointment form.
 
4. Click Add New Action and add the below code in Deluge Editor:
  1. //Booking from the next day
  2. startDate = zoho.currentdate.addDay(1);

  3. //Allow booking for the next 5 days
  4. endDate = startDate.addDay(4);

  5. //Loop through the dates and add them to the Date of Appointment drop down field. We need the next five dates. Hence adding 5 elements to a list. For adding more dates, check Points To Note.
  6. list = {1,2,3,4,5};
  7. for each index l in list
  8. {
  9.  input.Date_of_Appointment:ui.add(startDate.toString());

  10. //update startDate to get the next date
  11.  startDate = startDate.addDay(1);
  12. }
 
5. In the same way, after a Date of Appointment is selected, the slots available in those days for the chosen doctor should be populated in the Appointment Slot field.
 
6. Click Add New Action and add the below code in the Deluge Editor:
  1. //Take the details of the chosen doctor
  2. doctor = Doctor[ID == input.Doctor_Name];

  3. //Getting the visiting hours of the doctor chosen
  4. from = doctor.From;
  5. to = doctor.To;

  6. //Getting the hours
  7. diff = from.hoursBetween(to);
  8. selectedSlots = List();

  9. //To get already selected slots for the chosen doctor on the chosen date
  10. for each d in Appointment[Doctor == input.Doctor_Name && Date_of_Appointment == input.Date_of_Appointment]
  11. {
  12.  selectedSlots.add(d.Appointment_Slot);
  13. }

  14. //Multiplying the number of hours by 2, since each appointment is assumed to be 30 minutes
  15. //We are padding diff * 2 number of spaces to 1 and then we are changing the spaces to 1. This will now help us to add diff * 2 number of slots from which the patient can choose.
  16. //We are using the below list to control the number of iterations in the following loop.
  17. list = leftpad("1",diff * 2).replaceAll(" ","1,").toList();
  18. for each index a in list
  19. {

  20. //Add the slot only when it is not already selected by another patient
  21.  if(!selectedSlots.contains(from.toString()))
  22.  {
  23.   input.Appointment_Slot:ui.add(from);
  24.  }

  25. //Find the next slot by adding 30 minutes.
  26.  from = from.addMinutes(30);

See how it works         

           

Points to Note  

  • To add more dates, check the below code:
  1. startDate = zoho.currentdate.addDay(1);

  2. //Allow booking for the next 30 days
  3. endDate = startDate.addDay(30);
  4. list = leftpad("1",30).replaceAll(" ","1,").toList();
  • The field type of From and To in the Doctor form is Time. Thus, the time difference can be a little difficult to calculate sometimes. We can have them as Date-Time fields too.