use of org.openmrs.module.appointmentscheduling.Appointment in project openmrs-module-mirebalais by PIH.
the class MarkAppointmentAsMissedOrCompletedTaskTest method shouldMarkActiveAppointmentsAsCompleteIfConsultAsPartOfVisit.
@Test
public void shouldMarkActiveAppointmentsAsCompleteIfConsultAsPartOfVisit() {
new MarkAppointmentsAsMissedOrCompletedTask().execute();
// sanity check: status isn't changed by default, since there are no consultations associated with this visit
assertThat(appointmentService.getAppointment(4).getStatus(), is(AppointmentStatus.INCONSULTATION));
assertThat(appointmentService.getAppointment(7).getStatus(), is(AppointmentStatus.WALKIN));
assertThat(appointmentService.getAppointment(8).getStatus(), is(AppointmentStatus.WAITING));
Location location1 = locationService.getLocation(1);
// location of the appointments, as defined in test dataset
Location location3 = locationService.getLocation(3);
// now add a visit to one appointment, and a visit with a consult to the other
Appointment appt4 = appointmentService.getAppointment(4);
Visit visit4 = testDataManager.visit().patient(appt4.getPatient()).visitType(1).started(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).save();
appt4.setVisit(visit4);
appointmentService.saveAppointment(appt4);
Appointment appt7 = appointmentService.getAppointment(7);
Visit visit7 = testDataManager.visit().patient(appt7.getPatient()).visitType(1).started(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounter(testDataManager.encounter().patient(appt7.getPatient()).encounterDatetime(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounterType(emrApiProperties.getVisitNoteEncounterType()).location(location1).save()).save();
appt7.setVisit(visit7);
appointmentService.saveAppointment(appt7);
Appointment appt8 = appointmentService.getAppointment(8);
Visit visit8 = testDataManager.visit().patient(appt8.getPatient()).visitType(1).started(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounter(testDataManager.encounter().patient(appt8.getPatient()).encounterDatetime(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounterType(emrApiProperties.getVisitNoteEncounterType()).location(location3).save()).save();
appt8.setVisit(visit8);
appointmentService.saveAppointment(appt8);
// run the task again
new MarkAppointmentsAsMissedOrCompletedTask().execute();
// should not be changed because associated visit did not have consult
assertThat(appointmentService.getAppointment(4).getStatus(), is(AppointmentStatus.INCONSULTATION));
// should not be changed since associated visit did not have consult at location
assertThat(appointmentService.getAppointment(7).getStatus(), is(AppointmentStatus.WALKIN));
// should be changed to COMPLETED since associated visit had consult at location
assertThat(appointmentService.getAppointment(8).getStatus(), is(AppointmentStatus.COMPLETED));
}
use of org.openmrs.module.appointmentscheduling.Appointment in project openmrs-module-pihcore by PIH.
the class MarkAppointmentsAsMissedOrCompletedTask method run.
@Override
public void run() {
log.info("Executing " + getClass());
AppointmentService appointmentService = Context.getService(AppointmentService.class);
AdtService adtService = Context.getService(AdtService.class);
Date endOfYesterday = new DateTime().withTime(23, 59, 59, 999).minusDays(1).toDate();
for (Appointment appointment : appointmentService.getAppointmentsByConstraints(null, endOfYesterday, null, null, null, null, Appointment.AppointmentStatus.getAppointmentsStatusByTypes(Arrays.asList(Appointment.AppointmentStatusType.SCHEDULED)))) {
appointment.setStatus(Appointment.AppointmentStatus.MISSED);
appointmentService.saveAppointment(appointment);
}
for (Appointment appointment : appointmentService.getAppointmentsByConstraints(null, endOfYesterday, null, null, null, null, Appointment.AppointmentStatus.getAppointmentsStatusByTypes(Arrays.asList(Appointment.AppointmentStatusType.ACTIVE)))) {
if (appointment.getVisit() != null && adtService.wrap(appointment.getVisit()).hasVisitNoteAtLocation(appointment.getTimeSlot().getAppointmentBlock().getLocation())) {
appointment.setStatus(Appointment.AppointmentStatus.COMPLETED);
appointmentService.saveAppointment(appointment);
}
}
}
use of org.openmrs.module.appointmentscheduling.Appointment in project openmrs-module-mirebalais by PIH.
the class MarkAppointmentsAsMissedOrCompletedTask method execute.
@Override
public void execute() {
AppointmentService appointmentService = Context.getService(AppointmentService.class);
AdtService adtService = Context.getService(AdtService.class);
Date endOfYesterday = new DateTime().withTime(23, 59, 59, 999).minusDays(1).toDate();
for (Appointment appointment : appointmentService.getAppointmentsByConstraints(null, endOfYesterday, null, null, null, null, Appointment.AppointmentStatus.getAppointmentsStatusByTypes(Arrays.asList(Appointment.AppointmentStatusType.SCHEDULED)))) {
appointment.setStatus(Appointment.AppointmentStatus.MISSED);
appointmentService.saveAppointment(appointment);
}
for (Appointment appointment : appointmentService.getAppointmentsByConstraints(null, endOfYesterday, null, null, null, null, Appointment.AppointmentStatus.getAppointmentsStatusByTypes(Arrays.asList(Appointment.AppointmentStatusType.ACTIVE)))) {
if (appointment.getVisit() != null && adtService.wrap(appointment.getVisit()).hasVisitNoteAtLocation(appointment.getTimeSlot().getAppointmentBlock().getLocation())) {
appointment.setStatus(Appointment.AppointmentStatus.COMPLETED);
appointmentService.saveAppointment(appointment);
}
}
}
use of org.openmrs.module.appointmentscheduling.Appointment in project openmrs-module-pihcore by PIH.
the class MarkAppointmentAsMissedOrCompletedTaskTest method shouldMarkActiveAppointmentsAsCompleteIfConsultAsPartOfVisit.
@Test
public void shouldMarkActiveAppointmentsAsCompleteIfConsultAsPartOfVisit() {
new MarkAppointmentsAsMissedOrCompletedTask().run();
// sanity check: status isn't changed by default, since there are no consultations associated with this visit
assertThat(appointmentService.getAppointment(4).getStatus(), is(AppointmentStatus.INCONSULTATION));
assertThat(appointmentService.getAppointment(7).getStatus(), is(AppointmentStatus.WALKIN));
assertThat(appointmentService.getAppointment(8).getStatus(), is(AppointmentStatus.WAITING));
Location location1 = locationService.getLocation(1);
// location of the appointments, as defined in test dataset
Location location3 = locationService.getLocation(3);
// now add a visit to one appointment, and a visit with a consult to the other
Appointment appt4 = appointmentService.getAppointment(4);
Visit visit4 = testDataManager.visit().patient(appt4.getPatient()).visitType(1).started(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).save();
appt4.setVisit(visit4);
appointmentService.saveAppointment(appt4);
Appointment appt7 = appointmentService.getAppointment(7);
Visit visit7 = testDataManager.visit().patient(appt7.getPatient()).visitType(1).started(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounter(testDataManager.encounter().patient(appt7.getPatient()).encounterDatetime(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounterType(getConsultationEncounterType()).location(location1).save()).save();
appt7.setVisit(visit7);
appointmentService.saveAppointment(appt7);
Appointment appt8 = appointmentService.getAppointment(8);
Visit visit8 = testDataManager.visit().patient(appt8.getPatient()).visitType(1).started(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounter(testDataManager.encounter().patient(appt8.getPatient()).encounterDatetime(new DateTime(2005, 1, 1, 0, 0, 0).toDate()).encounterType(emrApiProperties.getVisitNoteEncounterType()).location(location3).save()).save();
appt8.setVisit(visit8);
appointmentService.saveAppointment(appt8);
// run the task again
new MarkAppointmentsAsMissedOrCompletedTask().run();
// should not be changed because associated visit did not have consult
assertThat(appointmentService.getAppointment(4).getStatus(), is(AppointmentStatus.INCONSULTATION));
// should not be changed since associated visit did not have consult at location
assertThat(appointmentService.getAppointment(7).getStatus(), is(AppointmentStatus.WALKIN));
// should be changed to COMPLETED since associated visit had consult at location
assertThat(appointmentService.getAppointment(8).getStatus(), is(AppointmentStatus.COMPLETED));
}
Aggregations