From b5b5dbb236e0eb0cbd2cc75a5af562b1bba669b1 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 26 Jan 2023 19:31:46 +0500 Subject: [PATCH 01/30] added broadcast reciever and service to reprocess the client --- .../src/main/AndroidManifest.xml | 1 + .../giz/application/GizMalawiApplication.java | 4 ++ .../giz/job/GizMalawiJobCreator.java | 2 + .../giz/job/GizReProcessJob.java | 27 +++++++++++++ .../giz/recievers/SyncStatusReciever.java | 40 +++++++++++++++++++ .../giz/repository/GizEventRepository.java | 37 +++++++++++++++++ .../service/ReProcessSyncIntentService.java | 27 +++++++++++++ 7 files changed, 138 insertions(+) create mode 100644 opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizReProcessJob.java create mode 100644 opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/SyncStatusReciever.java create mode 100644 opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java diff --git a/opensrp-giz-malawi/src/main/AndroidManifest.xml b/opensrp-giz-malawi/src/main/AndroidManifest.xml index b35bd70ca..9bde642de 100644 --- a/opensrp-giz-malawi/src/main/AndroidManifest.xml +++ b/opensrp-giz-malawi/src/main/AndroidManifest.xml @@ -291,6 +291,7 @@ + formSubmissionIDs = new ArrayList<>(); + addFormSubmissionIds(formSubmissionIDs, missingClientRegister); + addFormSubmissionIds(formSubmissionIDs,missingECClient); + + + try { + if(formSubmissionIDs.size()>0) + GizUtils.initiateEventProcessing(formSubmissionIDs); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + public void addFormSubmissionIds(List ids, String query) + { + SQLiteDatabase database = getReadableDatabase(); + Cursor cursor = database.rawQuery(query, null); + int columnIndex = cursor.getColumnIndex("formSubmissionId"); + if(cursor.getCount() > 0) { + cursor.moveToFirst(); + do { + ids.add(cursor.getString(columnIndex)); + } while (cursor.moveToNext()); + } + cursor.close(); + } } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java new file mode 100644 index 000000000..3ed8a23a3 --- /dev/null +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java @@ -0,0 +1,27 @@ +package org.smartregister.giz.service; + +import android.app.IntentService; +import android.content.Intent; + +import androidx.annotation.Nullable; + +import org.smartregister.giz.application.GizMalawiApplication; + +public class ReProcessSyncIntentService extends IntentService { + + public static final String TAG = "ReValidateSyncIntentService"; + + public ReProcessSyncIntentService() + { + super(TAG); + } + + public ReProcessSyncIntentService(String name) { + super(name); + } + + @Override + protected void onHandleIntent(@Nullable Intent intent) { + GizMalawiApplication.getInstance().gizEventRepository().ReprocessClients(); + } +} From 21b014b738741e1db33594f5f7d189bc9f769c55 Mon Sep 17 00:00:00 2001 From: vend Date: Tue, 31 Jan 2023 05:21:19 +0500 Subject: [PATCH 02/30] added the corrections in the PR review --- .../giz/application/GizMalawiApplication.java | 4 ++-- ...essJob.java => GIZClientReprocessJob.java} | 2 +- .../giz/job/GizMalawiJobCreator.java | 4 ++-- ...va => GizReprocessSyncStatusReceiver.java} | 6 ++--- .../giz/repository/GizEventRepository.java | 22 +++++++++---------- .../service/ReProcessSyncIntentService.java | 4 ++-- 6 files changed, 20 insertions(+), 22 deletions(-) rename opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/{GizReProcessJob.java => GIZClientReprocessJob.java} (93%) rename opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/{SyncStatusReciever.java => GizReprocessSyncStatusReceiver.java} (85%) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/application/GizMalawiApplication.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/application/GizMalawiApplication.java index 65d731e7f..842d06542 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/application/GizMalawiApplication.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/application/GizMalawiApplication.java @@ -63,7 +63,7 @@ import org.smartregister.giz.job.GizMalawiJobCreator; import org.smartregister.giz.processor.GizMalawiProcessorForJava; import org.smartregister.giz.processor.TripleResultProcessor; -import org.smartregister.giz.recievers.SyncStatusReciever; +import org.smartregister.giz.recievers.GizReprocessSyncStatusReceiver; import org.smartregister.giz.repository.ChildAlertUpdatedRepository; import org.smartregister.giz.repository.ClientRegisterTypeRepository; import org.smartregister.giz.repository.DailyTalliesRepository; @@ -366,7 +366,7 @@ public void onCreate() { initOfflineSchedules(); SyncStatusBroadcastReceiver.init(this); - this.registerReceiver(new SyncStatusReciever(), + this.registerReceiver(new GizReprocessSyncStatusReceiver(), new IntentFilter(SyncStatusBroadcastReceiver.ACTION_SYNC_STATUS)); LocationHelper.init(GizUtils.ALLOWED_LEVELS, GizUtils.DEFAULT_LOCATION_LEVEL); jsonSpecHelper = new JsonSpecHelper(this); diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizReProcessJob.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java similarity index 93% rename from opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizReProcessJob.java rename to opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java index 2098024b0..705502740 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizReProcessJob.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java @@ -11,7 +11,7 @@ import org.smartregister.giz.service.ReProcessSyncIntentService; import org.smartregister.job.BaseJob; -public class GizReProcessJob extends BaseJob { +public class GIZClientReprocessJob extends BaseJob { public static final String TAG = "GizReValidationJob"; diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizMalawiJobCreator.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizMalawiJobCreator.java index c7b1af287..dc6cb89a9 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizMalawiJobCreator.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GizMalawiJobCreator.java @@ -54,8 +54,8 @@ public Job create(@NonNull String tag) { return new GizVaccineUpdateJob(); case ImageUploadServiceJob.TAG: return new ImageUploadServiceJob(); - case GizReProcessJob.TAG: - return new GizReProcessJob(); + case GIZClientReprocessJob.TAG: + return new GIZClientReprocessJob(); default: Timber.w(GizMalawiJobCreator.class.getCanonicalName(), "%s is not declared in Job Creator", tag); diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/SyncStatusReciever.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java similarity index 85% rename from opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/SyncStatusReciever.java rename to opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java index f9063d7e5..a6cb71650 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/SyncStatusReciever.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java @@ -6,7 +6,7 @@ import android.os.Bundle; import org.smartregister.domain.FetchStatus; -import org.smartregister.giz.job.GizReProcessJob; +import org.smartregister.giz.job.GIZClientReprocessJob; import java.io.Serializable; @@ -14,7 +14,7 @@ import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_FETCH_STATUS; -public class SyncStatusReciever extends BroadcastReceiver { +public class GizReprocessSyncStatusReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle data = intent.getExtras(); @@ -23,7 +23,7 @@ public void onReceive(Context context, Intent intent) { if (fetchStatusSerializable instanceof FetchStatus) { FetchStatus fetchStatus = (FetchStatus) fetchStatusSerializable; if (fetchStatus.equals(FetchStatus.fetched)) { - GizReProcessJob.scheduleJobImmediately(GizReProcessJob.TAG); + GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG); Timber.d("Broadcast data fetched"); } else if (fetchStatus.equals(FetchStatus.nothingFetched)) { Timber.d("Broadcast data not fetched"); diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index a7cf85585..d3f9a992a 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -11,6 +11,8 @@ import java.util.ArrayList; import java.util.List; +import timber.log.Timber; + public class GizEventRepository extends BaseRepository { public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType) { @@ -26,33 +28,29 @@ public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType) return hasEvent; } - public void ReprocessClients() - { + public void processSkippedClients() { String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'"; String missingECClient = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'"; List formSubmissionIDs = new ArrayList<>(); addFormSubmissionIds(formSubmissionIDs, missingClientRegister); - addFormSubmissionIds(formSubmissionIDs,missingECClient); - + addFormSubmissionIds(formSubmissionIDs, missingECClient); try { - if(formSubmissionIDs.size()>0) - GizUtils.initiateEventProcessing(formSubmissionIDs); + if (formSubmissionIDs.size() > 0) + GizUtils.initiateEventProcessing(formSubmissionIDs); } catch (Exception e) { - e.printStackTrace(); + Timber.e(e); } } - - public void addFormSubmissionIds(List ids, String query) - { + public void addFormSubmissionIds(List ids, String query) { SQLiteDatabase database = getReadableDatabase(); Cursor cursor = database.rawQuery(query, null); int columnIndex = cursor.getColumnIndex("formSubmissionId"); - if(cursor.getCount() > 0) { + if (cursor.getCount() > 0) { cursor.moveToFirst(); - do { + do { ids.add(cursor.getString(columnIndex)); } while (cursor.moveToNext()); } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java index 3ed8a23a3..bd8f70b84 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java @@ -9,7 +9,7 @@ public class ReProcessSyncIntentService extends IntentService { - public static final String TAG = "ReValidateSyncIntentService"; + public static final String TAG = "ReProcessSyncIntentService"; public ReProcessSyncIntentService() { @@ -22,6 +22,6 @@ public ReProcessSyncIntentService(String name) { @Override protected void onHandleIntent(@Nullable Intent intent) { - GizMalawiApplication.getInstance().gizEventRepository().ReprocessClients(); + GizMalawiApplication.getInstance().gizEventRepository().processSkippedClients(); } } From 16470ec611d30ab8ee575878fb54da8fc77e9172 Mon Sep 17 00:00:00 2001 From: vend Date: Tue, 31 Jan 2023 06:42:46 +0500 Subject: [PATCH 03/30] added UnitTest for GizEventRepository --- opensrp-giz-malawi/build.gradle | 2 + .../repository/GizEventRepositoryTest.java | 95 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 0273facee..3fd58b65a 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -404,6 +404,8 @@ dependencies { implementation "androidx.multidex:multidex:2.0.1" testImplementation "androidx.work:work-testing:2.7.1" + androidTestImplementation 'androidx.test:runner:1.3.0' + androidTestImplementation 'androidx.test:core:1.3.0' def robolectricVersion = '4.1' diff --git a/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java b/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java new file mode 100644 index 000000000..3dd3a7709 --- /dev/null +++ b/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java @@ -0,0 +1,95 @@ +package org.smartregister.giz.repository; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.smartregister.giz.util.GizUtils; +import org.smartregister.repository.Repository; +import org.smartregister.view.activity.DrishtiApplication; + +import net.sqlcipher.Cursor; +import net.sqlcipher.database.SQLiteDatabase; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({DrishtiApplication.class}) +public class GizEventRepositoryTest { + + private GizEventRepository repository; + private static final String BASE_ENTITY_ID = "base_entity_id"; + private static final String EVENT_TYPE = "event_type"; + private static final String FORM_SUBMISSION_ID = "form_submission_id"; + + @Mock + private SQLiteDatabase sqLiteDatabase; + + @Mock + private GizUtils gizUtils; + + @Mock + private Cursor cursor; + + @Mock + private Repository baseRepository; + + @Mock + private DrishtiApplication drishtiApplication; + + @Before + public void setUp() { + repository = new GizEventRepository(); + MockitoAnnotations.initMocks(this); + PowerMockito.mockStatic(DrishtiApplication.class); + when(DrishtiApplication.getInstance()).thenReturn(drishtiApplication); + when(drishtiApplication.getRepository()).thenReturn(baseRepository); + when(baseRepository.getReadableDatabase()).thenReturn(sqLiteDatabase); + } + + @Test + public void testHasEvent(){ + when(sqLiteDatabase.query( + "event", + new String[]{"baseEntityId"}, + "baseEntityId = ? and eventType = ? ", + new String[]{BASE_ENTITY_ID, EVENT_TYPE}, + null, + null, + null, + "1" + )).thenReturn(cursor); + + when(cursor.getCount()).thenReturn(1); + + boolean hasEvent = repository.hasEvent(BASE_ENTITY_ID, EVENT_TYPE); + + assertTrue(hasEvent); + } + + + + @Test + public void testAddFormSubmissionIds() { + when(baseRepository.getReadableDatabase()).thenReturn(sqLiteDatabase); + when(sqLiteDatabase.rawQuery("query", null)).thenReturn(cursor); + when(cursor.getCount()).thenReturn(1); + when(cursor.getColumnIndex("formSubmissionId")).thenReturn(0); + when(cursor.moveToFirst()).thenReturn(true); + when(cursor.getString(0)).thenReturn("formSubmissionId"); + + List formSubmissionIds = new ArrayList<>(); + repository.addFormSubmissionIds(formSubmissionIds, "query"); + + assertFalse(formSubmissionIds.isEmpty()); + } +} From 443625a0330278d91f9125c771adc228f5025b19 Mon Sep 17 00:00:00 2001 From: vend Date: Wed, 1 Feb 2023 18:21:12 +0500 Subject: [PATCH 04/30] added more corrections to the PR changed the job trigger to isComplete action added a check for existing formsubmission id while population the list corrected the job tag --- .../giz/job/GIZClientReprocessJob.java | 2 +- .../GizReprocessSyncStatusReceiver.java | 21 +++++++------------ .../giz/repository/GizEventRepository.java | 3 ++- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java index 705502740..0c511d2ef 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/job/GIZClientReprocessJob.java @@ -13,7 +13,7 @@ public class GIZClientReprocessJob extends BaseJob { - public static final String TAG = "GizReValidationJob"; + public static final String TAG = "GIZClientReprocessJob"; @NonNull @NotNull diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java index a6cb71650..be227cd86 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java @@ -12,6 +12,7 @@ import timber.log.Timber; +import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_COMPLETE_STATUS; import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_FETCH_STATUS; public class GizReprocessSyncStatusReceiver extends BroadcastReceiver { @@ -19,22 +20,14 @@ public class GizReprocessSyncStatusReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Bundle data = intent.getExtras(); if (data != null) { - Serializable fetchStatusSerializable = data.getSerializable(EXTRA_FETCH_STATUS); - if (fetchStatusSerializable instanceof FetchStatus) { - FetchStatus fetchStatus = (FetchStatus) fetchStatusSerializable; - if (fetchStatus.equals(FetchStatus.fetched)) { - GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG); - Timber.d("Broadcast data fetched"); - } else if (fetchStatus.equals(FetchStatus.nothingFetched)) { - Timber.d("Broadcast data not fetched"); - } else if (fetchStatus.equals(FetchStatus.noConnection)) { - Timber.d("Broadcast data fetch failed"); - } - - //} + boolean isComplete = data.getBoolean(EXTRA_COMPLETE_STATUS,false); + if(isComplete) + { + GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG); + Timber.d("fetch completed"); } } - System.out.println("Broadcast Recieved"); + Timber.d("broadcast Recieved"); } } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index d3f9a992a..a9cb4d60b 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -51,7 +51,8 @@ public void addFormSubmissionIds(List ids, String query) { if (cursor.getCount() > 0) { cursor.moveToFirst(); do { - ids.add(cursor.getString(columnIndex)); + if (ids.contains(cursor.getString(columnIndex))) + ids.add(cursor.getString(columnIndex)); } while (cursor.moveToNext()); } cursor.close(); From b322055796adccc3e806d7f5d6342756b15d00c8 Mon Sep 17 00:00:00 2001 From: vend Date: Wed, 1 Feb 2023 18:37:37 +0500 Subject: [PATCH 05/30] corrected the condition --- .../org/smartregister/giz/repository/GizEventRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index a9cb4d60b..f6da24c35 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -51,7 +51,7 @@ public void addFormSubmissionIds(List ids, String query) { if (cursor.getCount() > 0) { cursor.moveToFirst(); do { - if (ids.contains(cursor.getString(columnIndex))) + if (!ids.contains(cursor.getString(columnIndex))) ids.add(cursor.getString(columnIndex)); } while (cursor.moveToNext()); } From 77e712278f56932677240b541c72b360cf1f18e5 Mon Sep 17 00:00:00 2001 From: vend Date: Wed, 1 Feb 2023 18:50:04 +0500 Subject: [PATCH 06/30] removed unused imports --- .../giz/recievers/GizReprocessSyncStatusReceiver.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java index be227cd86..395f49d77 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java @@ -5,15 +5,9 @@ import android.content.Intent; import android.os.Bundle; -import org.smartregister.domain.FetchStatus; import org.smartregister.giz.job.GIZClientReprocessJob; - -import java.io.Serializable; - import timber.log.Timber; - import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_COMPLETE_STATUS; -import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_FETCH_STATUS; public class GizReprocessSyncStatusReceiver extends BroadcastReceiver { @Override From c405d493b29d4bcfeccca8baee14fa49f88a7779 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Feb 2023 11:20:53 +0500 Subject: [PATCH 07/30] reformatted the code --- .../giz/recievers/GizReprocessSyncStatusReceiver.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java index 395f49d77..722179522 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java @@ -6,7 +6,9 @@ import android.os.Bundle; import org.smartregister.giz.job.GIZClientReprocessJob; + import timber.log.Timber; + import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_COMPLETE_STATUS; public class GizReprocessSyncStatusReceiver extends BroadcastReceiver { @@ -14,14 +16,13 @@ public class GizReprocessSyncStatusReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Bundle data = intent.getExtras(); if (data != null) { - boolean isComplete = data.getBoolean(EXTRA_COMPLETE_STATUS,false); - if(isComplete) - { + boolean isComplete = data.getBoolean(EXTRA_COMPLETE_STATUS, false); + if (isComplete) { GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG); Timber.d("fetch completed"); } } - Timber.d("broadcast Recieved"); + Timber.d("broadcast Recieved"); } } From 51d924713dcfdcf093778a75e1df243c4cbd8403 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Feb 2023 13:31:39 +0500 Subject: [PATCH 08/30] updated according to the PR feedback --- .../giz/recievers/GizReprocessSyncStatusReceiver.java | 2 +- .../giz/repository/GizEventRepository.java | 11 +++++------ .../giz/repository/GizEventRepositoryTest.java | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java index 722179522..b52c7b552 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java @@ -19,7 +19,7 @@ public void onReceive(Context context, Intent intent) { boolean isComplete = data.getBoolean(EXTRA_COMPLETE_STATUS, false); if (isComplete) { GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG); - Timber.d("fetch completed"); + Timber.d("Sync complete"); } } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index f6da24c35..c7151f9d9 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -9,7 +9,7 @@ import org.smartregister.repository.BaseRepository; import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; import timber.log.Timber; @@ -31,28 +31,27 @@ public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType) public void processSkippedClients() { String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'"; String missingECClient = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'"; - List formSubmissionIDs = new ArrayList<>(); + HashSet formSubmissionIDs = new HashSet<>(); addFormSubmissionIds(formSubmissionIDs, missingClientRegister); addFormSubmissionIds(formSubmissionIDs, missingECClient); try { if (formSubmissionIDs.size() > 0) - GizUtils.initiateEventProcessing(formSubmissionIDs); + GizUtils.initiateEventProcessing(new ArrayList<>(formSubmissionIDs)); } catch (Exception e) { Timber.e(e); } } - public void addFormSubmissionIds(List ids, String query) { + public void addFormSubmissionIds(HashSet ids, String query) { SQLiteDatabase database = getReadableDatabase(); Cursor cursor = database.rawQuery(query, null); int columnIndex = cursor.getColumnIndex("formSubmissionId"); if (cursor.getCount() > 0) { cursor.moveToFirst(); do { - if (!ids.contains(cursor.getString(columnIndex))) - ids.add(cursor.getString(columnIndex)); + ids.add(cursor.getString(columnIndex)); } while (cursor.moveToNext()); } cursor.close(); diff --git a/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java b/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java index 3dd3a7709..1309a48a5 100644 --- a/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java +++ b/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java @@ -16,6 +16,7 @@ import net.sqlcipher.database.SQLiteDatabase; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import static org.junit.Assert.assertFalse; @@ -87,7 +88,7 @@ public void testAddFormSubmissionIds() { when(cursor.moveToFirst()).thenReturn(true); when(cursor.getString(0)).thenReturn("formSubmissionId"); - List formSubmissionIds = new ArrayList<>(); + HashSet formSubmissionIds = new HashSet<>(); repository.addFormSubmissionIds(formSubmissionIds, "query"); assertFalse(formSubmissionIds.isEmpty()); From 04021302fc41deb65398a306e70258c4f1f58acf Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Feb 2023 13:36:23 +0500 Subject: [PATCH 09/30] changed androidTestImplemenation to testImplementation --- opensrp-giz-malawi/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 3fd58b65a..874bb6631 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -404,8 +404,8 @@ dependencies { implementation "androidx.multidex:multidex:2.0.1" testImplementation "androidx.work:work-testing:2.7.1" - androidTestImplementation 'androidx.test:runner:1.3.0' - androidTestImplementation 'androidx.test:core:1.3.0' + testImplementation 'androidx.test:runner:1.3.0' + testImplementation 'androidx.test:core:1.3.0' def robolectricVersion = '4.1' From d3d2cfd1bcc7b9bdf6a29fa780acb72d3cac1fc0 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 2 Feb 2023 13:46:52 +0500 Subject: [PATCH 10/30] codacy issues removed --- .../smartregister/giz/repository/GizEventRepositoryTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java b/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java index 1309a48a5..9fef81b1a 100644 --- a/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java +++ b/opensrp-giz-malawi/src/test/java/org/smartregister/giz/repository/GizEventRepositoryTest.java @@ -14,11 +14,7 @@ import net.sqlcipher.Cursor; import net.sqlcipher.database.SQLiteDatabase; - -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; From 277e50cbe2439c5bc7c4e354b85b8382a3371e5d Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 10 Feb 2023 14:10:57 +0500 Subject: [PATCH 11/30] added android 12 compatibility --- build.gradle | 4 +-- opensrp-giz-malawi/build.gradle | 7 +++++- .../src/main/AndroidManifest.xml | 25 ++++++++++--------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index c7334cc60..94191f599 100644 --- a/build.gradle +++ b/build.gradle @@ -39,8 +39,8 @@ subprojects { ext.androidToolsBuildGradle = '4.0.1' ext.androidBuildToolsVersion = '29.0.3' ext.androidMinSdkVersion = 18 - ext.androidCompileSdkVersion = 29 - ext.androidTargetSdkVersion = 29 + ext.androidCompileSdkVersion = 31 + ext.androidTargetSdkVersion = 31 ext.androidAnnotationsVersion = '3.0.1' ext.androidAnnotationsAPIVersion = '3.0.1' diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 874bb6631..8cc7cf975 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -232,6 +232,8 @@ android { } configurations.all { exclude group: 'com.github.lecho', module: 'hellocharts-library' + exclude group: 'com.evernote', module: 'android-job' + } } @@ -376,7 +378,10 @@ dependencies { // Because RxAndroid releases are few and far between, it is recommended you also // explicitly depend on RxJava's latest version for bug fixes and new features. implementation 'io.reactivex.rxjava2:rxjava:2.1.5' - implementation 'com.evernote:android-job:1.2.6' + implementation('com.github.devv911:android-job:1.4.5') { + exclude group: 'com.google.android', module: 'android' + } + implementation 'androidx.work:work-runtime:2.7.1' implementation 'com.github.lecho:hellocharts-android:1.5.8@aar' implementation 'id.zelory:compressor:2.1.1' implementation('com.google.android.material:material:1.0.0') { diff --git a/opensrp-giz-malawi/src/main/AndroidManifest.xml b/opensrp-giz-malawi/src/main/AndroidManifest.xml index 9bde642de..60c2dffaf 100644 --- a/opensrp-giz-malawi/src/main/AndroidManifest.xml +++ b/opensrp-giz-malawi/src/main/AndroidManifest.xml @@ -50,6 +50,7 @@ android:name=".activity.LoginActivity" android:screenOrientation="portrait" android:theme="@style/AppTheme.Login" + android:exported="true" android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> @@ -280,18 +281,18 @@ android:theme="@style/ChildTheme.NoActionBar" tools:replace="android:theme" /> - - - - - - - - - - - - + + + + + + + + + + + + Date: Tue, 14 Mar 2023 11:11:35 +0300 Subject: [PATCH 12/30] Code cleanup --- .../src/main/AndroidManifest.xml | 24 +++++++++---------- .../processor/GizMalawiProcessorForJava.java | 3 +++ .../GizReprocessSyncStatusReceiver.java | 4 ++-- .../giz/repository/GizEventRepository.java | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/opensrp-giz-malawi/src/main/AndroidManifest.xml b/opensrp-giz-malawi/src/main/AndroidManifest.xml index 60c2dffaf..01b8a3fc9 100644 --- a/opensrp-giz-malawi/src/main/AndroidManifest.xml +++ b/opensrp-giz-malawi/src/main/AndroidManifest.xml @@ -281,18 +281,18 @@ android:theme="@style/ChildTheme.NoActionBar" tools:replace="android:theme" /> - - - - - - - - - - - - + + + + + + + + + + + + formSubmissionIDs = new HashSet<>(); addFormSubmissionIds(formSubmissionIDs, missingClientRegister); addFormSubmissionIds(formSubmissionIDs, missingECClient); From 35ca0722f1820ce26cec16a3d39ae4544d4c1ae3 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 14 Mar 2023 11:14:56 +0300 Subject: [PATCH 13/30] Log skipped clients for reprocessing --- .../org/smartregister/giz/repository/GizEventRepository.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index 4b2cec805..1e7886f34 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -36,8 +36,10 @@ public void processSkippedClients() { addFormSubmissionIds(formSubmissionIDs, missingECClient); try { - if (formSubmissionIDs.size() > 0) + Timber.e("Found %d skipped clients", formSubmissionIDs.size()); + if (formSubmissionIDs.size() > 0) { GizUtils.initiateEventProcessing(new ArrayList<>(formSubmissionIDs)); + } } catch (Exception e) { Timber.e(e); } From fa8589fe40d3b5e922c11b36c2e9f086fab515bf Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Wed, 15 Mar 2023 01:29:56 +0300 Subject: [PATCH 14/30] Process skipped clients events in-order of eventDate after processing clients - Update versionCode and versionName to 47 and 0.4.7 --- opensrp-giz-malawi/build.gradle | 4 +- .../giz/activity/LoginActivity.java | 14 ++++ .../GizReprocessSyncStatusReceiver.java | 1 - .../giz/repository/GizEventRepository.java | 69 ++++++++++++++++--- .../service/ReProcessSyncIntentService.java | 44 +++++++++++- 5 files changed, 119 insertions(+), 13 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 8cc7cf975..12daad4e2 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -35,8 +35,8 @@ android { applicationId "org.smartregister.giz" minSdkVersion androidMinSdkVersion targetSdkVersion androidTargetSdkVersion - versionCode 46 - versionName "0.4.6" + versionCode 47 + versionName "0.4.7" multiDexEnabled true buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l" buildConfigField "boolean", "TIME_CHECK", "false" diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java index 5e61dbbc2..418d167e8 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java @@ -2,6 +2,7 @@ import android.content.Intent; import android.os.Bundle; +import android.widget.EditText; import org.smartregister.anc.library.AncLibrary; import org.smartregister.anc.library.activity.SiteCharacteristicsEnterActivity; @@ -9,10 +10,13 @@ import org.smartregister.giz.presenter.LoginPresenter; import org.smartregister.giz.util.GizConstants; import org.smartregister.giz.util.GizUtils; +import org.smartregister.security.SecurityHelper; import org.smartregister.task.SaveTeamLocationsTask; import org.smartregister.view.activity.BaseLoginActivity; import org.smartregister.view.contract.BaseLoginContract; +import java.util.Locale; + public class LoginActivity extends BaseLoginActivity implements BaseLoginContract.View { @Override @@ -62,4 +66,14 @@ protected void attachBaseContext(android.content.Context base) { String lang = GizUtils.getLanguage(base.getApplicationContext()); super.attachBaseContext(GizUtils.setAppLocale(base, lang)); } +/* + @Override + protected void attemptLogin() { + EditText userNameEdt = findViewById(R.id.login_user_name_edit_text); + EditText passwordEdt = findViewById(R.id.login_password_edit_text); + + String username = userNameEdt.getText().toString().trim(); + char[] password = SecurityHelper.readValue(passwordEdt.getText()); + mLoginPresenter.attemptLogin(username, password); + }*/ } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java index 14d9392c1..d7dae0e1c 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/recievers/GizReprocessSyncStatusReceiver.java @@ -20,7 +20,6 @@ public void onReceive(Context context, Intent intent) { boolean isComplete = data.getBoolean(EXTRA_COMPLETE_STATUS, false); if (isComplete) { GIZClientReprocessJob.scheduleJobImmediately(GIZClientReprocessJob.TAG); - Timber.d("Finished reprocessing events and clients"); } } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index 1e7886f34..be2b04690 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -5,11 +5,19 @@ import net.sqlcipher.Cursor; import net.sqlcipher.database.SQLiteDatabase; +import org.apache.commons.lang3.StringUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import org.smartregister.domain.Event; +import org.smartregister.giz.application.GizMalawiApplication; import org.smartregister.giz.util.GizUtils; import org.smartregister.repository.BaseRepository; +import org.smartregister.repository.EventClientRepository; +import org.smartregister.util.JsonFormUtils; import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import timber.log.Timber; @@ -28,34 +36,77 @@ public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType) return hasEvent; } - public void processSkippedClients() { - String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'"; - String missingECClient = "SELECT DISTINCT baseEntityId, formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'"; + public HashSet processSkippedClients() { + String missingClientsFromClientRegisterQuery = "SELECT DISTINCT baseEntityId, formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'"; + String missingClientsFromECClientQuery = "SELECT DISTINCT baseEntityId, formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'"; HashSet formSubmissionIDs = new HashSet<>(); - addFormSubmissionIds(formSubmissionIDs, missingClientRegister); - addFormSubmissionIds(formSubmissionIDs, missingECClient); + HashSet baseEntityIds = new HashSet<>(); + addFormSubmissionIds(formSubmissionIDs, baseEntityIds, missingClientsFromClientRegisterQuery); + addFormSubmissionIds(formSubmissionIDs, baseEntityIds, missingClientsFromECClientQuery); try { Timber.e("Found %d skipped clients", formSubmissionIDs.size()); if (formSubmissionIDs.size() > 0) { GizUtils.initiateEventProcessing(new ArrayList<>(formSubmissionIDs)); } + + Timber.d("Finished reprocessing events and clients"); } catch (Exception e) { Timber.e(e); } - } + return baseEntityIds; + } - public void addFormSubmissionIds(HashSet ids, String query) { + protected void addFormSubmissionIds(HashSet formSubmissionIds, HashSet baseEntityIds, String query) { SQLiteDatabase database = getReadableDatabase(); Cursor cursor = database.rawQuery(query, null); - int columnIndex = cursor.getColumnIndex("formSubmissionId"); + int formSubmissionIdColIndex = cursor.getColumnIndex("formSubmissionId"); + int baseEntityIdColIndex = cursor.getColumnIndex("baseEntityId"); + if (cursor.getCount() > 0) { cursor.moveToFirst(); do { - ids.add(cursor.getString(columnIndex)); + formSubmissionIds.add(cursor.getString(formSubmissionIdColIndex)); + baseEntityIds.add(cursor.getString(baseEntityIdColIndex)); } while (cursor.moveToNext()); } + cursor.close(); } + + public List getEventsByBaseEntityId(String baseEntityId) { + ArrayList eventsList = new ArrayList<>(); + EventClientRepository eventClientRepository = GizMalawiApplication.getInstance().eventClientRepository(); + + if (StringUtils.isBlank(baseEntityId)) { + return eventsList; + } else { + Cursor cursor = null; + + try { + cursor = this.getReadableDatabase().rawQuery("SELECT json FROM event WHERE " + + EventClientRepository.event_column.baseEntityId.name() + + " = ? ORDER BY eventDate ASC", new String[]{baseEntityId}); + + while (cursor.moveToNext()) { + String jsonEventStr = cursor.getString(0); + jsonEventStr = jsonEventStr.replaceAll("'", ""); + Event event = eventClientRepository.convert(jsonEventStr, Event.class); + + eventsList.add(event); + } + + } catch (Exception var10) { + Timber.e(var10); + } finally { + if (cursor != null) { + cursor.close(); + } + + } + + return eventsList; + } + } } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java index bd8f70b84..bca4d9bc8 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java @@ -5,7 +5,18 @@ import androidx.annotation.Nullable; +import org.smartregister.domain.Client; +import org.smartregister.domain.Event; +import org.smartregister.domain.db.EventClient; import org.smartregister.giz.application.GizMalawiApplication; +import org.smartregister.giz.repository.GizEventRepository; +import org.smartregister.repository.EventClientRepository; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import timber.log.Timber; public class ReProcessSyncIntentService extends IntentService { @@ -22,6 +33,37 @@ public ReProcessSyncIntentService(String name) { @Override protected void onHandleIntent(@Nullable Intent intent) { - GizMalawiApplication.getInstance().gizEventRepository().processSkippedClients(); + GizEventRepository gizEventRepository = GizMalawiApplication.getInstance().gizEventRepository(); + HashSet clientBaseEntityIds = gizEventRepository.processSkippedClients(); + + processSkippedClientEvents(gizEventRepository, clientBaseEntityIds); + } + + private void processSkippedClientEvents(GizEventRepository gizEventRepository, HashSet clientBaseEntityIds) { + Timber.d("Processing events for %d skipped clients", clientBaseEntityIds.size()); + EventClientRepository eventClientRepository = GizMalawiApplication.getInstance().eventClientRepository(); + + for (String clientBaseEntityId: clientBaseEntityIds) { + Client client = eventClientRepository.fetchClientByBaseEntityId(clientBaseEntityId); + if (client.getDeathdate() != null) { + continue; + } + + List eventsList = gizEventRepository.getEventsByBaseEntityId(clientBaseEntityId); + + List eventClientList = new ArrayList<>(); + Timber.d("Processing %d events for client %s", eventsList.size(), clientBaseEntityId); + + for (Event event: eventsList) { + eventClientList.add(new EventClient(event, client)); + } + + try { + GizMalawiApplication.getInstance().getClientProcessor() + .processClient(eventClientList); + } catch (Exception e) { + Timber.e(e); + } + } } } From eb00e3dc5301836f580258ee3c0f94d6097e6fe1 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 15 Dec 2022 12:06:19 +0300 Subject: [PATCH 15/30] Append APK file name with version and variant --- opensrp-giz-malawi/build.gradle | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 12daad4e2..1ccbb3f87 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -213,6 +213,19 @@ android { } } + // https://stackoverflow.com/a/27119543/152938 + applicationVariants.all { variant -> + variant.outputs.all { output -> + outputFileName = new File(outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk")) + } + } + + testVariants.all { variant -> + variant.outputs.all { output -> + outputFileName = new File(outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk")) + } + } + packagingOptions { exclude 'META-INF/LICENSE.md' exclude 'META-INF/NOTICE.md' From e2a409821dbede29cf13b80b78ea4a1746c28f32 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 15 Dec 2022 12:07:42 +0300 Subject: [PATCH 16/30] Separate oauth client id and secret for different variants --- .gitignore | 1 + README.md | 2 + opensrp-giz-malawi/build.gradle | 66 +++++++++++++++++++-------------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 11dbe9dc3..fab06d91c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ target/ tmp/ opensrp-giz-malawi/debug/ opensrp-giz-malawi/preview/ +opensrp-giz-malawi/releaseDebug/ *google-services.json \ No newline at end of file diff --git a/README.md b/README.md index 31f8e529a..eb4dd6fa0 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ These instructions will get you a copy of the project up and running on your loc ## Development setup +Get the + ### Steps to set up [OpenSRP android client app build](https://smartregister.atlassian.net/wiki/spaces/Documentation/pages/6619236/OpenSRP+App+Build) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 1ccbb3f87..cff766835 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -25,6 +25,30 @@ jacoco { toolVersion = jacocoVersion } +Properties properties = new Properties() +if (project.rootProject.file("local.properties").exists()) { + properties.load(project.rootProject.file("local.properties").newDataInputStream()) +} else{ + project.logger.error("local.properties file does not exist") +} + +ext.getLocalProperty = { key -> + if (properties != null && properties.containsKey(key)) { + return properties[key] + } else { + project.logger.error(key + " could not be found. Setting it to an empty string") + return "\"\"" + } +} + + +ext.checkKeys = { keys -> + keys.each { key -> + if (properties == null || !properties.containsKey(key)) { + project.logger.error(key + " is missing from the local.properties") + } + } +} android { useLibrary 'org.apache.http.legacy' @@ -50,34 +74,7 @@ android { testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - if (project.rootProject.file("local.properties").exists()) { - - Properties properties = new Properties() - properties.load(project.rootProject.file("local.properties").newDataInputStream()) - - if (properties != null && properties.containsKey("oauth.client.id")) { - - buildConfigField "String", "OAUTH_CLIENT_ID", properties["oauth.client.id"] - - } else { - project.logger.error("oauth.client.id variable is not set in your local.properties") - buildConfigField "String", "OAUTH_CLIENT_ID", "\"sample_client_id\"" - } - - - if (properties != null && properties.containsKey("oauth.client.secret")) { - - buildConfigField "String", "OAUTH_CLIENT_SECRET", properties["oauth.client.secret"] - - } else { - project.logger.error("oauth.client.secret variable is not set in your local.properties") - buildConfigField "String", "OAUTH_CLIENT_SECRET", "\"sample_client_secret\"" - } - } else { - buildConfigField "String", "OAUTH_CLIENT_ID", '""' - buildConfigField "String", "OAUTH_CLIENT_SECRET", '""' - } - + checkKeys(["oauth.client.id.production", "oauth.client.secret.production", "oauth.client.id.stage", "oauth.client.secret.stage", "oauth.client.id.preview", "oauth.client.secret.preview"]) javaCompileOptions { annotationProcessorOptions { @@ -128,6 +125,10 @@ android { buildConfigField "int", "GROWTH_MONITORING_SYNC_TIME", '15' buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Province", "District", "Facility", "Village"}' buildConfigField "String[]", "HEALTH_FACILITY_LEVELS", '{"Country", "Province", "District", "Health Facility", "Village"}' + + buildConfigField "String", "OAUTH_CLIENT_ID", getLocalProperty("oauth.client.id.production") + buildConfigField "String", "OAUTH_CLIENT_SECRET", getLocalProperty("oauth.client.secret.production") + } releaseDebug { @@ -157,6 +158,9 @@ android { buildConfigField "int", "GROWTH_MONITORING_SYNC_TIME", '15' buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Province", "District", "Facility", "Village"}' buildConfigField "String[]", "HEALTH_FACILITY_LEVELS", '{"Country", "Province", "District", "Health Facility", "Village"}' + + buildConfigField "String", "OAUTH_CLIENT_ID", getLocalProperty("oauth.client.id.production") + buildConfigField "String", "OAUTH_CLIENT_SECRET", getLocalProperty("oauth.client.secret.production") } preview { @@ -185,6 +189,9 @@ android { buildConfigField "int", "GROWTH_MONITORING_SYNC_TIME", '15' buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Province", "District", "Facility", "Village"}' buildConfigField "String[]", "HEALTH_FACILITY_LEVELS", '{"Country", "Province", "District", "Health Facility", "Village"}' + + buildConfigField "String", "OAUTH_CLIENT_ID", getLocalProperty("oauth.client.id.preview") + buildConfigField "String", "OAUTH_CLIENT_SECRET", getLocalProperty("oauth.client.secret.preview") } debug { @@ -210,6 +217,9 @@ android { buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Province", "District", "Facility", "Village"}' buildConfigField "String[]", "HEALTH_FACILITY_LEVELS", '{"Country", "Province", "District", "Health Facility", "Village"}' testCoverageEnabled true + + buildConfigField "String", "OAUTH_CLIENT_ID", getLocalProperty("oauth.client.id.stage") + buildConfigField "String", "OAUTH_CLIENT_SECRET", getLocalProperty("oauth.client.secret.stage") } } From 0c4106b32e13b60b91f14a202f3e9854dabb5f02 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 19 Dec 2022 22:04:00 +0300 Subject: [PATCH 17/30] Comment out code in client processor --- opensrp-giz-malawi/build.gradle | 4 ++-- .../java/org/smartregister/giz/presenter/LoginPresenter.java | 1 + .../giz/processor/GizMalawiProcessorForJava.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index cff766835..5f8536d3b 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -142,7 +142,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rule.pro' resValue "string", 'opensrp_url', '"https://opensrp.health.gov.mw/opensrp/"' buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10' - buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10' + buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '2' buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2' buildConfigField "int", "VACCINE_SYNC_TIME", '0' buildConfigField "int", "DATABASE_VERSION", '20' @@ -316,7 +316,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' } - api('org.smartregister:opensrp-client-core:5.0.9-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-core:5.0.12-LOCAL-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' exclude group: 'com.github.bmelnychuk', module: 'atv' diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/LoginPresenter.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/LoginPresenter.java index 57effe738..9c9af4813 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/LoginPresenter.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/LoginPresenter.java @@ -38,6 +38,7 @@ public LoginPresenter(BaseLoginContract.View loginView) { mLoginView = new WeakReference<>(loginView); mLoginInteractor = new LoginInteractor(this); mLoginModel = new BaseLoginModel(); + } @Override diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java index 56a2c15fd..8fa066dc1 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java @@ -141,7 +141,7 @@ public synchronized void processClient(List eventClientList, boolea @Override public void processClient(List eventClients) throws Exception { - ClientClassification clientClassification = assetJsonToJava("ec_client_classification.json", + /*ClientClassification clientClassification = assetJsonToJava("ec_client_classification.json", ClientClassification.class); Table vaccineTable = assetJsonToJava("ec_client_vaccine.json", Table.class); Table weightTable = assetJsonToJava("ec_client_weight.json", Table.class); @@ -233,7 +233,7 @@ else if (eventType.equals(VaccineIntentService.EVENT_TYPE) || eventType Runnable runnable = () -> updateClientAlerts(clientsForAlertUpdates); appExecutors.diskIO().execute(runnable); - } + }*/ } From 2f54b4be7e2c1fe57b9f6ce52a18365c1005b78d Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Wed, 15 Mar 2023 01:31:17 +0300 Subject: [PATCH 18/30] Fix commented out code in client processor --- .../giz/processor/GizMalawiProcessorForJava.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java index 8fa066dc1..56a2c15fd 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/processor/GizMalawiProcessorForJava.java @@ -141,7 +141,7 @@ public synchronized void processClient(List eventClientList, boolea @Override public void processClient(List eventClients) throws Exception { - /*ClientClassification clientClassification = assetJsonToJava("ec_client_classification.json", + ClientClassification clientClassification = assetJsonToJava("ec_client_classification.json", ClientClassification.class); Table vaccineTable = assetJsonToJava("ec_client_vaccine.json", Table.class); Table weightTable = assetJsonToJava("ec_client_weight.json", Table.class); @@ -233,7 +233,7 @@ else if (eventType.equals(VaccineIntentService.EVENT_TYPE) || eventType Runnable runnable = () -> updateClientAlerts(clientsForAlertUpdates); appExecutors.diskIO().execute(runnable); - }*/ + } } From 5c5cf23546eef04922dc45da18d82c1808d3d55b Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 16 Mar 2023 17:56:17 +0300 Subject: [PATCH 19/30] Update ANC version to fix next button in form - Update immunization library to fix duplicate vaccines and services - Fix client-core version --- opensrp-giz-malawi/build.gradle | 42 +++++++- ...ntactWizardJsonFormFragmentPresenter2.java | 95 +++++++++++++++++++ 2 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 opensrp-giz-malawi/src/main/java/org/smartregister/anc/library/presenter/ContactWizardJsonFormFragmentPresenter2.java diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 5f8536d3b..10a4f3940 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -10,6 +10,8 @@ buildscript { classpath "gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:$coverallsVersion" classpath 'io.fabric.tools:gradle:1.30.0' classpath 'com.google.gms:google-services:4.3.10' + //classpath "org.anarres.jarjar:jarjar-gradle:1.0.0" + //classpath 'net.vrallev.gradle:jarjar-gradle:1.1.0' } } @@ -18,6 +20,8 @@ apply plugin: 'jacoco' apply plugin: 'com.github.kt3k.coveralls' apply plugin: 'io.fabric' apply plugin: 'org.smartregister.gradle.jarjar' +//apply plugin: 'net.vrallev.jarjar' +//apply plugin: 'org.anarres.jarjar' apply plugin: 'com.google.gms.google-services' @@ -264,6 +268,14 @@ tasks.withType(Test) { jacoco.includeNoLocationClasses = true } +/*jarJar { + remove ["org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter"] +}*/ +/*jarjar { + srcExcludes = ["org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter"] +}*/ + + dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9' @@ -294,7 +306,30 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } - api('org.smartregister:opensrp-client-anc:2.0.3.29-LOCAL-SNAPSHOT@aar') { + /*api jarjar.repackage { + + from ('org.smartregister:opensrp-client-anc:2.0.3.29-LOCAL-SNAPSHOT@aar') { + transitive = true + exclude group: 'id.zelory', module: 'compressor' + exclude group: 'org.smartregister', module: 'opensrp-client-core' + exclude group: 'org.smartregister', module: 'opensrp-client-native-form' + exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' + exclude group: 'com.android.support', module: 'appcompat-v7' + } + classDelete "org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter" + }*/ + //from + + //exclude "org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter" + /*transitive = true + exclude group: 'id.zelory', module: 'compressor' + exclude group: 'org.smartregister', module: 'opensrp-client-core' + exclude group: 'org.smartregister', module: 'opensrp-client-native-form' + exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' + exclude group: 'com.android.support', module: 'appcompat-v7'*/ +// + + api('org.smartregister:opensrp-client-anc:2.0.3.40-LOCAL-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' exclude group: 'org.smartregister', module: 'opensrp-client-core' @@ -302,7 +337,6 @@ dependencies { exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' exclude group: 'com.android.support', module: 'appcompat-v7' } -// api('org.smartregister:opensrp-client-native-form:2.1.11-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' @@ -316,7 +350,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' } - api('org.smartregister:opensrp-client-core:5.0.12-LOCAL-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-core:5.0.9-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' exclude group: 'com.github.bmelnychuk', module: 'atv' @@ -350,7 +384,7 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } - api('org.smartregister:opensrp-client-immunization:4.0.6-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-immunization:4.0.7-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' exclude group: 'org.smartregister', module: 'opensrp-client-core' diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/anc/library/presenter/ContactWizardJsonFormFragmentPresenter2.java b/opensrp-giz-malawi/src/main/java/org/smartregister/anc/library/presenter/ContactWizardJsonFormFragmentPresenter2.java new file mode 100644 index 000000000..2c8d80338 --- /dev/null +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/anc/library/presenter/ContactWizardJsonFormFragmentPresenter2.java @@ -0,0 +1,95 @@ +package org.smartregister.anc.library.presenter; + +import android.text.TextUtils; +import android.util.Log; +import android.view.View; + +import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.fragments.JsonFormFragment; +import com.vijay.jsonwizard.interactors.JsonFormInteractor; +import com.vijay.jsonwizard.presenters.JsonWizardFormFragmentPresenter; +import com.vijay.jsonwizard.views.JsonFormFragmentView; +import com.vijay.jsonwizard.widgets.NativeRadioButtonFactory; + +import org.apache.commons.lang3.StringUtils; +import org.smartregister.anc.library.fragment.ContactWizardJsonFormFragment; +import org.smartregister.anc.library.util.ANCFormUtils; +import org.smartregister.anc.library.util.ConstantsUtils; + +/** + * Created by keyman on 04/08/18. + */ +public class ContactWizardJsonFormFragmentPresenter2 extends JsonWizardFormFragmentPresenter { + + public static final String TAG = ContactWizardJsonFormFragmentPresenter2.class.getName(); + + public ContactWizardJsonFormFragmentPresenter2(JsonFormFragment formFragment, JsonFormInteractor jsonFormInteractor) { + super(formFragment, jsonFormInteractor); + } + + @Override + public void setUpToolBar() { + super.setUpToolBar(); + + } + + @Override + protected boolean moveToNextWizardStep() { + String nextStep = getFormFragment().getJsonApi().nextStep(); + if (StringUtils.isNotBlank(nextStep)) { + + getFormFragment().getJsonApi().getAppExecutors().mainThread().execute(new Runnable() { + @Override + public void run() { + + JsonFormFragment next = ContactWizardJsonFormFragment.getFormFragment(nextStep); + JsonFormFragmentView jsonFormFragmentView = getView(); + if (jsonFormFragmentView != null) { + jsonFormFragmentView.hideKeyBoard(); + jsonFormFragmentView.transactThis(next); + } + } + }); + + return true; + } + return false; + } + + @Override + public void onClick(View view) { + key = (String) view.getTag(com.vijay.jsonwizard.R.id.key); + type = (String) view.getTag(com.vijay.jsonwizard.R.id.type); + switch (type) { + case ConstantsUtils.EXPANSION_PANEL: + String info = (String) view.getTag(com.vijay.jsonwizard.R.id.label_dialog_info); + if (!TextUtils.isEmpty(info)) { + showInformationDialog(view); + } + break; + case ConstantsUtils.EXTENDED_RADIO_BUTTON: + showInformationDialog(view); + break; + default: + super.onClick(view); + break; + } + } + + @Override + protected void nativeRadioButtonClickActions(View view) { + String type = (String) view.getTag(com.vijay.jsonwizard.R.id.specify_type); + String specifyWidget = (String) view.getTag(com.vijay.jsonwizard.R.id.specify_widget); + Log.i(TAG, "The dialog content widget is this: " + specifyWidget); + if (JsonFormConstants.CONTENT_INFO.equals(type) && specifyWidget.equals(JsonFormConstants.DATE_PICKER)) { + NativeRadioButtonFactory.showDateDialog(view); + } else if (JsonFormConstants.CONTENT_INFO.equals(type) && !specifyWidget.equals(JsonFormConstants.DATE_PICKER)) { + ANCFormUtils formUtils = new ANCFormUtils(); + formUtils.showGenericDialog(view); + } else if (view.getId() == com.vijay.jsonwizard.R.id.label_edit_button) { + setRadioViewsEditable(view); + } else { + showInformationDialog(view); + } + } +} \ No newline at end of file From b4bb240a7e8a3a42b623cb26dfe91bd3b4bd3aac Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 20 Mar 2023 18:52:59 +0300 Subject: [PATCH 20/30] Fix OPD Close event processing - Add config to close ec_client records when an OPD Close event is encountered - Filter out closed records from the OPD register --- .../src/main/assets/ec_client_classification.json | 7 +++++++ .../smartregister/giz/activity/GizOpdProfileActivity.java | 3 +++ .../giz/configuration/OpdRegisterQueryProvider.java | 8 ++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/opensrp-giz-malawi/src/main/assets/ec_client_classification.json b/opensrp-giz-malawi/src/main/assets/ec_client_classification.json index 9d13c07c1..14fa61bfb 100644 --- a/opensrp-giz-malawi/src/main/assets/ec_client_classification.json +++ b/opensrp-giz-malawi/src/main/assets/ec_client_classification.json @@ -268,6 +268,13 @@ "creates_case": [ "reason_for_defaulting" ] + }, + { + "field": "eventType", + "field_value": "OPD Close", + "closes_case": [ + "ec_client" + ] } ] } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/GizOpdProfileActivity.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/GizOpdProfileActivity.java index af2887059..8f0e61677 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/GizOpdProfileActivity.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/GizOpdProfileActivity.java @@ -146,6 +146,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (jsonString != null && requester != null) { requester.onFormProcessingResult(jsonString); requester = null; + } else { + // TODO: Review if this is actually required + super.onActivityResult(requestCode, resultCode, data); } initiateSync(); } else { diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/OpdRegisterQueryProvider.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/OpdRegisterQueryProvider.java index c502e2a87..1d5b75280 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/OpdRegisterQueryProvider.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/OpdRegisterQueryProvider.java @@ -36,7 +36,7 @@ public String getObjectIdsQuery(@Nullable String filters, @Nullable String mainC "FROM ec_client_search \n" + "inner join client_register_type crt on crt.base_entity_id = ec_client_search.object_id \n" + "inner join opd_client_visits ocv on ocv.base_entity_id = ec_client_search.object_id \n" + - "WHERE crt.register_type = 'opd' AND ec_client_search.date_removed IS NULL AND phrase MATCH '%s*'\n" + + "WHERE ec_client_search.is_closed = false AND crt.register_type = 'opd' AND ec_client_search.date_removed IS NULL AND phrase MATCH '%s*'\n" + "And ocv.visit_group = '" + todayDate + "'\n" + "ORDER BY last_interacted_with DESC"; sql = sql.replace("%s", filters); @@ -46,7 +46,7 @@ public String getObjectIdsQuery(@Nullable String filters, @Nullable String mainC String sql = "SELECT object_id, last_interacted_with FROM ec_client_search " + "inner join client_register_type crt on crt.base_entity_id = ec_client_search.object_id " + - "WHERE crt.register_type = 'opd' AND ec_client_search.date_removed IS NULL AND phrase MATCH '%s*' " + + "WHERE ec_client_search.is_closed = false AND crt.register_type = 'opd' AND ec_client_search.date_removed IS NULL AND phrase MATCH '%s*' " + "ORDER BY last_interacted_with DESC"; sql = sql.replace("%s", filters); return sql; @@ -57,14 +57,14 @@ public String getObjectIdsQuery(@Nullable String filters, @Nullable String mainC "FROM ec_client\n" + "inner join client_register_type crt on crt.base_entity_id = ec_client.id \n" + "inner join opd_client_visits ocv on ocv.base_entity_id = ec_client.id \n" + - "WHERE crt.register_type = 'opd'\n" + + "WHERE ec_client.is_closed = false AND crt.register_type = 'opd'\n" + "And ocv.visit_group = '" + todayDate + "'\n" + "ORDER BY last_interacted_with DESC"; return sqlQuery; } else { return - "SELECT object_id, last_interacted_with FROM ec_client_search inner join client_register_type crt on crt.base_entity_id = ec_client_search.object_id WHERE crt.register_type = 'opd' " + + "SELECT object_id, last_interacted_with FROM ec_client_search inner join client_register_type crt on crt.base_entity_id = ec_client_search.object_id WHERE ec_client_search.is_closed = false AND crt.register_type = 'opd' " + "ORDER BY last_interacted_with DESC"; } } From 6bd8dfab55a853e96ab18cdda380131881163ba4 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 20 Mar 2023 20:06:50 +0300 Subject: [PATCH 21/30] Mark deceased children as closed in ec_client - Update child register query to use ec_client.is_removed flag --- .../src/main/assets/ec_client_classification.json | 4 ++++ .../repository/GizChildRegisterQueryProvider.java | 12 ++++++++++++ .../java/org/smartregister/giz/util/GizUtils.java | 3 +++ 3 files changed, 19 insertions(+) diff --git a/opensrp-giz-malawi/src/main/assets/ec_client_classification.json b/opensrp-giz-malawi/src/main/assets/ec_client_classification.json index 14fa61bfb..8f3a99bcb 100644 --- a/opensrp-giz-malawi/src/main/assets/ec_client_classification.json +++ b/opensrp-giz-malawi/src/main/assets/ec_client_classification.json @@ -202,6 +202,10 @@ "field_value": "Death", "creates_case": [ "deceased" + ], + "closes_case": [ + "ec_client", + "ec_child_details" ] }, { diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java index e3af90747..9e0136aac 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java @@ -91,4 +91,16 @@ public String[] mainColumns() { getMotherDetailsTable() + ".alt_phone_number as mother_guardian_number"}; } + @Override + public String getActiveChildrenQuery() { + return "SELECT count(id) FROM " + this.getChildDetailsTable() + " INNER JOIN " + this.getDemographicTable() + " ON "+ this.getDemographicTable() + ".id = " + this.getChildDetailsTable() + ".id WHERE (" + + "date_removed" + " IS NULL AND (" + this.getChildDetailsTable() + ".inactive is NOT true OR " + this.getChildDetailsTable() + ".inactive is NULL) AND " + "is_closed" + " IS NOT '1')" + + " AND " + this.getDemographicTable() + ".is_closed IS NOT '1'"; + } + + @Override + public String getActiveChildrenIds() { + return "SELECT " + this.getChildDetailsTable() + ".id" + " FROM " + this.getChildDetailsTable() + " INNER JOIN " + this.getDemographicTable() + " ON " + this.getChildDetailsTable() + "." + "id" + " = " + this.getDemographicTable() + "." + "id" + " WHERE (" + this.getChildDetailsTable() + "." + "date_removed" + " IS NULL AND (" + this.getChildDetailsTable() + ".inactive is NOT true OR " + this.getChildDetailsTable() + ".inactive is NULL) AND " + this.getChildDetailsTable() + "." + "is_closed" + " IS NOT '1') AND " + this.getDemographicTable() + ".is_closed IS NOT '1' ORDER BY " + this.getDemographicTable() + "." + "last_interacted_with" + " DESC "; + } + } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizUtils.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizUtils.java index 2dd18d044..e72a74c87 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizUtils.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizUtils.java @@ -185,11 +185,14 @@ public static boolean updateClientDeath(@NonNull EventClient eventClient) { } values.put(Constants.KEY.DOD, Utils.convertDateFormat(client.getDeathdate())); values.put(Constants.KEY.DATE_REMOVED, Utils.convertDateFormat(client.getDeathdate().toDate(), Utils.DB_DF)); + values.put(Constants.KEY.IS_CLOSED, true); + AllCommonsRepository allCommonsRepository = GizMalawiApplication.getInstance().context().allCommonsRepositoryobjects(GizConstants.TABLE_NAME.ALL_CLIENTS); if (allCommonsRepository != null) { allCommonsRepository.update(GizConstants.TABLE_NAME.ALL_CLIENTS, values, client.getBaseEntityId()); allCommonsRepository.updateSearch(client.getBaseEntityId()); } + return true; } return false; From a834abb7cd5096b76e3b778225e7ab62624c7718 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 21 Mar 2023 16:34:49 +0300 Subject: [PATCH 22/30] Update README setup instructions --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eb4dd6fa0..cd75a5ad4 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,10 @@ These instructions will get you a copy of the project up and running on your loc ## Prerequisites [Tools and Frameworks Setup](https://smartregister.atlassian.net/wiki/spaces/Documentation/pages/6619207/Tools+and+Frameworks+Setup) -## Development setup - -Get the - ### Steps to set up -[OpenSRP android client app build](https://smartregister.atlassian.net/wiki/spaces/Documentation/pages/6619236/OpenSRP+App+Build) +- [OpenSRP android client app build](https://smartregister.atlassian.net/wiki/spaces/Documentation/pages/6619236/OpenSRP+App+Build) +- Add the client-id and client-secret values for the three environments i.e. stage, preview and production. Add these values to the `local.properties` as `client.id.[stage|preview|production]` and `client.secret.[stage|preview|production]`. +- Add the `google-services.json` to `opensrp-client-giz-malawi/opensrp-giz-malawi` ### Running the tests From 07c67a83d5ecd4b675882242a7d51d44845e1d4a Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 21 Mar 2023 17:29:14 +0300 Subject: [PATCH 23/30] Remove unused imports --- .../java/org/smartregister/giz/activity/LoginActivity.java | 4 ---- .../org/smartregister/giz/repository/GizEventRepository.java | 3 --- 2 files changed, 7 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java index 418d167e8..25f3c1938 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/LoginActivity.java @@ -2,7 +2,6 @@ import android.content.Intent; import android.os.Bundle; -import android.widget.EditText; import org.smartregister.anc.library.AncLibrary; import org.smartregister.anc.library.activity.SiteCharacteristicsEnterActivity; @@ -10,13 +9,10 @@ import org.smartregister.giz.presenter.LoginPresenter; import org.smartregister.giz.util.GizConstants; import org.smartregister.giz.util.GizUtils; -import org.smartregister.security.SecurityHelper; import org.smartregister.task.SaveTeamLocationsTask; import org.smartregister.view.activity.BaseLoginActivity; import org.smartregister.view.contract.BaseLoginContract; -import java.util.Locale; - public class LoginActivity extends BaseLoginActivity implements BaseLoginContract.View { @Override diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java index be2b04690..4b88dc99d 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizEventRepository.java @@ -6,14 +6,11 @@ import net.sqlcipher.database.SQLiteDatabase; import org.apache.commons.lang3.StringUtils; -import org.json.JSONArray; -import org.json.JSONObject; import org.smartregister.domain.Event; import org.smartregister.giz.application.GizMalawiApplication; import org.smartregister.giz.util.GizUtils; import org.smartregister.repository.BaseRepository; import org.smartregister.repository.EventClientRepository; -import org.smartregister.util.JsonFormUtils; import java.util.ArrayList; import java.util.HashSet; From 4626b37c7acd769a40fc3f705f17679fc5d393f5 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 24 Mar 2023 11:28:24 +0300 Subject: [PATCH 24/30] Fix PNC registration form cannot move to the next page Fixes https://github.com/opensrp/opensrp-client-giz-malawi/issues/510 --- opensrp-giz-malawi/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 10a4f3940..df5f8fca6 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -337,7 +337,8 @@ dependencies { exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' exclude group: 'com.android.support', module: 'appcompat-v7' } - api('org.smartregister:opensrp-client-native-form:2.1.11-SNAPSHOT@aar') { + + api('org.smartregister:opensrp-client-native-form:2.1.14.1-GIZ-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' exclude group: 'com.android.support', module: 'recyclerview-v7' From 7e93ddf19bc59cacba206d99d370fc3ddf70d9c3 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 24 Mar 2023 17:18:37 +0300 Subject: [PATCH 25/30] Process death and OPD close events - These events had not been previously processed due to a bug --- opensrp-giz-malawi/build.gradle | 23 ---------------- .../giz/activity/ChildProfileActivity.java | 1 + .../giz/repository/GizMalawiRepository.java | 5 ++++ .../service/ReProcessSyncIntentService.java | 26 +++++++++++++++++++ .../smartregister/giz/util/GizConstants.java | 1 + 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index df5f8fca6..41bf434a6 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -306,29 +306,6 @@ dependencies { exclude group: 'com.android.support', module: 'appcompat-v7' } - /*api jarjar.repackage { - - from ('org.smartregister:opensrp-client-anc:2.0.3.29-LOCAL-SNAPSHOT@aar') { - transitive = true - exclude group: 'id.zelory', module: 'compressor' - exclude group: 'org.smartregister', module: 'opensrp-client-core' - exclude group: 'org.smartregister', module: 'opensrp-client-native-form' - exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' - exclude group: 'com.android.support', module: 'appcompat-v7' - } - classDelete "org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter" - }*/ - //from - - //exclude "org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter" - /*transitive = true - exclude group: 'id.zelory', module: 'compressor' - exclude group: 'org.smartregister', module: 'opensrp-client-core' - exclude group: 'org.smartregister', module: 'opensrp-client-native-form' - exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views' - exclude group: 'com.android.support', module: 'appcompat-v7'*/ -// - api('org.smartregister:opensrp-client-anc:2.0.3.40-LOCAL-SNAPSHOT@aar') { transitive = true exclude group: 'id.zelory', module: 'compressor' diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/ChildProfileActivity.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/ChildProfileActivity.java index 4e19c2b97..52af55a8f 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/ChildProfileActivity.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/activity/ChildProfileActivity.java @@ -8,6 +8,7 @@ import org.smartregister.view.activity.BaseProfileActivity; public class ChildProfileActivity extends BaseProfileActivity { + @Override protected void attachBaseContext(android.content.Context base) { // get language from prefs diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizMalawiRepository.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizMalawiRepository.java index 0d9702084..3b925bd89 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizMalawiRepository.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizMalawiRepository.java @@ -5,8 +5,10 @@ import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; +import net.sqlcipher.Cursor; import net.sqlcipher.database.SQLiteDatabase; +import org.apache.commons.lang3.StringUtils; import org.smartregister.AllConstants; import org.smartregister.anc.library.repository.ContactTasksRepository; import org.smartregister.anc.library.repository.PartialContactRepository; @@ -15,7 +17,10 @@ import org.smartregister.child.util.Utils; import org.smartregister.child.util.VaccineOverdueCountRepositoryHelper; import org.smartregister.configurableviews.repository.ConfigurableViewsRepository; +import org.smartregister.domain.Client; +import org.smartregister.domain.Event; import org.smartregister.domain.db.Column; +import org.smartregister.domain.db.EventClient; import org.smartregister.giz.BuildConfig; import org.smartregister.giz.application.GizMalawiApplication; import org.smartregister.giz.util.GizConstants; diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java index bca4d9bc8..03b973a69 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/service/ReProcessSyncIntentService.java @@ -5,11 +5,15 @@ import androidx.annotation.Nullable; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; import org.smartregister.domain.Client; import org.smartregister.domain.Event; import org.smartregister.domain.db.EventClient; import org.smartregister.giz.application.GizMalawiApplication; import org.smartregister.giz.repository.GizEventRepository; +import org.smartregister.giz.util.GizConstants; +import org.smartregister.repository.AllSharedPreferences; import org.smartregister.repository.EventClientRepository; import java.util.ArrayList; @@ -37,6 +41,15 @@ protected void onHandleIntent(@Nullable Intent intent) { HashSet clientBaseEntityIds = gizEventRepository.processSkippedClients(); processSkippedClientEvents(gizEventRepository, clientBaseEntityIds); + + AllSharedPreferences allSharedPreferences = Context.getInstance().allSharedPreferences(); + boolean isProcessed = allSharedPreferences.getBooleanPreference(GizConstants.Pref.DEATH_AND_OPD_CLOSE_REPROCESSED); + if (!isProcessed) { + reprocessEventsOfType("OPD Close"); + reprocessEventsOfType("Death"); + + allSharedPreferences.saveBooleanPreference(GizConstants.Pref.DEATH_AND_OPD_CLOSE_REPROCESSED, true); + } } private void processSkippedClientEvents(GizEventRepository gizEventRepository, HashSet clientBaseEntityIds) { @@ -66,4 +79,17 @@ private void processSkippedClientEvents(GizEventRepository gizEventRepository, H } } } + + protected void reprocessEventsOfType(String eventType) { + EventClientRepository eventClientRepository = GizMalawiApplication.getInstance().eventClientRepository(); + ArrayList eventTypes = new ArrayList<>(); + eventTypes.add(eventType); + List opdCloseEvents = eventClientRepository.fetchEventClientsByEventTypes(eventTypes); + + try { + GizMalawiApplication.getInstance().getClientProcessor().processClient(opdCloseEvents); + } catch (Exception e) { + Timber.e(e); + } + } } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizConstants.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizConstants.java index e5e56fcba..69eea592b 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizConstants.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/util/GizConstants.java @@ -85,6 +85,7 @@ public interface Pref { String APP_VERSION_CODE = "APP_VERSION_CODE"; String INDICATOR_DATA_INITIALISED = "INDICATOR_DATA_INITIALISED"; String URL_VERSION = "URL_VERSION"; + String DEATH_AND_OPD_CLOSE_REPROCESSED = "DEATH_AND_OPD_CLOSE_REPROCESSED"; } public interface File { From 27b7787d90c7282a1384a32baca120573b2ada47 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 24 Mar 2023 17:31:53 +0300 Subject: [PATCH 26/30] Fix All Clients register search to remove dead clients --- .../configuration/AllClientsRegisterQueryProvider.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/AllClientsRegisterQueryProvider.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/AllClientsRegisterQueryProvider.java index d186d11aa..81bd49338 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/AllClientsRegisterQueryProvider.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/configuration/AllClientsRegisterQueryProvider.java @@ -36,7 +36,7 @@ public String getObjectIdsQuery(@Nullable String filters, @Nullable String mainC "FROM ec_client_search \n" + "inner join client_register_type crt on crt.base_entity_id = ec_client_search.object_id \n" + "inner join opd_client_visits ocv on ocv.base_entity_id = ec_client_search.object_id \n" + - "WHERE crt.register_type = 'opd' AND ec_client_search.date_removed IS NULL AND phrase MATCH '%s*'\n" + + "WHERE crt.register_type = 'opd' AND (ec_client_search.dod IS NULL AND ec_client_search.is_closed = 0) AND phrase MATCH '%s*'\n" + "And ocv.visit_group = '" + todayDate + "'\n" + "ORDER BY last_interacted_with DESC"; @@ -44,7 +44,7 @@ public String getObjectIdsQuery(@Nullable String filters, @Nullable String mainC return sql; } else { String sql = - "SELECT object_id, last_interacted_with FROM ec_client_search WHERE date_removed IS NULL AND phrase MATCH '%s*' " + + "SELECT object_id, last_interacted_with FROM ec_client_search WHERE date_removed IS NULL AND is_closed = 0 AND phrase MATCH '%s*' " + "ORDER BY last_interacted_with DESC"; sql = sql.replace("%s", filters); return sql; @@ -55,14 +55,14 @@ public String getObjectIdsQuery(@Nullable String filters, @Nullable String mainC "FROM ec_client\n" + "inner join client_register_type crt on crt.base_entity_id = ec_client.id \n" + "inner join opd_client_visits ocv on ocv.base_entity_id = ec_client.id \n" + - "WHERE crt.register_type = 'opd'\n" + + "WHERE crt.register_type = 'opd'\n AND ec_client.is_closed = 0 AND ec_client.date_removed IS NULL" + "And ocv.visit_group = '" + todayDate + "'\n" + "ORDER BY last_interacted_with DESC"; return sqlQuery; } else { return - "SELECT object_id, last_interacted_with FROM ec_client_search WHERE date_removed IS NULL and is_closed == 0 " + + "SELECT object_id, last_interacted_with FROM ec_client_search WHERE date_removed IS NULL and is_closed = 0 " + "ORDER BY last_interacted_with DESC"; } } From 502694fe7894fb37a4d5dac36adfd601065ff6b4 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 24 Mar 2023 17:45:24 +0300 Subject: [PATCH 27/30] Code cleanup --- opensrp-giz-malawi/build.gradle | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 41bf434a6..0e3529fed 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -10,8 +10,6 @@ buildscript { classpath "gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:$coverallsVersion" classpath 'io.fabric.tools:gradle:1.30.0' classpath 'com.google.gms:google-services:4.3.10' - //classpath "org.anarres.jarjar:jarjar-gradle:1.0.0" - //classpath 'net.vrallev.gradle:jarjar-gradle:1.1.0' } } @@ -20,8 +18,6 @@ apply plugin: 'jacoco' apply plugin: 'com.github.kt3k.coveralls' apply plugin: 'io.fabric' apply plugin: 'org.smartregister.gradle.jarjar' -//apply plugin: 'net.vrallev.jarjar' -//apply plugin: 'org.anarres.jarjar' apply plugin: 'com.google.gms.google-services' @@ -268,14 +264,6 @@ tasks.withType(Test) { jacoco.includeNoLocationClasses = true } -/*jarJar { - remove ["org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter"] -}*/ -/*jarjar { - srcExcludes = ["org.smartregister.anc.library.presenter.ContactWizardJsonFormFragmentPresenter"] -}*/ - - dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9' From eeab005a38936626a4e4d473b1649441cde1b6a9 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 24 Mar 2023 17:47:32 +0300 Subject: [PATCH 28/30] Update versionName and versionCode to 0.4.8 and 48 --- opensrp-giz-malawi/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index 0e3529fed..a368c7c26 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -59,8 +59,8 @@ android { applicationId "org.smartregister.giz" minSdkVersion androidMinSdkVersion targetSdkVersion androidTargetSdkVersion - versionCode 47 - versionName "0.4.7" + versionCode 48 + versionName "0.4.8" multiDexEnabled true buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l" buildConfigField "boolean", "TIME_CHECK", "false" From 57aa2d32c37e084a04f04a6d9e2cc06e7d534629 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 27 Mar 2023 01:58:24 +0300 Subject: [PATCH 29/30] Fix Child register search showing deceased clients --- .../giz/presenter/ChildRegisterFragmentPresenter.java | 2 +- .../giz/repository/GizChildRegisterQueryProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/ChildRegisterFragmentPresenter.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/ChildRegisterFragmentPresenter.java index 261e30a34..f3e0d3a7e 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/ChildRegisterFragmentPresenter.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/presenter/ChildRegisterFragmentPresenter.java @@ -15,7 +15,7 @@ public ChildRegisterFragmentPresenter(ChildRegisterFragmentContract.View view, C @Override public String getMainCondition() { - return String.format(" %s is null AND %s == 0 ", + return String.format(" (%s is null AND %s = 0) ", Utils.metadata().getRegisterQueryProvider().getDemographicTable() + "." + Constants.KEY.DATE_REMOVED, Utils.metadata().getRegisterQueryProvider().getDemographicTable() + "." + Constants.KEY.IS_CLOSED); } diff --git a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java index 9e0136aac..22d0f2132 100644 --- a/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java +++ b/opensrp-giz-malawi/src/main/java/org/smartregister/giz/repository/GizChildRegisterQueryProvider.java @@ -41,7 +41,7 @@ public String getCountExecuteQuery(String mainCondition, String filters) { private String getFilter(String filters) { if (StringUtils.isNotBlank(filters)) { - return String.format(" AND " + getDemographicTable() + ".first_name like '%%%1$s%%' " + " OR " + getDemographicTable() + ".last_name like '%%%1$s%%' " + " OR " + getDemographicTable() + ".opensrp_id like '%%%1$s%%' ", filters); + return String.format(" AND ( " + getDemographicTable() + ".first_name like '%%%1$s%%' " + " OR " + getDemographicTable() + ".last_name like '%%%1$s%%' " + " OR " + getDemographicTable() + ".opensrp_id like '%%%1$s%%' ) ", filters); } return ""; } From af4d11296c391520f3d867288b9d26bc5906d1ec Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 27 Mar 2023 02:00:20 +0300 Subject: [PATCH 30/30] Update versionName and versionCode to 0.4.9 and 49 --- opensrp-giz-malawi/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-giz-malawi/build.gradle b/opensrp-giz-malawi/build.gradle index a368c7c26..b8d9a2ea8 100644 --- a/opensrp-giz-malawi/build.gradle +++ b/opensrp-giz-malawi/build.gradle @@ -59,8 +59,8 @@ android { applicationId "org.smartregister.giz" minSdkVersion androidMinSdkVersion targetSdkVersion androidTargetSdkVersion - versionCode 48 - versionName "0.4.8" + versionCode 49 + versionName "0.4.9" multiDexEnabled true buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l" buildConfigField "boolean", "TIME_CHECK", "false"