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));
}
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;
}
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();
}
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());
}
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);
}
Aggregations