use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailDiscontinueNonCodedDrugOrderIfOrderableOfPreviousAndNewOrderDontMatch.
@Test
public void saveOrder_shouldFailDiscontinueNonCodedDrugOrderIfOrderableOfPreviousAndNewOrderDontMatch() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584);
DrugOrder drugOrder = previousOrder.cloneForDiscontinuing();
drugOrder.setDrugNonCoded("non coded drug citrigine");
drugOrder.setPreviousOrder(previousOrder);
drugOrder.setDateActivated(new Date());
drugOrder.setOrderer(providerService.getProvider(1));
drugOrder.setEncounter(encounterService.getEncounter(6));
expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
orderService.saveOrder(drugOrder, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldThrowAmbiguousOrderExceptionIfAnActiveDrugOrderForTheSameDrugFormulationExists.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldThrowAmbiguousOrderExceptionIfAnActiveDrugOrderForTheSameDrugFormulationExists() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrdersWithSameConceptAndDifferentFormAndStrength.xml");
final Patient patient = patientService.getPatient(2);
// sanity check that we have an active order for the same concept
DrugOrder existingOrder = (DrugOrder) orderService.getOrder(1000);
assertTrue(existingOrder.isActive());
// New Drug order
DrugOrder order = new DrugOrder();
order.setPatient(patient);
order.setDrug(existingOrder.getDrug());
order.setEncounter(encounterService.getEncounter(6));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(existingOrder.getCareSetting());
order.setDosingType(FreeTextDosingInstructions.class);
order.setDosingInstructions("2 for 5 days");
order.setQuantity(10.0);
order.setQuantityUnits(conceptService.getConcept(51));
order.setNumRefills(2);
expectedException.expect(AmbiguousOrderException.class);
expectedException.expectMessage("Order.cannot.have.more.than.one");
orderService.saveOrder(order, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailIfDrugNonCodedInPreviousDrugOrderDoesNotMatchThatOfTheRevisedDrugOrder.
@Test
public void saveOrder_shouldFailIfDrugNonCodedInPreviousDrugOrderDoesNotMatchThatOfTheRevisedDrugOrder() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
DrugOrder previousOrder = (DrugOrder) orderService.getOrder(584);
DrugOrder order = previousOrder.cloneForRevision();
String drugNonCodedParacetemol = "non coded aspirin";
order.setDateActivated(new Date());
order.setOrderer(providerService.getProvider(1));
order.setEncounter(encounterService.getEncounter(6));
assertFalse(previousOrder.getDrugNonCoded().equals(drugNonCodedParacetemol));
order.setDrugNonCoded(drugNonCodedParacetemol);
order.setPreviousOrder(previousOrder);
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 saveRetrospectiveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExistsAtOrderDateActivated.
@Test
public void saveRetrospectiveOrder_shouldFailIfAnActiveDrugOrderForTheSameConceptAndCareSettingExistsAtOrderDateActivated() throws ParseException {
executeDataSet("org/openmrs/api/include/OrderServiceTest-ordersWithAutoExpireDate.xml");
Date newOrderDateActivated = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2008-11-19 13:00:10");
final Patient patient = patientService.getPatient(12);
final Concept orderConcept = conceptService.getConcept(88);
// sanity check that we have an active order for the same concept
DrugOrder duplicateOrder = (DrugOrder) orderService.getOrder(202);
assertTrue(duplicateOrder.isActive(newOrderDateActivated));
assertEquals(orderConcept, duplicateOrder.getConcept());
DrugOrder order = new DrugOrder();
order.setPatient(patient);
order.setConcept(orderConcept);
order.setEncounter(encounterService.getEncounter(17));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(duplicateOrder.getCareSetting());
order.setDateActivated(newOrderDateActivated);
order.setDrug(duplicateOrder.getDrug());
order.setDose(duplicateOrder.getDose());
order.setDoseUnits(duplicateOrder.getDoseUnits());
order.setRoute(duplicateOrder.getRoute());
order.setFrequency(duplicateOrder.getFrequency());
order.setQuantity(duplicateOrder.getQuantity());
order.setQuantityUnits(duplicateOrder.getQuantityUnits());
order.setNumRefills(duplicateOrder.getNumRefills());
expectedException.expect(AmbiguousOrderException.class);
expectedException.expectMessage("Order.cannot.have.more.than.one");
orderService.saveRetrospectiveOrder(order, null);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfTheExistingDrugOrderMatchesTheConceptAndDrugOfTheDCOrder.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
public void saveOrder_shouldPassIfTheExistingDrugOrderMatchesTheConceptAndDrugOfTheDCOrder() {
final DrugOrder orderToDiscontinue = (DrugOrder) orderService.getOrder(444);
assertTrue(OrderUtilTest.isActiveOrder(orderToDiscontinue, null));
DrugOrder order = new DrugOrder();
order.setDrug(orderToDiscontinue.getDrug());
order.setOrderType(orderService.getOrderTypeByName("Drug order"));
order.setAction(Order.Action.DISCONTINUE);
order.setOrderReasonNonCoded("Discontinue this");
order.setPatient(orderToDiscontinue.getPatient());
order.setConcept(orderToDiscontinue.getConcept());
order.setOrderer(orderToDiscontinue.getOrderer());
order.setCareSetting(orderToDiscontinue.getCareSetting());
order.setEncounter(encounterService.getEncounter(6));
order.setDateActivated(new Date());
order.setDosingType(SimpleDosingInstructions.class);
order.setDose(orderToDiscontinue.getDose());
order.setDoseUnits(orderToDiscontinue.getDoseUnits());
order.setRoute(orderToDiscontinue.getRoute());
order.setFrequency(orderToDiscontinue.getFrequency());
order.setQuantity(orderToDiscontinue.getQuantity());
order.setQuantityUnits(orderToDiscontinue.getQuantityUnits());
order.setNumRefills(orderToDiscontinue.getNumRefills());
orderService.saveOrder(order, null);
Assert.assertNotNull("previous order should be discontinued", orderToDiscontinue.getDateStopped());
}
Aggregations