Search in sources :

Example 36 with Order

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

the class OrderServiceTest method getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatientAndCareSetting.

/**
 * @see OrderService#getActiveOrders(org.openmrs.Patient, org.openmrs.OrderType,
 *      org.openmrs.CareSetting, java.util.Date)
 */
@Test
public void getActiveOrders_shouldReturnAllActiveOrdersForTheSpecifiedPatientAndCareSetting() {
    Patient patient = patientService.getPatient(2);
    CareSetting careSetting = orderService.getCareSetting(1);
    List<Order> orders = orderService.getActiveOrders(patient, null, careSetting, null);
    assertEquals(4, orders.size());
    Order[] expectedOrders = { orderService.getOrder(3), orderService.getOrder(444), orderService.getOrder(5), orderService.getOrder(7) };
    assertThat(orders, hasItems(expectedOrders));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 37 with Order

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

the class OrderServiceTest method discontinueOrder_shouldFailForAVoidedOrder.

/**
 * @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
 *      org.openmrs.Provider, org.openmrs.Encounter)
 */
@Test
public void discontinueOrder_shouldFailForAVoidedOrder() {
    Order orderToDiscontinue = orderService.getOrder(8);
    Encounter encounter = encounterService.getEncounter(3);
    assertTrue(orderToDiscontinue.getVoided());
    expectedException.expect(CannotStopInactiveOrderException.class);
    expectedException.expectMessage(mss.getMessage("Order.cannot.discontinue.inactive"));
    orderService.discontinueOrder(orderToDiscontinue, "testing", null, null, encounter);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 38 with Order

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

the class OrderServiceTest method unvoidOrder_shouldStopThePreviousOrderIfTheSpecifiedOrderIsADiscontinuation.

/**
 * @see OrderService#unvoidOrder(org.openmrs.Order)
 */
@Test
public void unvoidOrder_shouldStopThePreviousOrderIfTheSpecifiedOrderIsADiscontinuation() {
    Order order = orderService.getOrder(22);
    assertEquals(Action.DISCONTINUE, order.getAction());
    Order previousOrder = order.getPreviousOrder();
    assertNotNull(previousOrder.getDateStopped());
    assertFalse(order.getVoided());
    // void the DC order for testing purposes so we can unvoid it later
    orderService.voidOrder(order, "None");
    Context.flushSession();
    assertTrue(order.getVoided());
    assertNull(previousOrder.getDateStopped());
    orderService.unvoidOrder(order);
    Context.flushSession();
    assertFalse(order.getVoided());
    assertNotNull(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 39 with Order

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

the class OrderServiceTest method voidOrder_shouldVoidAnOrder.

/**
 * @see OrderService#voidOrder(org.openmrs.Order, String)
 */
@Test
public void voidOrder_shouldVoidAnOrder() {
    Order order = orderService.getOrder(1);
    assertFalse(order.getVoided());
    assertNull(order.getDateVoided());
    assertNull(order.getVoidedBy());
    assertNull(order.getVoidReason());
    orderService.voidOrder(order, "None");
    assertTrue(order.getVoided());
    assertNotNull(order.getDateVoided());
    assertNotNull(order.getVoidedBy());
    assertNotNull(order.getVoidReason());
}
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 40 with Order

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

the class OrderServiceTest method saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThisConcept() {
    Order previousOrder = orderService.getOrder(7);
    assertTrue(OrderUtilTest.isActiveOrder(previousOrder, null));
    Order order = previousOrder.cloneForDiscontinuing();
    order.setDateActivated(new Date());
    order.setOrderReasonNonCoded("Discontinue this");
    order.setEncounter(encounterService.getEncounter(6));
    order.setOrderer(providerService.getProvider(1));
    Concept newConcept = conceptService.getConcept(5089);
    assertFalse(previousOrder.getConcept().equals(newConcept));
    order.setConcept(newConcept);
    expectedException.expect(EditedOrderDoesNotMatchPreviousException.class);
    expectedException.expectMessage("The orderable of the previous order and the new one order don't match");
    orderService.saveOrder(order, null);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Concept(org.openmrs.Concept) Date(java.util.Date) 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