diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 42410d87ae..87c75f77a7 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -310,8 +310,8 @@ android { togo { dimension = 'baseDimension' applicationIdSuffix ".togo" - versionCode 23 - versionName "1.2.5" + versionCode 26 + versionName "1.2.7" buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '1000' buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '500' buildConfigField "String", 'opensrp_url', '"https://wcaro-tg.smartregister.org/opensrp/"' @@ -322,13 +322,15 @@ android { buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village"}' buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"Village"' buildConfigField "String", 'DEFAULT_LOCATION', '"Village"' - buildConfigField "int", "DATABASE_VERSION", '20' + buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '10' + buildConfigField "int", "MAX_READ_TIMEOUT", '10' + buildConfigField "int", "DATABASE_VERSION", '21' } liberia { dimension = 'baseDimension' - versionCode 6 - versionName "0.1.12" - buildConfigField "String", 'opensrp_url', '"https://wcaro-liberia.smartregister.org/opensrp/"' + versionCode 7 + versionName "1.0.0" + buildConfigField "String", 'opensrp_url', '"https://wcaro-lr.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/liberia/"' buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"' buildConfigField "String[]", "LOCATION_HIERACHY", '{"Clinic" , "CHSS" , "CHA"}' @@ -336,6 +338,8 @@ android { buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Clinic" , "CHSS" , "CHA"}' buildConfigField "String", 'DEFAULT_LOCATION', '"Village"' buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"CHA"' + buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5' + buildConfigField "int", "MAX_READ_TIMEOUT", '5' buildConfigField "int", "DATABASE_VERSION", '7' } lmh { @@ -397,6 +401,8 @@ dependencies { //For viewing PDFs in the app implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1' + implementation 'com.github.lecho:hellocharts-android:v1.5.8@aar' + testImplementation "org.koin:koin-test:2.0.1" testImplementation 'junit:junit:4.13' testImplementation 'org.mockito:mockito-core:3.1.0' diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java b/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java index 60cd2f377b..e593ba6063 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/sync/ChwSyncIntentService.java @@ -1,22 +1,9 @@ package org.smartregister.chw.sync; -import org.smartregister.chw.dao.EventDao; import org.smartregister.sync.intent.SyncIntentService; public class ChwSyncIntentService extends SyncIntentService { - @Override - protected void handleSync() { - // fetch the last downloaded serverVersion before any unsyced data - Long serverVersion = EventDao.getMinimumVerifiedServerVersion(); - if (serverVersion != null) - org.smartregister.util.Utils.getAllSharedPreferences().saveLastSyncDate(serverVersion); - - // flag all contentious events as unsynced - EventDao.markEventsForReUpload(); - super.handleSync(); - } - @Override public int getEventPullLimit() { return 1000; @@ -24,6 +11,6 @@ public int getEventPullLimit() { @Override protected Integer getEventBatchSize(){ - return 250; - } + return 50; + } // Should this be configurable? } diff --git a/opensrp-chw/src/togo/java/org/smartregister/chw/application/ChwApplicationFlv.java b/opensrp-chw/src/togo/java/org/smartregister/chw/application/ChwApplicationFlv.java index 538e82908e..7335e0204e 100644 --- a/opensrp-chw/src/togo/java/org/smartregister/chw/application/ChwApplicationFlv.java +++ b/opensrp-chw/src/togo/java/org/smartregister/chw/application/ChwApplicationFlv.java @@ -1,4 +1,8 @@ package org.smartregister.chw.application; public class ChwApplicationFlv extends DefaultChwApplicationFlv { + @Override + public boolean showChildrenUnderFiveAndGirlsAgeNineToEleven() { + return true; + } } diff --git a/opensrp-chw/src/togo/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/togo/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index d07ce1ce9f..7dcee515f0 100644 --- a/opensrp-chw/src/togo/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/togo/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -1,10 +1,14 @@ package org.smartregister.chw.repository; +import static org.smartregister.repository.BaseRepository.TYPE_Synced; +import static org.smartregister.repository.BaseRepository.TYPE_Valid; + import android.content.Context; import android.database.Cursor; import net.sqlcipher.database.SQLiteDatabase; +import org.apache.commons.lang3.StringUtils; import org.joda.time.format.DateTimeFormat; import org.json.JSONObject; import org.smartregister.chw.anc.AncLibrary; @@ -51,6 +55,9 @@ public class ChwRepositoryFlv { + private static final String EVENT_ID = "id"; + private static final String _ID = "_id"; + public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, int newVersion) { Timber.w(ChwRepository.class.getName(), "Upgrading database from version " + oldVersion + " to " @@ -109,6 +116,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 20: upgradeToVersion20(db); break; + case 21: + upgradeToVersion21(db); + break; default: break; } @@ -116,14 +126,6 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, } } - private static void upgradeToVersion20(SQLiteDatabase db) { - try { - db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;"); - } catch (Exception e) { - Timber.e(e, "upgradeToVersion20"); - } - } - private static void upgradeToVersion2(Context context, SQLiteDatabase db) { try { db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_EVENT_ID_COL); @@ -336,6 +338,7 @@ private static List readEvents(Cursor cursor) { while (!cursor.isAfterLast()) { String json = cursor.getString(cursor.getColumnIndex("json")); Event event = syncHelper.convert(new JSONObject(json), Event.class); + event.setEventId(getEventId(json)); events.add(event); cursor.moveToNext(); } @@ -348,6 +351,24 @@ private static List readEvents(Cursor cursor) { return events; } + private static String getEventId(String jsonString) { + JSONObject jsonObject; + String eventId = null; + if (StringUtils.isNotEmpty(jsonString)) { + try { + jsonObject = new JSONObject(jsonString); + if (jsonObject.has(EVENT_ID)) { + eventId = jsonObject.getString(EVENT_ID); + }else if (jsonObject.has(_ID)) { + eventId = jsonObject.getString(_ID); + } + } catch (Exception ex) { + Timber.e(ex); + } + } + return eventId; + } + private static void processHFNextVisitDateObs(List events, SQLiteDatabase sqLiteDatabase) { // Save missing PNC Health Facility visit (next visit) details for (Event event : events) { @@ -420,17 +441,17 @@ private static void upgradeToVersion17(SQLiteDatabase db) { Timber.e(e, "upgradeToVersion17"); } } - + private static void upgradeToVersion18(SQLiteDatabase db) { try { ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance(); initializeIndicatorDefinitions(reportingLibraryInstance, db); - } catch (Exception e){ + } catch (Exception e) { Timber.e(e, "upgradeToVersion18"); } } - - private static void upgradeToVersion19(Context context, SQLiteDatabase db) { + + private static void upgradeToVersion19(Context context, SQLiteDatabase db) { try { db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL); db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_IS_VOIDED_COL_INDEX); @@ -440,4 +461,42 @@ private static void upgradeToVersion19(Context context, SQLiteDatabase db) { Timber.e(e); } } + + private static void upgradeToVersion20(SQLiteDatabase db) { + try { + db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;"); + } catch (Exception e) { + Timber.e(e, "upgradeToVersion20"); + } + } + + private static void upgradeToVersion21(SQLiteDatabase db) { + List events = new ArrayList<>(); + String eventTableName = EventClientRepository.Table.event.name(); + String eventIdCol = EventClientRepository.event_column.eventId.name(); + String eventSyncStatusCol = EventClientRepository.event_column.syncStatus.name(); + String eventValidCol = EventClientRepository.event_column.validationStatus.name(); + String jsonCol = EventClientRepository.event_column.json.name(); + String formSubmissionCol = EventClientRepository.event_column.formSubmissionId.name(); + + Cursor cursor; + String selection = eventIdCol + " IS NULL AND " + eventValidCol + " = ?"; + try { + cursor = db.query(eventTableName, new String[]{jsonCol}, + selection, new String[]{TYPE_Valid}, null, null, null); + events = readEvents(cursor); + } catch (Exception ex) { + Timber.e(ex); + } + String updateSQL; + for (Event event : events) { + updateSQL = String.format("UPDATE %s SET %s = '%s', %s = '%s' WHERE %s = '%s';", eventTableName, + eventIdCol, event.getEventId(), eventSyncStatusCol, TYPE_Synced, formSubmissionCol, event.getFormSubmissionId()); + try { + db.execSQL(updateSQL); + } catch (Exception e) { + Timber.e(e, "upgradeToVersion21 "); + } + } + } }