Search in sources :

Example 41 with Encounter

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

the class HibernateEncounterDAO method getEncountersByVisit.

/**
 * @see org.openmrs.api.db.EncounterDAO#getEncountersByVisit(Visit, boolean)
 */
@Override
@SuppressWarnings("unchecked")
public List<Encounter> getEncountersByVisit(Visit visit, boolean includeVoided) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class).add(Restrictions.eq("visit", visit));
    if (!includeVoided) {
        crit.add(Restrictions.eq("voided", false));
    }
    crit.addOrder(Order.asc("encounterDatetime"));
    return crit.list();
}
Also used : Encounter(org.openmrs.Encounter) Criteria(org.hibernate.Criteria) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria)

Example 42 with Encounter

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

the class OrderServiceTest method saveOrder_shouldSetAutoExpireDateOfDrugOrderIfAutoExpireDateIsNotSet.

@Test
public void saveOrder_shouldSetAutoExpireDateOfDrugOrderIfAutoExpireDateIsNotSet() throws ParseException {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-drugOrderAutoExpireDate.xml");
    Drug drug = conceptService.getDrug(3000);
    DrugOrder drugOrder = new DrugOrder();
    Encounter encounter = encounterService.getEncounter(3);
    drugOrder.setEncounter(encounter);
    drugOrder.setPatient(patientService.getPatient(7));
    drugOrder.setCareSetting(orderService.getCareSetting(1));
    drugOrder.setOrderer(Context.getProviderService().getProvider(1));
    drugOrder.setDrug(drug);
    drugOrder.setDosingType(SimpleDosingInstructions.class);
    drugOrder.setDose(300.0);
    drugOrder.setDoseUnits(conceptService.getConcept(50));
    drugOrder.setQuantity(20.0);
    drugOrder.setQuantityUnits(conceptService.getConcept(51));
    drugOrder.setFrequency(orderService.getOrderFrequency(3));
    drugOrder.setRoute(conceptService.getConcept(22));
    drugOrder.setNumRefills(0);
    drugOrder.setOrderType(null);
    drugOrder.setDateActivated(TestUtil.createDateTime("2014-08-03"));
    // 20 days
    drugOrder.setDuration(20);
    drugOrder.setDurationUnits(conceptService.getConcept(1001));
    Order savedOrder = orderService.saveOrder(drugOrder, null);
    Order loadedOrder = orderService.getOrder(savedOrder.getId());
    Assert.assertEquals(TestUtil.createDateTime("2014-08-22 23:59:59"), loadedOrder.getAutoExpireDate());
}
Also used : Drug(org.openmrs.Drug) DrugOrder(org.openmrs.DrugOrder) DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 43 with Encounter

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

the class OrderServiceTest method shouldSetTheCorrectSortWeightWhenAddingAnOrderWithANegativePosition.

@Test
public void shouldSetTheCorrectSortWeightWhenAddingAnOrderWithANegativePosition() {
    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());
    Order newOrderWithNegativePosition = 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(newOrderWithNegativePosition, -1);
    Context.getOrderService().saveOrderGroup(savedOrderGroup);
    Context.flushSession();
    OrderGroup secondSavedOrderGroup = Context.getOrderService().getOrderGroupByUuid(orderGroup.getUuid());
    assertEquals(3, secondSavedOrderGroup.getOrders().size());
    assertEquals("The new order gets added at the last position", newOrderWithNegativePosition.getUuid(), secondSavedOrderGroup.getOrders().get(2).getUuid());
    assertThat("The new order has a higher sortWeight than the second", secondSavedOrderGroup.getOrders().get(2).getSortWeight().compareTo(secondSavedOrderGroup.getOrders().get(1).getSortWeight()), is(1));
    Order newOrderWithInvalidPosition = 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();
    expectedException.expect(APIException.class);
    expectedException.expectMessage("Cannot add a member which is out of range of the list");
    secondSavedOrderGroup.addOrder(newOrderWithInvalidPosition, secondSavedOrderGroup.getOrders().size() + 1);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) LinkedHashSet(java.util.LinkedHashSet) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) OrderSet(org.openmrs.OrderSet) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 44 with Encounter

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

the class OrderServiceTest method shouldSetTheCorrectSortWeightWhenAddingAnOrderInOrderGroup.

@Test
public void shouldSetTheCorrectSortWeightWhenAddingAnOrderInOrderGroup() {
    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 newOrderWithoutAnyPosition = 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(newOrderWithoutAnyPosition);
    Context.getOrderService().saveOrderGroup(savedOrderGroup);
    Context.flushSession();
    OrderGroup secondSavedOrderGroup = 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());
    assertEquals("The third order in  savedOrderGroup is the same which is sent third in the List", secondSavedOrderGroup.getOrders().get(2).getUuid(), newOrderWithoutAnyPosition.getUuid());
    assertThat("The third order has a higher sortWeight than the second", savedOrderGroup.getOrders().get(2).getSortWeight().compareTo(savedOrderGroup.getOrders().get(1).getSortWeight()), is(1));
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) LinkedHashSet(java.util.LinkedHashSet) OrderBuilder(org.openmrs.api.builder.OrderBuilder) OrderGroup(org.openmrs.OrderGroup) OrderSet(org.openmrs.OrderSet) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Example 45 with Encounter

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

the class OrderServiceTest method discontinueOrder_shouldFailForADiscontinuationOrder.

/**
 * @see OrderService#discontinueOrder(org.openmrs.Order, String, java.util.Date,
 *      org.openmrs.Provider, org.openmrs.Encounter)
 */
@Test
public void discontinueOrder_shouldFailForADiscontinuationOrder() {
    executeDataSet("org/openmrs/api/include/OrderServiceTest-discontinuedOrder.xml");
    Order discontinuationOrder = orderService.getOrder(26);
    assertEquals(Action.DISCONTINUE, discontinuationOrder.getAction());
    Encounter encounter = encounterService.getEncounter(3);
    expectedException.expect(CannotStopDiscontinuationOrderException.class);
    expectedException.expectMessage(mss.getMessage("Order.action.cannot.discontinue"));
    orderService.discontinueOrder(discontinuationOrder, "Test if I can discontinue this", null, null, encounter);
}
Also used : DrugOrder(org.openmrs.DrugOrder) TestOrder(org.openmrs.TestOrder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Order(org.openmrs.Order) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19