Search in sources :

Example 1 with Order

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

Example 2 with Order

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

Example 3 with Order

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

Example 4 with Order

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

Example 5 with Order

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

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