Skip to content

Commit

Permalink
TRUNK-4571 - Get encounters by creation/modification date
Browse files Browse the repository at this point in the history
  • Loading branch information
jkondrat committed Feb 23, 2015
1 parent 78aee3d commit 027d9b7
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 34 deletions.
5 changes: 5 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
<version>1.7.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Feb 23, 2015

It does not look correct to me that we should include the findbugs library in the release. How do you feel about this? :)

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Feb 26, 2015

@jkondrat if we changed the scope to test or provided, would these annotations complain at runtime?
ReactiveX/RxJava#211

<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
16 changes: 15 additions & 1 deletion api/src/main/java/org/openmrs/api/EncounterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openmrs.annotation.Authorized;
import org.openmrs.api.db.EncounterDAO;
import org.openmrs.api.handler.EncounterVisitHandler;
import org.openmrs.parameter.EncounterSearchCriteria;
import org.openmrs.util.PrivilegeConstants;

/**
Expand Down Expand Up @@ -203,11 +204,24 @@ public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, D
* @should exclude voided encounters
* @should include voided encounters
*/
@Deprecated
@Authorized( { PrivilegeConstants.GET_ENCOUNTERS })
public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, Date toDate,
Collection<Form> enteredViaForms, Collection<EncounterType> encounterTypes, Collection<Provider> providers,
Collection<VisitType> visitTypes, Collection<Visit> visits, boolean includeVoided);

/**
* Get all encounters that match a variety of (nullable) criteria contained in the parameter object.
* Each extra value for a parameter that is provided acts as an "and" and will reduce the number of results returned
*
* @param encounterSearchCriteria the object containing search parameters
* @return a list of encounters ordered by increasing encounterDatetime
* @since 1.12
* @should get encounters by date changed
*/
@Authorized( { PrivilegeConstants.GET_ENCOUNTERS })
public List<Encounter> getEncounters(EncounterSearchCriteria encounterSearchCriteria);

/**
* Voiding a encounter essentially removes it from circulation
*
Expand Down Expand Up @@ -804,7 +818,7 @@ public List<Encounter> getEncounters(String query, Integer patientId, Integer st
* Unretire an EncounterRole. This brings back the given encounter role and says that it can be
* used again
*
* @param encounterRole the encounter role to unretire
* @param encounterType the encounter role to unretire
* @throws APIException
* @since 1.9
* @should unretire type and unmark attributes
Expand Down
24 changes: 8 additions & 16 deletions api/src/main/java/org/openmrs/api/db/EncounterDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package org.openmrs.api.db;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand All @@ -22,13 +21,11 @@
import org.openmrs.Encounter;
import org.openmrs.EncounterRole;
import org.openmrs.EncounterType;
import org.openmrs.Form;
import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.Provider;
import org.openmrs.Visit;
import org.openmrs.VisitType;
import org.openmrs.api.EncounterService;
import org.openmrs.parameter.EncounterSearchCriteria;

/**
* Encounter-related database functions
Expand Down Expand Up @@ -67,14 +64,9 @@ public interface EncounterDAO {
public List<Encounter> getEncountersByPatientId(Integer patientId) throws DAOException;

/**
* @see org.openmrs.api.EncounterService#getEncounters(org.openmrs.Patient,
* org.openmrs.Location, java.util.Date, java.util.Date, java.util.Collection,
* java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection,
* boolean)
* @see org.openmrs.api.EncounterService#getEncounters(org.openmrs.parameter.EncounterSearchCriteria)
*/
public List<Encounter> getEncounters(Patient patient, Location location, Date fromDate, Date toDate,
Collection<Form> enteredViaForms, Collection<EncounterType> encounterTypes, Collection<Provider> providers,
Collection<VisitType> visitTypes, Collection<Visit> visits, boolean includeVoided);
public List<Encounter> getEncounters(EncounterSearchCriteria encounterSearchCriteria);

/**
* Save an Encounter Type
Expand Down Expand Up @@ -199,7 +191,7 @@ public List<Encounter> getEncounters(Patient patient, Location location, Date fr
/**
* Saves an encounter role
*
* @param encounter role to be saved
* @param encounterRole role to be saved
* @throws org.openmrs.api.db.DAOException
*/
public EncounterRole saveEncounterRole(EncounterRole encounterRole) throws DAOException;
Expand Down Expand Up @@ -234,12 +226,12 @@ public List<Encounter> getEncounters(Patient patient, Location location, Date fr
* @param includeRetired include retired
* @return enconter roles
* @throws org.openmrs.api.db.DAOException
* @see org.openmrs.api.EncounterRoleService#getAllEncounterRoles(boolan includeRetired)
* @see org.openmrs.api.EncounterService#getAllEncounterRoles(boolean includeRetired)
*/
public List<EncounterRole> getAllEncounterRoles(boolean includeRetired) throws DAOException;

/**
* @see org.openmrs.api.EncounterRoleService#getEncounterRoleByName(String name)
* @see org.openmrs.api.EncounterService#getEncounterRoleByName(String name)
*/
public EncounterRole getEncounterRoleByName(String name) throws DAOException;

Expand All @@ -249,7 +241,7 @@ public List<Encounter> getEncounters(Patient patient, Location location, Date fr
public List<Encounter> getEncountersNotAssignedToAnyVisit(Patient patient) throws DAOException;

/**
* @see EncounterService#getEncountersByVisitsAndPatient(Patient, boolean, String, Date, Date)
* @see EncounterService#getEncountersByVisitsAndPatient(Patient, boolean, String, java.lang.Integer, java.lang.Integer)
*/
List<Encounter> getEncountersByVisitsAndPatient(Patient patient, boolean includeVoided, String query, Integer start,
Integer length);
Expand All @@ -265,7 +257,7 @@ List<Encounter> getEncountersByVisitsAndPatient(Patient patient, boolean include
* @param name encounter role name
* @return encounter roles
* @throws org.openmrs.api.db.DAOException
* @see org.openmrs.api.EncounterRoleService#getEncounterRolesByName(String name)
* @see org.openmrs.api.EncounterService#getEncounterRolesByName(String name)
*/

public List<EncounterRole> getEncounterRolesByName(String name) throws DAOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.openmrs.api.context.Context;
import org.openmrs.api.db.DAOException;
import org.openmrs.api.db.EncounterDAO;
import org.openmrs.parameter.EncounterSearchCriteria;

/**
* Hibernate specific dao for the {@link EncounterService} All calls should be made on the
Expand Down Expand Up @@ -110,15 +111,23 @@ public List<Encounter> getEncountersByPatientId(Integer patientId) throws DAOExc
}

/**
* @see org.openmrs.api.db.EncounterDAO#getEncounters(org.openmrs.Patient, org.openmrs.Location,
* java.util.Date, java.util.Date, java.util.Collection, java.util.Collection,
* java.util.Collection, boolean)
* @see org.openmrs.api.db.EncounterDAO#getEncounters(org.openmrs.parameter.EncounterSearchCriteria)
*/
@SuppressWarnings("unchecked")
@Override
public List<Encounter> getEncounters(Patient patient, Location location, Date fromDate, Date toDate,
Collection<Form> enteredViaForms, Collection<EncounterType> encounterTypes, Collection<Provider> providers,
Collection<VisitType> visitTypes, Collection<Visit> visits, boolean includeVoided) {
public List<Encounter> getEncounters(EncounterSearchCriteria encounterSearchCriteria) {

Patient patient = encounterSearchCriteria.getPatient();
Location location = encounterSearchCriteria.getLocation();
Date fromDate = encounterSearchCriteria.getFromDate();
Date toDate = encounterSearchCriteria.getToDate();
Date dateChanged = encounterSearchCriteria.getDateChanged();
Collection<Form> enteredViaForms = encounterSearchCriteria.getEnteredViaForms();
Collection<EncounterType> encounterTypes = encounterSearchCriteria.getEncounterTypes();
Collection<Provider> providers = encounterSearchCriteria.getProviders();
Collection<VisitType> visitTypes = encounterSearchCriteria.getVisitTypes();
Collection<Visit> visits = encounterSearchCriteria.getVisits();
Boolean includeVoided = encounterSearchCriteria.getIncludeVoided();

Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class);

Expand All @@ -134,6 +143,10 @@ public List<Encounter> getEncounters(Patient patient, Location location, Date fr
if (toDate != null) {
crit.add(Restrictions.le("encounterDatetime", toDate));
}
if (dateChanged != null) {
crit.add(Restrictions.or(Restrictions.and(Restrictions.isNull("dateChanged"), Restrictions.ge("dateCreated",
dateChanged)), Restrictions.ge("dateChanged", dateChanged)));
}
if (enteredViaForms != null && enteredViaForms.size() > 0) {
crit.add(Restrictions.in("form", enteredViaForms));
}
Expand Down Expand Up @@ -420,7 +433,7 @@ private Criteria createEncounterByQueryCriteria(String query, Integer patientId,
}

/**
* @see org.openmrs.api.db.EncounterDAO#getEncountersByVisit(Visit)
* @see org.openmrs.api.db.EncounterDAO#getEncountersByVisit(Visit, boolean)
*/
@Override
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -491,7 +504,7 @@ public EncounterRole getEncounterRoleByName(String name) throws DAOException {
* Convenience method since this DAO fetches several different domain objects by uuid
*
* @param uuid uuid to fetch
* @param table a simple classname (e.g. "Encounter")
* @param clazz a simple classname (e.g. "Encounter")
* @return
*/
@SuppressWarnings("unchecked")
Expand Down
41 changes: 35 additions & 6 deletions api/src/main/java/org/openmrs/api/impl/EncounterServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.openmrs.api.context.Context;
import org.openmrs.api.db.EncounterDAO;
import org.openmrs.api.handler.EncounterVisitHandler;
import org.openmrs.parameter.EncounterSearchCriteria;
import org.openmrs.util.HandlerUtil;
import org.openmrs.util.OpenmrsClassLoader;
import org.openmrs.util.OpenmrsConstants;
Expand Down Expand Up @@ -292,9 +293,16 @@ public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, D
public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, Date toDate,
Collection<Form> enteredViaForms, Collection<EncounterType> encounterTypes, Collection<User> providers,
boolean includeVoided) {
return Context.getEncounterService().filterEncountersByViewPermissions(
dao.getEncounters(who, loc, fromDate, toDate, enteredViaForms, encounterTypes, usersToProviders(providers),
null, null, includeVoided), null);
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteria();
encounterSearchCriteria.setPatient(who);
encounterSearchCriteria.setLocation(loc);
encounterSearchCriteria.setFromDate(fromDate);
encounterSearchCriteria.setToDate(toDate);
encounterSearchCriteria.setEnteredViaForms(enteredViaForms);
encounterSearchCriteria.setEncounterTypes(encounterTypes);
encounterSearchCriteria.setProviders(usersToProviders(providers));
encounterSearchCriteria.setIncludeVoided(includeVoided);
return this.getEncounters(encounterSearchCriteria);
}

/**
Expand All @@ -319,15 +327,36 @@ private Collection<Provider> usersToProviders(Collection<User> users) {
* @see org.openmrs.api.EncounterService#getEncounters(org.openmrs.Patient,
* org.openmrs.Location, java.util.Date, java.util.Date, java.util.Collection,
* java.util.Collection, java.util.Collection, boolean)
* @deprecated replaced by
* {@link #getEncounters(org.openmrs.parameter.EncounterSearchCriteria)}
*/
@Deprecated
@Override
@Transactional(readOnly = true)
public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, Date toDate,
Collection<Form> enteredViaForms, Collection<EncounterType> encounterTypes, Collection<Provider> providers,
Collection<VisitType> visitTypes, Collection<Visit> visits, boolean includeVoided) {
return Context.getEncounterService().filterEncountersByViewPermissions(
dao.getEncounters(who, loc, fromDate, toDate, enteredViaForms, encounterTypes, providers, visitTypes, visits,
includeVoided), null);
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteria();
encounterSearchCriteria.setPatient(who);
encounterSearchCriteria.setLocation(loc);
encounterSearchCriteria.setFromDate(fromDate);
encounterSearchCriteria.setToDate(toDate);
encounterSearchCriteria.setEnteredViaForms(enteredViaForms);
encounterSearchCriteria.setEncounterTypes(encounterTypes);
encounterSearchCriteria.setProviders(providers);
encounterSearchCriteria.setVisitTypes(visitTypes);
encounterSearchCriteria.setVisits(visits);
encounterSearchCriteria.setIncludeVoided(includeVoided);
return this.getEncounters(encounterSearchCriteria);
}

/**
* @see org.openmrs.api.EncounterService#getEncounters(org.openmrs.parameter.EncounterSearchCriteria)
*/
public List<Encounter> getEncounters(EncounterSearchCriteria encounterSearchCriteria) {
// the second search parameter is null as it defaults to authenticated user from context
return Context.getEncounterService().filterEncountersByViewPermissions(dao.getEncounters(encounterSearchCriteria),
null);
}

/**
Expand Down
Loading

0 comments on commit 027d9b7

Please sign in to comment.