Search in sources :

Example 26 with Order

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

the class OrderServiceTest method saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThatOfTheRevisedOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldFailIfConceptInPreviousOrderDoesNotMatchThatOfTheRevisedOrder() {
    Order previousOrder = orderService.getOrder(7);
    Order order = previousOrder.cloneForRevision();
    order.setDateActivated(new Date());
    order.setOrderer(providerService.getProvider(1));
    order.setEncounter(encounterService.getEncounter(6));
    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)

Example 27 with Order

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

the class OrderServiceTest method shouldSetTheCorrectSortWeightWhenAddingAnOrderWithANegativePosition.

@Test
public void shouldSetTheCorrectSortWeightWhenAddingAnOrderWithANegativePosition() {
    executeDataSet(ORDER_SET);
    Encounter encounter = encounterService.getEncounter(3);
    OrderSet orderSet = Context.getOrderSetService().getOrderSet(2000);
    OrderGroup orderGroup = new OrderGroup();
    orderGroup.setOrderSet(orderSet);
    orderGroup.setPatient(encounter.getPatient());
    orderGroup.setEncounter(encounter);
    Order firstOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    Order secondOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    Set<Order> orders = new LinkedHashSet<>();
    orders.add(firstOrderWithOrderGroup);
    orders.add(secondOrderWithOrderGroup);
    encounter.setOrders(orders);
    for (OrderGroup og : encounter.getOrderGroups()) {
        if (og.getId() == null) {
            Context.getOrderService().saveOrderGroup(og);
        }
    }
    Context.flushSession();
    OrderGroup savedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
    Order newOrderWithNegativePosition = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(savedOrderGroup).build();
    savedOrderGroup.addOrder(newOrderWithNegativePosition, -1);
    Context.getOrderService().saveOrderGroup(savedOrderGroup);
    Context.flushSession();
    OrderGroup secondSavedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
    assertEquals(3, secondSavedOrderGroup.getOrders().size());
    assertEquals("The new order gets added at the last position", newOrderWithNegativePosition.getUuid(), secondSavedOrderGroup.getOrders().get(2).getUuid());
    assertThat("The new order has a higher sortWeight than the second", secondSavedOrderGroup.getOrders().get(2).getSortWeight().compareTo(secondSavedOrderGroup.getOrders().get(1).getSortWeight()), is(1));
    Order newOrderWithInvalidPosition = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(savedOrderGroup).build();
    expectedException.expect(APIException.class);
    expectedException.expectMessage("Cannot add a member which is out of range of the list");
    secondSavedOrderGroup.addOrder(newOrderWithInvalidPosition, secondSavedOrderGroup.getOrders().size() + 1);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) LinkedHashSet(java.util.LinkedHashSet) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) OrderSet(org.openmrs.OrderSet) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 28 with Order

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

the class OrderServiceTest method getRevisionOrder_shouldNotReturnAVoidedRevisionOrder.

/**
 * @see OrderService#getRevisionOrder(org.openmrs.Order)
 */
@Test
public void getRevisionOrder_shouldNotReturnAVoidedRevisionOrder() {
    Order order = orderService.getOrder(7);
    Order revision1 = order.cloneForRevision();
    revision1.setEncounter(order.getEncounter());
    revision1.setOrderer(order.getOrderer());
    orderService.saveOrder(revision1, null);
    assertEquals(revision1, orderService.getRevisionOrder(order));
    orderService.voidOrder(revision1, "Testing");
    assertThat(orderService.getRevisionOrder(order), is(nullValue()));
    // should return the new unvoided revision
    Order revision2 = order.cloneForRevision();
    revision2.setEncounter(order.getEncounter());
    revision2.setOrderer(order.getOrderer());
    orderService.saveOrder(revision2, null);
    assertEquals(revision2, orderService.getRevisionOrder(order));
}
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 29 with Order

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

the class OrderServiceTest method saveOrder_shouldNotAllowRevisingAStoppedOrder.

/**
 * @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
 */
@Test
public void saveOrder_shouldNotAllowRevisingAStoppedOrder() {
    Order originalOrder = orderService.getOrder(1);
    assertNotNull(originalOrder.getDateStopped());
    Order revisedOrder = originalOrder.cloneForRevision();
    revisedOrder.setEncounter(encounterService.getEncounter(4));
    revisedOrder.setInstructions("Take after a meal");
    revisedOrder.setOrderer(providerService.getProvider(1));
    revisedOrder.setDateActivated(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 30 with Order

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

the class OrderServiceTest method shouldSetTheCorrectSortWeightWhenAddingAnOrderInOrderGroup.

@Test
public void shouldSetTheCorrectSortWeightWhenAddingAnOrderInOrderGroup() {
    executeDataSet(ORDER_SET);
    Encounter encounter = encounterService.getEncounter(3);
    OrderSet orderSet = Context.getOrderSetService().getOrderSet(2000);
    OrderGroup orderGroup = new OrderGroup();
    orderGroup.setOrderSet(orderSet);
    orderGroup.setPatient(encounter.getPatient());
    orderGroup.setEncounter(encounter);
    Order firstOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    Order secondOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    Set<Order> orders = new LinkedHashSet<>();
    orders.add(firstOrderWithOrderGroup);
    orders.add(secondOrderWithOrderGroup);
    encounter.setOrders(orders);
    for (OrderGroup og : encounter.getOrderGroups()) {
        if (og.getId() == null) {
            Context.getOrderService().saveOrderGroup(og);
        }
    }
    Context.flushSession();
    OrderGroup savedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
    assertEquals("The first order in  savedOrderGroup is the same which is sent first in the List", firstOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(0).getUuid());
    assertEquals("The second order in  savedOrderGroup is the same which is sent second in the List", secondOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(1).getUuid());
    assertThat("The first order has a lower sortWeight than the second", savedOrderGroup.getOrders().get(0).getSortWeight().compareTo(savedOrderGroup.getOrders().get(1).getSortWeight()), is(-1));
    Order newOrderWithoutAnyPosition = new OrderBuilder().withAction(Order.Action.NEW).withPatient(7).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(3).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(savedOrderGroup).build();
    savedOrderGroup.addOrder(newOrderWithoutAnyPosition);
    Context.getOrderService().saveOrderGroup(savedOrderGroup);
    Context.flushSession();
    OrderGroup secondSavedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
    assertEquals("The first order in  savedOrderGroup is the same which is sent first in the List", firstOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(0).getUuid());
    assertEquals("The second order in  savedOrderGroup is the same which is sent second in the List", secondOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(1).getUuid());
    assertEquals("The third order in  savedOrderGroup is the same which is sent third in the List", secondSavedOrderGroup.getOrders().get(2).getUuid(), newOrderWithoutAnyPosition.getUuid());
    assertThat("The third order has a higher sortWeight than the second", savedOrderGroup.getOrders().get(2).getSortWeight().compareTo(savedOrderGroup.getOrders().get(1).getSortWeight()), is(1));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) LinkedHashSet(java.util.LinkedHashSet) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) OrderSet(org.openmrs.OrderSet) Encounter(org.openmrs.Encounter) 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