use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.
the class HibernateOrderDAOTest method saveOrderGroup_shouldSaveOrderGroup.
/**
* @see {@link HibernateOrderDAO#saveOrderGroup(OrderGroup)}
* @throws Exception
*/
@Test
public void saveOrderGroup_shouldSaveOrderGroup() {
OrderGroup newOrderGroup = new OrderGroup();
final Order order = 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()).build();
newOrderGroup.setOrders(new ArrayList<Order>() {
{
add(order);
}
});
OrderGroup savedOrderGroup = dao.saveOrderGroup(newOrderGroup);
assertNotNull("OrderGroup gets saved", savedOrderGroup.getOrderGroupId());
for (Order savedOrder : savedOrderGroup.getOrders()) {
assertNull("Order is not saved as a part of Order Group", savedOrder.getOrderId());
}
}
use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.
the class OrderValidatorTest method saveOrder_shouldNotSaveOrderIfInvalidOrderGroupPatient.
@Test
public void saveOrder_shouldNotSaveOrderIfInvalidOrderGroupPatient() {
executeDataSet(ORDER_SET);
OrderGroup orderGroup = new OrderGroup();
orderGroup.setEncounter(Context.getEncounterService().getEncounter(5));
orderGroup.setPatient(Context.getPatientService().getPatient(2));
Order order = 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();
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("patient"));
Assert.assertEquals("Order.error.orderPatientAndOrderGroupPatientMismatch", errors.getFieldError("patient").getCode());
}
use of org.openmrs.api.builder.OrderBuilder in project openmrs-core by openmrs.
the class OrderValidatorTest method saveOrder_shouldNotSaveOrderIfInvalidOrderGroupEncounter.
@Test
public void saveOrder_shouldNotSaveOrderIfInvalidOrderGroupEncounter() {
executeDataSet(ORDER_SET);
OrderGroup orderGroup = new OrderGroup();
orderGroup.setEncounter(Context.getEncounterService().getEncounter(5));
Order order = 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();
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasErrors());
}
use of org.openmrs.api.builder.OrderBuilder 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