Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Method doing multiple things
public Slot makeAppointment(Doctor d, Hospital h, Patient p, Date startTime, Date endTime) throws Exception {
// Check if hospital is open during this time period
String hospitalServiceBaseUrl = ConfigReader.readConfigName("hospitalServiceBaseUrl");
HospitalService hospitalService = new HospitalService(hospitalServiceBaseUrl);
DateRange range = hospitalService.getWorkingHours();
if (!range.contains(startTime) || !range.contains(endTime)) {
throw new Exception("Hospital isn't open in this time period");
// Check if doctor has no other appointment in this time period
String scheduleServiceBaseUrl = ConfigReader.readConfigName("scheduleServiceBaseUrl");
ScheduleSerivce scheduleService = new ScheduleService(scheduleServiceBaseUrl);
Slot s = scheduleService.getAppointmentSlots(d).stream()
.filter(slot -> !slot.isOccupied()) // Only consider free slots
.filter(slot -> slot.contains(startTime) && slot.contains(endTime)) // Only consider slots which contain this time period
// Create the appointment
Slot bookedSlot = scheduleService.bookSlot(d, p, s);
// Notify doctor using custom email template
DoctorEmailTemplate doctorEmailTemplate = new DoctorEmailTemplate(d, p, bookedSlot);
notificationService.notify(d, doctorEmailTemplate);
// Notify patient using custom email template
PatientEmailTemplate patientEmailTemplate = new PatientEmailTemplate(d, p, bookedSlot);
notificationService.notify(p, patientEmailTemplate);
return bookedSlot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment