About
import java.util.List;
public class HealthcareServiceImpl implements HealthcareService { private HealthcareDAOImpl dao = new HealthcareDAOImpl(); private Validator validator = new Validator();
@Override
public void searchAvailableDoctors(String specialization) throws HealthcareException {
List<Doctor> list = dao.searchAvailableDoctors(specialization);
if (list.isEmpty()) {
throw new HealthcareException("Service NO_RECORDS_FOUND");
}
list.forEach(d -> System.out.print("Doctor id: " + d.getDoctorId() +
", Doctor name: " + d.getDoctorName() +
", Specialization: " + d.getSpecialization() +
", Available date: " + d.getAvailableDate() +
", Available Time: " + d.getAvailableTime() + "\n"));
}
@Override
public void viewAvailableDoctors() {
List<Doctor> list = dao.viewAvailableDoctors();
list.forEach(d -> System.out.print("Doctor id: " + d.getDoctorId() +
", Doctor name: " + d.getDoctorName() +
", Specialization: " + d.getSpecialization() +
", Available date: " + d.getAvailableDate() +
", Available Time: " + d.getAvailableTime() + "\n"));
}
@Override
public Appointment bookAppointment(Patient p, int doctorId) throws HealthcareException {
Appointment appointment = new Appointment();
for (Doctor d : dao.viewAvailableDoctors()) {
if (d.getDoctorId() == doctorId) {
p.setAppointmentDate(d.getAvailableDate());
p.setAppointmentTime(d.getAvailableTime());
try {
validator.validate(p);
} catch (HealthcareException e) {
throw new HealthcareException("Service, INVALID_DOCTOR_ID");
}
appointment.setPatientId(p.getPatientId());
appointment.setAppointmentTime(d.getAvailableTime());
appointment.setAppointmentDate(d.getAvailableDate());
appointment.setDoctorId(d.getDoctorId());
appointment.setStatus(Status.CONFIRMED);
return dao.bookAppointment(appointment);
}
}
throw new HealthcareException("Service, INVALID_DOCTOR_ID");
}
}