Search in sources :

Example 1 with DrugOrder

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

Example 2 with DrugOrder

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

Example 3 with DrugOrder

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

Example 4 with DrugOrder

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());
}
Also used : DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 5 with DrugOrder

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());
}
Also used : DrugOrder(org.openmrs.DrugOrder) 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