use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExists.
/**
* @see OrderService#saveOrder(Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExists() {
final Patient patient = patientService.getPatient(2);
final Concept triomuneThirty = conceptService.getConcept(792);
// sanity check that we have an active order for the same concept
DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(3);
assertTrue(duplicateOrder.isActive());
assertEquals(triomuneThirty, duplicateOrder.getConcept());
DrugOrder drugOrder = new DrugOrder();
drugOrder.setPatient(patient);
drugOrder.setCareSetting(orderService.getCareSetting(1));
drugOrder.setConcept(triomuneThirty);
drugOrder.setEncounter(encounterService.getEncounter(6));
drugOrder.setOrderer(providerService.getProvider(1));
drugOrder.setCareSetting(duplicateOrder.getCareSetting());
drugOrder.setDrug(duplicateOrder.getDrug());
drugOrder.setDose(duplicateOrder.getDose());
drugOrder.setDoseUnits(duplicateOrder.getDoseUnits());
drugOrder.setRoute(duplicateOrder.getRoute());
drugOrder.setFrequency(duplicateOrder.getFrequency());
drugOrder.setQuantity(duplicateOrder.getQuantity());
drugOrder.setQuantityUnits(duplicateOrder.getQuantityUnits());
drugOrder.setNumRefills(duplicateOrder.getNumRefills());
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_shouldSetConceptForDrugOrdersIfNull.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldSetConceptForDrugOrdersIfNull() {
Patient patient = patientService.getPatient(7);
CareSetting careSetting = orderService.getCareSetting(2);
OrderType orderType = orderService.getOrderTypeByName("Drug order");
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = encounterService.getEncounter(3);
order.setEncounter(encounter);
order.setPatient(patient);
order.setDrug(conceptService.getDrug(2));
order.setCareSetting(careSetting);
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDateActivated(encounter.getEncounterDatetime());
order.setOrderType(orderType);
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("None");
order.setDosingInstructions("Test Instruction");
orderService.saveOrder(order, null);
assertNotNull(order.getOrderId());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheDCOrder.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheDCOrder() {
final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(5);
assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null));
// create a different test drug
Drug discontinuationOrderDrug = new Drug();
discontinuationOrderDrug.setConcept(orderToDiscontinue.getConcept());
discontinuationOrderDrug = conceptService.saveDrug(discontinuationOrderDrug);
assertNotEquals(discontinuationOrderDrug, orderToDiscontinue.getDrug());
assertNotNull(orderToDiscontinue.getDrug());
DrugOrder order = orderToDiscontinue.cloneForRevision();
order.setDateActivated(new Date());
order.setOrderer(providerService.getProvider(1));
order.setEncounter(encounterService.getEncounter(6));
order.setDrug(discontinuationOrderDrug);
order.setOrderReasonNonCoded("Discontinue this");
expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
orderService.saveOrder(order, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheRevisedOrder.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldFailIfTheExistingDrugOrderMatchesTheConceptAndNotDrugOfTheRevisedOrder() {
final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(5);
// create a different test drug
Drug discontinuationOrderDrug = new Drug();
discontinuationOrderDrug.setConcept(orderToDiscontinue.getConcept());
discontinuationOrderDrug = conceptService.saveDrug(discontinuationOrderDrug);
assertNotEquals(discontinuationOrderDrug, orderToDiscontinue.getDrug());
assertNotNull(orderToDiscontinue.getDrug());
DrugOrder order = orderToDiscontinue.cloneForRevision();
order.setDateActivated(new Date());
order.setOrderer(providerService.getProvider(1));
order.setEncounter(encounterService.getEncounter(6));
order.setDrug(discontinuationOrderDrug);
expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
orderService.saveOrder(order, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveDrugOrdersWithTheSameDrug.
/**
* @see OrderServiceImpl#discontinueExistingOrdersIfNecessary()
*/
@Test(expected = AmbiguousOrderException.class)
public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveDrugOrdersWithTheSameDrug() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-ambiguousDrugOrders.xml");
DrugOrder order = new DrugOrder();
order.setAction(Order.Action.DISCONTINUE);
order.setOrderReasonNonCoded("Discontinue this");
order.setDrug(conceptService.getDrug(3));
order.setEncounter(encounterService.getEncounter(7));
order.setPatient(patientService.getPatient(9));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order = (DrugOrder) orderService.saveOrder(order, null);
}
Aggregations