Search in sources :

Example 1 with Appointment

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));
}
Also used : Appointment(org.openmrs.module.appointmentscheduling.Appointment) Visit(org.openmrs.Visit) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 2 with Appointment

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);
        }
    }
}
Also used : Appointment(org.openmrs.module.appointmentscheduling.Appointment) AdtService(org.openmrs.module.emrapi.adt.AdtService) Date(java.util.Date) DateTime(org.joda.time.DateTime) AppointmentService(org.openmrs.module.appointmentscheduling.api.AppointmentService)

Example 3 with 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);
        }
    }
}
Also used : Appointment(org.openmrs.module.appointmentscheduling.Appointment) AdtService(org.openmrs.module.emrapi.adt.AdtService) Date(java.util.Date) DateTime(org.joda.time.DateTime) AppointmentService(org.openmrs.module.appointmentscheduling.api.AppointmentService)

Example 4 with 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));
}
Also used : Appointment(org.openmrs.module.appointmentscheduling.Appointment) Visit(org.openmrs.Visit) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Aggregations

DateTime (org.joda.time.DateTime)4 Appointment (org.openmrs.module.appointmentscheduling.Appointment)4 Date (java.util.Date)2 Test (org.junit.Test)2 Location (org.openmrs.Location)2 Visit (org.openmrs.Visit)2 AppointmentService (org.openmrs.module.appointmentscheduling.api.AppointmentService)2 AdtService (org.openmrs.module.emrapi.adt.AdtService)2 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1