Search in sources :

Example 26 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihEncounterValidatorTest method testShouldRemoveVisitIfNotSuitable.

@Test
public void testShouldRemoveVisitIfNotSuitable() throws Exception {
    Patient patient = new Patient();
    Location location = new Location();
    Visit notSuitable = new Visit();
    notSuitable.setPatient(patient);
    notSuitable.setStartDatetime(DateUtils.addDays(new Date(), -7));
    notSuitable.setStopDatetime(DateUtils.addDays(new Date(), -6));
    notSuitable.setLocation(location);
    Encounter encounter = new Encounter();
    encounter.setId(1);
    encounter.setPatient(patient);
    encounter.setLocation(location);
    encounter.setEncounterDatetime(new Date());
    // we attempt to assign a non-suitable visit to the encounter
    notSuitable.addEncounter(encounter);
    validator.validate(encounter, null);
    Assert.assertNull(encounter.getVisit());
    Assert.assertThat(notSuitable.getEncounters(), not(contains(encounter)));
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Example 27 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasNoOrders.

@Test
public void shouldMergePatientsWhenNonPreferredPatientHasNoOrders() throws Exception {
    Patient preferredPatient = patientService.getPatient(6);
    List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(preferredPatient);
    // patient has 1 Radiology Encounter
    Assert.assertEquals(1, encountersByPatient.size());
    Assert.assertEquals("RadiologyOrder", encountersByPatient.get(0).getEncounterType().getName());
    Set<Order> orders = encountersByPatient.get(0).getOrders();
    Assert.assertEquals(1, orders.size());
    Order radiologyOrder = null;
    for (Order order : orders) {
        radiologyOrder = order;
    }
    Assert.assertEquals("RadiologyOrder", radiologyOrder.getOrderType().getName());
    Patient nonPreferredPatient = patientService.getPatient(10001);
    adtService.mergePatients(preferredPatient, nonPreferredPatient);
    assertTrue("RadiologyOrder is present after merging the patients", orderService.getAllOrdersByPatient(preferredPatient).contains(radiologyOrder));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 28 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasRadiologyOrdersInOverlappingVisit.

@Test
public void shouldMergePatientsWhenNonPreferredPatientHasRadiologyOrdersInOverlappingVisit() throws Exception {
    Patient preferredPatient = patientService.getPatient(6);
    Patient nonPreferredPatient = patientService.getPatient(10004);
    List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(nonPreferredPatient);
    // patient has 1 Radiology Encounter
    Assert.assertEquals(1, encountersByPatient.size());
    Assert.assertEquals("RadiologyOrder", encountersByPatient.get(0).getEncounterType().getName());
    Set<Order> orders = encountersByPatient.get(0).getOrders();
    Assert.assertEquals(1, orders.size());
    Order radiologyOrder = null;
    for (Order order : orders) {
        radiologyOrder = order;
    }
    Assert.assertEquals("RadiologyOrder", radiologyOrder.getOrderType().getName());
    adtService.mergePatients(preferredPatient, nonPreferredPatient);
    assertTrue("RadiologyOrder was not merged", orderService.getAllOrdersByPatient(preferredPatient).contains(radiologyOrder));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 29 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasDrugOrders.

// this restriction has been relaxed in Core 2.x  A "non-preferred" patient can now have orders as long as they aren't of the same type as those of the preferred patient
// ignoring this test, should eventually remove but keeping it around for now
@Test
public void shouldMergePatientsWhenNonPreferredPatientHasDrugOrders() throws Exception {
    Patient preferredPatient = patientService.getPatient(6);
    // patient with unvoided DrugOrder
    Patient nonPreferredPatient = patientService.getPatient(10002);
    List<Encounter> encountersByPatient = encounterService.getEncountersByPatient(nonPreferredPatient);
    // nonPreferred patient has no RadiologyOrders
    Assert.assertEquals(1, encountersByPatient.size());
    Assert.assertNotEquals("RadiologyOrder", encountersByPatient.get(0).getEncounterType().getName());
    List<Order> allNonPreferredPatientOrders = orderService.getAllOrdersByPatient(nonPreferredPatient);
    Assert.assertEquals(1, allNonPreferredPatientOrders.size());
    Order nonPreferredPatientOrder = null;
    for (Order order : allNonPreferredPatientOrders) {
        nonPreferredPatientOrder = order;
    }
    Assert.assertNotEquals("RadiologyOrder", nonPreferredPatientOrder.getOrderType().getName());
    try {
        adtService.mergePatients(preferredPatient, nonPreferredPatient);
    } catch (Exception e) {
        Assert.assertEquals("Cannot merge patients where the not preferred patient has unvoided orders", e.getMessage());
    }
    assertTrue("DrugOrder was merged", (orderService.getAllOrdersByPatient(preferredPatient).contains(nonPreferredPatientOrder) == true));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) Test(org.junit.Test)

Example 30 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class ReopenVisitDispositionActionTest method reopenVisitAction_shouldReopenVisitIfNoSubsequentVisitAtSameLocation.

@Test
public void reopenVisitAction_shouldReopenVisitIfNoSubsequentVisitAtSameLocation() {
    Encounter encounter = Context.getEncounterService().getEncounter(1002);
    // sanity check
    assertNotNull(encounter.getVisit().getStopDatetime());
    reopenVisitDispositionAction.action(new EncounterDomainWrapper(encounter), null, null);
    assertNull(encounter.getVisit().getStopDatetime());
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper) Encounter(org.openmrs.Encounter) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19