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)));
}
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));
}
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));
}
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));
}
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());
}
Aggregations