Search in sources :

Example 11 with OrderSet

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

the class OrderSetServiceTest method shouldNotAutomaticallyPropagateToSetMembersIfExcludingOrderSet.

@Test
public void shouldNotAutomaticallyPropagateToSetMembersIfExcludingOrderSet() {
    executeDataSet(ORDER_SET);
    List<OrderSet> orderSets = orderSetService.getOrderSets(false);
    Integer numberOfOrderSetMembers = 0;
    for (OrderSet oS : orderSets) {
        numberOfOrderSetMembers = numberOfOrderSetMembers + oS.getOrderSetMembers().size();
    }
    assertEquals(new Integer(4), numberOfOrderSetMembers);
}
Also used : OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with OrderSet

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

the class EncounterServiceTest method shouldSaveOrderGroupAlongWithOrders.

@Test
public void shouldSaveOrderGroupAlongWithOrders() {
    executeDataSet(ORDER_SET);
    // Created a new Encounter
    Encounter encounter = new Encounter();
    encounter.setPatient(Context.getPatientService().getPatient(3));
    encounter.setEncounterType(Context.getEncounterService().getEncounterType(1));
    encounter.setEncounterDatetime(new Date());
    Context.getEncounterService().saveEncounter(encounter);
    Integer encounterId = Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getId();
    // Created a new OrderGroup
    OrderSet orderSet = Context.getOrderSetService().getOrderSet(2000);
    OrderGroup orderGroup = new OrderGroup();
    orderGroup.setOrderSet(orderSet);
    orderGroup.setPatient(encounter.getPatient());
    orderGroup.setEncounter(Context.getEncounterService().getEncounter(encounterId));
    // Added this OrderGroup to two new orders
    Order firstOrderWithOrderGroup = new OrderBuilder().withAction(Order.Action.NEW).withPatient(3).withConcept(1000).withCareSetting(1).withOrderer(1).withEncounter(encounterId).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(3).withConcept(1001).withCareSetting(1).withOrderer(1).withEncounter(encounterId).withDateActivated(new Date()).withOrderType(17).withUrgency(Order.Urgency.ON_SCHEDULED_DATE).withScheduledDate(new Date()).withOrderGroup(orderGroup).build();
    // Add these orders to the Encounter
    encounter.addOrder(firstOrderWithOrderGroup);
    encounter.addOrder(secondOrderWithOrderGroup);
    Context.getEncounterService().saveEncounter(encounter);
    Context.flushSession();
    List<Order> orders = new ArrayList<>(Context.getEncounterService().getEncounterByUuid(encounter.getUuid()).getOrders());
    assertNotNull("OrderGroup is saved", orders.get(0).getOrderGroup());
    assertEquals("OrderGroup isa same for both the orders ", true, orders.get(0).getOrderGroup().equals(orders.get(1).getOrderGroup()));
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) OrderSet(org.openmrs.OrderSet) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 13 with OrderSet

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

the class OrderSetServiceTest method orderSetBuilder.

private OrderSet orderSetBuilder(boolean orderSetRetired, boolean orderSetMemberRetired) {
    OrderSet orderSet = new OrderSet();
    orderSet.setName("Test Order Set");
    orderSet.setDescription("Test Order Set Description");
    orderSet.setOperator(OrderSet.Operator.ALL);
    OrderSetMember orderSetMember = new OrderSetMember();
    orderSetMember.setOrderType(orderService.getOrderType(100));
    orderSetMember.setConcept(conceptService.getConcept(1000));
    orderSetMember.setCreator(new User(1));
    orderSetMember.setDateCreated(new Date());
    orderSetMember.setRetired(orderSetMemberRetired);
    orderSetMember.setOrderSet(orderSet);
    List<OrderSetMember> orderSetMembers = new ArrayList<>(Collections.singletonList(orderSetMember));
    orderSet.setOrderSetMembers(orderSetMembers);
    orderSet.setCreator(new User(1));
    orderSet.setDateCreated(new Date());
    orderSet.setRetired(orderSetRetired);
    return orderSet;
}
Also used : OrderSetMember(org.openmrs.OrderSetMember) User(org.openmrs.User) OrderSet(org.openmrs.OrderSet) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 14 with OrderSet

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

the class OrderSetServiceTest method shouldSaveAndUpdateOrderSet.

@Test
public void shouldSaveAndUpdateOrderSet() {
    executeDataSet(ORDER_SET);
    OrderSet orderSet = orderSetBuilder(false, false);
    OrderSet orderSetObj = orderSetService.saveOrderSet(orderSet);
    orderSetObj.setOperator(OrderSet.Operator.ONE);
    orderSetObj.setDescription("Test Order Set Description Updated");
    assertNull("OrderSet is new and is not changed", orderSetObj.getChangedBy());
    assertNull("OrderSet is new and has no change date", orderSetObj.getDateChanged());
    orderSetService.saveOrderSet(orderSetObj);
    Context.flushSession();
    assertNotNull("OrderSet has a order_set_id", orderSetObj.getId());
    assertEquals("OrderSet has updated description", "Test Order Set Description Updated", orderSetObj.getDescription());
    assertEquals("OrderSet has updated operator", "ONE", orderSetObj.getOperator().toString());
    assertNotNull("OrderSet has been changed", orderSetObj.getChangedBy());
    assertNotNull("OrderSet has been changed on some date", orderSetObj.getDateChanged());
}
Also used : OrderSet(org.openmrs.OrderSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with OrderSet

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

the class OrderSetServiceTest method shouldAddOrderSetMemberAtLastPositionInsideAnExistingOrderSetIfPositionIsNull.

@Test
public void shouldAddOrderSetMemberAtLastPositionInsideAnExistingOrderSetIfPositionIsNull() {
    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);
    orderSet.addOrderSetMember(newOrderSetMember, null);
    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 last position", newOrderSetMember.getUuid(), savedOrderSet.getOrderSetMembers().get(initialSize).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)

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