Search in sources :

Example 11 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersByLocation.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldGetEncountersByLocation() {
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setLocation(new Location(1)).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(6, encounters.size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 12 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersByVisit.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection,
 *      boolean)
 */
@Test
public void getEncounters_shouldGetEncountersByVisit() {
    List<Visit> visits = new ArrayList<>();
    visits.add(new Visit(1));
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setVisits(visits).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(2, encounters.size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) Visit(org.openmrs.Visit) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 13 with EncounterSearchCriteria

use of org.openmrs.parameter.EncounterSearchCriteria in project openmrs-core by openmrs.

the class HibernateEncounterDAO method getEncounters.

/**
 * @see org.openmrs.api.db.EncounterDAO#getEncounters(org.openmrs.parameter.EncounterSearchCriteria)
 */
@SuppressWarnings("unchecked")
@Override
public List<Encounter> getEncounters(EncounterSearchCriteria searchCriteria) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class);
    if (searchCriteria.getPatient() != null && searchCriteria.getPatient().getPatientId() != null) {
        crit.add(Restrictions.eq("patient", searchCriteria.getPatient()));
    }
    if (searchCriteria.getLocation() != null && searchCriteria.getLocation().getLocationId() != null) {
        crit.add(Restrictions.eq("location", searchCriteria.getLocation()));
    }
    if (searchCriteria.getFromDate() != null) {
        crit.add(Restrictions.ge("encounterDatetime", searchCriteria.getFromDate()));
    }
    if (searchCriteria.getToDate() != null) {
        crit.add(Restrictions.le("encounterDatetime", searchCriteria.getToDate()));
    }
    if (searchCriteria.getDateChanged() != null) {
        crit.add(Restrictions.or(Restrictions.and(Restrictions.isNull("dateChanged"), Restrictions.ge("dateCreated", searchCriteria.getDateChanged())), Restrictions.ge("dateChanged", searchCriteria.getDateChanged())));
    }
    if (searchCriteria.getEnteredViaForms() != null && !searchCriteria.getEnteredViaForms().isEmpty()) {
        crit.add(Restrictions.in("form", searchCriteria.getEnteredViaForms()));
    }
    if (searchCriteria.getEncounterTypes() != null && !searchCriteria.getEncounterTypes().isEmpty()) {
        crit.add(Restrictions.in("encounterType", searchCriteria.getEncounterTypes()));
    }
    if (searchCriteria.getProviders() != null && !searchCriteria.getProviders().isEmpty()) {
        crit.createAlias("encounterProviders", "ep");
        crit.add(Restrictions.in("ep.provider", searchCriteria.getProviders()));
    }
    if (searchCriteria.getVisitTypes() != null && !searchCriteria.getVisitTypes().isEmpty()) {
        crit.createAlias("visit", "v");
        crit.add(Restrictions.in("v.visitType", searchCriteria.getVisitTypes()));
    }
    if (searchCriteria.getVisits() != null && !searchCriteria.getVisits().isEmpty()) {
        crit.add(Restrictions.in("visit", searchCriteria.getVisits()));
    }
    if (!searchCriteria.getIncludeVoided()) {
        crit.add(Restrictions.eq("voided", false));
    }
    crit.addOrder(Order.asc("encounterDatetime"));
    return crit.list();
}
Also used : Criteria(org.hibernate.Criteria) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria)

Aggregations

EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)13 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)12 Test (org.junit.Test)10 Encounter (org.openmrs.Encounter)10 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)10 ArrayList (java.util.ArrayList)4 EncounterService (org.openmrs.api.EncounterService)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Order (org.openmrs.Order)2 OrderService (org.openmrs.api.OrderService)2 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 Criteria (org.hibernate.Criteria)1 EncounterType (org.openmrs.EncounterType)1 Form (org.openmrs.Form)1 Location (org.openmrs.Location)1 Patient (org.openmrs.Patient)1 User (org.openmrs.User)1 Visit (org.openmrs.Visit)1 VisitType (org.openmrs.VisitType)1