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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations