Skip to content

Commit

Permalink
[ANDROSDK-1161] Order TEI query by lastUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarciabnz committed Jun 2, 2020
1 parent bbde3a7 commit f45445a
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
package org.hisp.dhis.android.core.trackedentity.search;

import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder;
import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper;
import org.hisp.dhis.android.core.arch.helpers.internal.EnumHelper;
import org.hisp.dhis.android.core.arch.repositories.scope.internal.FilterItemOperator;
import org.hisp.dhis.android.core.arch.repositories.scope.internal.RepositoryScopeFilterItem;
import org.hisp.dhis.android.core.common.AssignedUserMode;
Expand Down Expand Up @@ -60,7 +58,6 @@ final class TrackedEntityInstanceLocalQueryHelper {

private static String TEI_UID = dot(TEI_ALIAS, "uid");
private static String TEI_ALL = dot(TEI_ALIAS, "*");
private static String TEI_STATE = dot(TEI_ALIAS, DataColumns.STATE);
private static String TEI_LAST_UPDATED = dot(TEI_ALIAS, "lastUpdated");

private static String ENROLLMENT_DATE = EnrollmentTableInfo.Columns.ENROLLMENT_DATE;
Expand Down Expand Up @@ -132,16 +129,7 @@ static String getSqlQuery(TrackedEntityInstanceQueryRepositoryScope scope, List<
}

// TODO In case a program uid is provided, the server orders by enrollmentStatus.
String order1 = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
CollectionsHelper.withSingleQuotationMarksArray(
EnumHelper.asStringList(State.TO_POST, State.TO_UPDATE, State.UPLOADING)));
String order2 = CollectionsHelper.commaAndSpaceSeparatedArrayValues(
CollectionsHelper.withSingleQuotationMarksArray(
EnumHelper.asStringList(State.SYNCED, State.SYNCED_VIA_SMS, State.SENT_VIA_SMS)));
queryStr += " ORDER BY CASE " +
"WHEN " + TEI_STATE + " IN (" + order1 + ") THEN 1 " +
"WHEN " + TEI_STATE + " IN (" + order2 + ") THEN 2 ELSE 3 END ASC, " +
TEI_LAST_UPDATED + " DESC ";
queryStr += " ORDER BY " + TEI_LAST_UPDATED + " DESC ";

if (limit > 0) {
queryStr += " LIMIT " + limit;
Expand Down

0 comments on commit f45445a

Please sign in to comment.