Search in sources :

Example 16 with OrderSet

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

the class OrderSetServiceTest method shouldRetireOrderSetAndOrderSetMembersAsWell.

@Test
public void shouldRetireOrderSetAndOrderSetMembersAsWell() {
    executeDataSet(ORDER_SET);
    int initialNumberOfOrderSets = orderSetService.getOrderSets(false).size();
    OrderSet orderSet = orderSetService.getOrderSet(2001);
    orderSetService.retireOrderSet(orderSet, "Testing");
    Context.flushSession();
    int numberOfOrderSetsAfterRetire = orderSetService.getOrderSets(false).size();
    assertEquals(initialNumberOfOrderSets - 1, numberOfOrderSetsAfterRetire);
    OrderSet retiredOrderSet = orderSetService.getOrderSet(2001);
    assertEquals(true, retiredOrderSet.getRetired());
    List<OrderSetMember> orderSetMembers = retiredOrderSet.getOrderSetMembers();
    for (OrderSetMember orderSetMember : orderSetMembers) {
        assertTrue(orderSetMember.getRetired());
    }
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 17 with OrderSet

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

the class OrderSetServiceTest method shouldFetchUnRetiredOrderSetMembers.

@Test
public void shouldFetchUnRetiredOrderSetMembers() {
    executeDataSet(ORDER_SET);
    OrderSet orderSet = orderSetService.getOrderSet(2000);
    int initialCountOfMembers = orderSet.getOrderSetMembers().size();
    OrderSetMember orderSetMember = orderSet.getOrderSetMembers().get(0);
    // Retiring an orderSetMember in an existing list of orderSetMembers
    orderSet.retireOrderSetMember(orderSetMember);
    orderSetService.saveOrderSet(orderSet);
    Context.flushSession();
    OrderSet savedOrderSet = orderSetService.getOrderSetByUuid(orderSet.getUuid());
    assertEquals("Count of orderSetMembers are not changed if we get all members", initialCountOfMembers, savedOrderSet.getOrderSetMembers().size());
    // Fetching the unRetired members
    int finalSize = savedOrderSet.getUnRetiredOrderSetMembers().size();
    assertEquals("Count of orderSetMembers gets modified if we filter out the retired members", initialCountOfMembers - 1, finalSize);
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 18 with OrderSet

use of org.openmrs.OrderSet 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

OrderSet (org.openmrs.OrderSet)18 Test (org.junit.Test)17 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 Date (java.util.Date)11 OrderSetMember (org.openmrs.OrderSetMember)8 Encounter (org.openmrs.Encounter)6 Order (org.openmrs.Order)6 OrderGroup (org.openmrs.OrderGroup)6 TestOrder (org.openmrs.TestOrder)6 OrderBuilder (org.openmrs.api.builder.OrderBuilder)6 User (org.openmrs.User)5 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 DrugOrder (org.openmrs.DrugOrder)4 OrderUtilTest (org.openmrs.order.OrderUtilTest)4 HashMap (java.util.HashMap)1