dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29936
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15188: Cleanup in tracker. Removed several methods from tracked entity instance store which now have bee...
------------------------------------------------------------
revno: 15188
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-05-07 11:03:42 +0200
message:
Cleanup in tracker. Removed several methods from tracked entity instance store which now have been replaced by the new TEI query api.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java
dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SelectAction.java
dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java 2014-05-04 14:04:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java 2014-05-07 09:03:42 +0000
@@ -298,26 +298,6 @@
Object getObjectValue( String property, String value, I18nFormat format );
/**
- * Get events which meet the criteria for searching
- *
- * @param searchKeys The key for searching entityInstances by attribute
- * values and/or a program
- * @param orgunit Organisation unit where entityInstances registered
- * @param followup Only getting entityInstances with program risked if this
- * property is true. And getting entityInstances without program
- * risked if its value is false
- * @param statusEnrollment The status of program of entityInstances. There
- * are three status, includes Active enrollments only, Completed
- * enrollments only and Active and completed enrollments
- * @parma min
- * @param max
- *
- * @return List of entityInstance
- */
- List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunit,
- Boolean followup, Integer statusEnrollment, Integer min, Integer max );
-
- /**
* Search entityInstances by phone number (performs partial search)
*
* @param phoneNumber The string for searching by phone number
@@ -382,47 +362,6 @@
Integer min, Integer max );
/**
- * Search entityInstances by attribute values and/or a program which
- * entityInstances enrolled into
- *
- * @param searchKeys The key for searching entityInstances by attribute
- * values, identifiers and/or a program
- * @param orgunit Organisation unit where entityInstances registered
- * @param followup Only getting entityInstances with program risked if this
- * property is true. And getting entityInstances without program
- * risked if its value is false
- * @param attributes The attribute values of these attribute are displayed
- * into result
- * @param statusEnrollment The status of program of entityInstances. There
- * are three status, includes Active enrollments only, Completed
- * enrollments only and Active and completed enrollments
- * @param min
- * @param max
- *
- * @return An object
- */
- Collection<TrackedEntityInstance> searchTrackedEntityInstances( List<String> searchKeys,
- Collection<OrganisationUnit> orgunit, Boolean followup, Collection<TrackedEntityAttribute> attributes,
- Integer statusEnrollment, Integer min, Integer max );
-
- /**
- * Get the number of entityInstances who meet the criteria for searching
- *
- * @param searchKeys The key for searching entityInstances by attribute
- * values and/or a program
- * @param orgunit Organisation unit where entityInstances registered
- * @param followup Only getting entityInstances with program risked if this
- * property is true. And getting entityInstances without program
- * risked if its value is false
- * @param statusEnrollment The status of program of entityInstances. There
- * are three status, includes Active enrollments only, Completed
- * enrollments only and Active and completed enrollments
- *
- * @return The number of entityInstances
- */
- int countSearchTrackedEntityInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunit,
- Boolean followup, Integer statusEnrollment );
- /**
* Get entityInstances by {@link TrackedEntity}
*
* @param trackedEntity {@link TrackedEntity}
@@ -430,5 +369,4 @@
* @return List of entityInstance
*/
Collection<TrackedEntityInstance> getTrackedEntityInstances( TrackedEntity trackedEntity );
-
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java 2014-05-04 14:04:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java 2014-05-07 09:03:42 +0000
@@ -127,29 +127,6 @@
Collection<TrackedEntityInstance> getByPhoneNumber( String phoneNumber, Integer min, Integer max );
/**
- * Search events which meet the criteria for searching
- *
- * @param searchKeys The key for searching entityInstances by attribute
- * values and/or a program
- * @param orgunit Organisation unit where entityInstances registered
- * @param followup Only getting entityInstances with program risked if this
- * property is true. And getting entityInstances without program
- * risked if its value is false
- * @param attributes The attribute values of these attribute are displayed
- * into result
- * @param statusEnrollment The status of program of entityInstances. There
- * are three status, includes Active enrollments only, Completed
- * enrollments only and Active and completed enrollments
- * @param min
- * @param max
- *
- * @return List of entityInstances
- */
- List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
- Boolean followup, Collection<TrackedEntityAttribute> attributes, Integer statusEnrollment, Integer min,
- Integer max );
-
- /**
* Search entityInstances who enrolled into a program with active status
*
* @param program Program
@@ -198,48 +175,6 @@
*/
Collection<TrackedEntityInstance> getByAttributeValue( String searchText, int attributeId, Integer min, Integer max );
- /**
- * Search entityInstances by attribute values and/or a program which
- * entityInstances enrolled into
- *
- * @param searchKeys The key for searching entityInstances by attribute
- * values, identifiers and/or a program
- * @param orgunit Organisation unit where entityInstances registered
- * @param followup Only getting entityInstances with program risked if this
- * property is true. And getting entityInstances without program
- * risked if its value is false
- * @param attributes The attribute values of these attribute are displayed
- * into result
- * @param statusEnrollment The status of program of entityInstances. There
- * are three status, includes Active enrollments only, Completed
- * enrollments only and Active and completed enrollments
- * @param min
- * @param max
- *
- * @return An object
- */
- Collection<TrackedEntityInstance> search( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
- Boolean followup, Collection<TrackedEntityAttribute> attributes, Integer statusEnrollment, Integer min,
- Integer max );
-
- /**
- * Get the number of entityInstances who meet the criteria for searching
- *
- * @param searchKeys The key for searching entityInstances by attribute
- * values and/or a program
- * @param orgunit Organisation unit where entityInstances registered
- * @param followup Only getting entityInstances with program risked if this
- * property is true. And getting entityInstances without program
- * risked if its value is false
- * @param statusEnrollment The status of program of entityInstances. There
- * are three status, includes Active enrollments only, Completed
- * enrollments only and Active and completed enrollments
- *
- * @return The number of entityInstances
- */
- int countSearch( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup,
- Integer statusEnrollment );
-
/**
* Get entityInstances by {@link TrackedEntity}
*
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-05-04 14:04:41 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-05-07 09:03:42 +0000
@@ -741,14 +741,6 @@
}
@Override
- public List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
- Boolean followup, Integer statusEnrollment, Integer min, Integer max )
- {
- return trackedEntityInstanceStore.getProgramStageInstances( searchKeys, orgunits, followup, null,
- statusEnrollment, min, max );
- }
-
- @Override
public Collection<TrackedEntityInstance> getTrackedEntityInstancesByPhone( String phoneNumber, Integer min,
Integer max )
{
@@ -800,27 +792,10 @@
{
return trackedEntityInstanceStore.getByAttributeValue( searchText, attributeId, min, max );
}
-
- @Override
- public Collection<TrackedEntityInstance> searchTrackedEntityInstances( List<String> searchKeys,
- Collection<OrganisationUnit> orgunits, Boolean followup, Collection<TrackedEntityAttribute> attributes,
- Integer statusEnrollment, Integer min, Integer max )
- {
- return trackedEntityInstanceStore.search( searchKeys, orgunits, followup, attributes, statusEnrollment, min,
- max );
- }
-
- @Override
- public int countSearchTrackedEntityInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
- Boolean followup, Integer statusEnrollment )
- {
- return trackedEntityInstanceStore.countSearch( searchKeys, orgunits, followup, statusEnrollment );
- }
@Override
public Collection<TrackedEntityInstance> getTrackedEntityInstances( TrackedEntity trackedEntity )
{
return trackedEntityInstanceStore.get( trackedEntity );
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java 2014-05-04 14:04:41 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java 2014-05-07 09:03:42 +0000
@@ -36,30 +36,20 @@
import static org.hisp.dhis.system.util.TextUtils.removeLastAnd;
import static org.hisp.dhis.system.util.TextUtils.removeLastComma;
import static org.hisp.dhis.system.util.TextUtils.removeLastOr;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM_EVENT_BY_STATUS;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM_INSTANCE;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_PROGRAM_STAGE;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.CREATED_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.LAST_UPDATED_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.ORG_UNIT_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.TRACKED_ENTITY_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.TRACKED_ENTITY_INSTANCE_ID;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Projections;
@@ -73,10 +63,8 @@
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramInstance;
-import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.program.ProgramStatus;
import org.hisp.dhis.system.util.SqlHelper;
import org.hisp.dhis.system.util.Timer;
@@ -88,7 +76,6 @@
import org.hisp.dhis.trackedentity.TrackedEntityInstanceStore;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.validation.ValidationCriteria;
-import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.transaction.annotation.Transactional;
@@ -100,8 +87,6 @@
extends HibernateIdentifiableObjectStore<TrackedEntityInstance>
implements TrackedEntityInstanceStore
{
- private static final Log log = LogFactory.getLog( HibernateTrackedEntityInstanceStore.class );
-
private static final Map<ProgramStatus, Integer> PROGRAM_STATUS_MAP = new HashMap<ProgramStatus, Integer>()
{
{
@@ -115,13 +100,6 @@
// Dependencies
// -------------------------------------------------------------------------
- private OrganisationUnitService organisationUnitService;
-
- public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
- {
- this.organisationUnitService = organisationUnitService;
- }
-
private StatementBuilder statementBuilder;
public void setStatementBuilder( StatementBuilder statementBuilder )
@@ -643,416 +621,6 @@
}
}
- @Override
- public List<Integer> getProgramStageInstances( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
- Boolean followup, Collection<TrackedEntityAttribute> attributes, Integer statusEnrollment, Integer min,
- Integer max )
- {
- String sql = searchTrackedEntityInstanceSql( false, searchKeys, orgunits, followup, attributes,
- statusEnrollment, min, max );
-
- List<Integer> programStageInstanceIds = new ArrayList<Integer>();
- try
- {
- programStageInstanceIds = jdbcTemplate.query( sql, new RowMapper<Integer>()
- {
- public Integer mapRow( ResultSet rs, int rowNum )
- throws SQLException
- {
- return rs.getInt( "programstageinstanceid" );
- }
- } );
- }
- catch ( Exception ex )
- {
- ex.printStackTrace();
- }
-
- return programStageInstanceIds;
- }
-
- private String searchTrackedEntityInstanceSql( boolean count, List<String> searchKeys,
- Collection<OrganisationUnit> orgunits, Boolean followup, Collection<TrackedEntityAttribute> attributes,
- Integer statusEnrollment, Integer min, Integer max )
- {
- String selector = count ? "count(*) " : "* ";
- String sql = "select " + selector + " from ( select distinct p.trackedentityinstanceid,";
-
- if ( attributes != null )
- {
- for ( TrackedEntityAttribute attribute : attributes )
- {
- sql += "(select value from trackedentityattributevalue where trackedentityinstanceid=p.trackedentityinstanceid and trackedentityattributeid="
- + attribute.getId() + " ) as " + PREFIX_TRACKED_ENTITY_ATTRIBUTE + "_" + attribute.getId() + " ,";
- }
- }
-
- String instanceWhere = "";
- String instanceOperator = " where ";
- String instanceGroupBy = " GROUP BY p.trackedentityinstanceid ";
- String otherWhere = "";
- String operator = " where ";
- String orderBy = "";
- boolean isSearchEvent = false;
- boolean isPriorityEvent = false;
- Collection<Integer> orgunitChilrenIds = null;
-
- if ( orgunits != null )
- {
- orgunitChilrenIds = getOrgunitChildren( orgunits );
- }
-
- for ( String searchKey : searchKeys )
- {
- String[] keys = searchKey.split( "_" );
-
- if ( keys.length <= 1 || keys[1] == null || keys[1].trim().isEmpty() || keys[1].equals( "null" ) )
- {
- continue;
- }
-
- String id = keys[1];
- String value = "";
-
- if ( keys.length >= 3 )
- {
- value = keys[2];
- }
-
- if ( keys[0].equals( PREFIX_TRACKED_ENTITY_ATTRIBUTE ) )
- {
- sql += "(select value from trackedentityattributevalue where trackedentityinstanceid=p.trackedentityinstanceid and trackedentityattributeid="
- + id + " ) as " + PREFIX_TRACKED_ENTITY_ATTRIBUTE + "_" + id + ",";
-
- String[] keyValues = value.split( " " );
- otherWhere += operator + "(";
- String opt = "";
-
- for ( String v : keyValues )
- {
- otherWhere += opt + " lower(" + PREFIX_TRACKED_ENTITY_ATTRIBUTE + "_" + id + ") like '%" + v + "%'";
- opt = "or";
- }
-
- otherWhere += ")";
- operator = " and ";
- }
- else if ( keys[0].equals( PREFIX_PROGRAM ) )
- {
- sql += "(select programid from programinstance pgi where trackedentityinstanceid=p.trackedentityinstanceid and programid="
- + id;
-
- if ( statusEnrollment != null )
- {
- sql += " and pgi.status=" + statusEnrollment;
- }
-
- sql += " limit 1 ) as " + PREFIX_PROGRAM + "_" + id + ",";
- otherWhere += operator + PREFIX_PROGRAM + "_" + id + "=" + id;
- operator = " and ";
- }
- else if ( keys[0].equals( PREFIX_PROGRAM_INSTANCE ) )
- {
- sql += "(select pi."
- + id
- + " from programinstance pi where trackedentityinstanceid=p.trackedentityinstanceid and pi.status=0 ";
-
- if ( keys.length == 5 )
- {
- sql += " and pi.programid=" + keys[4];
- }
- else
- {
- sql += " limit 1 ";
- }
-
- sql += ") as " + PREFIX_PROGRAM_INSTANCE + "_" + id + ",";
- otherWhere += operator + PREFIX_PROGRAM_INSTANCE + "_" + id + "='" + keys[2] + "'";
- operator = " and ";
- }
- else if ( keys[0].equals( PREFIX_PROGRAM_EVENT_BY_STATUS ) )
- {
- isSearchEvent = true;
- isPriorityEvent = Boolean.parseBoolean( keys[5] );
- instanceWhere += instanceOperator + "pgi.trackedentityinstanceid=p.trackedentityinstanceid and ";
- instanceWhere += "pgi.programid=" + id + " and ";
- instanceWhere += "pgi.status=" + ProgramInstance.STATUS_ACTIVE;
-
- String operatorStatus = "";
- String condition = " and ( ";
-
- for ( int index = 6; index < keys.length; index++ )
- {
- int statusEvent = Integer.parseInt( keys[index] );
- switch ( statusEvent )
- {
- case ProgramStageInstance.COMPLETED_STATUS:
- instanceWhere += condition + operatorStatus
- + "( psi.executiondate is not null and psi.executiondate>='" + keys[2]
- + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=true ";
-
- // get events by orgunit children
- if ( keys[4].equals( "-1" ) )
- {
- instanceWhere += " and psi.organisationunitid in( "
- + getCommaDelimitedString( orgunitChilrenIds ) + " )";
- }
-
- // get events by selected orgunit
- else if ( !keys[4].equals( "0" ) )
- {
- instanceWhere += " and psi.organisationunitid=" + getOrgUnitId( keys );
- }
-
- instanceWhere += ")";
- operatorStatus = " OR ";
- condition = "";
- continue;
- case ProgramStageInstance.VISITED_STATUS:
- instanceWhere += condition + operatorStatus
- + "( psi.executiondate is not null and psi.executiondate>='" + keys[2]
- + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=false ";
-
- // get events by orgunit children
- if ( keys[4].equals( "-1" ) )
- {
- instanceWhere += " and psi.organisationunitid in( "
- + getCommaDelimitedString( orgunitChilrenIds ) + " )";
- }
-
- // get events by selected orgunit
- else if ( !keys[4].equals( "0" ) )
- {
- instanceWhere += " and psi.organisationunitid=" + getOrgUnitId( keys );
- }
-
- instanceWhere += ")";
- operatorStatus = " OR ";
- condition = "";
- continue;
- case ProgramStageInstance.FUTURE_VISIT_STATUS:
- instanceWhere += condition + operatorStatus + "( psi.executiondate is null and psi.duedate>='"
- + keys[2] + "' and psi.duedate<='" + keys[3]
- + "' and psi.status is not null and (DATE(now()) - DATE(psi.duedate) <= 0) ";
-
- // get events by orgunit children
- if ( keys[4].equals( "-1" ) )
- {
- instanceWhere += " and p.organisationunitid in( "
- + getCommaDelimitedString( orgunitChilrenIds ) + " )";
- }
-
- // get events by selected orgunit
- else if ( !keys[4].equals( "0" ) )
- {
- instanceWhere += " and p.organisationunitid=" + getOrgUnitId( keys );
- }
-
- instanceWhere += ")";
- operatorStatus = " OR ";
- condition = "";
- continue;
- case ProgramStageInstance.LATE_VISIT_STATUS:
- instanceWhere += condition + operatorStatus + "( psi.executiondate is null and psi.duedate>='"
- + keys[2] + "' and psi.duedate<='" + keys[3]
- + "' and psi.status is not null and (DATE(now()) - DATE(psi.duedate) > 0) ";
-
- // get events by orgunit children
- if ( keys[4].equals( "-1" ) )
- {
- instanceWhere += " and p.organisationunitid in( "
- + getCommaDelimitedString( orgunitChilrenIds ) + " )";
- }
-
- // get events by selected orgunit
- else if ( !keys[4].equals( "0" ) )
- {
- instanceWhere += " and p.organisationunitid=" + getOrgUnitId( keys );
- }
-
- instanceWhere += ")";
- operatorStatus = " OR ";
- condition = "";
- continue;
- case ProgramStageInstance.SKIPPED_STATUS:
- instanceWhere += condition + operatorStatus + "( psi.status=5 and psi.duedate>='" + keys[2]
- + "' and psi.duedate<='" + keys[3] + "' ";
-
- // get events by orgunit children
- if ( keys[4].equals( "-1" ) )
- {
- instanceWhere += " and psi.organisationunitid in( "
- + getCommaDelimitedString( orgunitChilrenIds ) + " )";
- }
-
- // get events by selected orgunit
- else if ( !keys[4].equals( "0" ) )
- {
- instanceWhere += " and p.organisationunitid=" + getOrgUnitId( keys );
- }
- instanceWhere += ")";
- operatorStatus = " OR ";
- condition = "";
- continue;
- default:
- continue;
- }
- }
- if ( condition.isEmpty() )
- {
- instanceWhere += ")";
- }
-
- instanceWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";
- instanceOperator = " and ";
- }
- else if ( keys[0].equals( PREFIX_PROGRAM_STAGE ) )
- {
- isSearchEvent = true;
- instanceWhere += instanceOperator
- + "pgi.trackedentityinstanceid=p.trackedentityinstanceid and psi.programstageid=" + id + " and ";
- instanceWhere += "psi.duedate>='" + keys[3] + "' and psi.duedate<='" + keys[4] + "' and ";
- instanceWhere += "psi.organisationunitid = " + keys[5] + " and ";
-
- int statusEvent = Integer.parseInt( keys[2] );
- switch ( statusEvent )
- {
- case ProgramStageInstance.COMPLETED_STATUS:
- instanceWhere += "psi.completed=true";
- break;
- case ProgramStageInstance.VISITED_STATUS:
- instanceWhere += "psi.executiondate is not null and psi.completed=false";
- break;
- case ProgramStageInstance.FUTURE_VISIT_STATUS:
- instanceWhere += "psi.executiondate is null and psi.duedate >= now()";
- break;
- case ProgramStageInstance.LATE_VISIT_STATUS:
- instanceWhere += "psi.executiondate is null and psi.duedate < now()";
- break;
- default:
- break;
- }
-
- instanceWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";
- instanceOperator = " and ";
- }
- }
-
- if ( orgunits != null && !isSearchEvent )
- {
- sql += "(select organisationunitid from trackedentityinstance where trackedentityinstanceid=p.trackedentityinstanceid and organisationunitid in ( "
- + getCommaDelimitedString( getOrganisationUnitIds( orgunits ) ) + " ) ) as orgunitid,";
- otherWhere += operator + "orgunitid in ( " + getCommaDelimitedString( getOrganisationUnitIds( orgunits ) )
- + " ) ";
- }
-
- sql = sql.substring( 0, sql.length() - 1 ) + " "; // Removing last comma
-
- String from = " from trackedentityinstance p ";
-
- if ( isSearchEvent )
- {
- String subSQL = " , psi.programstageinstanceid as programstageinstanceid, pgs.name as programstagename, psi.duedate as duedate ";
-
- if ( isPriorityEvent )
- {
- subSQL += ",pgi.followup ";
- orderBy = " ORDER BY pgi.followup desc, p.trackedentityinstanceid, duedate asc ";
- instanceGroupBy += ",pgi.followup ";
- }
- else
- {
- orderBy = " ORDER BY p.trackedentityinstanceid, duedate asc ";
- }
-
- sql = sql + subSQL + from + " inner join programinstance pgi on "
- + " (pgi.trackedentityinstanceid=p.trackedentityinstanceid) "
- + " inner join programstageinstance psi on (psi.programinstanceid=pgi.programinstanceid) "
- + " inner join programstage pgs on (pgs.programstageid=psi.programstageid) ";
-
- instanceGroupBy += ",psi.programstageinstanceid, pgs.name, psi.duedate ";
-
- from = " ";
- }
-
- sql += from + instanceWhere;
- if ( followup != null )
- {
- sql += " AND pgi.followup=" + followup;
- }
- if ( isSearchEvent )
- {
- sql += instanceGroupBy;
- }
- sql += orderBy;
- sql += " ) as searchresult";
- sql += otherWhere;
-
- if ( min != null && max != null )
- {
- sql += " limit " + max + " offset " + min;
- }
-
- log.info( "Search tracked entity instance SQL: " + sql );
-
- return sql;
- }
-
- private Integer getOrgUnitId( String[] keys )
- {
- Integer orgUnitId;
- try
- {
- orgUnitId = Integer.parseInt( keys[4] );
- }
- catch ( NumberFormatException e )
- {
- // handle as uid
- OrganisationUnit ou = organisationUnitService.getOrganisationUnit( keys[4] );
- orgUnitId = ou.getId();
- }
- return orgUnitId;
- }
-
- private Collection<Integer> getOrgunitChildren( Collection<OrganisationUnit> orgunits )
- {
- Collection<Integer> orgUnitIds = new HashSet<Integer>();
-
- if ( orgunits != null )
- {
- for ( OrganisationUnit orgunit : orgunits )
- {
- orgUnitIds
- .addAll( organisationUnitService.getOrganisationUnitHierarchy().getChildren( orgunit.getId() ) );
- orgUnitIds.remove( orgunit.getId() );
- }
- }
-
- if ( orgUnitIds.size() == 0 )
- {
- orgUnitIds.add( 0 );
- }
-
- return orgUnitIds;
- }
-
- private Collection<Integer> getOrganisationUnitIds( Collection<OrganisationUnit> orgunits )
- {
- Collection<Integer> orgUnitIds = new HashSet<Integer>();
-
- for ( OrganisationUnit orgUnit : orgunits )
- {
- orgUnitIds.add( orgUnit.getId() );
- }
-
- if ( orgUnitIds.size() == 0 )
- {
- orgUnitIds.add( 0 );
- }
-
- return orgUnitIds;
- }
-
@SuppressWarnings( "unchecked" )
@Override
public Collection<TrackedEntityInstance> getByAttributeValue( String searchText, int attributeId, Integer min,
@@ -1079,41 +647,6 @@
return entityInstances;
}
-
- @Override
- public Collection<TrackedEntityInstance> search( List<String> searchKeys, Collection<OrganisationUnit> orgunits,
- Boolean followup, Collection<TrackedEntityAttribute> attributes, Integer statusEnrollment, Integer min,
- Integer max )
- {
- String sql = searchTrackedEntityInstanceSql( false, searchKeys, orgunits, followup, attributes,
- statusEnrollment, min, max );
- Collection<TrackedEntityInstance> instances = new HashSet<TrackedEntityInstance>();
- try
- {
- instances = jdbcTemplate.query( sql, new RowMapper<TrackedEntityInstance>()
- {
- public TrackedEntityInstance mapRow( ResultSet rs, int rowNum )
- throws SQLException
- {
- return get( rs.getInt( 1 ) );
- }
- } );
- }
- catch ( Exception ex )
- {
- ex.printStackTrace();
- }
- return instances;
- }
-
- @Override
- public int countSearch( List<String> searchKeys, Collection<OrganisationUnit> orgunits, Boolean followup,
- Integer statusEnrollment )
- {
- String sql = searchTrackedEntityInstanceSql( true, searchKeys, orgunits, followup, null, statusEnrollment,
- null, null );
- return jdbcTemplate.queryForObject( sql, Integer.class );
- }
@SuppressWarnings( "unchecked" )
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml 2014-05-04 14:04:41 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml 2014-05-07 09:03:42 +0000
@@ -77,8 +77,6 @@
<property name="clazz"
value="org.hisp.dhis.trackedentity.TrackedEntityInstance" />
<property name="sessionFactory" ref="sessionFactory" />
- <property name="organisationUnitService"
- ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="statementBuilder" ref="statementBuilder" />
</bean>
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java 2014-05-06 13:09:14 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetAttributesByProgramAction.java 2014-05-07 09:03:42 +0000
@@ -29,7 +29,6 @@
*/
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SelectAction.java 2014-05-06 13:09:14 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SelectAction.java 2014-05-07 09:03:42 +0000
@@ -29,7 +29,6 @@
*/
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
=== modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java'
--- dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java 2014-04-23 23:45:11 +0000
+++ dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/SearchPatientAction.java 2014-05-07 09:03:42 +0000
@@ -41,6 +41,7 @@
import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.trackedentity.TrackedEntityInstance;
+import org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams;
import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -139,10 +140,12 @@
orgunits.add( organisationUnit );
}
- total = patientService.countSearchTrackedEntityInstances( searchTexts, orgunits, null, ProgramInstance.STATUS_ACTIVE );
+ //TODO re-implement using TrackedEntityInstanceService.getTrackedEntityInstances( TrackedEntityInstanceQueryParams )
+
+ //total = patientService.countSearchTrackedEntityInstances( searchTexts, orgunits, null, ProgramInstance.STATUS_ACTIVE );
this.paging = createPaging( total );
- patients = patientService.searchTrackedEntityInstances( searchTexts, orgunits, null, null, ProgramInstance.STATUS_ACTIVE,
- paging.getStartPos(), paging.getPageSize() );
+ //patients = patientService.searchTrackedEntityInstances( searchTexts, orgunits, null, null, ProgramInstance.STATUS_ACTIVE,
+ // paging.getStartPos(), paging.getPageSize() );
if ( !searchBySelectedOrgunit )
{