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