use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfOrderTypeIsNullAndNotMappedToTheConceptClass.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfOrderTypeIsNullAndNotMappedToTheConceptClass() {
Order order = new Order();
order.setPatient(patientService.getPatient(7));
order.setConcept(conceptService.getConcept(9));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setEncounter(encounterService.getEncounter(3));
order.setDateActivated(new Date());
expectedException.expect(OrderEntryException.class);
expectedException.expectMessage("Order.type.cannot.determine");
orderService.saveOrder(order, null);
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldDiscontinueExistingActiveOrderIfNewOrderBeingSavedWithActionToDiscontinue.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldDiscontinueExistingActiveOrderIfNewOrderBeingSavedWithActionToDiscontinue() {
DrugOrder order = new DrugOrder();
order.setAction(Order.Action.DISCONTINUE);
order.setOrderReasonNonCoded("Discontinue this");
order.setDrug(conceptService.getDrug(3));
order.setEncounter(encounterService.getEncounter(5));
order.setPatient(patientService.getPatient(7));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setEncounter(encounterService.getEncounter(3));
order.setOrderType(orderService.getOrderType(1));
order.setDateActivated(new Date());
order.setDosingType(SimpleDosingInstructions.class);
order.setDose(500.0);
order.setDoseUnits(conceptService.getConcept(50));
order.setFrequency(orderService.getOrderFrequency(1));
order.setRoute(conceptService.getConcept(22));
order.setNumRefills(10);
order.setQuantity(20.0);
order.setQuantityUnits(conceptService.getConcept(51));
// We are trying to discontinue order id 111 in standardTestDataset.xml
Order expectedPreviousOrder = orderService.getOrder(111);
Assert.assertNull(expectedPreviousOrder.getDateStopped());
order = (DrugOrder) orderService.saveOrder(order, null);
Assert.assertNotNull("should populate dateStopped in previous order", expectedPreviousOrder.getDateStopped());
Assert.assertNotNull("should save discontinue order", order.getId());
Assert.assertEquals(expectedPreviousOrder, order.getPreviousOrder());
Assert.assertNotNull(expectedPreviousOrder.getDateStopped());
Assert.assertEquals(order.getDateActivated(), order.getAutoExpireDate());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method voidOrder_shouldUnsetDateStoppedOfThePreviousOrderIfTheSpecifiedOrderIsADiscontinuation.
/**
* @see OrderService#voidOrder(org.openmrs.Order, String)
*/
@Test
public void voidOrder_shouldUnsetDateStoppedOfThePreviousOrderIfTheSpecifiedOrderIsADiscontinuation() {
Order order = orderService.getOrder(22);
assertEquals(Action.DISCONTINUE, order.getAction());
Order previousOrder = order.getPreviousOrder();
assertNotNull(previousOrder.getDateStopped());
assertFalse(order.getVoided());
orderService.voidOrder(order, "None");
// Ensures order interceptor is okay with all the changes
Context.flushSession();
assertTrue(order.getVoided());
assertNull(previousOrder.getDateStopped());
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldNotAllowRevisingAnExpiredOrder.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldNotAllowRevisingAnExpiredOrder() {
Order originalOrder = orderService.getOrder(6);
assertNotNull(originalOrder.getAutoExpireDate());
assertTrue(originalOrder.getAutoExpireDate().before(new Date()));
Order revisedOrder = originalOrder.cloneForRevision();
revisedOrder.setEncounter(encounterService.getEncounter(6));
revisedOrder.setInstructions("Take after a meal");
revisedOrder.setOrderer(providerService.getProvider(1));
revisedOrder.setDateActivated(new Date());
revisedOrder.setAutoExpireDate(new Date());
expectedException.expect(CannotStopInactiveOrderException.class);
expectedException.expectMessage(mss.getMessage("Order.cannot.discontinue.inactive"));
orderService.saveOrder(revisedOrder, null);
}
use of org.openmrs.Order in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator() {
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, "orderEntry.OrderNumberGenerator");
Context.getAdministrationService().saveGlobalProperty(gp);
Order order = new TestOrder();
order.setPatient(patientService.getPatient(7));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setOrderType(orderService.getOrderType(2));
order.setEncounter(encounterService.getEncounter(3));
order.setDateActivated(new Date());
order = orderService.saveOrder(order, null);
assertTrue(order.getOrderNumber().startsWith(TimestampOrderNumberGenerator.ORDER_NUMBER_PREFIX));
}
Aggregations