Search in sources :

Example 6 with OrderSetMember

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

the class OrderSetServiceTest method orderSetBuilder.

private OrderSet orderSetBuilder(boolean orderSetRetired, boolean orderSetMemberRetired) {
    OrderSet orderSet = new OrderSet();
    orderSet.setName("Test Order Set");
    orderSet.setDescription("Test Order Set Description");
    orderSet.setOperator(OrderSet.Operator.ALL);
    OrderSetMember orderSetMember = new OrderSetMember();
    orderSetMember.setOrderType(orderService.getOrderType(100));
    orderSetMember.setConcept(conceptService.getConcept(1000));
    orderSetMember.setCreator(new User(1));
    orderSetMember.setDateCreated(new Date());
    orderSetMember.setRetired(orderSetMemberRetired);
    orderSetMember.setOrderSet(orderSet);
    List<OrderSetMember> orderSetMembers = new ArrayList<>(Collections.singletonList(orderSetMember));
    orderSet.setOrderSetMembers(orderSetMembers);
    orderSet.setCreator(new User(1));
    orderSet.setDateCreated(new Date());
    orderSet.setRetired(orderSetRetired);
    return orderSet;
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) User(org.openmrs.User) OrderSet(org.openmrs.OrderSet) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 7 with OrderSetMember

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

the class OrderSetServiceTest method shouldAddOrderSetMemberAtLastPositionInsideAnExistingOrderSetIfPositionIsNull.

@Test
public void shouldAddOrderSetMemberAtLastPositionInsideAnExistingOrderSetIfPositionIsNull() {
    executeDataSet(ORDER_SET);
    OrderSet orderSet = orderSetService.getOrderSet(2001);
    Integer initialSize = orderSet.getOrderSetMembers().size();
    OrderSetMember newOrderSetMember = new OrderSetMember();
    newOrderSetMember.setOrderType(orderService.getOrderType(100));
    newOrderSetMember.setConcept(conceptService.getConcept(1002));
    newOrderSetMember.setCreator(new User(1));
    newOrderSetMember.setDateCreated(new Date());
    newOrderSetMember.setRetired(false);
    orderSet.addOrderSetMember(newOrderSetMember, null);
    Context.getOrderSetService().saveOrderSet(orderSet);
    Context.flushSession();
    OrderSet savedOrderSet = Context.getOrderSetService().getOrderSetByUuid(orderSet.getUuid());
    assertEquals("Size of the orderSetMembers got updated", initialSize + 1, savedOrderSet.getOrderSetMembers().size());
    assertEquals("New OrderSetMember got added at last position", newOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(initialSize).getUuid());
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) User(org.openmrs.User) OrderSet(org.openmrs.OrderSet) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with OrderSetMember

use of org.openmrs.OrderSetMember 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 9 with OrderSetMember

use of org.openmrs.OrderSetMember 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 10 with OrderSetMember

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

the class OrderSetServiceTest method shouldFetchOrderSetMemberByUuid.

@Test
public void shouldFetchOrderSetMemberByUuid() {
    String orderSetUuid = "2d3fb1d0-ae06-22e3-a5e2-0140211c2002";
    executeDataSet(ORDER_SET);
    OrderSetMember orderSetMember = orderSetService.getOrderSetMemberByUuid(orderSetUuid);
    assertNotNull(orderSetMember.getId());
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

OrderSetMember (org.openmrs.OrderSetMember)10 Test (org.junit.Test)8 OrderSet (org.openmrs.OrderSet)8 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)8 Date (java.util.Date)6 User (org.openmrs.User)5 ArrayList (java.util.ArrayList)2