Search in sources :

Example 6 with OrderSet

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

the class OrderSetServiceTest method shouldRetrieveOrderSetMembersOfAnOrderSet.

@Test
public void shouldRetrieveOrderSetMembersOfAnOrderSet() {
    executeDataSet(ORDER_SET);
    OrderSet orderSet = orderSetService.getOrderSet(2001);
    assertEquals("OrderSet should contain orderSetmembers", 2, orderSet.getOrderSetMembers().size());
    OrderSet orderSet1 = orderSetService.getOrderSet(2000);
    assertEquals("OrderSet should not contain retired orderSetMembers", 2, orderSet1.getOrderSetMembers().size());
}
Also used : OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with OrderSet

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

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

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

the class OrderSetServiceTest method shouldSaveOrderSet.

@Test
public void shouldSaveOrderSet() {
    executeDataSet(ORDER_SET);
    Integer initialNumberOfOrderSets = orderSetService.getOrderSets(false).size();
    OrderSet orderSet = orderSetBuilder(false, false);
    OrderSet orderSetObj = orderSetService.saveOrderSet(orderSet);
    Context.flushSession();
    List<OrderSet> orderSets = orderSetService.getOrderSets(false);
    assertEquals("A new order set was saved to the exisiting list of order sets", initialNumberOfOrderSets + 1, orderSets.size());
    assertNotNull("OrderSet has a order_set_id", orderSetObj.getId());
}
Also used : OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with OrderSet

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

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