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.
Steps to follow
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:
//Booking from the next day
startDate = zoho.currentdate.addDay(1);
//Allow booking for the next 5 days
endDate = startDate.addDay(4);
//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.
list = {1,2,3,4,5};
for each index l in list
{
input.Date_of_Appointment:ui.add(startDate.toString());
//update startDate to get the next date
startDate = startDate.addDay(1);
}
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:
//Take the details of the chosen doctor
doctor = Doctor[ID == input.Doctor_Name];
//Getting the visiting hours of the doctor chosen
from = doctor.From;
to = doctor.To;
//Getting the hours
diff = from.hoursBetween(to);
selectedSlots = List();
//To get already selected slots for the chosen doctor on the chosen date
for each d in Appointment[Doctor == input.Doctor_Name && Date_of_Appointment == input.Date_of_Appointment]
{
selectedSlots.add(d.Appointment_Slot);
}
//Multiplying the number of hours by 2, since each appointment is assumed to be 30 minutes
//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.
//We are using the below list to control the number of iterations in the following loop.
list = leftpad("1",diff * 2).replaceAll(" ","1,").toList();
for each index a in list
{
//Add the slot only when it is not already selected by another patient
if(!selectedSlots.contains(from.toString()))
{
input.Appointment_Slot:ui.add(from);
}
//Find the next slot by adding 30 minutes.
from = from.addMinutes(30);
}
See how it works
Points to Note
startDate = zoho.currentdate.addDay(1);
//Allow booking for the next 30 days
endDate = startDate.addDay(30);
list = leftpad("1",30).replaceAll(" ","1,").toList();