Search in sources :

Example 66 with DrugOrder

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);
}
Also used : DrugOrder(org.openmrs.DrugOrder) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 67 with DrugOrder

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()));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 68 with DrugOrder

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);
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Patient(org.openmrs.Patient) Date(java.util.Date) Ignore(org.junit.Ignore) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

DrugOrder (org.openmrs.DrugOrder)68 Test (org.junit.Test)64 OrderUtilTest (org.openmrs.order.OrderUtilTest)64 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)64 BindException (org.springframework.validation.BindException)38 Errors (org.springframework.validation.Errors)38 Patient (org.openmrs.Patient)22 Date (java.util.Date)18 Encounter (org.openmrs.Encounter)17 Concept (org.openmrs.Concept)12 CareSetting (org.openmrs.CareSetting)11 Order (org.openmrs.Order)11 OrderType (org.openmrs.OrderType)11 TestOrder (org.openmrs.TestOrder)11 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)7 Drug (org.openmrs.Drug)7 GlobalProperty (org.openmrs.GlobalProperty)7 Calendar (java.util.Calendar)5 SimpleDateFormat (java.text.SimpleDateFormat)1 Ignore (org.junit.Ignore)1