use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndDrugNonCodedAndCareSettingExists.
/**
* @see OrderService#saveOrder(Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndDrugNonCodedAndCareSettingExists() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
final Concept nonCodedConcept = orderService.getNonCodedDrugConcept();
// sanity check that we have an active order for the same concept
DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(584);
assertTrue(duplicateOrder.isActive());
assertEquals(nonCodedConcept, duplicateOrder.getConcept());
DrugOrder drugOrder = duplicateOrder.copy();
drugOrder.setDrugNonCoded("non coded drug crocine");
expectedException.expect(AmbiguousOrderException.class);
expectedException.expectMessage("Order.cannot.have.more.than.one");
orderService.saveOrder(drugOrder, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldNotAllowEditingAnExistingOrder.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldNotAllowEditingAnExistingOrder() {
final DrugOrder order = (DrugOrder) orderService.getOrder(5);
expectedException.expect(UnchangeableObjectException.class);
expectedException.expectMessage("Order.cannot.edit.existing");
orderService.saveOrder(order, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldRevisePreviousNonCodedOrderIfItIsAlreadyExisting.
@Test
public void saveOrder_shouldRevisePreviousNonCodedOrderIfItIsAlreadyExisting() {
// We are trying to discontinue order id 584 in OrderServiceTest-nonCodedDrugs.xml
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584);
DrugOrder order = previousOrder.cloneForRevision();
order.setDateActivated(new Date());
order.setOrderer(providerService.getProvider(1));
order.setEncounter(encounterService.getEncounter(6));
order.setAsNeeded(true);
order.setPreviousOrder(previousOrder);
DrugOrder saveOrder = (DrugOrder) orderService.saveOrder(order, null);
Assert.assertTrue(saveOrder.getAsNeeded());
assertNotNull(orderService.getOrder(saveOrder.getOrderId()));
}
use of org.openmrs.DrugOrder 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.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldSetAutoExpireDateForReviseOrderWithSimpleDosingInstructions.
@Test
public void saveOrder_shouldSetAutoExpireDateForReviseOrderWithSimpleDosingInstructions() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrderAutoExpireDate.xml");
DrugOrder originalOrder = (DrugOrder) orderService.getOrder(111);
assertTrue(originalOrder.isActive());
DrugOrder revisedOrder = originalOrder.cloneForRevision();
revisedOrder.setOrderer(originalOrder.getOrderer());
revisedOrder.setEncounter(originalOrder.getEncounter());
revisedOrder.setNumRefills(0);
revisedOrder.setAutoExpireDate(null);
revisedOrder.setDuration(10);
revisedOrder.setDurationUnits(conceptService.getConcept(1001));
orderService.saveOrder(revisedOrder, null);
assertNotNull(revisedOrder.getAutoExpireDate());
}
Aggregations