Search in sources :

Example 1 with OrderSetMember

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

the class OrderSetServiceImpl method saveOrderSetInternal.

/**
 * @see org.openmrs.api.OrderSetService#saveOrderSet(OrderSet)
 */
private synchronized OrderSet saveOrderSetInternal(OrderSet orderSet) throws APIException {
    if (CollectionUtils.isEmpty(orderSet.getOrderSetMembers())) {
        return dao.save(orderSet);
    }
    for (OrderSetMember orderSetMember : orderSet.getOrderSetMembers()) {
        if (null == orderSetMember.getOrderSet()) {
            orderSetMember.setOrderSet(orderSet);
        }
    }
    for (OrderSetMember orderSetMember : orderSet.getOrderSetMembers()) {
        if (orderSetMember.getRetired()) {
            orderSetMember.setRetiredBy(Context.getAuthenticatedUser());
            orderSetMember.setDateRetired(new Date());
        }
    }
    return dao.save(orderSet);
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) Date(java.util.Date)

Example 2 with OrderSetMember

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

the class OrderSetServiceTest method shouldAddOrderSetMemberFromTheEndOfTheListIfNegativePositionIsGiven.

@Test
public void shouldAddOrderSetMemberFromTheEndOfTheListIfNegativePositionIsGiven() {
    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);
    Integer position = -2;
    orderSet.addOrderSetMember(newOrderSetMember, position);
    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 given position", newOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(position + initialSize + 1).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 3 with OrderSetMember

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

the class OrderSetServiceTest method shouldReturnInTheSameArrangementInWhichTheOrderSetMembersAreSaved.

@Test
public void shouldReturnInTheSameArrangementInWhichTheOrderSetMembersAreSaved() {
    executeDataSet(ORDER_SET);
    OrderSet newOrderSet = new OrderSet();
    newOrderSet.setOperator(OrderSet.Operator.ALL);
    newOrderSet.setName("NewOrderSet");
    newOrderSet.setDescription("New Order Set");
    OrderSetMember firstOrderSetMember = new OrderSetMember();
    firstOrderSetMember.setOrderType(orderService.getOrderType(100));
    firstOrderSetMember.setConcept(conceptService.getConcept(1000));
    firstOrderSetMember.setCreator(new User(1));
    firstOrderSetMember.setDateCreated(new Date());
    firstOrderSetMember.setRetired(false);
    OrderSetMember secondOrderSetMember = new OrderSetMember();
    secondOrderSetMember.setOrderType(orderService.getOrderType(100));
    secondOrderSetMember.setConcept(conceptService.getConcept(1001));
    secondOrderSetMember.setCreator(new User(1));
    secondOrderSetMember.setDateCreated(new Date());
    secondOrderSetMember.setRetired(false);
    OrderSetMember thirdOrderSetMember = new OrderSetMember();
    thirdOrderSetMember.setOrderType(orderService.getOrderType(100));
    thirdOrderSetMember.setConcept(conceptService.getConcept(1001));
    thirdOrderSetMember.setCreator(new User(1));
    thirdOrderSetMember.setDateCreated(new Date());
    thirdOrderSetMember.setRetired(false);
    List<OrderSetMember> orderSetMembers = new ArrayList<>(Arrays.asList(firstOrderSetMember, thirdOrderSetMember, secondOrderSetMember));
    newOrderSet.setOrderSetMembers(orderSetMembers);
    OrderSet savedOrderSet = orderSetService.saveOrderSet(newOrderSet);
    Context.flushSession();
    assertEquals(firstOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(0).getUuid());
    assertEquals(thirdOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(1).getUuid());
    assertEquals(secondOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(2).getUuid());
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) User(org.openmrs.User) OrderSet(org.openmrs.OrderSet) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with OrderSetMember

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

the class OrderSetServiceTest method shouldDeleteAnOrderSetMemberInAnOrderSet.

@Test
public void shouldDeleteAnOrderSetMemberInAnOrderSet() {
    executeDataSet(ORDER_SET);
    OrderSet orderSet = orderSetService.getOrderSet(2001);
    int initialCountOfMembers = orderSet.getOrderSetMembers().size();
    OrderSetMember orderSetMember = orderSet.getOrderSetMembers().get(0);
    // Removing an orderSetMember in an existing list of orderSetMembers
    orderSet.removeOrderSetMember(orderSetMember);
    orderSetService.saveOrderSet(orderSet);
    Context.flushSession();
    OrderSet savedOrderSet = orderSetService.getOrderSetByUuid(orderSet.getUuid());
    assertEquals("Count of orderSetMembers changes after removing a member from the orderSet", initialCountOfMembers - 1, savedOrderSet.getOrderSetMembers().size());
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with OrderSetMember

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

the class OrderSetServiceTest method shouldAddOrderSetMemberAtSomePositionInsideAnExistingOrderSet.

@Test
public void shouldAddOrderSetMemberAtSomePositionInsideAnExistingOrderSet() {
    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);
    Integer position = 2;
    orderSet.addOrderSetMember(newOrderSetMember, position);
    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 given position", newOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(position).getUuid());
    Integer newPosition = savedOrderSet.getOrderSetMembers().size() + 1;
    OrderSetMember orderSetMemberToBeAddedAtPosition = new OrderSetMember();
    orderSetMemberToBeAddedAtPosition.setOrderType(orderService.getOrderType(100));
    orderSetMemberToBeAddedAtPosition.setConcept(conceptService.getConcept(1002));
    orderSetMemberToBeAddedAtPosition.setCreator(new User(1));
    orderSetMemberToBeAddedAtPosition.setDateCreated(new Date());
    orderSetMemberToBeAddedAtPosition.setRetired(false);
    expectedException.expect(APIException.class);
    expectedException.expectMessage("Cannot add a member which is out of range of the list");
    orderSet.addOrderSetMember(orderSetMemberToBeAddedAtPosition, newPosition);
}
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)

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