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