use of org.openmrs.Order in project openmrs-module-pihcore by PIH.
the class PihRadiologyOrdersMergeActionsComponentTest method shouldMergePatientsWhenNonPreferredPatientHasOnlyRadiologyOrders.
@Test
public void shouldMergePatientsWhenNonPreferredPatientHasOnlyRadiologyOrders() 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(10003);
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 shouldFailToMergePatientsWhenNonPreferredPatientHasDrugOrders.
// 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
@Ignore
public void shouldFailToMergePatientsWhenNonPreferredPatientHasDrugOrders() 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) == false));
}
use of org.openmrs.Order in project openmrs-module-pihcore by PIH.
the class PihTestOrdersMergeActions method beforeMergingPatients.
@Override
public void beforeMergingPatients(Patient preferred, Patient notPreferred) {
List<Order> orders = orderService.getAllOrdersByPatient(notPreferred);
if (orders != null && orders.size() > 0) {
this.unvoidOrders = new ArrayList<Integer>();
for (Order order : orders) {
if (order.getOrderType().getUuid().equals(LAB_TRACKING_TESTORDER_TYPE_UUID) && !order.isVoided()) {
// void Lab Tracking orders so openmrs-core will allowed them to be merged
orderService.voidOrder(order, "pre-merge labtracking orders");
this.unvoidOrders.add(order.getId());
}
}
}
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceImpl method getOrderHistoryByOrderNumber.
/**
* @see org.openmrs.api.OrderService#getOrderHistoryByOrderNumber(java.lang.String)
*/
@Override
@Transactional(readOnly = true)
public List<Order> getOrderHistoryByOrderNumber(String orderNumber) {
List<Order> orders = new ArrayList<>();
Order order = dao.getOrderByOrderNumber(orderNumber);
while (order != null) {
orders.add(order);
order = order.getPreviousOrder();
}
return orders;
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceImpl method discontinueOrder.
/**
* @see org.openmrs.api.OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
* org.openmrs.Provider, org.openmrs.Encounter)
*/
@Override
public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, Date discontinueDate, Provider orderer, Encounter encounter) {
if (discontinueDate == null) {
discontinueDate = aMomentBefore(new Date());
}
stopOrder(orderToDiscontinue, discontinueDate, false);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReasonNonCoded(reasonNonCoded);
newOrder.setOrderer(orderer);
newOrder.setEncounter(encounter);
newOrder.setDateActivated(discontinueDate);
return saveOrderInternal(newOrder, null);
}
Aggregations