in serverless-workflow-examples/serverless-workflow-functions-events-quarkus/src/main/java/org/acme/sw/onboarding/services/ScheduleService.java [51:69]
public Appointment createAppointment(final Patient patient) {
final Appointment appointment = new Appointment();
final String doctorId = patient.getAssignedDoctor().getId();
appointment.setPatient(patient);
// better case scenario we set an appointment today an hour from now :)
appointment.setDate(LocalDateTime.now().plusHours(1));
appointment.setDoctor(patient.getAssignedDoctor());
// let's find room for our patient
if (this.schedule.get(doctorId) != null) {
final Optional<LocalDateTime> lastDate = this.schedule.get(doctorId).stream().max(Comparator.nullsFirst(Comparator.naturalOrder()));
appointment.setDate(this.addOneDayFirstHourInMorning(lastDate.orElseThrow(IllegalStateException::new)));
} else { // this doctor hasn't been set an appointment yet
this.schedule.put(doctorId, new ArrayList<>());
}
this.schedule.get(doctorId).add(appointment.getDate());
return appointment;
}