Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mininum report data filter #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;

import org.apache.commons.lang3.StringUtils;
import org.smartregister.reporting.ReportingLibrary;
import org.smartregister.reporting.domain.CompositeIndicatorTally;
import org.smartregister.reporting.domain.IndicatorQuery;
Expand All @@ -20,6 +21,7 @@
import org.smartregister.reporting.repository.IndicatorQueryRepository;
import org.smartregister.reporting.repository.IndicatorRepository;
import org.smartregister.reporting.util.Constants;
import org.smartregister.reporting.util.ReportingUtils;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.util.Utils;

Expand Down Expand Up @@ -47,8 +49,9 @@

public class ReportIndicatorDaoImpl implements ReportIndicatorDao {
public static final String REPORT_LAST_PROCESSED_DATE = "REPORT_LAST_PROCESSED_DATE";
public static String DAILY_TALLY_DATE_FORMAT = "yyyy-MM-dd";

public static String DAILY_TALLY_DATE_FORMAT = "yyyy-MM-dd";
public static final String MIN_REPORT_DATE = ReportingUtils.getAllSharedPreferences().getPreference(Constants.ReportingConfig.MIN_REPORT_DATE);
public static String PREVIOUS_REPORT_DATES_QUERY = "select distinct eventDate, " + EventClientRepository.event_column.updatedAt + " from "
+ EventClientRepository.Table.event.name();

Expand Down Expand Up @@ -172,14 +175,23 @@ protected void saveTallies(Map<String, IndicatorQuery> indicatorQueries, Map.Ent
@VisibleForTesting
@NonNull
protected LinkedHashMap<String, Date> getReportEventDates(@NonNull Date timeNow, @Nullable String lastProcessedDate, @NonNull SQLiteDatabase database) {
String monthLimitQueryFilter = StringUtils.isNotBlank(MIN_REPORT_DATE) ?
EventClientRepository.event_column.eventDate + " > '" + MIN_REPORT_DATE + "'" : "";

ArrayList<HashMap<String, String>> values;
String resultQuery;
boolean hasMonthLimitFilter = StringUtils.isNotBlank(monthLimitQueryFilter);
if (lastProcessedDate == null || lastProcessedDate.isEmpty()) {
values = dailyIndicatorCountRepository.rawQuery(database, PREVIOUS_REPORT_DATES_QUERY);
resultQuery = hasMonthLimitFilter ? String.format("%s where %s", PREVIOUS_REPORT_DATES_QUERY, monthLimitQueryFilter) : PREVIOUS_REPORT_DATES_QUERY;
} else {
values = dailyIndicatorCountRepository.rawQuery(database, PREVIOUS_REPORT_DATES_QUERY.concat(" where " + EventClientRepository.event_column.updatedAt + " > '" + lastProcessedDate + "'" + " order by eventDate asc"));
if (hasMonthLimitFilter)
monthLimitQueryFilter = " and " + monthLimitQueryFilter;

resultQuery = PREVIOUS_REPORT_DATES_QUERY.concat(" where " + EventClientRepository.event_column.updatedAt + " > '" + lastProcessedDate + "'" + monthLimitQueryFilter + " order by eventDate asc");
}

values = dailyIndicatorCountRepository.rawQuery(database, resultQuery);

LinkedHashMap<String, Date> reportEventDates = new LinkedHashMap<>();

Date eventDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ interface IndicatorQueryRepository {

interface ReportingConfig {
String SHOULD_ALLOW_ZERO_TALLIES = "SHOULD_ALLOW_ZERO_TALLIES";
String MIN_REPORT_DATE = "MIN_REPORT_DATE";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;

import org.smartregister.util.Utils;

import java.util.ArrayList;

/**
* Created by Ephraim Kigamba - [email protected] on 2019-07-09
*/

public class ReportingUtils {
public class ReportingUtils extends Utils {

/**
* Checks if a column exists on the table. An {@link Exception} is expected to be thrown by the sqlite
Expand Down Expand Up @@ -83,7 +85,7 @@ public static boolean isTableExists(@NonNull SQLiteDatabase sqliteDatabase, @Non

public static ArrayList<Object[]> performQuery(@NonNull SQLiteDatabase sqliteDatabase, @NonNull String query) {
ArrayList<Object[]> rows = new ArrayList<>();
Cursor cursor = sqliteDatabase.rawQuery(query,null);
Cursor cursor = sqliteDatabase.rawQuery(query, null);
if (null != cursor) {
int cols = cursor.getColumnCount();
rows.add(cursor.getColumnNames());
Expand Down