Last active
May 29, 2021 12:23
-
-
Save kislayverma/69d96b7b18497e7b6d376de6114fb9d2 to your computer and use it in GitHub Desktop.
Method doing multiple things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
.findFirst(); | |
// Create the appointment | |
s.setIsOccupied(true); | |
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