From 7631c7ab29c21c4b11156af74ea2f42af9722ac6 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Feb 2023 14:30:23 +0500 Subject: [PATCH 1/2] chaged the ba Unique ID source to 1 --- opensrp-chw/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 7f885101af..5b1a3c73a6 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -234,7 +234,7 @@ android { versionName "1.0.8" buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10000' buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10000' - buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2' + buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '1' buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/ba/"' buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"' From 4cab193059b2b9c4a5f1f571dde2d89f5edb6d1f Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 17 Feb 2023 17:32:45 +0500 Subject: [PATCH 2/2] washCheck migration added --- build.gradle | 2 +- opensrp-chw/build.gradle | 2 +- .../chw/repository/ChwRepositoryFlv.java | 7 +++ .../chw/repository/ChwRepositoryFlv.java | 7 +++ .../chw/repository/ChwRepositoryFlv.java | 6 +++ .../chw/repository/ChwRepositoryFlv.java | 6 +++ .../chw/repository/ChwRepositoryFlv.java | 8 +++- .../chw/repository/ChwRepositoryFlv.java | 6 +++ .../chw/util/RepositoryUtils.java | 46 +++++++++++++++++-- .../chw/repository/ChwRepositoryFlv.java | 33 +------------ 10 files changed, 84 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index 7187516bb0..cdf12ebfef 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ allprojects { maven { url "https://cloudant.github.io/cloudant-sync-eap/repository" } maven { url 'https://maven.fabric.io/public' } maven { url "https://s3.amazonaws.com/repo.commonsware.com" } - maven { url 'https://nexus.pentaho.org/content/groups/omni/' } + // maven { url 'https://nexus.pentaho.org/content/groups/omni/' } maven { url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases' content { diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index 5b1a3c73a6..6a2e40c23c 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -286,7 +286,7 @@ android { buildConfigField "String", 'DEFAULT_LOCATION', '"VILLAGE/COMMUNAUTE"' buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5' buildConfigField "int", "MAX_READ_TIMEOUT", '5' - buildConfigField "int", "DATABASE_VERSION", '12' + buildConfigField "int", "DATABASE_VERSION", '13' } guinea { dimension = 'baseDimension' diff --git a/opensrp-chw/src/ba/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/ba/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index 0a4ab3f3e5..41329c4921 100644 --- a/opensrp-chw/src/ba/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/ba/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -102,6 +102,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 23: upgradeToVersion23(context, db); break; + case 24: + upgradeToVersion24(db); + default: break; } @@ -371,4 +374,8 @@ private static void upgradeToVersion23(Context context, SQLiteDatabase db) { } } + private static void upgradeToVersion24(SQLiteDatabase db) { + RepositoryUtils.reprocessWashCheckVisits(db); + } + } diff --git a/opensrp-chw/src/chad/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/chad/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index f50fdad831..08704796b7 100644 --- a/opensrp-chw/src/chad/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/chad/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -70,6 +70,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 15: upgradeToVersion15(db); break; + case 16: + upgradeToVersion16(db); + break; default: break; } @@ -214,6 +217,10 @@ private static void upgradeToVersion15(SQLiteDatabase db) { RepositoryUtils.updateNullEventIds(db); } + private static void upgradeToVersion16(SQLiteDatabase db) { + RepositoryUtils.reprocessWashCheckVisits(db); + } + private static void initializeIndicatorDefinitions(ReportingLibrary reportingLibrary, SQLiteDatabase sqLiteDatabase) { String childIndicatorsConfigFile = "config/child-reporting-indicator-definitions.yml"; String ancIndicatorConfigFile = "config/anc-reporting-indicator-definitions.yml"; diff --git a/opensrp-chw/src/drc/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/drc/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index a7075c42af..e51fe8096e 100644 --- a/opensrp-chw/src/drc/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/drc/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -48,6 +48,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 12: upgradeToVersion12(db); break; + case 13: + upgradeToVersion13(db); default: break; } @@ -165,4 +167,8 @@ private static void upgradeToVersion11(SQLiteDatabase db) { private static void upgradeToVersion12(SQLiteDatabase db) { RepositoryUtils.updateNullEventIds(db); } + + private static void upgradeToVersion13(SQLiteDatabase db) { + RepositoryUtils.reprocessWashCheckVisits(db); + } } diff --git a/opensrp-chw/src/guinea/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/guinea/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index 81e8ad5229..184f43b089 100644 --- a/opensrp-chw/src/guinea/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/guinea/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -50,6 +50,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 8: upgradeToVersion8(db); break; + case 9: + upgradeToVersion9(db); default: break; } @@ -158,5 +160,9 @@ private static void upgradeToVersion7(SQLiteDatabase db) { } } + private static void upgradeToVersion9(SQLiteDatabase db) { + RepositoryUtils.reprocessWashCheckVisits(db); + } + } diff --git a/opensrp-chw/src/liberia/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/liberia/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index d0b52a8cc2..5d7b6a97f6 100644 --- a/opensrp-chw/src/liberia/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/liberia/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -49,6 +49,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 8: upgradeToVersion8(db); break; + case 9: + upgradeToVersion9(db); default: break; } @@ -152,6 +154,10 @@ private static void upgradeToVersion7(SQLiteDatabase db) { } private static void upgradeToVersion8(SQLiteDatabase db) { - RepositoryUtils.updateNullEventIds(db); + RepositoryUtils.updateNullEventIds(db); + } + + private static void upgradeToVersion9(SQLiteDatabase db) { + RepositoryUtils.reprocessWashCheckVisits(db); } } \ No newline at end of file diff --git a/opensrp-chw/src/lmh/java/org/smartregister/chw/repository/ChwRepositoryFlv.java b/opensrp-chw/src/lmh/java/org/smartregister/chw/repository/ChwRepositoryFlv.java index 23a4e227ab..51a0136251 100644 --- a/opensrp-chw/src/lmh/java/org/smartregister/chw/repository/ChwRepositoryFlv.java +++ b/opensrp-chw/src/lmh/java/org/smartregister/chw/repository/ChwRepositoryFlv.java @@ -47,6 +47,8 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, case 7: upgradeToVersion7(db); break; + case 8: + upgradeToVersion8(db); default: break; } @@ -146,4 +148,8 @@ private static void upgradeToVersion7(SQLiteDatabase db) { Timber.e(e, "upgradeToVersion7"); } } + + private static void upgradeToVersion8(SQLiteDatabase db) { + RepositoryUtils.reprocessWashCheckVisits(db); + } } \ No newline at end of file diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java index abcb2e487f..7c98ded7cf 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/RepositoryUtils.java @@ -1,17 +1,18 @@ package org.smartregister.chw.util; -import static org.smartregister.repository.BaseRepository.TYPE_Synced; -import static org.smartregister.repository.BaseRepository.TYPE_Valid; - import android.database.Cursor; + import net.sqlcipher.database.SQLiteDatabase; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; +import org.smartregister.chw.anc.util.NCUtils; import org.smartregister.chw.application.ChwApplication; import org.smartregister.chw.core.application.CoreChwApplication; import org.smartregister.chw.core.utils.CoreConstants; +import org.smartregister.chw.dao.WashCheckDao; import org.smartregister.domain.Event; +import org.smartregister.domain.db.EventClient; import org.smartregister.family.util.DBConstants; import org.smartregister.repository.EventClientRepository; import org.smartregister.sync.helper.ECSyncHelper; @@ -22,6 +23,9 @@ import timber.log.Timber; +import static org.smartregister.repository.BaseRepository.TYPE_Synced; +import static org.smartregister.repository.BaseRepository.TYPE_Valid; + public interface RepositoryUtils { String EVENT_ID = "id"; @@ -114,7 +118,7 @@ static List readEvents(Cursor cursor) { return events; } - static String getEventId(String jsonString) { + static String getEventId(String jsonString) { JSONObject jsonObject; String eventId = null; if (StringUtils.isNotEmpty(jsonString)) { @@ -132,4 +136,38 @@ static String getEventId(String jsonString) { return eventId; } + + static void reprocessWashCheckVisits(SQLiteDatabase db) { + try { + // add all the wash check tasks to the visit table // will assist the event + List wash_visits = WashCheckDao.getAllWashCheckVisits(db); + for (String visit_id : wash_visits) { + db.execSQL("delete from visits where visit_id = '" + visit_id + "'"); + db.execSQL("delete from visit_details where visit_id = '" + visit_id + "'"); + } + + // reprocess all wash check events + List eventClients = WashCheckDao.getWashCheckEvents(db); + for (EventClient eventClient : eventClients) { + if (eventClient == null) continue; + + NCUtils.processHomeVisit(eventClient); // save locally + } + + // add missing columns to the DB + List columns = new ArrayList<>(); + columns.add(ChildDBConstants.KEY.RELATIONAL_ID); + DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.FAMILY_MEMBER, columns); + + // add missing columns + List child_columns = new ArrayList<>(); + child_columns.add(DBConstants.KEY.DOB); + child_columns.add(DBConstants.KEY.DATE_REMOVED); + DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.CHILD, child_columns); + + } catch (Exception e) { + Timber.e(e); + } + } + } 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 e7fbba4475..0dfd166f50 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 @@ -18,7 +18,6 @@ import org.smartregister.chw.core.utils.ChildDBConstants; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.chw.dao.ChwPNCDao; -import org.smartregister.chw.dao.WashCheckDao; import org.smartregister.chw.domain.PNCHealthFacilityVisitSummary; import org.smartregister.chw.util.Constants; import org.smartregister.chw.util.PNCVisitUtil; @@ -28,7 +27,6 @@ import org.smartregister.domain.Event; import org.smartregister.domain.db.Column; import org.smartregister.domain.db.EventClient; -import org.smartregister.family.util.DBConstants; import org.smartregister.immunization.repository.RecurringServiceRecordRepository; import org.smartregister.immunization.repository.RecurringServiceTypeRepository; import org.smartregister.immunization.repository.VaccineRepository; @@ -232,36 +230,7 @@ private static void upgradeToVersion10(SQLiteDatabase db) { } private static void upgradeToVersion11(SQLiteDatabase db) { - try { - // add all the wash check tasks to the visit table // will assist the event - List wash_visits = WashCheckDao.getAllWashCheckVisits(db); - for (String visit_id : wash_visits) { - db.execSQL("delete from visits where visit_id = '" + visit_id + "'"); - db.execSQL("delete from visit_details where visit_id = '" + visit_id + "'"); - } - - // reprocess all wash check events - List eventClients = WashCheckDao.getWashCheckEvents(db); - for (EventClient eventClient : eventClients) { - if (eventClient == null) continue; - - NCUtils.processHomeVisit(eventClient); // save locally - } - - // add missing columns to the DB - List columns = new ArrayList<>(); - columns.add(ChildDBConstants.KEY.RELATIONAL_ID); - DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.FAMILY_MEMBER, columns); - - // add missing columns - List child_columns = new ArrayList<>(); - child_columns.add(DBConstants.KEY.DOB); - child_columns.add(DBConstants.KEY.DATE_REMOVED); - DatabaseMigrationUtils.addFieldsToFTSTable(db, CoreChwApplication.createCommonFtsObject(), CoreConstants.TABLE_NAME.CHILD, child_columns); - - } catch (Exception e) { - Timber.e(e); - } + RepositoryUtils.reprocessWashCheckVisits(db); } private static void upgradeToVersion12(SQLiteDatabase db, int oldDbVersion) {