use of org.openmrs.Order in project openmrs-module-pihcore by PIH.
the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasRadiologyOrdersInOverlappingVisit.
// TODO un-ignore once we have the EMR API module updated
@Test
@Ignore
public void shouldMergePatientsWhenNonPreferredPatientHasRadiologyOrdersInOverlappingVisit() throws Exception {
PihRadiologyOrdersMergeActions pihRadiologyOrdersMergeActions = Context.getRegisteredComponent("pihRadiologyOrdersMergeActions", PihRadiologyOrdersMergeActions.class);
Config config = mock(Config.class);
runtimeProperties.setProperty(ConfigLoader.PIH_CONFIGURATION_RUNTIME_PROPERTY, "mirebalais");
config = new Config(ConfigLoader.loadFromRuntimeProperties());
pihRadiologyOrdersMergeActions.setConfig(config);
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.Order 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 not present after merging the patients", orderService.getAllOrdersByPatient(preferredPatient).contains(radiologyOrder));
}
use of org.openmrs.Order in project openmrs-module-pihcore by PIH.
the class PihRadiologyOrdersMergeActions method beforeMergingPatients.
/**
* This method will be called before calling the underlying OpenMRS
* {@link org.openmrs.api.PatientService#mergePatients(org.openmrs.Patient, org.openmrs.Patient)} method, but in the
* same transaction. Any thrown exception will cancel the merge
*
* @param preferred
* @param notPreferred
*/
@Override
public void beforeMergingPatients(Patient preferred, Patient notPreferred) {
if (config.isComponentEnabled(Components.RADIOLOGY)) {
OrderType radiologyTestOrderType = radiologyProperties.getRadiologyTestOrderType();
List<Order> orders = orderService.getAllOrdersByPatient(notPreferred);
if (orders != null && orders.size() > 0) {
this.unvoidOrders = new ArrayList<Integer>();
for (Order order : orders) {
if (order.getOrderType().equals(radiologyTestOrderType) && !order.isVoided()) {
// void Radiology orders so openmrs-core will allowed them to be merged
orderService.voidOrder(order, "pre-merge radiology orders");
this.unvoidOrders.add(order.getId());
}
}
}
}
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderUtilTest method checkScheduleOverlap_shouldReturnTrueIfOrder1StartsBeforeOrder2AndEndsAfterOrder2.
/**
* @see OrderUtil#checkScheduleOverlap(Order,Order)
*/
@Test
public void checkScheduleOverlap_shouldReturnTrueIfOrder1StartsBeforeOrder2AndEndsAfterOrder2() {
Date date = new Date();
Order order1 = new Order();
// Order1 scheduled after 4 days getting expired after 14 days
order1.setScheduledDate(DateUtils.addDays(date, 4));
order1.setAutoExpireDate(DateUtils.addDays(date, 14));
order1.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
Order order2 = new Order();
order2.setDateActivated(date);
// Order2 scheduled after 6 days getting expired after 10 days
order2.setScheduledDate(DateUtils.addDays(date, 6));
order2.setAutoExpireDate(DateUtils.addDays(date, 10));
order2.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
assertTrue(OrderUtil.checkScheduleOverlap(order1, order2));
assertTrue(OrderUtil.checkScheduleOverlap(order2, order1));
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderUtilTest method checkScheduleOverlap_shouldReturnFalseIfOrder1EndsBeforeOrder2Starts.
/**
* @see OrderUtil#checkScheduleOverlap(Order,Order)
*/
@Test
public void checkScheduleOverlap_shouldReturnFalseIfOrder1EndsBeforeOrder2Starts() {
Date date = new Date();
Order order1 = new Order();
order1.setDateActivated(date);
// Order1 getting expired after 2 days
order1.setAutoExpireDate(DateUtils.addDays(date, 2));
Order order2 = new Order();
order2.setDateActivated(date);
// Order2 scheduled after 4 days
order2.setScheduledDate(DateUtils.addDays(date, 4));
order2.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
assertFalse(OrderUtil.checkScheduleOverlap(order1, order2));
assertFalse(OrderUtil.checkScheduleOverlap(order2, order1));
}
Aggregations