Skip to content

Commit

Permalink
AP-64 | Sukreet | Ignore cancelled appointments for determining confl…
Browse files Browse the repository at this point in the history
…icts. (Bahmni#38)
  • Loading branch information
sukreet authored Jul 9, 2020
1 parent 21882b2 commit fa22355
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openmrs.module.appointments.model.AppointmentConflictType;
import org.openmrs.module.appointments.dao.AppointmentDao;
import org.openmrs.module.appointments.model.Appointment;
import org.openmrs.module.appointments.model.AppointmentStatus;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -48,7 +49,8 @@ private boolean isConflicting(Appointment appointment, Appointment patientAppoin
return !patientAppointment.isSameAppointment(appointment)
&& !patientAppointment.getVoided()
&& patientAppointment.isFutureAppointment()
&& isAppointmentOverlapping(patientAppointment, appointment);
&& isAppointmentOverlapping(patientAppointment, appointment)
&& patientAppointment.getStatus() != AppointmentStatus.Cancelled;
}

private boolean isAppointmentOverlapping(Appointment patientAppointment, Appointment appointment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.openmrs.module.appointments.dao.AppointmentDao;
import org.openmrs.module.appointments.helper.DateHelper;
import org.openmrs.module.appointments.model.Appointment;
import org.openmrs.module.appointments.model.AppointmentStatus;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -54,6 +55,26 @@ public void shouldReturnDoubleBookingConflictWithSameTime() {
assertEquals(patientAppointment,appointments.get(0));
}

@Test
public void shouldNotConflictWithCancelledAppointmentOnSameTime() {
Patient patient = new Patient();
patient.setId(1);
Appointment patientAppointment = new Appointment();
patientAppointment.setStartDateTime(DateHelper.getDate(2119,8,1,11,0,0));
patientAppointment.setEndDateTime(DateHelper.getDate(2119,8,1,12,0,0));
patientAppointment.setStatus(AppointmentStatus.Cancelled);

Appointment appointment = new Appointment();
appointment.setPatient(patient);
appointment.setStartDateTime(DateHelper.getDate(2119,8,1,11,0,0));
appointment.setEndDateTime(DateHelper.getDate(2119,8,1,12,0,0));
when(appointmentDao.getAppointmentsForPatient(1)).thenReturn(Collections.singletonList(patientAppointment));

List<Appointment> appointments = patientDoubleBookingConflict.getConflicts(Collections.singletonList(appointment));

assertNotNull(appointments);
assertEquals(0,appointments.size());
}

@Test
public void shouldReturnAppointmentWithOverlapping() {
Expand Down

0 comments on commit fa22355

Please sign in to comment.