Search in sources :

Example 6 with OrderBuilder

use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.

the class HibernateOrderDAOTest method saveOrderGroup_shouldSaveOrderGroup.

/**
 * @see {@link HibernateOrderDAO#saveOrderGroup(OrderGroup)}
 * @throws Exception
 */
@Test
public void saveOrderGroup_shouldSaveOrderGroup() {
    OrderGroup newOrderGroup = new OrderGroup();
    final Order order = 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()).build();
    newOrderGroup.setOrders(new ArrayList<Order>() {

        {
            add(order);
        }
    });
    OrderGroup savedOrderGroup = dao.saveOrderGroup(newOrderGroup);
    assertNotNull("OrderGroup gets saved", savedOrderGroup.getOrderGroupId());
    for (Order savedOrder : savedOrderGroup.getOrders()) {
        assertNull("Order is not saved as a part of Order Group", savedOrder.getOrderId());
    }
}
Also used : Order(org.openmrs.Order) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with OrderBuilder

use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.

the class OrderValidatorTest method saveOrder_shouldNotSaveOrderIfInvalidOrderGroupPatient.

@Test
public void saveOrder_shouldNotSaveOrderIfInvalidOrderGroupPatient() {
    executeDataSet(ORDER_SET);
    OrderGroup orderGroup = new OrderGroup();
    orderGroup.setEncounter(Context.getEncounterService().getEncounter(5));
    orderGroup.setPatient(Context.getPatientService().getPatient(2));
    Order order = 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();
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("patient"));
    Assert.assertEquals("Order.error.orderPatientAndOrderGroupPatientMismatch", errors.getFieldError("patient").getCode());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) OrderBuilder(org.openmrs.api.builder.OrderBuilder) Errors(org.springframework.validation.Errors) OrderGroup(org.openmrs.OrderGroup) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 8 with OrderBuilder

use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.

the class OrderValidatorTest method saveOrder_shouldNotSaveOrderIfInvalidOrderGroupEncounter.

@Test
public void saveOrder_shouldNotSaveOrderIfInvalidOrderGroupEncounter() {
    executeDataSet(ORDER_SET);
    OrderGroup orderGroup = new OrderGroup();
    orderGroup.setEncounter(Context.getEncounterService().getEncounter(5));
    Order order = 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();
    Errors errors = new BindException(order, "order");
    new OrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasErrors());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) DrugOrder(org.openmrs.DrugOrder) OrderBuilder(org.openmrs.api.builder.OrderBuilder) Errors(org.springframework.validation.Errors) OrderGroup(org.openmrs.OrderGroup) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 9 with OrderBuilder

use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.

the class OrderServiceTest method shouldSetTheCorrectSortWeightWhenAddingAnOrderAtAPosition.

@Test
public void shouldSetTheCorrectSortWeightWhenAddingAnOrderAtAPosition() {
    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 newOrderAtPosition1 = 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();
    Order newOrderAtPosition2 = 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(newOrderAtPosition1, 0);
    savedOrderGroup.addOrder(newOrderAtPosition2, 1);
    Context.getOrderService().saveOrderGroup(savedOrderGroup);
    OrderGroup secondSavedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
    assertEquals(4, savedOrderGroup.getOrders().size());
    assertEquals("The first order in  savedOrderGroup is the same which is sent first in the List", newOrderAtPosition1.getUuid(), secondSavedOrderGroup.getOrders().get(0).getUuid());
    assertEquals("The second order in  savedOrderGroup is the same which is sent second in the List", newOrderAtPosition2.getUuid(), secondSavedOrderGroup.getOrders().get(1).getUuid());
    assertEquals("The third order in  savedOrderGroup is the same which is sent third in the List", firstOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(2).getUuid());
    assertEquals("The fourth order in  savedOrderGroup is the same which is sent first in the List", secondOrderWithOrderGroup.getUuid(), savedOrderGroup.getOrders().get(3).getUuid());
    assertThat("The third order has a lower sortWeight than the fourth", savedOrderGroup.getOrders().get(2).getSortWeight().compareTo(savedOrderGroup.getOrders().get(3).getSortWeight()), is(-1));
    assertThat("The second order has a lower sortWeight than the third", savedOrderGroup.getOrders().get(1).getSortWeight().compareTo(savedOrderGroup.getOrders().get(2).getSortWeight()), is(-1));
    assertThat("The first order has a lower sortWeight than the second", savedOrderGroup.getOrders().get(0).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

Date (java.util.Date)9 Test (org.junit.Test)9 Order (org.openmrs.Order)9 OrderGroup (org.openmrs.OrderGroup)9 OrderBuilder (org.openmrs.api.builder.OrderBuilder)9 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)9 TestOrder (org.openmrs.TestOrder)8 DrugOrder (org.openmrs.DrugOrder)6 Encounter (org.openmrs.Encounter)6 OrderSet (org.openmrs.OrderSet)6 OrderUtilTest (org.openmrs.order.OrderUtilTest)6 LinkedHashSet (java.util.LinkedHashSet)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 ArrayList (java.util.ArrayList)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 HashMap (java.util.HashMap)1