Search in sources :

Example 11 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldFailIfOrderTypeIsNullAndNotMappedToTheConceptClass.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfOrderTypeIsNullAndNotMappedToTheConceptClass() {
    Order order = new Order();
    order.setPatient(patientService.getPatient(7));
    order.setConcept(conceptService.getConcept(9));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    expectedException.expect(OrderEntryException.class);
    expectedException.expectMessage("Order.type.cannot.determine");
    orderService.saveOrder(order, null);
}
Also used : 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 12 with Order

use of org.openmrs.Order 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 13 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderServiceTest method voidOrder_shouldUnsetDateStoppedOfThePreviousOrderIfTheSpecifiedOrderIsADiscontinuation.

/**
 * @see OrderService#voidOrder(org.openmrs.Order, String)
 */
@Test
public void voidOrder_shouldUnsetDateStoppedOfThePreviousOrderIfTheSpecifiedOrderIsADiscontinuation() {
    Order order = orderService.getOrder(22);
    assertEquals(Action.DISCONTINUE, order.getAction());
    Order previousOrder = order.getPreviousOrder();
    assertNotNull(previousOrder.getDateStopped());
    assertFalse(order.getVoided());
    orderService.voidOrder(order, "None");
    // Ensures order interceptor is okay with all the changes
    Context.flushSession();
    assertTrue(order.getVoided());
    assertNull(previousOrder.getDateStopped());
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 14 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldNotAllowRevisingAnExpiredOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldNotAllowRevisingAnExpiredOrder() {
    Order originalOrder = orderService.getOrder(6);
    assertNotNull(originalOrder.getAutoExpireDate());
    assertTrue(originalOrder.getAutoExpireDate().before(new Date()));
    Order revisedOrder = originalOrder.cloneForRevision();
    revisedOrder.setEncounter(encounterService.getEncounter(6));
    revisedOrder.setInstructions("Take after a meal");
    revisedOrder.setOrderer(providerService.getProvider(1));
    revisedOrder.setDateActivated(new Date());
    revisedOrder.setAutoExpireDate(new Date());
    expectedException.expect(CannotStopInactiveOrderException.class);
    expectedException.expectMessage(mss.getMessage("Order.cannot.discontinue.inactive"));
    orderService.saveOrder(revisedOrder, null);
}
Also used : 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 15 with Order

use of org.openmrs.Order in project openmrs-core by openmrs.

the class OrderServiceTest method saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldSetTheOrderNumberReturnedByTheConfiguredGenerator() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, "orderEntry.OrderNumberGenerator");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Order order = new TestOrder();
    order.setPatient(patientService.getPatient(7));
    order.setConcept(conceptService.getConcept(5497));
    order.setOrderer(providerService.getProvider(1));
    order.setCareSetting(orderService.getCareSetting(1));
    order.setOrderType(orderService.getOrderType(2));
    order.setEncounter(encounterService.getEncounter(3));
    order.setDateActivated(new Date());
    order = orderService.saveOrder(order, null);
    assertTrue(order.getOrderNumber().startsWith(TimestampOrderNumberGenerator.ORDER_NUMBER_PREFIX));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) TestOrder(org.openmrs.TestOrder) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

Order (org.openmrs.Order)155 Test (org.junit.Test)133 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)115 TestOrder (org.openmrs.TestOrder)114 DrugOrder (org.openmrs.DrugOrder)106 OrderUtilTest (org.openmrs.order.OrderUtilTest)97 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)77 Date (java.util.Date)67 Encounter (org.openmrs.Encounter)41 Patient (org.openmrs.Patient)36 BindException (org.springframework.validation.BindException)20 Errors (org.springframework.validation.Errors)20 Concept (org.openmrs.Concept)15 CareSetting (org.openmrs.CareSetting)11 Obs (org.openmrs.Obs)11 SimpleDateFormat (java.text.SimpleDateFormat)10 OrderGroup (org.openmrs.OrderGroup)10 ArrayList (java.util.ArrayList)9 Calendar (java.util.Calendar)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9