Search in sources :

Example 86 with Order

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));
}
Also used : Order(org.openmrs.Order) Config(org.openmrs.module.pihcore.config.Config) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 87 with Order

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));
}
Also used : Order(org.openmrs.Order) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Ignore(org.junit.Ignore) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 88 with Order

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());
            }
        }
    }
}
Also used : Order(org.openmrs.Order)

Example 89 with Order

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;
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with Order

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);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Date(java.util.Date)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9