use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveOrdersForTheGivenConcepts.
/**
* @see OrderServiceImpl#discontinueExistingOrdersIfNecessary()
*/
@Test(expected = AmbiguousOrderException.class)
public void saveOrder_shouldThrowAmbiguousOrderExceptionIfDisconnectingMultipleActiveOrdersForTheGivenConcepts() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinueAmbiguousOrderByConcept.xml");
DrugOrder order = new DrugOrder();
order.setAction(Order.Action.DISCONTINUE);
order.setOrderReasonNonCoded("Discontinue this");
order.setConcept(conceptService.getConcept(88));
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);
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldPassIfAnKnownDrugOrderForTheSameDrugFormulationSpecified.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext, org.openmrs.Order[])
*/
@Test
public void saveOrder_shouldPassIfAnKnownDrugOrderForTheSameDrugFormulationSpecified() {
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);
OrderContext orderContext = new OrderContext();
orderContext.setAttribute(OrderService.PARALLEL_ORDERS, new String[] { existingOrder.getUuid() });
orderService.saveOrder(order, orderContext);
assertNotNull(orderService.getOrder(order.getOrderId()));
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class OrderServiceTest method saveOrder_shouldFailForRevisionOrderIfAnActiveDrugOrderForTheSameConceptAndCareSettingsExists.
/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
@Test
@Ignore("Ignored because it fails after removal of deprecated methods TRUNK-4772")
public void saveOrder_shouldFailForRevisionOrderIfAnActiveDrugOrderForTheSameConceptAndCareSettingsExists() {
final Patient patient = patientService.getPatient(2);
final Concept aspirin = conceptService.getConcept(88);
DrugOrder firstOrder = new DrugOrder();
firstOrder.setPatient(patient);
firstOrder.setConcept(aspirin);
firstOrder.setEncounter(encounterService.getEncounter(6));
firstOrder.setOrderer(providerService.getProvider(1));
firstOrder.setCareSetting(orderService.getCareSetting(2));
firstOrder.setDrug(conceptService.getDrug(3));
firstOrder.setDateActivated(new Date());
firstOrder.setAutoExpireDate(DateUtils.addDays(new Date(), 10));
firstOrder.setDosingType(FreeTextDosingInstructions.class);
firstOrder.setDosingInstructions("2 for 5 days");
firstOrder.setQuantity(10.0);
firstOrder.setQuantityUnits(conceptService.getConcept(51));
firstOrder.setNumRefills(0);
orderService.saveOrder(firstOrder, null);
// New order in future for same concept and care setting
DrugOrder secondOrder = new DrugOrder();
secondOrder.setPatient(firstOrder.getPatient());
secondOrder.setConcept(firstOrder.getConcept());
secondOrder.setEncounter(encounterService.getEncounter(6));
secondOrder.setOrderer(providerService.getProvider(1));
secondOrder.setCareSetting(firstOrder.getCareSetting());
secondOrder.setDrug(conceptService.getDrug(3));
secondOrder.setDateActivated(new Date());
secondOrder.setScheduledDate(DateUtils.addDays(firstOrder.getEffectiveStopDate(), 1));
secondOrder.setUrgency(Order.Urgency.ON_SCHEDULED_DATE);
secondOrder.setDosingType(FreeTextDosingInstructions.class);
secondOrder.setDosingInstructions("2 for 5 days");
secondOrder.setQuantity(10.0);
secondOrder.setQuantityUnits(conceptService.getConcept(51));
secondOrder.setNumRefills(0);
orderService.saveOrder(secondOrder, null);
// Revise second order to have scheduled date overlapping with active order
DrugOrder revision = secondOrder.cloneForRevision();
revision.setScheduledDate(DateUtils.addDays(firstOrder.getEffectiveStartDate(), 2));
revision.setEncounter(encounterService.getEncounter(6));
revision.setOrderer(providerService.getProvider(1));
expectedException.expect(APIException.class);
expectedException.expectMessage("Order.cannot.have.more.than.one");
orderService.saveOrder(revision, null);
}
Aggregations