diff --git a/opensrp-core/src/main/java/org/smartregister/job/DuplicateCleanerWorker.java b/opensrp-core/src/main/java/org/smartregister/job/DuplicateCleanerWorker.java index fb878525ad..bb0966cb33 100644 --- a/opensrp-core/src/main/java/org/smartregister/job/DuplicateCleanerWorker.java +++ b/opensrp-core/src/main/java/org/smartregister/job/DuplicateCleanerWorker.java @@ -34,6 +34,12 @@ public static boolean shouldSchedule() { return !allSharedPreferences.getBooleanPreference(AllConstants.PREF_KEY.DUPLICATE_IDS_FIXED); } + /** + * Schedule this job to run periodically + * + * @param context + * @param mins - Duration after which the job repeatedly runs. This should be at least 15 mins + */ public static void schedulePeriodically(Context context, int mins) { PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(DuplicateCleanerWorker.class, mins, TimeUnit.MINUTES) .build(); @@ -49,7 +55,7 @@ public Result doWork() { if (!allSharedPreferences.getBooleanPreference(AllConstants.PREF_KEY.DUPLICATE_IDS_FIXED)) { DuplicateZeirIdStatus duplicateZeirIdStatus = AppHealthUtils.cleanUniqueZeirIds(); - Timber.i("Doing some cleaning work"); + Timber.i("Started doing duplicate client-identifier cleanup"); if (duplicateZeirIdStatus != null && duplicateZeirIdStatus.equals(DuplicateZeirIdStatus.CLEANED)) { allSharedPreferences.saveBooleanPreference(AllConstants.PREF_KEY.DUPLICATE_IDS_FIXED, true); WorkManager.getInstance(mContext).cancelWorkById(this.getId()); diff --git a/opensrp-core/src/test/java/org/smartregister/repository/EventClientRepositoryTest.java b/opensrp-core/src/test/java/org/smartregister/repository/EventClientRepositoryTest.java index 222fb88758..8b27488bd6 100644 --- a/opensrp-core/src/test/java/org/smartregister/repository/EventClientRepositoryTest.java +++ b/opensrp-core/src/test/java/org/smartregister/repository/EventClientRepositoryTest.java @@ -748,7 +748,7 @@ public MatrixCursor getCursorMaxRowId() { public void testCleanDuplicateMotherIdsShouldFixAndMarkDuplicateClientsUnSynced() throws Exception { String DUPLICATES_SQL = "WITH duplicates AS ( " + " WITH clients AS ( " + - " SELECT baseEntityId, COALESCE(json_extract(json, '$.identifiers.ZEIR_ID'), json_extract(json, '$.identifiers.M_ZEIR_ID')) zeir_id " + + " SELECT baseEntityId, COALESCE(json_extract(json, '$.identifiers.ZEIR_ID'), json_extract(json, '$.identifiers.M_ZEIR_ID'), json_extract(json, '$.identifiers.zeir_id'), json_extract(json, '$.identifiers.ANC_ID')) zeir_id " + " FROM client " + " ) " + " SELECT b.* FROM (SELECT baseEntityId, zeir_id FROM clients GROUP BY zeir_id HAVING count(zeir_id) > 1) a " +