Search in sources :

Example 6 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderUtilTest method checkScheduleOverlap_shouldReturnTrueIfOrder2StartsBeforeOrder1AndEndsAfterOrder1.

/**
 * @throws ParseException
 * @see OrderUtil#checkScheduleOverlap(org.openmrs.Order, org.openmrs.Order)
 */
@Test
public void checkScheduleOverlap_shouldReturnTrueIfOrder2StartsBeforeOrder1AndEndsAfterOrder1() throws ParseException {
    DateFormat df = new SimpleDateFormat("dd/MM/yyy");
    Order order1 = new Order();
    order1.setDateActivated(df.parse("03/08/2014"));
    order1.setAutoExpireDate(df.parse("05/08/2014"));
    Order order2 = new Order();
    order2.setDateActivated(df.parse("01/08/2014"));
    order2.setAutoExpireDate(df.parse("07/08/2014"));
    assertTrue(OrderUtil.checkScheduleOverlap(order1, order2));
    assertTrue(OrderUtil.checkScheduleOverlap(order2, order1));
}
Also used : Order(org.openmrs.Order) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 7 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class HibernateOrderDAO method isOrderFrequencyInUse.

/**
 * @see org.openmrs.api.db.OrderDAO#isOrderFrequencyInUse(org.openmrs.OrderFrequency)
 */
@Override
public boolean isOrderFrequencyInUse(OrderFrequency orderFrequency) {
    Map<String, ClassMetadata> metadata = sessionFactory.getAllClassMetadata();
    for (ClassMetadata classMetadata : metadata.values()) {
        Class<?> entityClass = classMetadata.getMappedClass();
        if (Order.class.equals(entityClass)) {
            // ignore the org.openmrs.Order class itself
            continue;
        }
        if (!Order.class.isAssignableFrom(entityClass)) {
            // not a sub class of Order
            continue;
        }
        String[] names = classMetadata.getPropertyNames();
        for (String name : names) {
            if (classMetadata.getPropertyType(name).getReturnedClass().equals(OrderFrequency.class)) {
                Criteria criteria = sessionFactory.getCurrentSession().createCriteria(entityClass);
                criteria.add(Restrictions.eq(name, orderFrequency));
                criteria.setMaxResults(1);
                if (!criteria.list().isEmpty()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Order(org.openmrs.Order) Criteria(org.hibernate.Criteria)

Example 8 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class HibernateOrderDAO method getOrderByOrderNumber.

/**
 * @see org.openmrs.api.db.OrderDAO#getOrderByOrderNumber(java.lang.String)
 */
@Override
public Order getOrderByOrderNumber(String orderNumber) {
    Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(Order.class, "order");
    searchCriteria.add(Restrictions.eq("order.orderNumber", orderNumber));
    return (Order) searchCriteria.uniqueResult();
}
Also used : Order(org.openmrs.Order) Criteria(org.hibernate.Criteria)

Example 9 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderServiceTest method unvoidOrder_shouldStopThePreviousOrderIfTheSpecifiedOrderIsARevision.

/**
 * @see OrderService#unvoidOrder(org.openmrs.Order)
 */
@Test
public void unvoidOrder_shouldStopThePreviousOrderIfTheSpecifiedOrderIsARevision() {
    Order order = orderService.getOrder(111);
    assertEquals(Action.REVISE, order.getAction());
    Order previousOrder = order.getPreviousOrder();
    assertNotNull(previousOrder.getDateStopped());
    assertFalse(order.getVoided());
    // void the revise order for testing purposes so we can unvoid it later
    orderService.voidOrder(order, "None");
    Context.flushSession();
    assertTrue(order.getVoided());
    assertNull(previousOrder.getDateStopped());
    orderService.unvoidOrder(order);
    Context.flushSession();
    assertFalse(order.getVoided());
    assertNotNull(previousOrder.getDateStopped());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 10 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldNotAllowRevisingAnOrderWithNoPreviousOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldNotAllowRevisingAnOrderWithNoPreviousOrder() {
    Order originalOrder = orderService.getOrder(111);
    assertTrue(originalOrder.isActive());
    Order revisedOrder = originalOrder.cloneForRevision();
    revisedOrder.setEncounter(encounterService.getEncounter(5));
    revisedOrder.setInstructions("Take after a meal");
    revisedOrder.setPreviousOrder(null);
    revisedOrder.setOrderer(providerService.getProvider(1));
    revisedOrder.setDateActivated(new Date());
    expectedException.expect(MissingRequiredPropertyException.class);
    expectedException.expectMessage(mss.getMessage("Order.previous.required"));
    orderService.saveOrder(revisedOrder, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) 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