From 12be34e5712d64acad3c626ac78fadf00aa20cc2 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 14 Sep 2022 10:20:11 +0300 Subject: [PATCH 01/17] AttentionFlagsTests --- build.gradle | 6 +- opensrp-anc/build.gradle | 11 +-- .../library/task/AttentionsFlagsTaskTest.java | 11 +-- .../library/task/AttentionsFlagsTaskTest.java | 94 +++++++++---------- 4 files changed, 58 insertions(+), 64 deletions(-) diff --git a/build.gradle b/build.gradle index cc7d0dabd..d69847398 100644 --- a/build.gradle +++ b/build.gradle @@ -77,9 +77,9 @@ subprojects { ext.androidToolsBuildGradle = '30.0.3' ext.androidBuildToolsVersion = '30.0.3' - ext.androidMinSdkVersion = 18 - ext.androidCompileSdkVersion = 30 - ext.androidTargetSdkVersion = 30 + ext.androidMinSdkVersion = 21 + ext.androidCompileSdkVersion = 31 + ext.androidTargetSdkVersion = 31 ext.androidAnnotationsVersion = '3.0.1' ext.androidAnnotationsAPIVersion = '3.0.1' ext.jacocoVersion = "0.7.9" diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 3b9f8111a..65226bb42 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -5,8 +5,8 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:4.1.3' - classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.10.2' - classpath 'com.google.gms:google-services:4.3.10' + classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0' + classpath 'com.google.gms:google-services:4.3.13' } configurations.all { resolutionStrategy { @@ -178,7 +178,7 @@ tasks.withType(Test) { dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' - implementation('org.smartregister:opensrp-client-native-form:2.1.19-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -205,7 +205,7 @@ dependencies { exclude group: 'org.smartregister', module: 'android-p2p-sync' } - api("org.smartregister:android-p2p-sync:0.3.8-aplha4-SNAPSHOT") { + api("org.smartregister:android-p2p-sync:0.3.9-DEV-SNAPSHOT") { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -256,9 +256,6 @@ dependencies { implementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime' testImplementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime' - implementation 'org.jacoco:org.jacoco.agent:0.8.7:runtime' - testImplementation 'org.jacoco:org.jacoco.agent:0.8.7:runtime' - testImplementation 'junit:junit:4.13.1' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation('com.squareup:fest-android:1.0.8') { diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java index cda763435..97a7620b6 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java @@ -4,9 +4,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; import org.powermock.reflect.Whitebox; import org.robolectric.RobolectricTestRunner; import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; @@ -20,21 +18,20 @@ @RunWith(RobolectricTestRunner.class) public class AttentionsFlagsTaskTest { - private static BaseHomeRegisterActivity baseHomeRegisterActivity; + AttentionFlagsTask attentionFlagMock; private static CommonPersonObjectClient commonPersonObjectClient; private final List attentionFlagList = new ArrayList<>(); Map details = new HashMap<>(); - @Mock - AttentionFlagsTask attentionFlagsTaskss; + private BaseHomeRegisterActivity baseHomeRegisterActivity; private AttentionFlagsTask attentionFlagsTask; @Before public void setUp() { String name = "asynctask", caseId = "e34343-343434-67"; - baseHomeRegisterActivity = new BaseHomeRegisterActivity(); + baseHomeRegisterActivity = Mockito.mock(BaseHomeRegisterActivity.class); commonPersonObjectClient = new CommonPersonObjectClient(caseId, details, name); attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); - attentionFlagsTaskss = Mockito.mock(AttentionFlagsTask.class); + attentionFlagMock = Mockito.mock(AttentionFlagsTask.class); } diff --git a/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java b/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java index ef122c5b2..fbad9739f 100644 --- a/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java +++ b/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java @@ -1,47 +1,47 @@ -package org.smartregister.anc.library.task; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.reflect.Whitebox; -import org.robolectric.RobolectricTestRunner; -import org.smartregister.anc.BaseUnitTest; -import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; -import org.smartregister.anc.library.domain.AttentionFlag; -import org.smartregister.commonregistry.CommonPersonObjectClient; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@RunWith(RobolectricTestRunner.class) -public class AttentionsFlagsTaskTest extends BaseUnitTest { - private static BaseHomeRegisterActivity baseHomeRegisterActivity; - private static CommonPersonObjectClient commonPersonObjectClient; - private final List attentionFlagList = new ArrayList<>(); - Map details = new HashMap<>(); - private AttentionFlagsTask attentionFlagsTask; - - @Before - public void setUp() { - String name = "asynctask"; - String caseId = "e34343-343434-67"; - baseHomeRegisterActivity = new BaseHomeRegisterActivity(); - commonPersonObjectClient = new CommonPersonObjectClient(caseId, details, name); - attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); - - } - - @Test - public void testAttentionFlags() throws InterruptedException { - attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); - attentionFlagsTask.execute(); - Whitebox.setInternalState(attentionFlagsTask, "onPostExecute"); - Thread.sleep(ASYNC_TIMEOUT); - //To check whether the Attention Flags have data in them - Assert.assertNotNull(attentionFlagList); - - } -} +//package org.smartregister.anc.library.task; +// +//import org.junit.Assert; +//import org.junit.Before; +//import org.junit.Test; +//import org.junit.runner.RunWith; +//import org.powermock.reflect.Whitebox; +//import org.robolectric.RobolectricTestRunner; +//import org.smartregister.anc.BaseUnitTest; +//import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; +//import org.smartregister.anc.library.domain.AttentionFlag; +//import org.smartregister.commonregistry.CommonPersonObjectClient; +// +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//@RunWith(RobolectricTestRunner.class) +//public class AttentionsFlagsTaskTest extends BaseUnitTest { +// private static BaseHomeRegisterActivity baseHomeRegisterActivity; +// private static CommonPersonObjectClient commonPersonObjectClient; +// private final List attentionFlagList = new ArrayList<>(); +// Map details = new HashMap<>(); +// private AttentionFlagsTask attentionFlagsTask; +// +// @Before +// public void setUp() { +// String name = "asynctask"; +// String caseId = "e34343-343434-67"; +// baseHomeRegisterActivity = new BaseHomeRegisterActivity(); +// commonPersonObjectClient = new CommonPersonObjectClient(caseId, details, name); +// attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); +// +// } +// +// @Test +// public void testAttentionFlags() throws InterruptedException { +// attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); +// attentionFlagsTask.execute(); +// Whitebox.setInternalState(attentionFlagsTask, "onPostExecute"); +// Thread.sleep(ASYNC_TIMEOUT); +// //To check whether the Attention Flags have data in them +// Assert.assertNotNull(attentionFlagList); +// +// } +//} From 4048959bf59b716fc93d27da2dfedc900e943842 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 21 Sep 2022 14:05:13 +0300 Subject: [PATCH 02/17] Async Task refactoring --- opensrp-anc/build.gradle | 35 ++++++++--------- .../anc/library/task/AttentionFlagsTask.java | 22 ++++++----- .../FetchPopulationCharacteristicsTask.java | 21 ++++++---- .../library/task/FetchProfileDataTask.java | 20 +++++++--- .../task/FetchSiteCharacteristicsTask.java | 33 ++++++++++++---- .../anc/library/task/FinalizeContactTask.java | 38 +++++++++++++------ .../task/LoadContactSummaryDataTask.java | 24 +++++++----- .../smartregister/anc/library/util/Utils.java | 4 +- .../library/task/AttentionsFlagsTaskTest.java | 5 ++- reference-app/build.gradle | 37 +++++++++--------- reference-app/src/main/AndroidManifest.xml | 2 +- .../anc/activity/LoginActivity.java | 2 +- .../anc/application/AncApplication.java | 8 ++-- 13 files changed, 154 insertions(+), 97 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 65226bb42..0fb8ce667 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -189,7 +189,7 @@ dependencies { exclude group: 'org.yaml', module: 'snakeyaml' exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:4.3.26-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.1-BETA-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' @@ -224,12 +224,12 @@ dependencies { exclude group: 'com.android.support', module: 'support-v4' } implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' - implementation 'junit:junit:4.12' + implementation 'junit:junit:4.13.2' implementation 'androidx.test:core:1.4.0' annotationProcessor 'com.jakewharton:butterknife:10.2.3' - implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar' + implementation 'net.zetetic:android-database-sqlcipher:4.5.1@aar' implementation 'commons-validator:commons-validator:1.7' - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.9.0' implementation 'org.greenrobot:eventbus:3.2.0' annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.2.0' implementation 'com.google.guava:guava:30.0-jre' @@ -237,41 +237,42 @@ 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.2.20' - implementation 'com.evernote:android-job:1.4.2' + implementation 'com.evernote:android-job:1.4.3' implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' implementation 'id.zelory:compressor:2.1.1' - implementation('com.google.android.material:material:1.4.0') { + implementation('com.google.android.material:material:1.6.1') { exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'cardview-v7' } implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.0' - implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation group: 'org.yaml', name: 'snakeyaml', version: '1.30' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'org.jeasy:easy-rules-core:3.3.0' implementation 'org.jeasy:easy-rules-mvel:3.3.0' implementation("com.itextpdf:itext7-core:7.1.12") implementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime' testImplementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime' - - testImplementation 'junit:junit:4.13.1' + implementation 'com.android.volley:volley:1.2.1' + implementation 'androidx.work:work-runtime:2.7.1' + testImplementation 'junit:junit:4.13.2' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation('com.squareup:fest-android:1.0.8') { exclude module: 'support-v4' } - testImplementation 'org.robolectric:robolectric:4.4' - testImplementation 'org.robolectric:shadows-multidex:4.4' + testImplementation 'org.robolectric:robolectric:4.8.1' + testImplementation 'org.robolectric:shadows-multidex:4.8.1' testImplementation 'com.ibm.fhir:fhir-model:4.8.3' // https://mvnrepository.com/artifact/org.hamcrest/hamcrest testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' //testImplementation 'org.robolectric:shadows-support-v4:3.4-rc2' - testImplementation "org.powermock:powermock-module-junit4:2.0.7" - testImplementation "org.powermock:powermock-module-junit4-rule:2.0.7" - testImplementation "org.powermock:powermock-api-mockito2:2.0.7" - testImplementation "org.powermock:powermock-classloading-xstream:2.0.7" - testImplementation 'org.mockito:mockito-core:3.5.15' + testImplementation "org.powermock:powermock-module-junit4:2.0.9" + testImplementation "org.powermock:powermock-module-junit4-rule:2.0.9" + testImplementation "org.powermock:powermock-api-mockito2:2.0.9" + testImplementation "org.powermock:powermock-classloading-xstream:2.0.9" + testImplementation 'org.mockito:mockito-core:4.6.1' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation 'org.skyscreamer:jsonassert:1.5.0' diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java index 577bfbe87..5b2d4876c 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java @@ -1,7 +1,5 @@ package org.smartregister.anc.library.task; -import android.os.AsyncTask; - import org.apache.commons.lang3.StringUtils; import org.jeasy.rules.api.Facts; import org.json.JSONObject; @@ -10,6 +8,7 @@ import org.smartregister.anc.library.domain.AttentionFlag; import org.smartregister.anc.library.domain.YamlConfig; import org.smartregister.anc.library.domain.YamlConfigItem; +import org.smartregister.anc.library.util.AppExecutors; import org.smartregister.anc.library.util.ConstantsUtils; import org.smartregister.anc.library.util.FilePathUtils; import org.smartregister.anc.library.util.Utils; @@ -21,18 +20,26 @@ import timber.log.Timber; -public class AttentionFlagsTask extends AsyncTask { +public class AttentionFlagsTask { private final BaseHomeRegisterActivity baseHomeRegisterActivity; private final List attentionFlagList = new ArrayList<>(); private final CommonPersonObjectClient pc; + private AppExecutors appExecutors; public AttentionFlagsTask(BaseHomeRegisterActivity baseHomeRegisterActivity, CommonPersonObjectClient pc) { this.baseHomeRegisterActivity = baseHomeRegisterActivity; this.pc = pc; } - @Override - protected Void doInBackground(Void... voids) { + public void execute() { + appExecutors = AncLibrary.getInstance().getAppExecutors(); + appExecutors.diskIO().execute(() -> { + this.addAttentionFlagsService(); + appExecutors.mainThread().execute(this::showAttentionFlagsDialogOnPostExec); + }); + } + + protected void addAttentionFlagsService() { try { JSONObject jsonObject = new JSONObject(AncLibrary.getInstance().getDetailsRepository().getAllDetailsForClient(pc.getCaseId()).get(ConstantsUtils.DetailsKeyUtils.ATTENTION_FLAG_FACTS)); @@ -65,12 +72,9 @@ protected Void doInBackground(Void... voids) { } catch (Exception e) { Timber.e(e, " --> "); } - - return null; } - @Override - protected void onPostExecute(Void result) { + protected void showAttentionFlagsDialogOnPostExec() { baseHomeRegisterActivity.showAttentionFlagsDialog(attentionFlagList); } } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTask.java index b0abefd0a..952068eb2 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTask.java @@ -1,8 +1,7 @@ package org.smartregister.anc.library.task; -import android.os.AsyncTask; - import org.smartregister.anc.library.contract.PopulationCharacteristicsContract; +import org.smartregister.anc.library.util.AppExecutors; import org.smartregister.anc.library.util.ConstantsUtils; import org.smartregister.domain.ServerSetting; import org.smartregister.sync.helper.ServerSettingsHelper; @@ -12,22 +11,30 @@ /** * Created by ndegwamartin on 28/08/2018. */ -public class FetchPopulationCharacteristicsTask extends AsyncTask> { +public class FetchPopulationCharacteristicsTask { private PopulationCharacteristicsContract.Presenter presenter; + private AppExecutors appExecutorService; public FetchPopulationCharacteristicsTask(PopulationCharacteristicsContract.Presenter presenter) { this.presenter = presenter; } - @Override - protected List doInBackground(final Void... params) { + public void execute() { + appExecutorService = new AppExecutors(); + appExecutorService.diskIO().execute(() -> { + List result = this.getServerSettingsService(); + appExecutorService.mainThread().execute(() -> this.renderViewOnPostExec(result)); + }); + } + + + public List getServerSettingsService() { ServerSettingsHelper helper = new ServerSettingsHelper(ConstantsUtils.PrefKeyUtils.POPULATION_CHARACTERISTICS); return helper.getServerSettings(); } - @Override - protected void onPostExecute(final List result) { + protected void renderViewOnPostExec(final List result) { presenter.renderView(result); } } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchProfileDataTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchProfileDataTask.java index 4e7b04475..b66564f2a 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchProfileDataTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchProfileDataTask.java @@ -1,9 +1,8 @@ package org.smartregister.anc.library.task; -import android.os.AsyncTask; - import org.smartregister.anc.library.event.ClientDetailsFetchedEvent; import org.smartregister.anc.library.repository.PatientRepository; +import org.smartregister.anc.library.util.AppExecutors; import org.smartregister.anc.library.util.Utils; import java.util.Map; @@ -11,20 +10,29 @@ /** * Created by ndegwamartin on 13/07/2018. */ -public class FetchProfileDataTask extends AsyncTask> { +public class FetchProfileDataTask { private boolean isForEdit; + private AppExecutors appExecutors; public FetchProfileDataTask(boolean isForEdit) { this.isForEdit = isForEdit; } - protected Map doInBackground(String... params) { - String baseEntityId = params[0]; + public void execute(String baseEntityId) { + appExecutors = new AppExecutors(); + appExecutors.diskIO().execute(() -> { + Map client = this.getWomanDetailsOnBackground(baseEntityId); + appExecutors.mainThread().execute(() -> postStickEventOnPostExec(client)); + }); + + } + + private Map getWomanDetailsOnBackground(String baseEntityId) { return PatientRepository.getWomanProfileDetails(baseEntityId); } - protected void onPostExecute(Map client) { + protected void postStickEventOnPostExec(Map client) { Utils.postStickyEvent(new ClientDetailsFetchedEvent(client, isForEdit)); } } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchSiteCharacteristicsTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchSiteCharacteristicsTask.java index fc8c4f98c..8779b8ebb 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchSiteCharacteristicsTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FetchSiteCharacteristicsTask.java @@ -1,9 +1,8 @@ package org.smartregister.anc.library.task; -import android.os.AsyncTask; - import org.smartregister.anc.library.contract.BaseCharacteristicsContract; import org.smartregister.anc.library.contract.PopulationCharacteristicsContract; +import org.smartregister.anc.library.util.AppExecutors; import org.smartregister.anc.library.util.ConstantsUtils; import org.smartregister.domain.ServerSetting; import org.smartregister.sync.helper.ServerSettingsHelper; @@ -13,22 +12,42 @@ /** * Created by ndegwamartin on 28/08/2018. */ -public class FetchSiteCharacteristicsTask extends AsyncTask> { +public class FetchSiteCharacteristicsTask { private BaseCharacteristicsContract.BasePresenter presenter; + private AppExecutors appExecutors; public FetchSiteCharacteristicsTask(PopulationCharacteristicsContract.Presenter presenter) { this.presenter = presenter; } - @Override - protected List doInBackground(final Void... params) { + /*** + * function that incorporates both background and UI threads + */ + public void execute() { + appExecutors = new AppExecutors(); + /** + * Background Thread + */ + appExecutors.diskIO().execute(() -> { + List result = this.getServerSettingsSWorkerService(); + if (!result.isEmpty()) { + /*** + * UI Thread + */ + appExecutors.mainThread().execute(() -> this.renderViewOnPostExecute(result)); + } + }); + + + } + + protected List getServerSettingsSWorkerService() { ServerSettingsHelper helper = new ServerSettingsHelper(ConstantsUtils.PrefKeyUtils.SITE_CHARACTERISTICS); return helper.getServerSettings(); } - @Override - protected void onPostExecute(final List result) { + protected void renderViewOnPostExecute(final List result) { presenter.renderView(result); } } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FinalizeContactTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FinalizeContactTask.java index 881ac6579..dbe0740f1 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FinalizeContactTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/FinalizeContactTask.java @@ -2,13 +2,13 @@ import android.content.Context; import android.content.Intent; -import android.os.AsyncTask; import org.smartregister.anc.library.R; import org.smartregister.anc.library.activity.ContactSummaryFinishActivity; import org.smartregister.anc.library.activity.ContactSummarySendActivity; import org.smartregister.anc.library.contract.ProfileContract; import org.smartregister.anc.library.repository.PatientRepository; +import org.smartregister.anc.library.util.AppExecutors; import org.smartregister.anc.library.util.ConstantsUtils; import java.lang.ref.WeakReference; @@ -16,11 +16,12 @@ import timber.log.Timber; -public class FinalizeContactTask extends AsyncTask { +public class FinalizeContactTask { private final Context context; private final ProfileContract.Presenter mProfilePresenter; private final Intent intent; private HashMap newWomanProfileDetails; + private AppExecutors appExecutors; public FinalizeContactTask(WeakReference context, ProfileContract.Presenter mProfilePresenter, Intent intent) { this.context = context.get(); @@ -28,16 +29,34 @@ public FinalizeContactTask(WeakReference context, ProfileContract.Prese this.intent = intent; } - @Override - protected void onPreExecute() { + /*** + * execute task with AppExecutors + */ + public void execute() { + appExecutors = new AppExecutors(); + appExecutors.mainThread().execute(this::getProgressDialog); + appExecutors.diskIO().execute(() -> { + /*** + * Background Thread + */ + this.processWomanDetailsServiceWorker(); + /*** + * UI Thread + */ + appExecutors.mainThread().execute(this::finishContactSummaryOnPostExecute); + }); + } + + protected void getProgressDialog() { ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message); ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage( String.format(context.getString(R.string.finalizing_contact), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data"); ((ContactSummaryFinishActivity) context).getProgressDialog().show(); } - @Override - protected Void doInBackground(Void... nada) { + + + protected void processWomanDetailsServiceWorker() { try { HashMap womanProfileDetails = (HashMap) PatientRepository .getWomanProfileDetails(intent.getExtras().getString(ConstantsUtils.IntentKeyUtils.BASE_ENTITY_ID)); @@ -50,14 +69,9 @@ protected Void doInBackground(Void... nada) { Timber.e(e); } - return null; - } - - - @Override - protected void onPostExecute(Void result) { + protected void finishContactSummaryOnPostExecute() { ((ContactSummaryFinishActivity) context).hideProgressDialog(); Intent contactSummaryIntent = new Intent(context, ContactSummarySendActivity.class); diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java index 972a16fde..070e7acf5 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java @@ -2,7 +2,6 @@ import android.content.Context; import android.content.Intent; -import android.os.AsyncTask; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -14,6 +13,7 @@ import org.smartregister.anc.library.adapter.ContactSummaryFinishAdapter; import org.smartregister.anc.library.contract.ProfileContract; import org.smartregister.anc.library.repository.PatientRepository; +import org.smartregister.anc.library.util.AppExecutors; import org.smartregister.anc.library.util.ConstantsUtils; import org.smartregister.anc.library.util.DBConstantsUtils; import org.smartregister.anc.library.util.Utils; @@ -22,12 +22,13 @@ import timber.log.Timber; -public class LoadContactSummaryDataTask extends AsyncTask { +public class LoadContactSummaryDataTask { private Context context; private Intent intent; private ProfileContract.Presenter mProfilePresenter; private Facts facts; private String baseEntityId; + private AppExecutors appExecutors; public LoadContactSummaryDataTask(Context context, Intent intent, ProfileContract.Presenter mProfilePresenter, Facts facts, String baseEntityId) { this.context = context; @@ -37,28 +38,31 @@ public LoadContactSummaryDataTask(Context context, Intent intent, ProfileContrac this.baseEntityId = baseEntityId; } + public void execute() { + appExecutors = new AppExecutors(); + appExecutors.mainThread().execute(this::showDialog); + appExecutors.diskIO().execute(() -> { + this.onProcess(); + appExecutors.mainThread().execute(this::finishAdapterOnPostExecute); + }); + } - @Override - protected Void doInBackground(Void... nada) { + private void onProcess() { try { ((ContactSummaryFinishActivity) context).process(); } catch (Exception e) { Timber.e(e, "%s --> loadContactSummaryData", this.getClass().getCanonicalName()); } - return null; - } - @Override - protected void onPreExecute() { + private void showDialog() { ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message); ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage(String.format(context.getString(R.string.summarizing_contact_number), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data"); ((ContactSummaryFinishActivity) context).getProgressDialog().show(); } - @Override - protected void onPostExecute(Void result) { + private void finishAdapterOnPostExecute() { HashMap clientDetails; try { clientDetails = (HashMap) intent.getSerializableExtra(ConstantsUtils.IntentKeyUtils.CLIENT_MAP); diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java index 98c862d29..b60836396 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java @@ -932,7 +932,7 @@ public static boolean checkJsonArrayString(String input) { @SuppressLint({"NewApi"}) public static String returnTranslatedStringJoinedValue(String value) { try { - if (StringUtils.isNotBlank(value) && value.charAt(0) == '[') { + if (StringUtils.isNotBlank(value) && value.startsWith("[")) { if (Utils.checkJsonArrayString(value)) { JSONArray jsonArray = new JSONArray(value); List translatedList = new ArrayList<>(); @@ -947,7 +947,7 @@ public static String returnTranslatedStringJoinedValue(String value) { return value.substring(1, value.length() - 1); } } - if (StringUtils.isNotBlank(value) && value.charAt(0) == '{') { + if (StringUtils.isNotBlank(value) && value.startsWith("{")) { JSONObject attentionFlagObject = new JSONObject(value); String text = attentionFlagObject.optString(JsonFormConstants.TEXT).trim(); String translated_text = StringUtils.isNotBlank(text) ? NativeFormLangUtils.translateDatabaseString(text, AncLibrary.getInstance().getApplicationContext()) : ""; diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java index 97a7620b6..4682e2fca 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java @@ -8,6 +8,7 @@ import org.powermock.reflect.Whitebox; import org.robolectric.RobolectricTestRunner; import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; +import org.smartregister.anc.library.activity.BaseUnitTest; import org.smartregister.anc.library.domain.AttentionFlag; import org.smartregister.commonregistry.CommonPersonObjectClient; @@ -16,8 +17,8 @@ import java.util.List; import java.util.Map; -@RunWith(RobolectricTestRunner.class) -public class AttentionsFlagsTaskTest { + +public class AttentionsFlagsTaskTest extends BaseUnitTest { AttentionFlagsTask attentionFlagMock; private static CommonPersonObjectClient commonPersonObjectClient; private final List attentionFlagList = new ArrayList<>(); diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 8ea21d039..55961edc5 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -6,8 +6,8 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.3' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.3' - classpath 'com.google.gms:google-services:4.3.9' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' + classpath 'com.google.gms:google-services:4.3.14' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' classpath 'org.smartregister:gradle-jarjar-plugin:1.0.0-SNAPSHOT' } } @@ -228,9 +228,9 @@ tasks.withType(Test) { dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' - def powerMockVersion = '2.0.7' + def powerMockVersion = '2.0.9' implementation project(":opensrp-anc") - implementation('org.smartregister:opensrp-client-native-form:2.1.17-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -242,7 +242,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:4.3.26-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.1-BETA-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' @@ -258,7 +258,7 @@ dependencies { exclude group: 'org.smartregister', module: 'android-p2p-sync' } - api("org.smartregister:android-p2p-sync:0.3.8-aplha4-SNAPSHOT") { + api("org.smartregister:android-p2p-sync:0.3.9-DEV-SNAPSHOT") { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -280,27 +280,27 @@ dependencies { } implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' annotationProcessor 'com.jakewharton:butterknife:10.2.3' - implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar' + implementation 'net.zetetic:android-database-sqlcipher:4.5.1@aar' implementation 'commons-validator:commons-validator:1.7' - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.9.0' implementation 'org.greenrobot:eventbus:3.2.0' annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.2.0' implementation 'com.google.guava:guava:30.0-jre' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'io.reactivex.rxjava2:rxjava:2.2.20' - implementation 'com.evernote:android-job:1.4.2' + implementation 'com.evernote:android-job:1.4.3' implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' implementation 'id.zelory:compressor:2.1.1' - implementation('com.google.android.material:material:1.4.0') { + implementation('com.google.android.material:material:1.6.1') { exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'cardview-v7' } implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.0' - implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation group: 'org.yaml', name: 'snakeyaml', version: '1.30' implementation 'de.hdodenhof:circleimageview:3.1.0' - implementation 'org.jeasy:easy-rules-core:3.3.0' + implementation 'org.jeasy:easy-rules-core:4.1.0' implementation 'org.jeasy:easy-rules-mvel:3.3.0' implementation 'com.flurry.android:analytics:11.6.0@aar' implementation 'com.flurry.android:analytics:11.6.0@aar' @@ -319,23 +319,24 @@ dependencies { exclude group: 'com.android.support', module: 'support-v4' } implementation 'com.google.firebase:firebase-perf' - - testImplementation 'junit:junit:4.13.1' + implementation 'com.android.volley:volley:1.2.1' + implementation 'androidx.work:work-runtime:2.7.1' + testImplementation 'junit:junit:4.13.2' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation('com.squareup:fest-android:1.0.8') { exclude module: 'support-v4' } // https://mvnrepository.com/artifact/org.hamcrest/hamcrest testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' - testImplementation 'org.robolectric:robolectric:4.4' - testImplementation 'org.robolectric:shadows-multidex:4.4' + testImplementation 'org.robolectric:robolectric:4.8.1' + testImplementation 'org.robolectric:shadows-multidex:4.8.1' testImplementation 'com.ibm.fhir:fhir-model:4.8.3' //testImplementation 'org.robolectric:shadows-support-v4:3.4-rc2' testImplementation "org.powermock:powermock-module-junit4:$powerMockVersion" testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testImplementation "org.powermock:powermock-api-mockito2:$powerMockVersion" testImplementation "org.powermock:powermock-classloading-xstream:$powerMockVersion" - testImplementation 'org.mockito:mockito-core:3.5.15' + testImplementation 'org.mockito:mockito-core:4.6.1' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation 'org.skyscreamer:jsonassert:1.5.0' } diff --git a/reference-app/src/main/AndroidManifest.xml b/reference-app/src/main/AndroidManifest.xml index ec4f67afc..64642da40 100644 --- a/reference-app/src/main/AndroidManifest.xml +++ b/reference-app/src/main/AndroidManifest.xml @@ -136,7 +136,7 @@ Date: Wed, 21 Sep 2022 15:05:25 +0300 Subject: [PATCH 03/17] Fix Failing tests --- .../anc/library/task/AttentionFlagsTask.java | 2 +- .../library/shadows/MyShadowAsyncTask.java | 31 --------- .../library/task/AttentionsFlagsTaskTest.java | 9 +-- .../library/task/FinalizeContactTaskTest.java | 64 +++++++++++-------- 4 files changed, 41 insertions(+), 65 deletions(-) delete mode 100644 opensrp-anc/src/test/java/org/smartregister/anc/library/shadows/MyShadowAsyncTask.java diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java index 5b2d4876c..275b72a73 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/AttentionFlagsTask.java @@ -32,7 +32,7 @@ public AttentionFlagsTask(BaseHomeRegisterActivity baseHomeRegisterActivity, Com } public void execute() { - appExecutors = AncLibrary.getInstance().getAppExecutors(); + appExecutors = new AppExecutors(); appExecutors.diskIO().execute(() -> { this.addAttentionFlagsService(); appExecutors.mainThread().execute(this::showAttentionFlagsDialogOnPostExec); diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/shadows/MyShadowAsyncTask.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/shadows/MyShadowAsyncTask.java deleted file mode 100644 index bcc752bd9..000000000 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/shadows/MyShadowAsyncTask.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.smartregister.anc.library.shadows; - -import android.os.AsyncTask; - -import org.robolectric.annotation.Implements; -import org.robolectric.annotation.RealObject; -import org.robolectric.shadows.ShadowAsyncTask; -import org.robolectric.shadows.ShadowAsyncTaskBridge; -import org.robolectric.util.ReflectionHelpers; - -/** - * Created by Ephraim Kigamba - ekigamba@ona.io on 2019-07-30 - */ - -@Implements(AsyncTask.class) -public class MyShadowAsyncTask extends ShadowAsyncTask { - @RealObject - private AsyncTask actualAsyncTask; - - public AsyncTask execute(P... params) { - ReflectionHelpers.setField(this, "status", AsyncTask.Status.RUNNING); - - ShadowAsyncTaskBridge bridge = ReflectionHelpers.callInstanceMethod(this, "getBridge"); - bridge.onPreExecute(); - - R result = ReflectionHelpers.callInstanceMethod(actualAsyncTask, "doInBackground", ReflectionHelpers.ClassParameter.from(Object[].class, params)); - bridge.onPostExecute(result); - - return actualAsyncTask; - } -} diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java index 4682e2fca..b660e08ac 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java @@ -5,10 +5,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.powermock.reflect.Whitebox; import org.robolectric.RobolectricTestRunner; import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; -import org.smartregister.anc.library.activity.BaseUnitTest; import org.smartregister.anc.library.domain.AttentionFlag; import org.smartregister.commonregistry.CommonPersonObjectClient; @@ -17,8 +15,8 @@ import java.util.List; import java.util.Map; - -public class AttentionsFlagsTaskTest extends BaseUnitTest { +@RunWith(RobolectricTestRunner.class) +public class AttentionsFlagsTaskTest { AttentionFlagsTask attentionFlagMock; private static CommonPersonObjectClient commonPersonObjectClient; private final List attentionFlagList = new ArrayList<>(); @@ -40,7 +38,6 @@ public void setUp() { public void testAttentionFlags() throws InterruptedException { attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); attentionFlagsTask.execute(); - Whitebox.setInternalState(attentionFlagsTask, "onPostExecute"); Thread.sleep(1000); //To check whether the Attention Flags have data in them Assert.assertNotNull(attentionFlagList); @@ -49,6 +46,6 @@ public void testAttentionFlags() throws InterruptedException { @Test public void testCheckBaseRegisterActivity(){ - Assert.assertNotNull(baseHomeRegisterActivity); + Assert.assertNotNull(baseHomeRegisterActivity); } } \ No newline at end of file diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java index 66a64de6f..ceecb712b 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java @@ -6,58 +6,68 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; -import org.robolectric.RobolectricTestRunner; +import org.powermock.reflect.Whitebox; import org.smartregister.anc.library.activity.BaseUnitTest; +import org.smartregister.anc.library.activity.ContactSummarySendActivity; import org.smartregister.anc.library.contract.ProfileContract; import java.lang.ref.WeakReference; import java.util.HashMap; -@RunWith(RobolectricTestRunner.class) + public class FinalizeContactTaskTest extends BaseUnitTest { - @Mock - private HashMap newWomanProfileDetails; private FinalizeContactTask finalizeContactTask; + private final HashMap newWomanProfileDetails = new HashMap<>(); + @Mock + WeakReference weakReferenceContext; private Context context; - public org.smartregister.Context context1; private ProfileContract.Presenter mProfilePresenter; private Intent intent; + @Mock + private FinalizeContactTask finalizeContactTaskMock; @Before public void setUp() { context = Mockito.mock(Context.class); - WeakReference weakReferenceContext = new WeakReference<>(context); + weakReferenceContext = new WeakReference<>(context); finalizeContactTask = new FinalizeContactTask(weakReferenceContext, mProfilePresenter, intent); + finalizeContactTaskMock = Mockito.mock(FinalizeContactTask.class); } -// @Test -// public void testFinalizeContact() throws InterruptedException { -// finalizeContactTask = new FinalizeContactTask(context, mProfilePresenter, new Intent()); -// finalizeContactTask.execute(); -// Whitebox.setInternalState(finalizeContactTask, "onPostExecute"); -// Thread.sleep(1000); -// //To check whether the FinalizeTaks Flags have data in them -// Assert.assertNotNull(newWomanProfileDetails); -// -// } + @Test + public void testGetProgressDialog() throws Exception { + PowerMockito.whenNew(FinalizeContactTask.class).withArguments(weakReferenceContext, mProfilePresenter, new Intent()).thenReturn(finalizeContactTask); + finalizeContactTask.execute(); + Thread.sleep(100); + intent = new Intent(context, ContactSummarySendActivity.class); + PowerMockito.whenNew(Intent.class).withArguments(context, ContactSummarySendActivity.class).thenReturn(intent); + Whitebox.invokeMethod(finalizeContactTaskMock, "getProgressDialog"); + PowerMockito.verifyPrivate(finalizeContactTaskMock).invoke("getProgressDialog"); + } @Test - public void testDoBackground() throws Exception { - WeakReference weakReferenceContext = new WeakReference<>(context); + public void testGetWomanProfileDetails() throws Exception { PowerMockito.whenNew(FinalizeContactTask.class).withArguments(weakReferenceContext, mProfilePresenter, new Intent()).thenReturn(finalizeContactTask); - FinalizeContactTask filter = new FinalizeContactTask(weakReferenceContext, mProfilePresenter, new Intent()) { - public FinalizeContactTask callProtectedMethod() { - doInBackground(); - return this; - } - }.callProtectedMethod(); - filter.doInBackground(); + finalizeContactTask.execute(); + Thread.sleep(1000); + Whitebox.invokeMethod(finalizeContactTaskMock, "processWomanDetailsServiceWorker"); + Assert.assertNotNull(newWomanProfileDetails); } -} +// @Test +// public void testInvokeFinishContactSummaryOnPostExecute() throws Exception { +// PowerMockito.whenNew(FinalizeContactTask.class).withArguments(weakReferenceContext, mProfilePresenter, new Intent()).thenReturn(finalizeContactTask); +// finalizeContactTask.execute(); +// Thread.sleep(100); +// intent = new Intent(context, ContactSummarySendActivity.class); +// PowerMockito.whenNew(Intent.class).withArguments(context, ContactSummarySendActivity.class).thenReturn(intent); +// Whitebox.invokeMethod(finalizeContactTaskMock, "finishContactSummaryOnPostExecute"); +// PowerMockito.verifyPrivate(finalizeContactTaskMock).invoke("finishContactSummaryOnPostExecute"); +// Mockito.verify(context).startActivity(intent); +// } +} \ No newline at end of file From 7ef32ea52f984db747a190a7e09c5d92ea99c3ab Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 21 Sep 2022 15:32:58 +0300 Subject: [PATCH 04/17] Resolving rules engine errors --- reference-app/build.gradle | 2 +- reference-app/src/main/AndroidManifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 55961edc5..881261f19 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -300,7 +300,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation group: 'org.yaml', name: 'snakeyaml', version: '1.30' implementation 'de.hdodenhof:circleimageview:3.1.0' - implementation 'org.jeasy:easy-rules-core:4.1.0' + implementation 'org.jeasy:easy-rules-core:3.3.0' implementation 'org.jeasy:easy-rules-mvel:3.3.0' implementation 'com.flurry.android:analytics:11.6.0@aar' implementation 'com.flurry.android:analytics:11.6.0@aar' diff --git a/reference-app/src/main/AndroidManifest.xml b/reference-app/src/main/AndroidManifest.xml index 64642da40..ec4f67afc 100644 --- a/reference-app/src/main/AndroidManifest.xml +++ b/reference-app/src/main/AndroidManifest.xml @@ -136,7 +136,7 @@ Date: Wed, 21 Sep 2022 17:09:36 +0300 Subject: [PATCH 05/17] Fix tests --- opensrp-anc/build.gradle | 36 ++++++++++--------- .../library/task/AttentionsFlagsTaskTest.java | 3 +- .../library/task/FinalizeContactTaskTest.java | 4 ++- reference-app/build.gradle | 27 +++++++------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 0fb8ce667..9b68e36f5 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -6,7 +6,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.3' classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0' - classpath 'com.google.gms:google-services:4.3.13' + classpath 'com.google.gms:google-services:4.3.14' } configurations.all { resolutionStrategy { @@ -224,12 +224,12 @@ dependencies { exclude group: 'com.android.support', module: 'support-v4' } implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' - implementation 'junit:junit:4.13.2' + implementation 'junit:junit:4.12' implementation 'androidx.test:core:1.4.0' annotationProcessor 'com.jakewharton:butterknife:10.2.3' - implementation 'net.zetetic:android-database-sqlcipher:4.5.1@aar' + implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar' implementation 'commons-validator:commons-validator:1.7' - implementation 'com.google.code.gson:gson:2.9.0' + implementation 'com.google.code.gson:gson:2.8.6' implementation 'org.greenrobot:eventbus:3.2.0' annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.2.0' implementation 'com.google.guava:guava:30.0-jre' @@ -237,18 +237,18 @@ 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.2.20' - implementation 'com.evernote:android-job:1.4.3' + implementation 'com.evernote:android-job:1.4.2' implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' implementation 'id.zelory:compressor:2.1.1' - implementation('com.google.android.material:material:1.6.1') { + implementation('com.google.android.material:material:1.4.0') { exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'cardview-v7' } implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation group: 'org.yaml', name: 'snakeyaml', version: '1.30' + implementation 'androidx.constraintlayout:constraintlayout:2.1.0' + implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'org.jeasy:easy-rules-core:3.3.0' implementation 'org.jeasy:easy-rules-mvel:3.3.0' @@ -256,23 +256,25 @@ dependencies { implementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime' testImplementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime' implementation 'com.android.volley:volley:1.2.1' - implementation 'androidx.work:work-runtime:2.7.1' - testImplementation 'junit:junit:4.13.2' + implementation 'org.jacoco:org.jacoco.agent:0.8.7:runtime' + testImplementation 'org.jacoco:org.jacoco.agent:0.8.7:runtime' + + testImplementation 'junit:junit:4.13.1' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation('com.squareup:fest-android:1.0.8') { exclude module: 'support-v4' } - testImplementation 'org.robolectric:robolectric:4.8.1' - testImplementation 'org.robolectric:shadows-multidex:4.8.1' + testImplementation 'org.robolectric:robolectric:4.4' + testImplementation 'org.robolectric:shadows-multidex:4.4' testImplementation 'com.ibm.fhir:fhir-model:4.8.3' // https://mvnrepository.com/artifact/org.hamcrest/hamcrest testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' //testImplementation 'org.robolectric:shadows-support-v4:3.4-rc2' - testImplementation "org.powermock:powermock-module-junit4:2.0.9" - testImplementation "org.powermock:powermock-module-junit4-rule:2.0.9" - testImplementation "org.powermock:powermock-api-mockito2:2.0.9" - testImplementation "org.powermock:powermock-classloading-xstream:2.0.9" - testImplementation 'org.mockito:mockito-core:4.6.1' + testImplementation "org.powermock:powermock-module-junit4:2.0.7" + testImplementation "org.powermock:powermock-module-junit4-rule:2.0.7" + testImplementation "org.powermock:powermock-api-mockito2:2.0.7" + testImplementation "org.powermock:powermock-classloading-xstream:2.0.7" + testImplementation 'org.mockito:mockito-core:3.5.15' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation 'org.skyscreamer:jsonassert:1.5.0' diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java index b660e08ac..dfe51be61 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java @@ -7,6 +7,7 @@ import org.mockito.Mockito; import org.robolectric.RobolectricTestRunner; import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; +import org.smartregister.anc.library.activity.BaseUnitTest; import org.smartregister.anc.library.domain.AttentionFlag; import org.smartregister.commonregistry.CommonPersonObjectClient; @@ -16,7 +17,7 @@ import java.util.Map; @RunWith(RobolectricTestRunner.class) -public class AttentionsFlagsTaskTest { +public class AttentionsFlagsTaskTest extends BaseUnitTest { AttentionFlagsTask attentionFlagMock; private static CommonPersonObjectClient commonPersonObjectClient; private final List attentionFlagList = new ArrayList<>(); diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java index ceecb712b..d8bee36a9 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java @@ -6,9 +6,11 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import org.smartregister.anc.library.activity.BaseUnitTest; import org.smartregister.anc.library.activity.ContactSummarySendActivity; @@ -17,7 +19,7 @@ import java.lang.ref.WeakReference; import java.util.HashMap; - +@RunWith(PowerMockRunner.class) public class FinalizeContactTaskTest extends BaseUnitTest { private FinalizeContactTask finalizeContactTask; diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 881261f19..b192a7eb1 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -6,8 +6,8 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.3' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.3' - classpath 'com.google.gms:google-services:4.3.14' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' + classpath 'com.google.gms:google-services:4.3.9' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' classpath 'org.smartregister:gradle-jarjar-plugin:1.0.0-SNAPSHOT' } } @@ -228,7 +228,7 @@ tasks.withType(Test) { dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' - def powerMockVersion = '2.0.9' + def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true @@ -280,25 +280,25 @@ dependencies { } implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' annotationProcessor 'com.jakewharton:butterknife:10.2.3' - implementation 'net.zetetic:android-database-sqlcipher:4.5.1@aar' + implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar' implementation 'commons-validator:commons-validator:1.7' - implementation 'com.google.code.gson:gson:2.9.0' + implementation 'com.google.code.gson:gson:2.8.6' implementation 'org.greenrobot:eventbus:3.2.0' annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.2.0' implementation 'com.google.guava:guava:30.0-jre' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'io.reactivex.rxjava2:rxjava:2.2.20' - implementation 'com.evernote:android-job:1.4.3' + implementation 'com.evernote:android-job:1.4.2' implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' implementation 'id.zelory:compressor:2.1.1' - implementation('com.google.android.material:material:1.6.1') { + implementation('com.google.android.material:material:1.4.0') { exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'cardview-v7' } implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation group: 'org.yaml', name: 'snakeyaml', version: '1.30' + implementation 'androidx.constraintlayout:constraintlayout:2.1.0' + implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'org.jeasy:easy-rules-core:3.3.0' implementation 'org.jeasy:easy-rules-mvel:3.3.0' @@ -320,23 +320,22 @@ dependencies { } implementation 'com.google.firebase:firebase-perf' implementation 'com.android.volley:volley:1.2.1' - implementation 'androidx.work:work-runtime:2.7.1' - testImplementation 'junit:junit:4.13.2' + testImplementation 'junit:junit:4.13.1' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation('com.squareup:fest-android:1.0.8') { exclude module: 'support-v4' } // https://mvnrepository.com/artifact/org.hamcrest/hamcrest testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' - testImplementation 'org.robolectric:robolectric:4.8.1' - testImplementation 'org.robolectric:shadows-multidex:4.8.1' + testImplementation 'org.robolectric:robolectric:4.4' + testImplementation 'org.robolectric:shadows-multidex:4.4' testImplementation 'com.ibm.fhir:fhir-model:4.8.3' //testImplementation 'org.robolectric:shadows-support-v4:3.4-rc2' testImplementation "org.powermock:powermock-module-junit4:$powerMockVersion" testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testImplementation "org.powermock:powermock-api-mockito2:$powerMockVersion" testImplementation "org.powermock:powermock-classloading-xstream:$powerMockVersion" - testImplementation 'org.mockito:mockito-core:4.6.1' + testImplementation 'org.mockito:mockito-core:3.5.15' testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3' testImplementation 'org.skyscreamer:jsonassert:1.5.0' } From 54da1e93abec65cdef5fbbd5ebb52fa39d009fdd Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Thu, 22 Sep 2022 10:49:25 +0300 Subject: [PATCH 06/17] Native form version 2.1.19 --- opensrp-anc/build.gradle | 2 +- reference-app/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 9b68e36f5..89daf0529 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -178,7 +178,7 @@ tasks.withType(Test) { dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' - implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:2.1.19-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' diff --git a/reference-app/build.gradle b/reference-app/build.gradle index b192a7eb1..a84a8f86b 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -230,7 +230,7 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") - implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:2.1.19-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' From a6e97b78aa336c473677b4794db6c221629c29e9 Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 23 Sep 2022 20:19:10 +0500 Subject: [PATCH 07/17] fixed the failing tests --- opensrp-anc/build.gradle | 2 +- .../main/java/org/smartregister/anc/library/AncLibrary.java | 3 +++ reference-app/build.gradle | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 89daf0529..c6b38eb40 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -189,7 +189,7 @@ dependencies { exclude group: 'org.yaml', module: 'snakeyaml' exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:6.0.1-BETA-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.2-BETA-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/AncLibrary.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/AncLibrary.java index 526626574..6601042b9 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/AncLibrary.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/AncLibrary.java @@ -73,6 +73,7 @@ public class AncLibrary { private final ActivityConfiguration activityConfiguration; private AncMetadata ancMetadata = new AncMetadata(); private AppExecutors appExecutors; + private static boolean eventHandlerSetup = false; private AncLibrary(@NonNull Context context, int dbVersion, @NonNull ActivityConfiguration activityConfiguration, @Nullable SubscriberInfoIndex subscriberInfoIndex, @Nullable RegisterQueryProvider registerQueryProvider) { @@ -173,7 +174,9 @@ private void setUpEventHandling() { eventBusBuilder.addIndex(subscriberInfoIndex); } + if(!eventHandlerSetup) eventBusBuilder.installDefaultEventBus(); + eventHandlerSetup = true; } catch (Exception e) { Timber.e(e, " --> setUpEventHandling"); } diff --git a/reference-app/build.gradle b/reference-app/build.gradle index a84a8f86b..dfec260b0 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -242,7 +242,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:6.0.1-BETA-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.2-BETA-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' From 796f96b70c52a05bfa20a839cb71050a50427373 Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 23 Sep 2022 20:44:54 +0500 Subject: [PATCH 08/17] fixed the failing test in CharacteristicsInteractorTest --- .../CharacteristicsInteractorTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/interactor/CharacteristicsInteractorTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/interactor/CharacteristicsInteractorTest.java index e33cd7f2d..9c6ffc675 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/interactor/CharacteristicsInteractorTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/interactor/CharacteristicsInteractorTest.java @@ -9,12 +9,24 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; import org.robolectric.util.ReflectionHelpers; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; import org.smartregister.anc.library.AncLibrary; import org.smartregister.anc.library.activity.BaseUnitTest; +import org.smartregister.anc.library.util.Utils; +import org.smartregister.configurableviews.ConfigurableViewsLibrary; +import org.smartregister.configurableviews.helper.ConfigurableViewsHelper; import org.smartregister.domain.Setting; +import org.smartregister.location.helper.LocationHelper; import org.smartregister.repository.AllSettings; +import org.smartregister.repository.AllSharedPreferences; +import org.smartregister.repository.FormDataRepository; +import org.smartregister.repository.Repository; +import org.smartregister.view.activity.DrishtiApplication; +import java.nio.charset.StandardCharsets; import java.util.Map; /** @@ -28,11 +40,60 @@ public class CharacteristicsInteractorTest extends BaseUnitTest { @Mock private AncLibrary ancLibrary; + public Context context; + + @Mock + private Repository repository; + + @Mock + private FormDataRepository formDataRepository; + + @Mock + private CoreLibrary coreLibrary; + + @Mock + private ConfigurableViewsLibrary configurableViewsLibrary; @Before public void setUp() { + + MockitoAnnotations.initMocks(this); + + context = Mockito.spy(Context.getInstance()); + context.updateApplicationContext(RuntimeEnvironment.application); + ReflectionHelpers.setField(context, "formDataRepository", formDataRepository); + //CoreLibrary.getInstance().context().allSharedPreferences() + Mockito.doReturn(Mockito.mock(AllSharedPreferences.class)).when(context).allSharedPreferences(); + ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", coreLibrary); + Mockito.when(coreLibrary.context()).thenReturn(context); +// CoreLibrary.init(context); + + // For areas where the library has been initiated wrongly, this will fix that + ReflectionHelpers.setStaticField(AncLibrary.class, "instance", null); + AncLibrary.init(context, 1); + LocationHelper.init(Utils.ALLOWED_LEVELS, Utils.DEFAULT_LOCATION_LEVEL); + + //Auto login by default + String password = "pwd"; + context.session().start(context.session().lengthInMilliseconds()); + context.configuration().getDrishtiApplication().setPassword(password.getBytes(StandardCharsets.UTF_8)); + context.session().setPassword(password.getBytes(StandardCharsets.UTF_8)); + + ReflectionHelpers.setStaticField(ConfigurableViewsLibrary.class, "instance", configurableViewsLibrary); + ConfigurableViewsHelper configurableViewsHelper = Mockito.mock(ConfigurableViewsHelper.class); + Mockito.when(configurableViewsLibrary.getConfigurableViewsHelper()).thenReturn(configurableViewsHelper); + + DrishtiApplication drishtiApplication = Mockito.mock(DrishtiApplication.class); + ReflectionHelpers.setStaticField(DrishtiApplication.class, "mInstance", drishtiApplication); + + Mockito.doReturn(repository).when(drishtiApplication).getRepository(); + Mockito.doReturn(false).when(context).IsUserLoggedOut(); + MockitoAnnotations.initMocks(this); ReflectionHelpers.setStaticField(AncLibrary.class, "instance", ancLibrary); + context = Mockito.spy(Context.getInstance()); + context.updateApplicationContext(RuntimeEnvironment.application); + } @Test From f3ea460ff66d9c59ffc66dd131a84eb07726c5a6 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Sun, 25 Sep 2022 11:34:59 +0300 Subject: [PATCH 09/17] Finalize contact task --- .../task/LoadContactSummaryDataTask.java | 208 +++++++++--------- ...etchPopulationCharacteristicsTaskTest.java | 70 ++++++ .../library/task/FinalizeContactTaskTest.java | 14 +- .../task/LoadContactSummaryDataTaskTest.java | 85 +++++++ 4 files changed, 260 insertions(+), 117 deletions(-) create mode 100644 opensrp-anc/src/test/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTaskTest.java create mode 100644 opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java index 070e7acf5..2ebe2d4f0 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java @@ -1,104 +1,104 @@ -package org.smartregister.anc.library.task; - -import android.content.Context; -import android.content.Intent; - -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import org.apache.commons.lang3.StringUtils; -import org.jeasy.rules.api.Facts; -import org.smartregister.anc.library.R; -import org.smartregister.anc.library.activity.ContactSummaryFinishActivity; -import org.smartregister.anc.library.adapter.ContactSummaryFinishAdapter; -import org.smartregister.anc.library.contract.ProfileContract; -import org.smartregister.anc.library.repository.PatientRepository; -import org.smartregister.anc.library.util.AppExecutors; -import org.smartregister.anc.library.util.ConstantsUtils; -import org.smartregister.anc.library.util.DBConstantsUtils; -import org.smartregister.anc.library.util.Utils; - -import java.util.HashMap; - -import timber.log.Timber; - -public class LoadContactSummaryDataTask { - private Context context; - private Intent intent; - private ProfileContract.Presenter mProfilePresenter; - private Facts facts; - private String baseEntityId; - private AppExecutors appExecutors; - - public LoadContactSummaryDataTask(Context context, Intent intent, ProfileContract.Presenter mProfilePresenter, Facts facts, String baseEntityId) { - this.context = context; - this.intent = intent; - this.mProfilePresenter = mProfilePresenter; - this.facts = facts; - this.baseEntityId = baseEntityId; - } - - public void execute() { - appExecutors = new AppExecutors(); - appExecutors.mainThread().execute(this::showDialog); - appExecutors.diskIO().execute(() -> { - this.onProcess(); - appExecutors.mainThread().execute(this::finishAdapterOnPostExecute); - }); - } - - private void onProcess() { - try { - ((ContactSummaryFinishActivity) context).process(); - } catch (Exception e) { - Timber.e(e, "%s --> loadContactSummaryData", this.getClass().getCanonicalName()); - } - - } - - private void showDialog() { - ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message); - ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage(String.format(context.getString(R.string.summarizing_contact_number), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data"); - ((ContactSummaryFinishActivity) context).getProgressDialog().show(); - } - - private void finishAdapterOnPostExecute() { - HashMap clientDetails; - try { - clientDetails = (HashMap) intent.getSerializableExtra(ConstantsUtils.IntentKeyUtils.CLIENT_MAP); - } catch (NullPointerException e) { - clientDetails = new HashMap<>(); - } - String edd = StringUtils.isNotBlank(facts.get(DBConstantsUtils.KeyUtils.EDD)) ? facts.get(DBConstantsUtils.KeyUtils.EDD) : clientDetails != null ? Utils.reverseHyphenSeperatedValues(clientDetails.get(ConstantsUtils.EDD), "-") : ""; - String contactNo = String.valueOf(intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)); - - if (edd != null && ((ContactSummaryFinishActivity) context).saveFinishMenuItem != null) { - PatientRepository.updateEDDDate(baseEntityId, Utils.reverseHyphenSeperatedValues(edd, "-")); - ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); - - } else if (edd == null && contactNo.contains("-")) { - ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); - } - - ContactSummaryFinishAdapter adapter = - new ContactSummaryFinishAdapter(context, ((ContactSummaryFinishActivity) context).getYamlConfigList(), facts); - adapter.notifyDataSetChanged(); - - // set up the RecyclerView - RecyclerView recyclerView = ((ContactSummaryFinishActivity) context).findViewById(R.id.contact_summary_finish_recycler); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(adapter); - // ((TextView) findViewById(R.id.section_details)).setText(crazyOutput); - ((ContactSummaryFinishActivity) context).hideProgressDialog(); - - //load profile details - - mProfilePresenter.refreshProfileView(baseEntityId); - String name = clientDetails.get(DBConstantsUtils.KeyUtils.FIRST_NAME); - if(clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME)!= null) - name = name +" "+ clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME); - - //Create PDF file stuff - mProfilePresenter.createContactSummaryPdf(name); - } -} +//package org.smartregister.anc.library.task; +// +//import android.content.Context; +//import android.content.Intent; +// +//import androidx.recyclerview.widget.LinearLayoutManager; +//import androidx.recyclerview.widget.RecyclerView; +// +//import org.apache.commons.lang3.StringUtils; +//import org.jeasy.rules.api.Facts; +//import org.smartregister.anc.library.R; +//import org.smartregister.anc.library.activity.ContactSummaryFinishActivity; +//import org.smartregister.anc.library.adapter.ContactSummaryFinishAdapter; +//import org.smartregister.anc.library.contract.ProfileContract; +//import org.smartregister.anc.library.repository.PatientRepository; +//import org.smartregister.anc.library.util.AppExecutors; +//import org.smartregister.anc.library.util.ConstantsUtils; +//import org.smartregister.anc.library.util.DBConstantsUtils; +//import org.smartregister.anc.library.util.Utils; +// +//import java.util.HashMap; +// +//import timber.log.Timber; +// +//public class LoadContactSummaryDataTask { +// private Context context; +// private Intent intent; +// private ProfileContract.Presenter mProfilePresenter; +// private Facts facts; +// private String baseEntityId; +// private AppExecutors appExecutors; +// +// public LoadContactSummaryDataTask(Context context, Intent intent, ProfileContract.Presenter mProfilePresenter, Facts facts, String baseEntityId) { +// this.context = context; +// this.intent = intent; +// this.mProfilePresenter = mProfilePresenter; +// this.facts = facts; +// this.baseEntityId = baseEntityId; +// } +// +// public void execute() { +// appExecutors = new AppExecutors(); +// appExecutors.mainThread().execute(this::showDialog); +// appExecutors.diskIO().execute(() -> { +// this.onProcess(); +// appExecutors.mainThread().execute(this::finishAdapterOnPostExecute); +// }); +// } +// +// protected void onProcess() { +// try { +// ((ContactSummaryFinishActivity) context).process(); +// } catch (Exception e) { +// Timber.e(e, "%s --> loadContactSummaryData", this.getClass().getCanonicalName()); +// } +// +// } +// +// protected void showDialog() { +// ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message); +// ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage(String.format(context.getString(R.string.summarizing_contact_number), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data"); +// ((ContactSummaryFinishActivity) context).getProgressDialog().show(); +// } +// +// protected void finishAdapterOnPostExecute() { +// HashMap clientDetails; +// try { +// clientDetails = (HashMap) intent.getSerializableExtra(ConstantsUtils.IntentKeyUtils.CLIENT_MAP); +// } catch (NullPointerException e) { +// clientDetails = new HashMap<>(); +// } +// String edd = StringUtils.isNotBlank(facts.get(DBConstantsUtils.KeyUtils.EDD)) ? facts.get(DBConstantsUtils.KeyUtils.EDD) : clientDetails != null ? Utils.reverseHyphenSeperatedValues(clientDetails.get(ConstantsUtils.EDD), "-") : ""; +// String contactNo = String.valueOf(intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)); +// +// if (edd != null && ((ContactSummaryFinishActivity) context).saveFinishMenuItem != null) { +// PatientRepository.updateEDDDate(baseEntityId, Utils.reverseHyphenSeperatedValues(edd, "-")); +// ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); +// +// } else if (edd == null && contactNo.contains("-")) { +// ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); +// } +// +// ContactSummaryFinishAdapter adapter = +// new ContactSummaryFinishAdapter(context, ((ContactSummaryFinishActivity) context).getYamlConfigList(), facts); +// adapter.notifyDataSetChanged(); +// +// // set up the RecyclerView +// RecyclerView recyclerView = ((ContactSummaryFinishActivity) context).findViewById(R.id.contact_summary_finish_recycler); +// recyclerView.setLayoutManager(new LinearLayoutManager(context)); +// recyclerView.setAdapter(adapter); +// // ((TextView) findViewById(R.id.section_details)).setText(crazyOutput); +// ((ContactSummaryFinishActivity) context).hideProgressDialog(); +// +// //load profile details +// +// mProfilePresenter.refreshProfileView(baseEntityId); +// String name = clientDetails.get(DBConstantsUtils.KeyUtils.FIRST_NAME); +// if(clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME)!= null) +// name = name +" "+ clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME); +// +// //Create PDF file stuff +// mProfilePresenter.createContactSummaryPdf(name); +// } +//} diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTaskTest.java new file mode 100644 index 000000000..d110680fa --- /dev/null +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FetchPopulationCharacteristicsTaskTest.java @@ -0,0 +1,70 @@ +package org.smartregister.anc.library.task; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; +import org.powermock.reflect.Whitebox; +import org.smartregister.anc.library.activity.BaseUnitTest; +import org.smartregister.anc.library.contract.PopulationCharacteristicsContract; +import org.smartregister.anc.library.task.FetchPopulationCharacteristicsTask; +import org.smartregister.domain.ServerSetting; +import org.smartregister.util.AppExecutors; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executor; + +public class FetchPopulationCharacteristicsTaskTest extends BaseUnitTest { + private final List settingList = new ArrayList<>(); + Executor executor; + @Mock + FetchPopulationCharacteristicsTask fetchPopulationCharacteristicsTask; + @Mock + private AppExecutors appExecutors; + private PopulationCharacteristicsContract.Presenter presenter; + + @Before + public void setUp() { + fetchPopulationCharacteristicsTask = Mockito.mock(FetchPopulationCharacteristicsTask.class); + Whitebox.setInternalState(fetchPopulationCharacteristicsTask, "presenter", presenter); + Whitebox.setInternalState(fetchPopulationCharacteristicsTask, "appExecutorService", appExecutors); + executor = Mockito.mock(Executor.class); + appExecutors = Mockito.mock(AppExecutors.class); + presenter = Mockito.mock(PopulationCharacteristicsContract.Presenter.class); + } + + @Test + public void testGetServerSettingsService() throws InterruptedException { + Mockito.doAnswer((Answer) invocation -> { + Runnable runnable = invocation.getArgument(0); + runnable.run(); + return null; + }).when(executor).execute(Mockito.any(Runnable.class)); + Mockito.when(appExecutors.diskIO()).thenReturn(executor); + FetchPopulationCharacteristicsTask characteristicsTask = new FetchPopulationCharacteristicsTask(presenter); + characteristicsTask.execute(); + Thread.sleep(1000); + Mockito.when(fetchPopulationCharacteristicsTask.getServerSettingsService()).thenReturn(settingList); + Assert.assertNotNull(settingList.size()); + + } + + @Test + public void testPresenterView() throws Exception { + Mockito.doAnswer((Answer) invocation -> { + Runnable runnable = invocation.getArgument(0); + runnable.run(); + return null; + }).when(executor).execute(Mockito.any(Runnable.class)); + Mockito.when(appExecutors.mainThread()).thenReturn(executor); + FetchPopulationCharacteristicsTask characteristicsTask = new FetchPopulationCharacteristicsTask(presenter); + characteristicsTask.execute(); + Thread.sleep(1000); + Mockito.when(fetchPopulationCharacteristicsTask.getServerSettingsService()).thenReturn(settingList); + presenter.renderView(settingList); + Assert.assertNotNull(presenter); + } +} \ No newline at end of file diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java index d8bee36a9..b2b0bb0b1 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/FinalizeContactTaskTest.java @@ -49,7 +49,7 @@ public void testGetProgressDialog() throws Exception { intent = new Intent(context, ContactSummarySendActivity.class); PowerMockito.whenNew(Intent.class).withArguments(context, ContactSummarySendActivity.class).thenReturn(intent); Whitebox.invokeMethod(finalizeContactTaskMock, "getProgressDialog"); - PowerMockito.verifyPrivate(finalizeContactTaskMock).invoke("getProgressDialog"); + Mockito.verify(finalizeContactTaskMock, Mockito.atLeastOnce()).getProgressDialog(); } @Test @@ -60,16 +60,4 @@ public void testGetWomanProfileDetails() throws Exception { Whitebox.invokeMethod(finalizeContactTaskMock, "processWomanDetailsServiceWorker"); Assert.assertNotNull(newWomanProfileDetails); } - -// @Test -// public void testInvokeFinishContactSummaryOnPostExecute() throws Exception { -// PowerMockito.whenNew(FinalizeContactTask.class).withArguments(weakReferenceContext, mProfilePresenter, new Intent()).thenReturn(finalizeContactTask); -// finalizeContactTask.execute(); -// Thread.sleep(100); -// intent = new Intent(context, ContactSummarySendActivity.class); -// PowerMockito.whenNew(Intent.class).withArguments(context, ContactSummarySendActivity.class).thenReturn(intent); -// Whitebox.invokeMethod(finalizeContactTaskMock, "finishContactSummaryOnPostExecute"); -// PowerMockito.verifyPrivate(finalizeContactTaskMock).invoke("finishContactSummaryOnPostExecute"); -// Mockito.verify(context).startActivity(intent); -// } } \ No newline at end of file diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java new file mode 100644 index 000000000..db9ecb849 --- /dev/null +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java @@ -0,0 +1,85 @@ +package org.smartregister.anc.library.task; + +import static org.robolectric.Shadows.shadowOf; + +import android.content.Context; +import android.content.Intent; +import android.os.Looper; + +import org.jeasy.rules.api.Facts; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; +import org.powermock.reflect.Whitebox; +import org.smartregister.anc.library.activity.BaseUnitTest; +import org.smartregister.anc.library.contract.ProfileContract; +import org.smartregister.util.AppExecutors; + +import java.util.concurrent.Executor; + +public class LoadContactSummaryDataTaskTest extends BaseUnitTest { + Executor executor; + @Mock + private ProfileContract.Presenter mProfilePresenter; + private LoadContactSummaryDataTask loadContactSummaryDataTaskMock; + @Mock + private Context context; + @Mock + private Intent intent; + private Facts facts; + private LoadContactSummaryDataTask loadContactSummaryDataTask; + @Mock + private AppExecutors appExecutors; + + @Before + public void setUp() { + loadContactSummaryDataTaskMock = Mockito.mock(LoadContactSummaryDataTask.class); + context = Mockito.mock(Context.class); + intent = Mockito.mock(Intent.class); + facts = new Facts(); + Whitebox.setInternalState(loadContactSummaryDataTaskMock, "context", context); + Whitebox.setInternalState(loadContactSummaryDataTaskMock, "intent", intent); + Whitebox.setInternalState(loadContactSummaryDataTaskMock, "mProfilePresenter", mProfilePresenter); + Whitebox.setInternalState(loadContactSummaryDataTaskMock, "baseEntityId", DUMMY_BASE_ENTITY_ID); + Whitebox.setInternalState(loadContactSummaryDataTaskMock, "facts", facts); + Whitebox.setInternalState(loadContactSummaryDataTaskMock, "appExecutors", appExecutors); + executor = Mockito.mock(Executor.class); + appExecutors = Mockito.mock(AppExecutors.class); + loadContactSummaryDataTask = new LoadContactSummaryDataTask(context, intent, mProfilePresenter, facts, DUMMY_BASE_ENTITY_ID); + } + + @Test + public void testOnProcess() throws Exception { + execute(); + Thread.sleep(ASYNC_TIMEOUT); + Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).onProcess(); + } + + @Test + public void testShowDialog() throws Exception { + Mockito.doReturn("Please wait").when(context).getString(ArgumentMatchers.anyInt()); + execute(); + shadowOf(Looper.getMainLooper()).idle(); + Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).showDialog(); + } + + @Test + public void testFinishAdapterOnPostExecute() throws Exception { + execute(); + Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).finishAdapterOnPostExecute(); + } + + private void execute() throws Exception { + Mockito.doAnswer((Answer) invocation -> { + Runnable runnable = invocation.getArgument(0); + runnable.run(); + return null; + }).when(executor).execute(Mockito.any(Runnable.class)); + Mockito.when(appExecutors.mainThread()).thenReturn(executor); + loadContactSummaryDataTask.execute(); + Thread.sleep(ASYNC_TIMEOUT); + } +} \ No newline at end of file From c7b6d8c36125db7a900c9c6ca81f1f798838eff8 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Sun, 25 Sep 2022 12:48:41 +0300 Subject: [PATCH 10/17] Load Contact summary data --- .../task/LoadContactSummaryDataTask.java | 205 +++++++++--------- .../task/LoadContactSummaryDataTaskTest.java | 170 +++++++-------- 2 files changed, 186 insertions(+), 189 deletions(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java index 2ebe2d4f0..34d5db7a3 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java @@ -1,104 +1,101 @@ -//package org.smartregister.anc.library.task; -// -//import android.content.Context; -//import android.content.Intent; -// -//import androidx.recyclerview.widget.LinearLayoutManager; -//import androidx.recyclerview.widget.RecyclerView; -// -//import org.apache.commons.lang3.StringUtils; -//import org.jeasy.rules.api.Facts; -//import org.smartregister.anc.library.R; -//import org.smartregister.anc.library.activity.ContactSummaryFinishActivity; -//import org.smartregister.anc.library.adapter.ContactSummaryFinishAdapter; -//import org.smartregister.anc.library.contract.ProfileContract; -//import org.smartregister.anc.library.repository.PatientRepository; -//import org.smartregister.anc.library.util.AppExecutors; -//import org.smartregister.anc.library.util.ConstantsUtils; -//import org.smartregister.anc.library.util.DBConstantsUtils; -//import org.smartregister.anc.library.util.Utils; -// -//import java.util.HashMap; -// -//import timber.log.Timber; -// -//public class LoadContactSummaryDataTask { -// private Context context; -// private Intent intent; -// private ProfileContract.Presenter mProfilePresenter; -// private Facts facts; -// private String baseEntityId; -// private AppExecutors appExecutors; -// -// public LoadContactSummaryDataTask(Context context, Intent intent, ProfileContract.Presenter mProfilePresenter, Facts facts, String baseEntityId) { -// this.context = context; -// this.intent = intent; -// this.mProfilePresenter = mProfilePresenter; -// this.facts = facts; -// this.baseEntityId = baseEntityId; -// } -// -// public void execute() { -// appExecutors = new AppExecutors(); -// appExecutors.mainThread().execute(this::showDialog); -// appExecutors.diskIO().execute(() -> { -// this.onProcess(); -// appExecutors.mainThread().execute(this::finishAdapterOnPostExecute); -// }); -// } -// -// protected void onProcess() { -// try { -// ((ContactSummaryFinishActivity) context).process(); -// } catch (Exception e) { -// Timber.e(e, "%s --> loadContactSummaryData", this.getClass().getCanonicalName()); -// } -// -// } -// -// protected void showDialog() { -// ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message); -// ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage(String.format(context.getString(R.string.summarizing_contact_number), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data"); -// ((ContactSummaryFinishActivity) context).getProgressDialog().show(); -// } -// -// protected void finishAdapterOnPostExecute() { -// HashMap clientDetails; -// try { -// clientDetails = (HashMap) intent.getSerializableExtra(ConstantsUtils.IntentKeyUtils.CLIENT_MAP); -// } catch (NullPointerException e) { -// clientDetails = new HashMap<>(); -// } -// String edd = StringUtils.isNotBlank(facts.get(DBConstantsUtils.KeyUtils.EDD)) ? facts.get(DBConstantsUtils.KeyUtils.EDD) : clientDetails != null ? Utils.reverseHyphenSeperatedValues(clientDetails.get(ConstantsUtils.EDD), "-") : ""; -// String contactNo = String.valueOf(intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)); -// -// if (edd != null && ((ContactSummaryFinishActivity) context).saveFinishMenuItem != null) { -// PatientRepository.updateEDDDate(baseEntityId, Utils.reverseHyphenSeperatedValues(edd, "-")); -// ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); -// -// } else if (edd == null && contactNo.contains("-")) { -// ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); -// } -// -// ContactSummaryFinishAdapter adapter = -// new ContactSummaryFinishAdapter(context, ((ContactSummaryFinishActivity) context).getYamlConfigList(), facts); -// adapter.notifyDataSetChanged(); -// -// // set up the RecyclerView -// RecyclerView recyclerView = ((ContactSummaryFinishActivity) context).findViewById(R.id.contact_summary_finish_recycler); -// recyclerView.setLayoutManager(new LinearLayoutManager(context)); -// recyclerView.setAdapter(adapter); -// // ((TextView) findViewById(R.id.section_details)).setText(crazyOutput); -// ((ContactSummaryFinishActivity) context).hideProgressDialog(); -// -// //load profile details -// -// mProfilePresenter.refreshProfileView(baseEntityId); -// String name = clientDetails.get(DBConstantsUtils.KeyUtils.FIRST_NAME); -// if(clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME)!= null) -// name = name +" "+ clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME); -// -// //Create PDF file stuff -// mProfilePresenter.createContactSummaryPdf(name); -// } -//} +package org.smartregister.anc.library.task; + +import android.content.Context; +import android.content.Intent; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import org.apache.commons.lang3.StringUtils; +import org.jeasy.rules.api.Facts; +import org.smartregister.anc.library.R; +import org.smartregister.anc.library.activity.ContactSummaryFinishActivity; +import org.smartregister.anc.library.adapter.ContactSummaryFinishAdapter; +import org.smartregister.anc.library.contract.ProfileContract; +import org.smartregister.anc.library.repository.PatientRepository; +import org.smartregister.anc.library.util.AppExecutors; +import org.smartregister.anc.library.util.ConstantsUtils; +import org.smartregister.anc.library.util.DBConstantsUtils; +import org.smartregister.anc.library.util.Utils; + +import java.util.HashMap; + +import timber.log.Timber; + +public class LoadContactSummaryDataTask { + private final Intent intent; + private final Context context; + private final ProfileContract.Presenter mProfilePresenter; + private final Facts facts; + private final String baseEntityId; + private AppExecutors appExecutors; + + public LoadContactSummaryDataTask(Context context, Intent intent, ProfileContract.Presenter mProfilePresenter, Facts facts, String baseEntityId) { + this.context = context; + this.intent = intent; + this.mProfilePresenter = mProfilePresenter; + this.facts = facts; + this.baseEntityId = baseEntityId; + } + + + public void execute() { + appExecutors = new AppExecutors(); + appExecutors.mainThread().execute(this::showDialog); + appExecutors.diskIO().execute(() -> { + this.onProcess(); + appExecutors.mainThread().execute(this::finishAdapterOnPostExecute); + }); + } + + private Void onProcess() { + try { + ((ContactSummaryFinishActivity) context).process(); + } catch (Exception e) { + Timber.e(e, "%s --> loadContactSummaryData", this.getClass().getCanonicalName()); + } + + return null; + } + + private void showDialog() { + ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message); + ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage(String.format(context.getString(R.string.summarizing_contact_number), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data"); + ((ContactSummaryFinishActivity) context).getProgressDialog().show(); + } + + private void finishAdapterOnPostExecute() { + HashMap clientDetails; + try { + clientDetails = (HashMap) intent.getSerializableExtra(ConstantsUtils.IntentKeyUtils.CLIENT_MAP); + } catch (NullPointerException e) { + clientDetails = new HashMap<>(); + } + String edd = StringUtils.isNotBlank(facts.get(DBConstantsUtils.KeyUtils.EDD)) ? facts.get(DBConstantsUtils.KeyUtils.EDD) : clientDetails != null ? Utils.reverseHyphenSeperatedValues(clientDetails.get(ConstantsUtils.EDD), "-") : ""; + String contactNo = String.valueOf(intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)); + + if (edd != null && ((ContactSummaryFinishActivity) context).saveFinishMenuItem != null) { + PatientRepository.updateEDDDate(baseEntityId, Utils.reverseHyphenSeperatedValues(edd, "-")); + ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); + + } else if (edd == null && contactNo.contains("-")) { + ((ContactSummaryFinishActivity) context).saveFinishMenuItem.setEnabled(true); + } + ContactSummaryFinishAdapter adapter = new ContactSummaryFinishAdapter(context, ((ContactSummaryFinishActivity) context).getYamlConfigList(), facts); + adapter.notifyDataSetChanged(); + // set up the RecyclerView + RecyclerView recyclerView = ((ContactSummaryFinishActivity) context).findViewById(R.id.contact_summary_finish_recycler); + recyclerView.setLayoutManager(new LinearLayoutManager(context)); + recyclerView.setAdapter(adapter); + // ((TextView) findViewById(R.id.section_details)).setText(crazyOutput); + ((ContactSummaryFinishActivity) context).hideProgressDialog(); + //load profile details + mProfilePresenter.refreshProfileView(baseEntityId); + String name = clientDetails.get(DBConstantsUtils.KeyUtils.FIRST_NAME); + if(clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME)!= null) + name = name +" "+ clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME); + + //Create PDF file stuff + mProfilePresenter.createContactSummaryPdf(name); + } +} \ No newline at end of file diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java index db9ecb849..d6e02c6fb 100644 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java +++ b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java @@ -1,85 +1,85 @@ -package org.smartregister.anc.library.task; - -import static org.robolectric.Shadows.shadowOf; - -import android.content.Context; -import android.content.Intent; -import android.os.Looper; - -import org.jeasy.rules.api.Facts; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.stubbing.Answer; -import org.powermock.reflect.Whitebox; -import org.smartregister.anc.library.activity.BaseUnitTest; -import org.smartregister.anc.library.contract.ProfileContract; -import org.smartregister.util.AppExecutors; - -import java.util.concurrent.Executor; - -public class LoadContactSummaryDataTaskTest extends BaseUnitTest { - Executor executor; - @Mock - private ProfileContract.Presenter mProfilePresenter; - private LoadContactSummaryDataTask loadContactSummaryDataTaskMock; - @Mock - private Context context; - @Mock - private Intent intent; - private Facts facts; - private LoadContactSummaryDataTask loadContactSummaryDataTask; - @Mock - private AppExecutors appExecutors; - - @Before - public void setUp() { - loadContactSummaryDataTaskMock = Mockito.mock(LoadContactSummaryDataTask.class); - context = Mockito.mock(Context.class); - intent = Mockito.mock(Intent.class); - facts = new Facts(); - Whitebox.setInternalState(loadContactSummaryDataTaskMock, "context", context); - Whitebox.setInternalState(loadContactSummaryDataTaskMock, "intent", intent); - Whitebox.setInternalState(loadContactSummaryDataTaskMock, "mProfilePresenter", mProfilePresenter); - Whitebox.setInternalState(loadContactSummaryDataTaskMock, "baseEntityId", DUMMY_BASE_ENTITY_ID); - Whitebox.setInternalState(loadContactSummaryDataTaskMock, "facts", facts); - Whitebox.setInternalState(loadContactSummaryDataTaskMock, "appExecutors", appExecutors); - executor = Mockito.mock(Executor.class); - appExecutors = Mockito.mock(AppExecutors.class); - loadContactSummaryDataTask = new LoadContactSummaryDataTask(context, intent, mProfilePresenter, facts, DUMMY_BASE_ENTITY_ID); - } - - @Test - public void testOnProcess() throws Exception { - execute(); - Thread.sleep(ASYNC_TIMEOUT); - Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).onProcess(); - } - - @Test - public void testShowDialog() throws Exception { - Mockito.doReturn("Please wait").when(context).getString(ArgumentMatchers.anyInt()); - execute(); - shadowOf(Looper.getMainLooper()).idle(); - Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).showDialog(); - } - - @Test - public void testFinishAdapterOnPostExecute() throws Exception { - execute(); - Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).finishAdapterOnPostExecute(); - } - - private void execute() throws Exception { - Mockito.doAnswer((Answer) invocation -> { - Runnable runnable = invocation.getArgument(0); - runnable.run(); - return null; - }).when(executor).execute(Mockito.any(Runnable.class)); - Mockito.when(appExecutors.mainThread()).thenReturn(executor); - loadContactSummaryDataTask.execute(); - Thread.sleep(ASYNC_TIMEOUT); - } -} \ No newline at end of file +//package org.smartregister.anc.library.task; +// +//import static org.robolectric.Shadows.shadowOf; +// +//import android.content.Context; +//import android.content.Intent; +//import android.os.Looper; +// +//import org.jeasy.rules.api.Facts; +//import org.junit.Before; +//import org.junit.Test; +//import org.mockito.ArgumentMatchers; +//import org.mockito.Mock; +//import org.mockito.Mockito; +//import org.mockito.stubbing.Answer; +//import org.powermock.reflect.Whitebox; +//import org.smartregister.anc.library.activity.BaseUnitTest; +//import org.smartregister.anc.library.contract.ProfileContract; +//import org.smartregister.util.AppExecutors; +// +//import java.util.concurrent.Executor; +// +//public class LoadContactSummaryDataTaskTest extends BaseUnitTest { +// Executor executor; +// @Mock +// private ProfileContract.Presenter mProfilePresenter; +// private LoadContactSummaryDataTask loadContactSummaryDataTaskMock; +// @Mock +// private Context context; +// @Mock +// private Intent intent; +// private Facts facts; +// private LoadContactSummaryDataTask loadContactSummaryDataTask; +// @Mock +// private AppExecutors appExecutors; +// +// @Before +// public void setUp() { +// loadContactSummaryDataTaskMock = Mockito.mock(LoadContactSummaryDataTask.class); +// context = Mockito.mock(Context.class); +// intent = Mockito.mock(Intent.class); +// facts = new Facts(); +// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "context", context); +// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "intent", intent); +// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "mProfilePresenter", mProfilePresenter); +// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "baseEntityId", DUMMY_BASE_ENTITY_ID); +// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "facts", facts); +// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "appExecutors", appExecutors); +// executor = Mockito.mock(Executor.class); +// appExecutors = Mockito.mock(AppExecutors.class); +// loadContactSummaryDataTask = new LoadContactSummaryDataTask(context, intent, mProfilePresenter, facts, DUMMY_BASE_ENTITY_ID); +// } +// +// @Test +// public void testOnProcess() throws Exception { +// execute(); +// Thread.sleep(ASYNC_TIMEOUT); +// Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).onProcess(); +// } +// +// @Test +// public void testShowDialog() throws Exception { +// Mockito.doReturn("Please wait").when(context).getString(ArgumentMatchers.anyInt()); +// execute(); +// shadowOf(Looper.getMainLooper()).idle(); +// Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).showDialog(); +// } +// +// @Test +// public void testFinishAdapterOnPostExecute() throws Exception { +// execute(); +// Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).finishAdapterOnPostExecute(); +// } +// +// private void execute() throws Exception { +// Mockito.doAnswer((Answer) invocation -> { +// Runnable runnable = invocation.getArgument(0); +// runnable.run(); +// return null; +// }).when(executor).execute(Mockito.any(Runnable.class)); +// Mockito.when(appExecutors.mainThread()).thenReturn(executor); +// loadContactSummaryDataTask.execute(); +// Thread.sleep(ASYNC_TIMEOUT); +// } +//} \ No newline at end of file From e8c3c8de35cb5d076a693ee9a74d9dbabe3d9c40 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 27 Sep 2022 18:23:08 +0300 Subject: [PATCH 11/17] client core version amendmend --- opensrp-anc/build.gradle | 2 +- .../task/LoadContactSummaryDataTaskTest.java | 85 ------------------- reference-app/build.gradle | 2 +- 3 files changed, 2 insertions(+), 87 deletions(-) delete mode 100644 opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index c6b38eb40..8b3cd994e 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -189,7 +189,7 @@ dependencies { exclude group: 'org.yaml', module: 'snakeyaml' exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:6.0.2-BETA-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' diff --git a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java b/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java deleted file mode 100644 index d6e02c6fb..000000000 --- a/opensrp-anc/src/test/java/org/smartregister/anc/library/task/LoadContactSummaryDataTaskTest.java +++ /dev/null @@ -1,85 +0,0 @@ -//package org.smartregister.anc.library.task; -// -//import static org.robolectric.Shadows.shadowOf; -// -//import android.content.Context; -//import android.content.Intent; -//import android.os.Looper; -// -//import org.jeasy.rules.api.Facts; -//import org.junit.Before; -//import org.junit.Test; -//import org.mockito.ArgumentMatchers; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.stubbing.Answer; -//import org.powermock.reflect.Whitebox; -//import org.smartregister.anc.library.activity.BaseUnitTest; -//import org.smartregister.anc.library.contract.ProfileContract; -//import org.smartregister.util.AppExecutors; -// -//import java.util.concurrent.Executor; -// -//public class LoadContactSummaryDataTaskTest extends BaseUnitTest { -// Executor executor; -// @Mock -// private ProfileContract.Presenter mProfilePresenter; -// private LoadContactSummaryDataTask loadContactSummaryDataTaskMock; -// @Mock -// private Context context; -// @Mock -// private Intent intent; -// private Facts facts; -// private LoadContactSummaryDataTask loadContactSummaryDataTask; -// @Mock -// private AppExecutors appExecutors; -// -// @Before -// public void setUp() { -// loadContactSummaryDataTaskMock = Mockito.mock(LoadContactSummaryDataTask.class); -// context = Mockito.mock(Context.class); -// intent = Mockito.mock(Intent.class); -// facts = new Facts(); -// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "context", context); -// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "intent", intent); -// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "mProfilePresenter", mProfilePresenter); -// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "baseEntityId", DUMMY_BASE_ENTITY_ID); -// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "facts", facts); -// Whitebox.setInternalState(loadContactSummaryDataTaskMock, "appExecutors", appExecutors); -// executor = Mockito.mock(Executor.class); -// appExecutors = Mockito.mock(AppExecutors.class); -// loadContactSummaryDataTask = new LoadContactSummaryDataTask(context, intent, mProfilePresenter, facts, DUMMY_BASE_ENTITY_ID); -// } -// -// @Test -// public void testOnProcess() throws Exception { -// execute(); -// Thread.sleep(ASYNC_TIMEOUT); -// Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).onProcess(); -// } -// -// @Test -// public void testShowDialog() throws Exception { -// Mockito.doReturn("Please wait").when(context).getString(ArgumentMatchers.anyInt()); -// execute(); -// shadowOf(Looper.getMainLooper()).idle(); -// Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).showDialog(); -// } -// -// @Test -// public void testFinishAdapterOnPostExecute() throws Exception { -// execute(); -// Mockito.verify(loadContactSummaryDataTaskMock, Mockito.atLeastOnce()).finishAdapterOnPostExecute(); -// } -// -// private void execute() throws Exception { -// Mockito.doAnswer((Answer) invocation -> { -// Runnable runnable = invocation.getArgument(0); -// runnable.run(); -// return null; -// }).when(executor).execute(Mockito.any(Runnable.class)); -// Mockito.when(appExecutors.mainThread()).thenReturn(executor); -// loadContactSummaryDataTask.execute(); -// Thread.sleep(ASYNC_TIMEOUT); -// } -//} \ No newline at end of file diff --git a/reference-app/build.gradle b/reference-app/build.gradle index dfec260b0..97e97c1a3 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -242,7 +242,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:6.0.2-BETA-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' From 8789ddb593d36996f17810182996cd038ba5ff1e Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:38:15 +0300 Subject: [PATCH 12/17] p2p sync version --- opensrp-anc/build.gradle | 4 ++-- reference-app/build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 8b3cd994e..bf7a32b3b 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -178,7 +178,7 @@ tasks.withType(Test) { dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' - implementation('org.smartregister:opensrp-client-native-form:2.1.19-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -205,7 +205,7 @@ dependencies { exclude group: 'org.smartregister', module: 'android-p2p-sync' } - api("org.smartregister:android-p2p-sync:0.3.9-DEV-SNAPSHOT") { + api("org.smartregister:android-p2p-sync:0.4.0-DEV-SNAPSHOT") { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 97e97c1a3..20c7569a6 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -230,7 +230,7 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") - implementation('org.smartregister:opensrp-client-native-form:2.1.19-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -258,7 +258,7 @@ dependencies { exclude group: 'org.smartregister', module: 'android-p2p-sync' } - api("org.smartregister:android-p2p-sync:0.3.9-DEV-SNAPSHOT") { + api("org.smartregister:android-p2p-sync:0.4.0-DEV-SNAPSHOT") { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'com.android.support', module: 'appcompat-v7' From 9a818aba3b2280fc6ca18aace9659746dbae2292 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 14:55:13 +0300 Subject: [PATCH 13/17] p2p-sync compatibility with android x --- opensrp-anc/build.gradle | 3 +++ reference-app/build.gradle | 3 +++ 2 files changed, 6 insertions(+) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index bf7a32b3b..a42124c7d 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -2,6 +2,9 @@ buildscript { repositories { mavenCentral() google() + maven { + url "https://s3.amazonaws.com/repo.commonsware.com" + } } dependencies { classpath 'com.android.tools.build:gradle:4.1.3' diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 20c7569a6..c77cf47c7 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -2,6 +2,9 @@ buildscript { repositories { mavenCentral() google() + maven { + url "https://s3.amazonaws.com/repo.commonsware.com" + } } dependencies { classpath 'com.android.tools.build:gradle:4.1.3' From c179a82026ac139b2ba820b0db2b93791ed8f9de Mon Sep 17 00:00:00 2001 From: vend Date: Fri, 21 Oct 2022 12:00:58 +0500 Subject: [PATCH 14/17] resolved android 12 issues --- .../config/profile_contact_tab_contacts.yml | 5 +- .../src/main/assets/json.form/anc_test.json | 38 +++ .../sub_form/tests_covid_19_sub_form.json | 316 ++++++++++++++++++ .../sub_form/tests_syphilis_sub_form.json | 40 ++- .../sub_form/tests_toxo_sub_form.json | 247 ++++++++++++++ .../assets/rule/tests_calculation_rules.yml | 23 ++ .../tests_expansion_panel_relevance_rules.yml | 19 +- .../assets/rule/tests_relevance_rules.yml | 163 ++++++++- .../repository/PreviousContactRepository.java | 3 +- .../src/main/resources/anc_test.properties | 5 +- .../profile_contact_tab_contacts.properties | 3 +- .../resources/test_covid_sub_form.properties | 24 ++ .../test_covid_sub_form_fr.properties | 0 .../test_covid_sub_form_ind.properties | 0 .../test_covid_sub_form_pt.properties | 0 .../tests_hepatitis_b_sub_form.properties | 2 +- .../tests_syphilis_sub_form.properties | 5 +- .../resources/tests_toxo_sub_form.properties | 25 ++ .../tests_toxo_sub_form_fr.properties | 0 .../tests_toxo_sub_form_ind.properties | 0 .../tests_toxo_sub_form_pt.properties | 0 reference-app/src/main/AndroidManifest.xml | 17 +- 22 files changed, 910 insertions(+), 25 deletions(-) create mode 100644 opensrp-anc/src/main/assets/json.form/sub_form/tests_covid_19_sub_form.json create mode 100644 opensrp-anc/src/main/assets/json.form/sub_form/tests_toxo_sub_form.json create mode 100644 opensrp-anc/src/main/resources/test_covid_sub_form.properties create mode 100644 opensrp-anc/src/main/resources/test_covid_sub_form_fr.properties create mode 100644 opensrp-anc/src/main/resources/test_covid_sub_form_ind.properties create mode 100644 opensrp-anc/src/main/resources/test_covid_sub_form_pt.properties create mode 100644 opensrp-anc/src/main/resources/tests_toxo_sub_form.properties create mode 100644 opensrp-anc/src/main/resources/tests_toxo_sub_form_fr.properties create mode 100644 opensrp-anc/src/main/resources/tests_toxo_sub_form_ind.properties create mode 100644 opensrp-anc/src/main/resources/tests_toxo_sub_form_pt.properties diff --git a/opensrp-anc/src/main/assets/config/profile_contact_tab_contacts.yml b/opensrp-anc/src/main/assets/config/profile_contact_tab_contacts.yml index 6d5bf9196..23e898a01 100644 --- a/opensrp-anc/src/main/assets/config/profile_contact_tab_contacts.yml +++ b/opensrp-anc/src/main/assets/config/profile_contact_tab_contacts.yml @@ -5,4 +5,7 @@ fields: relevance: "phys_symptoms != ''" - template: "{{profile_contact_tab_contacts.average_weight_gain_per_week_since_last_contact}}: {weight_gain} kg" - relevance: "weight_gain != ''" \ No newline at end of file + relevance: "weight_gain != '' && weight_gain != '0'" + +- template: "{{profile_contact_tab_contacts.total_weight_gain}}: {tot_weight_gain} kg" + relevance: "weight_gain == '' || weight_gain == '0'" \ No newline at end of file diff --git a/opensrp-anc/src/main/assets/json.form/anc_test.json b/opensrp-anc/src/main/assets/json.form/anc_test.json index 7f7ea041a..812366a55 100644 --- a/opensrp-anc/src/main/assets/json.form/anc_test.json +++ b/opensrp-anc/src/main/assets/json.form/anc_test.json @@ -361,6 +361,44 @@ } } }, + { + "key": "accordion_covid-19", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "text": "{{anc_test.step2.accordion_covid_19.text}}", + "accordion_info_text": "{{anc_test.step2.accordion_covid_19.text}}", + "accordion_info_title": "{{anc_test.step2.accordion_covid_19.text}}", + "type": "expansion_panel", + "content_form": "tests_covid_19_sub_form", + "container": "anc_test", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_expansion_panel_relevance_rules.yml" + } + } + } + }, + { + "key": "accordion_toxo", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "text": "{{anc_test.step2.accordion_toxo.text}}", + "accordion_info_text": "{{anc_test.step2.accordion_toxo.info.text}}", + "accordion_info_title": "{{anc_test.step2.accordion_toxo.text}}", + "type": "expansion_panel", + "content_form": "tests_toxo_sub_form", + "container": "anc_test", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_expansion_panel_relevance_rules.yml" + } + } + } + }, { "key": "accordion_syphilis", "openmrs_entity_parent": "", diff --git a/opensrp-anc/src/main/assets/json.form/sub_form/tests_covid_19_sub_form.json b/opensrp-anc/src/main/assets/json.form/sub_form/tests_covid_19_sub_form.json new file mode 100644 index 000000000..704ebad16 --- /dev/null +++ b/opensrp-anc/src/main/assets/json.form/sub_form/tests_covid_19_sub_form.json @@ -0,0 +1,316 @@ +{ + "content_form": [ + { + "key": "covid_status", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163725AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "label": "{{tests_covid_sub_form.step1.covid_status.label}}", + "label_text_style": "bold", + "text_color": "#000000", + "type": "extended_radio_button", + "options": [ + { + "key": "done_today", + "text": "{{tests_covid_sub_form.step1.covid_test_status.options.done_today.text}}", + "type": "done_today", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165383AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "done_earlier", + "text": "{{tests_covid_sub_form.step1.covid_test_status.options.done_earlier.text}}", + "type": "done_earlier", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165385AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "ordered", + "text": "{{tests_covid_sub_form.step1.covid_test_status.options.ordered.text}}", + "type": "ordered", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165384AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "not_done", + "text": "{{tests_covid_sub_form.step1.covid_test_status.options.not_done.text}}", + "type": "not_done", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "1118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "{{tests_covid_sub_form.step1.covid_test_status.v_required.err}}" + } + }, + { + "key": "spacer", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "spacer", + "type": "spacer", + "spacer_height": "10dp" + }, + { + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "key": "covid_date_today_hidden", + "type": "hidden", + "label_text_style": "bold", + "text_color": "#000000", + "calculation": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_calculation_rules.yml" + } + } + } + }, + { + "key": "covid_test_date", + "openmrs_entity_parent": "300AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "openmrs_entity": "concept", + "openmrs_entity_id": "163724AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "date_picker", + "hint": "{{tests_covid_sub_form.step1.covid_test_date.hint}}", + "expanded": "false", + "max_date": "today", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + }, + "calculation": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_calculation_rules.yml" + } + } + }, + "v_required": { + "value": true, + "err": "{{tests_covid_sub_form.step1.covid_test_date.v_required.err}}" + } + }, + { + "key": "covid_test_type", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "", + "type": "native_radio", + "label": "{{tests_covid_sub_form.step1.covid_test_type.label}}", + "label_text_style": "bold", + "options": [ + { + "key": "covid_pcr_test", + "text": "{{tests_covid_sub_form.step1.covid_test_rtpcr.label.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "covid_antigen_test", + "text": "{{tests_covid_sub_form.step1.covid_test_antigen.label.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "covid_igg_test", + "text": "{{tests_covid_sub_form.step1.covid_test_igg.label.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "covid_igm_test", + "text": "{{tests_covid_sub_form.step1.covid_test_igmr.label.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + }, + "v_required": { + "value": true, + "err": "{{tests_covid_sub_form.step1.covid_test_type.v_required.err}}" + } + }, + { + "key": "covid_pcr_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_covid_sub_form.step1.covid_test_rtpcr.label.text}}", + "label_text_style": "bold", + "options": [ + { + "key": "positive", + "text": "{{tests_covid_sub_form.step1.covid.options.positive.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "negative", + "text": "{{tests_covid_sub_form.step1.covid.options.negative.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "covid_antigen_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_covid_sub_form.step1.covid_test_antigen.label.text}}", + "label_text_style": "bold", + "options": [ + { + "key": "positive", + "text": "{{tests_covid_sub_form.step1.covid.options.positive.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "negative", + "text": "{{tests_covid_sub_form.step1.covid.options.negative.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "covid_igg_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_covid_sub_form.step1.covid_test_igg.label.text}}", + "label_text_style": "bold", + "options": [ + { + "key": "positive", + "text": "{{tests_covid_sub_form.step1.covid.options.positive.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "negative", + "text": "{{tests_covid_sub_form.step1.covid.options.negative.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "covid_igm_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_covid_sub_form.step1.covid_test_igmr.label.text}}", + "label_text_style": "bold", + "options": [ + { + "key": "positive", + "text": "{{tests_covid_sub_form.step1.covid.options.positive.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "negative", + "text": "{{tests_covid_sub_form.step1.covid.options.negative.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "", + "key": "covid_positive", + "type": "hidden", + "label_text_style": "bold", + "text_color": "#000000", + "calculation": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_calculation_rules.yml" + } + } + } + } + ], + "count": 1, + "properties_file_name": "test_covid_sub_form" +} \ No newline at end of file diff --git a/opensrp-anc/src/main/assets/json.form/sub_form/tests_syphilis_sub_form.json b/opensrp-anc/src/main/assets/json.form/sub_form/tests_syphilis_sub_form.json index 67b4ecd37..af168e581 100644 --- a/opensrp-anc/src/main/assets/json.form/sub_form/tests_syphilis_sub_form.json +++ b/opensrp-anc/src/main/assets/json.form/sub_form/tests_syphilis_sub_form.json @@ -1,4 +1,22 @@ -{ +{"global_previous": [ + "blood_type_test_status", + "hiv_test_partner_result", + "hiv_test_status", + "hiv_test_result", + "hiv_test_partner_status", + "hepb_test_status", + "hepc_test_status", + "syph_test_status", + "tb_screening_status", + "hiv_positive", + "urine_test_status", + "hb_test_status", + "syphilis_positive", + "hepc_positive", + "syph_test_status", + "ultrasound", + "hepb_positive" +], "content_form": [ { "key": "syph_test_status", @@ -200,7 +218,7 @@ "openmrs_entity_parent": "", "openmrs_entity": "concept", "openmrs_entity_id": "165422AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - "type": "native_radio", + "type": "check_box", "label": "{{tests_syphilis_sub_form.step1.syph_test_type.label}}", "label_text_style": "bold", "options": [ @@ -362,6 +380,24 @@ } } }, + { + "key": "syphilis_positive_and_pencillin_allergy_toaster", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "{{tests_syphilis_sub_form.step1.syphilis_positive_and_pencillin_allergy_toaster.text}}", + "toaster_info_text": "{{tests_syphilis_sub_form.step1.syphilis_positive_and_pencillin_allergy_toaster.toaster_info_text}}", + "toaster_info_title": "{{tests_syphilis_sub_form.step1.syphilis_positive_and_pencillin_allergy_toaster.toaster_info_title}}", + "toaster_type": "problem", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, { "key": "syphilis_danger_toaster", "openmrs_entity_parent": "", diff --git a/opensrp-anc/src/main/assets/json.form/sub_form/tests_toxo_sub_form.json b/opensrp-anc/src/main/assets/json.form/sub_form/tests_toxo_sub_form.json new file mode 100644 index 000000000..a03daa89c --- /dev/null +++ b/opensrp-anc/src/main/assets/json.form/sub_form/tests_toxo_sub_form.json @@ -0,0 +1,247 @@ +{ + "content_form": [ + { + "key": "toxo_test_status", + "openmrs_entity_parent": "300AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "openmrs_entity": "concept", + "openmrs_entity_id": "163725AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "label": "{{tests_toxo_sub_form.step1.toxo_test_status.label}}", + "label_text_style": "bold", + "text_color": "#000000", + "type": "extended_radio_button", + "content_form": "tests_toxo_sub_form", + "options": [ + { + "key": "done_today", + "text": "{{tests_toxo_sub_form.step1.toxo_test_status.options.done_today.text}}", + "type": "done_today", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165383AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "done_earlier", + "text": "{{tests_toxo_sub_form.step1.toxo_test_status.options.done_earlier.text}}", + "type": "done_earlier", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165385AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "ordered", + "text": "{{tests_toxo_sub_form.step1.toxo_test_status.options.ordered.text}}", + "type": "ordered", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165384AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "not_done", + "text": "{{tests_toxo_sub_form.step1.toxo_test_status.options.not_done.text}}", + "type": "not_done", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "1118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ] + }, + { + "key": "spacer", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "spacer", + "type": "spacer", + "spacer_height": "10dp" + }, + { + "key": "toxo_test_date", + "openmrs_entity_parent": "300AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "openmrs_entity": "concept", + "openmrs_entity_id": "163724AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "date_picker", + "hint": "{{tests_toxo_sub_form.step1.toxo_test_date.hint}}", + "expanded": "false", + "max_date": "today", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + }, + "calculation": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_calculation_rules.yml" + } + } + }, + "v_required": { + "value": true, + "err": "{{tests_toxo_sub_form.step1.toxo_test_date.v_required.err}}" + } + }, + { + "key": "toxo_igg_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_toxo_sub_form.step1.toxo_igg_test.label}}", + "label_text_style": "bold", + "options": [ + { + "key": "positive", + "text": "{{tests_toxo_sub_form.step1.toxo_igg_test.options.positive.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "negative", + "text": "{{tests_toxo_sub_form.step1.toxo_igg_test.options.negative.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "{{tests_toxo_sub_form.step1.toxo_igg_test.v_required.err}}" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "toxo_igm_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_toxo_sub_form.step1.toxo_igm_test.label}}", + "label_text_style": "bold", + "options": [ + { + "key": "positive", + "text": "{{tests_toxo_sub_form.step1.toxo_igm_test.options.positive.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "negative", + "text": "{{tests_toxo_sub_form.step1.toxo_igm_test.options.negative.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "{{tests_toxo_sub_form.step1.toxo_igm_test.v_required.err}}" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "toxo_avidity_test", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163126AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "native_radio", + "label": "{{tests_toxo_sub_form.step1.toxo_avidity_test.label}}", + "label_text_style": "bold", + "options": [ + { + "key": "less_than_60", + "text": "{{tests_toxo_sub_form.step1.toxo_avidity_test.options.less_than_60.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163115AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "key": "greater_than_60", + "text": "{{tests_toxo_sub_form.step1.toxo_avidity_test.options.greater_than_60.text}}", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "163118AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + ], + "v_required": { + "value": true, + "err": "{{tests_toxo_sub_form.step1.toxo_avidity_test.v_required.err}}" + }, + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "toaster_toxoplasmosis_susceptible", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "{{tests_toxo_sub_form.step1.toaster_toxoplasmosis_susceptible.text}}", + "toaster_info_text": "{{tests_toxo_sub_form.step1.toaster_toxoplasmosis_susceptible.toaster_info_text}}", + "toaster_type": "warning", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "toaster_toxoplasmosis_immune", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "{{tests_toxo_sub_form.step1.toaster_toxoplasmosis_immune.text}}", + "toaster_info_text": "{{tests_toxo_sub_form.step1.toaster_toxoplasmosis_immune.toaster_info_text}}", + "toaster_type": "warning", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + }, + { + "key": "toaster_toxoplasmosis_positive", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "{{tests_toxo_sub_form.step1.toaster_toxoplasmosis_positive.text}}", + "toaster_info_text": "{{tests_toxo_sub_form.step1.toaster_toxoplasmosis_positive.toaster_info_text}}", + "toaster_type": "problem", + "relevance": { + "rules-engine": { + "ex-rules": { + "rules-file": "tests_relevance_rules.yml" + } + } + } + } + ], + "count": 1, + "properties_file_name": "tests_toxo_sub_form" +} + diff --git a/opensrp-anc/src/main/assets/rule/tests_calculation_rules.yml b/opensrp-anc/src/main/assets/rule/tests_calculation_rules.yml index 7f7aa1b8c..b536d51ea 100644 --- a/opensrp-anc/src/main/assets/rule/tests_calculation_rules.yml +++ b/opensrp-anc/src/main/assets/rule/tests_calculation_rules.yml @@ -271,3 +271,26 @@ priority: 1 condition: "step2_hb_test_status != '' && step2_hb_test_status == 'done_today'" actions: - "calculation = helper.getDateToday()" +--- +name: step1_covid_positive +description: covid_positive +priority: 1 +condition: "(step1_covid_pcr_test == 'positive') || (step1_covid_antigen_test == 'positive') || (step1_covid_igg_test == 'positive') || (step1_covid_igm_test == 'positive')" +actions: + - "calculation = 1" +--- +name: step1_covid_date_today_hidden +description: Covid_test_date +priority: 1 +condition: "step1_covid_status != '' && step1_covid_status == 'done_today'" +actions: + - "calculation = helper.getDateToday()" +--- +name: step1_toxo_test_date +description: toxo_test_date +priority: 1 +condition: "step1_toxo_test_status == 'done_today'" +actions: + - "calculation = helper.getDateToday()" + + diff --git a/opensrp-anc/src/main/assets/rule/tests_expansion_panel_relevance_rules.yml b/opensrp-anc/src/main/assets/rule/tests_expansion_panel_relevance_rules.yml index 1f9555192..be15ea76c 100644 --- a/opensrp-anc/src/main/assets/rule/tests_expansion_panel_relevance_rules.yml +++ b/opensrp-anc/src/main/assets/rule/tests_expansion_panel_relevance_rules.yml @@ -30,7 +30,7 @@ actions: name: step1_accordion_hepatitis_c description: Hepatitis C test priority: 1 -condition: "((helper.getValueFromAccordion('accordion_hiv', 'step1_hiv_positive') == '1' || global_pop_hepc == true || (!global_alcohol_substance_use.isEmpty() && global_alcohol_substance_use.contains('injectable_drugs')) || (!global_occupation.isEmpty() && global_occupation.contains('informal_employment_sex_worker')))) && (global_contact_no == 1 || (global_contact_no > 1 && (global_previous_hepc_test_status == '' || global_previous_hepc_test_status == 'not_done' || global_previous_hepc_test_status == 'ordered')))" +condition: "helper.getValueFromAccordion('accordion_hiv', 'step1_hiv_positive') == '1' || global_alcohol_substance_use.contains('injectable_drugs') || global_occupation.contains('informal_employment_sex_worker') || global_previous_hepc_test_status.contains('') || global_previous_hepc_test_status.contains('not_done') || global_previous_hepc_test_status.contains ('ordered')" actions: - "isRelevant = true" --- @@ -100,7 +100,7 @@ actions: name: step2_accordion_partner_hiv description: Partner HIV test priority: 1 -condition: "(global_partner_hiv_status == 'dont_know' || global_partner_hiv_status == '') && (global_contact_no == 1 || (global_contact_no > 1 && ((global_previous_hiv_test_partner_status == 'done_earlier' || global_previous_hiv_test_partner_status == 'done_today') && global_previous_hiv_test_partner_result == 'inconclusive') || global_previous_hiv_test_partner_status == ''))" +condition: "global_partner_hiv_status.contains('dont_know') || global_partner_hiv_status == ''" actions: - "isRelevant = true" --- @@ -111,6 +111,7 @@ condition: "global_contact_no == 1 || (global_contact_no > 1 && (global_previous actions: - "isRelevant = true" --- + name: step2_accordion_blood_type description: step2 blood type accordion priority: 1 @@ -129,5 +130,19 @@ name: step2_accordion_blood_haemoglobin description: hb_test_status priority: 1 condition: "(global_contact_no > 1 && (global_previous_hb_test_status != '' && (global_previous_hb_test_status == 'done_earlier' || global_previous_hb_test_status == 'done_today')))" +actions: + - "isRelevant = true" +--- +name: step2_accordion_covid-19 +description: accordion_covid-19 +priority: 1 +condition: "1 == 1" +actions: + - "isRelevant = true" +--- +name: step2_accordion_toxo +description: accordion_covid-19 +priority: 1 +condition: "1 == 1" actions: - "isRelevant = true" \ No newline at end of file diff --git a/opensrp-anc/src/main/assets/rule/tests_relevance_rules.yml b/opensrp-anc/src/main/assets/rule/tests_relevance_rules.yml index 6f12301c0..2f139666b 100644 --- a/opensrp-anc/src/main/assets/rule/tests_relevance_rules.yml +++ b/opensrp-anc/src/main/assets/rule/tests_relevance_rules.yml @@ -429,42 +429,42 @@ actions: name: step1_rapid_syphilis_test description: Rapid syphilis test (RST) priority: 1 -condition: "((step1_syph_test_status == 'done_today' || step1_syph_test_status == 'done_earlier') && step1_syph_test_type == 'rapid_syphilis')" +condition: "((step1_syph_test_status == 'done_today' || step1_syph_test_status == 'done_earlier') && step1_syph_test_type.contains('rapid_syphilis'))" actions: - "isRelevant = true" --- name: step2_rapid_syphilis_test description: Rapid syphilis test (RST) priority: 1 -condition: "((step2_syph_test_status == 'done_today' || step2_syph_test_status == 'done_earlier') && step2_syph_test_type == 'rapid_syphilis')" +condition: "((step2_syph_test_status == 'done_today' || step2_syph_test_status == 'done_earlier') && step2_syph_test_type.contains('rapid_syphilis'))" actions: - "isRelevant = true" --- name: step1_rpr_syphilis_test description: Rapid plasma reagin (RPR) test priority: 1 -condition: "((step1_syph_test_status == 'done_today' || step1_syph_test_status == 'done_earlier') && step1_syph_test_type == 'rapid_plasma')" +condition: "((step1_syph_test_status == 'done_today' || step1_syph_test_status == 'done_earlier') && step1_syph_test_type.contains('rapid_plasma'))" actions: - "isRelevant = true" --- name: step2_rpr_syphilis_test description: Rapid plasma reagin (RPR) test priority: 1 -condition: "((step2_syph_test_status == 'done_today' || step2_syph_test_status == 'done_earlier') && step2_syph_test_type == 'rapid_plasma')" +condition: "((step2_syph_test_status == 'done_today' || step2_syph_test_status == 'done_earlier') && step2_syph_test_type.contains('rapid_plasma'))" actions: - "isRelevant = true" --- name: step1_lab_syphilis_test description: Off-site lab test for syphilis priority: 1 -condition: "((step1_syph_test_status == 'done_today' || step1_syph_test_status == 'done_earlier') && step1_syph_test_type == 'off_site_lab')" +condition: "((step1_syph_test_status == 'done_today' || step1_syph_test_status == 'done_earlier') && step1_syph_test_type.contains('off_site_lab'))" actions: - "isRelevant = true" --- name: step2_lab_syphilis_test description: Off-site lab test for syphilis priority: 1 -condition: "((step2_syph_test_status == 'done_today' || step2_syph_test_status == 'done_earlier') && step2_syph_test_type == 'off_site_lab')" +condition: "((step2_syph_test_status == 'done_today' || step2_syph_test_status == 'done_earlier') && step2_syph_test_type.contains('off_site_lab'))" actions: - "isRelevant = true" --- @@ -475,6 +475,15 @@ condition: "step1_syphilis_positive == 1" actions: - "isRelevant = true" --- + +name: step1_syphilis_positive_and_pencillin_allergy_toaster +description: Syphilis test positive +priority: 1 +condition: "step1_syphilis_positive == 1" +actions: + - "isRelevant = true" +--- + name: step2_syphilis_danger_toaster description: Syphilis test positive priority: 1 @@ -1068,4 +1077,144 @@ description: other_test_result priority: 1 condition: "step2_other_test == 'done_earlier' || step2_other_test == 'done_today'" actions: -- "isRelevant = true" \ No newline at end of file +- "isRelevant = true" +--- +name: step1_covid_test_date +description: COVID test date +priority: 1 +condition: "(step1_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_covid_test_date +description: COVID test date +priority: 1 +condition: "(step2_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step1_covid_test_type +description: COVID test type +priority: 1 +condition: "(step1_covid_status == 'done_today' || step1_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_covid_test_type +description: COVID test type +priority: 1 +condition: "(step2_covid_status == 'done_today' || step2_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step1_covid_pcr_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step1_covid_test_type == 'covid_pcr_test' && step1_covid_status == 'done_today') || (step1_covid_test_type == 'hbsag_lab_based' && step1_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_covid_pcr_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step2_covid_test_type == 'covid_pcr_test' && step2_covid_status == 'done_today') || (step2_covid_test_type == 'hbsag_lab_based' && step2_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step1_covid_antigen_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step1_covid_test_type == 'covid_antigen_test' && step1_covid_status == 'done_today') || (step1_covid_test_type == 'covid_antigen_test' && step1_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_covid_antigen_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step2_covid_test_type == 'covid_antigen_test' && step2_covid_status == 'done_today') || (step2_covid_test_type == 'covid_antigen_test' && step2_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step1_covid_igg_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step1_covid_test_type == 'covid_igg_test' && step1_covid_status == 'done_today') || (step1_covid_test_type == 'covid_igg_test' && step1_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_covid_igg_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step2_covid_test_type == 'covid_igg_test' && step2_covid_status == 'done_today') || (step2_covid_test_type == 'covid_igg_test' && step2_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step1_covid_igm_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step1_covid_test_type == 'covid_igm_test' && step1_covid_status == 'done_today') || (step1_covid_test_type == 'covid_igm_test' && step1_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_covid_igm_test +description: HBsAg laboratory-based immunoassay (recommended) +priority: 1 +condition: "(step2_covid_test_type == 'covid_igm_test' && step2_covid_status == 'done_today') || (step2_covid_test_type == 'covid_igm_test' && step2_covid_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step1_toxo_test_status +description: toxo_test_status +priority: 1 +condition: "global_contact_no == 1 || (global_contact_no > 1 && (global_gest_age_openmrs != '' && (global_gest_age_openmrs == 20 || global_gest_age_openmrs == 28)))" +actions: + - "isRelevant = true" +--- +name: step2_toxo_test_date +description: toxo_test_datedate +priority: 1 +condition: "step2_toxo_test_status != '' && step2_toxo_test_status == 'done_earlier'" +actions: + - "isRelevant = true" +--- +name: step2_toxo_igg_test +description: toxo_igg_test +priority: 1 +condition: "(step2_toxo_test_status == 'done_today' || step2_toxo_test_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_toxo_igm_test +description: toxo_igm_test +priority: 1 +condition: "(step2_toxo_test_status == 'done_today' || step2_toxo_test_status == 'done_earlier')" +actions: + - "isRelevant = true" +--- +name: step2_toxo_avidity_test +description: toxo_avidity_test +priority: 1 +condition: "(step2_toxo_igm_test == 'positive')" +actions: + - "isRelevant = true" +--- +name: step2_toaster_toxoplasmosis_susceptible +description: toaster_toxoplasmosis_susceptible +priority: 1 +condition: "(step2_toxo_igm_test == 'negative' && step2_toxo_igg_test == 'negative')" +actions: + - "isRelevant = true" +--- +name: step2_toaster_toxoplasmosis_immune +description: toaster_toxoplasmosis_immune +priority: 1 +condition: "(step2_toxo_igm_test == 'negative' && step2_toxo_igg_test == 'positive') || (step2_toxo_igm_test == 'positive' && step2_toxo_igg_test == 'positive' && (global_gest_age_openmrs != '' && global_gest_age_openmrs < 16) && step2_toxo_avidity_test == 'greater_than_60')" +actions: + - "isRelevant = true" +--- +name: step2_toaster_toxoplasmosis_positive +description: toaster_toxoplasmosis_positive +priority: 1 +condition: "(step2_toxo_igm_test == 'positive' && step2_toxo_igg_test == 'negative') || (step2_toxo_igm_test == 'positive' && step2_toxo_igg_test == 'positive' && (global_gest_age_openmrs != '' && global_gest_age_openmrs > 16) && step2_toxo_avidity_test == 'greater_than_60') || (step2_toxo_avidity_test == 'less_than_60')" +actions: + - "isRelevant = true" \ No newline at end of file diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java index 57166e072..ac1d0ecd4 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java @@ -320,6 +320,7 @@ public Facts getPreviousContactFacts(String baseEntityId, String contactNo, bool String selection = ""; String orderBy = "MAX("+ ID + ") DESC"; String[] selectionArgs = null; + int contactNumber = Integer.parseInt(contactNo); Facts previousContactFacts = new Facts(); try { SQLiteDatabase db = getReadableDatabase(); @@ -351,7 +352,7 @@ public Facts getPreviousContactFacts(String baseEntityId, String contactNo, bool } previousContactFacts.put(CONTACT_NO, selectionArgs[1]); return previousContactFacts; - } else if (Integer.parseInt(contactNo) > 0) { + } else if (contactNumber > 0) { return getPreviousContactFacts(baseEntityId, contactNo, false); } } catch (Exception e) { diff --git a/opensrp-anc/src/main/resources/anc_test.properties b/opensrp-anc/src/main/resources/anc_test.properties index b84f88741..efc631c4c 100644 --- a/opensrp-anc/src/main/resources/anc_test.properties +++ b/opensrp-anc/src/main/resources/anc_test.properties @@ -51,7 +51,10 @@ anc_test.step2.accordion_other_tests.text = Other Tests anc_test.step2.accordion_ultrasound.accordion_info_title = Ultrasound test anc_test.step1.accordion_ultrasound.accordion_info_title = Ultrasound test anc_test.step2.accordion_hepatitis_b.text = Hepatitis B test +anc_test.step2.accordion_covid_19.text = COVID-19 test anc_test.step1.accordion_syphilis.accordion_info_title = Syphilis test anc_test.step2.accordion_blood_haemoglobin.text = Blood Haemoglobin test anc_test.step1.accordion_urine.accordion_info_text = A urine test is required at the first contact, last contact in 2nd trimester, and 2nd contact in 3rd trimester OR anytime the woman reports pain during urination (dysuria). A dipstick test is required if the woman has a repeat high BP reading (140/90 or higher). Otherwise, a urine test is optional. The urine test checks for bacterial or other infections that can lead to adverse outcomes for the neonate. The urine dipstick test can check for proteins in the urine, which can be a sign of pre-eclampsia. -anc_test.step2.accordion_syphilis.text = Syphilis test \ No newline at end of file +anc_test.step2.accordion_syphilis.text = Syphilis test +anc_test.step2.accordion_toxo.text = Toxoplasmosis test +anc_test.step2.accordion_toxo.info.text = Screening for toxoplasmosis is required at the first visit. If the woman is immune, there is no need for further testing. If susceptible, the test should be repeated in the 2nd and 3rd trimesters. \ No newline at end of file diff --git a/opensrp-anc/src/main/resources/profile_contact_tab_contacts.properties b/opensrp-anc/src/main/resources/profile_contact_tab_contacts.properties index 72fb17318..24bd0d5c4 100644 --- a/opensrp-anc/src/main/resources/profile_contact_tab_contacts.properties +++ b/opensrp-anc/src/main/resources/profile_contact_tab_contacts.properties @@ -1,2 +1,3 @@ profile_contact_tab_contacts.physiological_symptoms = Physiological symptoms -profile_contact_tab_contacts.average_weight_gain_per_week_since_last_contact = Average weight gain per week since last contact \ No newline at end of file +profile_contact_tab_contacts.average_weight_gain_per_week_since_last_contact = Average weight gain per week since last contact +profile_contact_tab_contacts.total_weight_gain = Total weight gain in pregnancy so far \ No newline at end of file diff --git a/opensrp-anc/src/main/resources/test_covid_sub_form.properties b/opensrp-anc/src/main/resources/test_covid_sub_form.properties new file mode 100644 index 000000000..c9f1d96ff --- /dev/null +++ b/opensrp-anc/src/main/resources/test_covid_sub_form.properties @@ -0,0 +1,24 @@ +tests_covid_sub_form.step1.covid_test_status.options.done_earlier.text = Done earlier +tests_covid_sub_form.step1.covid_test_status.options.done_today.text = Done today +tests_covid_sub_form.step1.covid_test_status.options.not_done.text = Not done +tests_covid_sub_form.step1.covid_test_status.options.ordered.text = Ordered + +tests_covid_sub_form.step1.covid_test_rtpcr.label.text = SARS-CoV2 RT-PCR +tests_covid_sub_form.step1.covid_test_antigen.label.text = SARS-CoV2 Antigen +tests_covid_sub_form.step1.covid_test_igg.label.text = SARS-CoV2 IgG +tests_covid_sub_form.step1.covid_test_igmr.label.text = SARS-CoV2 IgM + +tests_covid_sub_form.step1.covid_status.label = COVID-19 test + +tests_covid_sub_form.step1.covid_test_status.v_required.err = COVID test is required +tests_covid_sub_form.step1.covid_test_date.v_required.err = COVID test date is required + +tests_covid_sub_form.step1.covid_test_type.label = COVID test type + + + +tests_covid_sub_form.step1.covid_test_date.hint = COVID test date + +tests_covid_sub_form.step1.covid_test_type.v_required.err = COVID test type is required +tests_covid_sub_form.step1.covid.options.positive.text = Positive +tests_covid_sub_form.step1.covid.options.negative.text = Negative \ No newline at end of file diff --git a/opensrp-anc/src/main/resources/test_covid_sub_form_fr.properties b/opensrp-anc/src/main/resources/test_covid_sub_form_fr.properties new file mode 100644 index 000000000..e69de29bb diff --git a/opensrp-anc/src/main/resources/test_covid_sub_form_ind.properties b/opensrp-anc/src/main/resources/test_covid_sub_form_ind.properties new file mode 100644 index 000000000..e69de29bb diff --git a/opensrp-anc/src/main/resources/test_covid_sub_form_pt.properties b/opensrp-anc/src/main/resources/test_covid_sub_form_pt.properties new file mode 100644 index 000000000..e69de29bb diff --git a/opensrp-anc/src/main/resources/tests_hepatitis_b_sub_form.properties b/opensrp-anc/src/main/resources/tests_hepatitis_b_sub_form.properties index 986761e6a..96410ec87 100644 --- a/opensrp-anc/src/main/resources/tests_hepatitis_b_sub_form.properties +++ b/opensrp-anc/src/main/resources/tests_hepatitis_b_sub_form.properties @@ -32,4 +32,4 @@ tests_hepatitis_b_sub_form.step1.hepatitis_b_info_toaster.text = Hep B negative. tests_hepatitis_b_sub_form.step1.hepb_test_status.options.done_earlier.text = Done earlier tests_hepatitis_b_sub_form.step1.hepb_test_status.options.done_today.text = Done today tests_hepatitis_b_sub_form.step1.hepb_test_status.options.not_done.text = Not done -tests_hepatitis_b_sub_form.step1.hepb_test_status.options.ordered.text = Ordered +tests_hepatitis_b_sub_form.step1.hepb_test_status.options.ordered.text = Ordered \ No newline at end of file diff --git a/opensrp-anc/src/main/resources/tests_syphilis_sub_form.properties b/opensrp-anc/src/main/resources/tests_syphilis_sub_form.properties index 86377e460..9e0156bca 100644 --- a/opensrp-anc/src/main/resources/tests_syphilis_sub_form.properties +++ b/opensrp-anc/src/main/resources/tests_syphilis_sub_form.properties @@ -1,5 +1,6 @@ tests_syphilis_sub_form.step1.syphilis_greater_5_toaster.text=This area has a high prevalence of syphilis (5% or greater). tests_syphilis_sub_form.step1.syphilis_danger_toaster.toaster_info_title=Syphilis test positive +tests_syphilis_sub_form.step1.syphilis_positive_and_pencillin_allergy_toaster.toaster_info_title = Syphilis positive and Penicillin allergy tests_syphilis_sub_form.step1.syph_test_notdone.options.stock_out.text=Stock out tests_syphilis_sub_form.step1.syph_test_type.label=Syphilis test type tests_syphilis_sub_form.step1.syphilis_greater_5_toaster.toaster_info_text=Use an on-site rapid syphilis test (RST), and, if positive, provide the first dose of treatment. Then refer the woman for a rapid plasma reagin (RPR) test. If the RPR test is positive, provide treatment according to the clinical phase of syphilis. @@ -24,9 +25,11 @@ tests_syphilis_sub_form.step1.syph_test_type.options.off_site_lab.text=Off-site tests_syphilis_sub_form.step1.syph_test_type.options.rapid_plasma.text=Rapid plasma reagin test tests_syphilis_sub_form.step1.syphilis_below_5_toaster.toaster_info_text=On-site rapid syphilis test (RST) should be used to test pregnant women for syphilis. tests_syphilis_sub_form.step1.syphilis_danger_toaster.text=Syphilis test positive +tests_syphilis_sub_form.step1.syphilis_positive_and_pencillin_allergy_toaster.text = Counseling for positive syphilis test and Penicillin allergy tests_syphilis_sub_form.step1.syphilis_test_date.v_required.err=Select the date of the syphilis test. tests_syphilis_sub_form.step1.syph_test_type.options.rapid_syphilis.text=Rapid syphilis test -tests_syphilis_sub_form.step1.syphilis_danger_toaster.toaster_info_text=Provide counselling and treatment according to protocol. +tests_syphilis_sub_form.step1.syphilis_positive_and_pencillin_allergy_toaster.toaster_info_text= Refer to penicillin susceptibility test.. +tests_syphilis_sub_form.step1.syphilis_danger_toaster.toaster_info_text tests_syphilis_sub_form.step1.syph_test_status.label=Syphilis test tests_syphilis_sub_form.step1.syph_test_status.options.not_done.text=Not done tests_syphilis_sub_form.step1.syph_test_status.options.done_today.text=Done today diff --git a/opensrp-anc/src/main/resources/tests_toxo_sub_form.properties b/opensrp-anc/src/main/resources/tests_toxo_sub_form.properties new file mode 100644 index 000000000..618af29dd --- /dev/null +++ b/opensrp-anc/src/main/resources/tests_toxo_sub_form.properties @@ -0,0 +1,25 @@ +tests_toxo_sub_form.step1.toxo_test_status.label = Toxoplasmosis test +tests_toxo_sub_form.step1.toxo_test_status.options.done_today.text = Done today +tests_toxo_sub_form.step1.toxo_test_status.options.done_earlier.text = Done earlier +tests_toxo_sub_form.step1.toxo_test_status.options.ordered.text = Ordered +tests_toxo_sub_form.step1.toxo_test_status.options.not_done.text = Not done +tests_toxo_sub_form.step1.toxo_test_date.hint = Toxopasmosis test date +tests_toxo_sub_form.step1.toxo_test_date.v_required.err = Please record date of Toxoplasmosis test +tests_toxo_sub_form.step1.toxo_igg_test.label = Toxoplasmosis IgG +tests_toxo_sub_form.step1.toxo_igg_test.options.positive.text = Positive +tests_toxo_sub_form.step1.toxo_igg_test.options.negative.text = Negative +tests_toxo_sub_form.step1.toxo_igg_test.v_required.err = Toxoplasmosis IgG result is required +tests_toxo_sub_form.step1.toxo_igm_test.label = Toxoplasmosis IgM +tests_toxo_sub_form.step1.toxo_igm_test.options.positive.text = Positive +tests_toxo_sub_form.step1.toxo_igm_test.options.negative.text = Negative +tests_toxo_sub_form.step1.toxo_igm_test.v_required.err = Toxoplasmosis IgM result is required +tests_toxo_sub_form.step1.toxo_avidity_test.label = Toxoplasmosis IgG Avidity +tests_toxo_sub_form.step1.toxo_avidity_test.options.less_than_60.text = < 60% +tests_toxo_sub_form.step1.toxo_avidity_test.options.greater_than_60.text = > 60% +tests_toxo_sub_form.step1.toxo_avidity_test.v_required.err = Toxoplasmosis IgG Avidity is required +tests_toxo_sub_form.step1.toaster_toxoplasmosis_susceptible.text =Toxoplasmosis susceptible counseling +tests_toxo_sub_form.step1.toaster_toxoplasmosis_susceptible.toaster_info_text =Woman susceptible to toxoplasmosis. Advise the consumption of well-cooked food and avoid handling a place with animal feces. +tests_toxo_sub_form.step1.toaster_toxoplasmosis_immune.text =Toxoplasmosis imune counseling +tests_toxo_sub_form.step1.toaster_toxoplasmosis_immune.toaster_info_text = Woman imune to toxoplasmosis. +tests_toxo_sub_form.step1.toaster_toxoplasmosis_positive.text =Toxoplasmosis positive counseling +tests_toxo_sub_form.step1.toaster_toxoplasmosis_positive.toaster_info_text = Woman positive to toxoplasmosis. Prescribe treatment according to protocol and referral to high level assistance. \ No newline at end of file diff --git a/opensrp-anc/src/main/resources/tests_toxo_sub_form_fr.properties b/opensrp-anc/src/main/resources/tests_toxo_sub_form_fr.properties new file mode 100644 index 000000000..e69de29bb diff --git a/opensrp-anc/src/main/resources/tests_toxo_sub_form_ind.properties b/opensrp-anc/src/main/resources/tests_toxo_sub_form_ind.properties new file mode 100644 index 000000000..e69de29bb diff --git a/opensrp-anc/src/main/resources/tests_toxo_sub_form_pt.properties b/opensrp-anc/src/main/resources/tests_toxo_sub_form_pt.properties new file mode 100644 index 000000000..e69de29bb diff --git a/reference-app/src/main/AndroidManifest.xml b/reference-app/src/main/AndroidManifest.xml index ec4f67afc..1875ae579 100644 --- a/reference-app/src/main/AndroidManifest.xml +++ b/reference-app/src/main/AndroidManifest.xml @@ -31,7 +31,8 @@ android:name=".activity.LoginActivity" android:screenOrientation="portrait" android:theme="@style/AncAppTheme.Login" - android:windowSoftInputMode="stateAlwaysHidden|adjustResize"> + android:windowSoftInputMode="stateAlwaysHidden|adjustResize" + android:exported="true"> @@ -143,13 +144,13 @@ android:resource="@xml/captured_images_path" /> - - - - - - - + + + + + + + Date: Wed, 26 Oct 2022 15:29:45 +0500 Subject: [PATCH 15/17] removed attention flag test --- .../library/task/AttentionsFlagsTaskTest.java | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java diff --git a/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java b/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java deleted file mode 100644 index fbad9739f..000000000 --- a/reference-app/src/test/java/org/smartregister/anc/library/task/AttentionsFlagsTaskTest.java +++ /dev/null @@ -1,47 +0,0 @@ -//package org.smartregister.anc.library.task; -// -//import org.junit.Assert; -//import org.junit.Before; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.powermock.reflect.Whitebox; -//import org.robolectric.RobolectricTestRunner; -//import org.smartregister.anc.BaseUnitTest; -//import org.smartregister.anc.library.activity.BaseHomeRegisterActivity; -//import org.smartregister.anc.library.domain.AttentionFlag; -//import org.smartregister.commonregistry.CommonPersonObjectClient; -// -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -// -//@RunWith(RobolectricTestRunner.class) -//public class AttentionsFlagsTaskTest extends BaseUnitTest { -// private static BaseHomeRegisterActivity baseHomeRegisterActivity; -// private static CommonPersonObjectClient commonPersonObjectClient; -// private final List attentionFlagList = new ArrayList<>(); -// Map details = new HashMap<>(); -// private AttentionFlagsTask attentionFlagsTask; -// -// @Before -// public void setUp() { -// String name = "asynctask"; -// String caseId = "e34343-343434-67"; -// baseHomeRegisterActivity = new BaseHomeRegisterActivity(); -// commonPersonObjectClient = new CommonPersonObjectClient(caseId, details, name); -// attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); -// -// } -// -// @Test -// public void testAttentionFlags() throws InterruptedException { -// attentionFlagsTask = new AttentionFlagsTask(baseHomeRegisterActivity, commonPersonObjectClient); -// attentionFlagsTask.execute(); -// Whitebox.setInternalState(attentionFlagsTask, "onPostExecute"); -// Thread.sleep(ASYNC_TIMEOUT); -// //To check whether the Attention Flags have data in them -// Assert.assertNotNull(attentionFlagList); -// -// } -//} From a4482a70ec7926844cf9b950ce6f4997a76445d6 Mon Sep 17 00:00:00 2001 From: vend Date: Wed, 26 Oct 2022 16:18:03 +0500 Subject: [PATCH 16/17] integer parsing moved under exception handling block --- .../anc/library/repository/PreviousContactRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java index ac1d0ecd4..d89658637 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java @@ -320,9 +320,9 @@ public Facts getPreviousContactFacts(String baseEntityId, String contactNo, bool String selection = ""; String orderBy = "MAX("+ ID + ") DESC"; String[] selectionArgs = null; - int contactNumber = Integer.parseInt(contactNo); Facts previousContactFacts = new Facts(); try { + int contactNumber = Integer.parseInt(contactNo); SQLiteDatabase db = getReadableDatabase(); if (StringUtils.isNotBlank(baseEntityId) && StringUtils.isNotBlank(contactNo)) { From c70884e34865b779543c9565e5abed37b3917ae9 Mon Sep 17 00:00:00 2001 From: vend Date: Thu, 27 Oct 2022 11:50:03 +0500 Subject: [PATCH 17/17] updated the core and native forms library and upgraded the version --- opensrp-anc/build.gradle | 4 ++-- .../anc/library/repository/PatientRepository.java | 3 +++ reference-app/build.gradle | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index a42124c7d..a39690d6f 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -181,7 +181,7 @@ tasks.withType(Test) { dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' - implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:3.1.1-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -192,7 +192,7 @@ dependencies { exclude group: 'org.yaml', module: 'snakeyaml' exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:6.0.2-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.0-BETA3-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PatientRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PatientRepository.java index 8088eb22b..8511c7bb6 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PatientRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PatientRepository.java @@ -155,11 +155,14 @@ public static void updateCohabitants(String form, String baseEntityId) { JSONObject jsonObject = new JSONObject(form); JSONArray fields = ANCJsonFormUtils.getSingleStepFormfields(jsonObject); JSONObject cohabitants = ANCJsonFormUtils.getFieldJSONObject(fields, DBConstantsUtils.KeyUtils.COHABITANTS); + JSONObject reminder = ANCJsonFormUtils.getFieldJSONObject(fields, DBConstantsUtils.KeyUtils.REMINDERS); String value = cohabitants.optString(ConstantsUtils.KeyUtils.VALUE, "[]"); + String remindersValue = reminder.optString(ConstantsUtils.KeyUtils.VALUE,"{}"); ContentValues contentValues = new ContentValues(); contentValues.put(DBConstantsUtils.KeyUtils.COHABITANTS, value); + contentValues.put(DBConstantsUtils.KeyUtils.REMINDERS,remindersValue); updatePatient(baseEntityId, contentValues, getRegisterQueryProvider().getDetailsTable()); diff --git a/reference-app/build.gradle b/reference-app/build.gradle index c77cf47c7..6614ae712 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -28,7 +28,7 @@ jacoco { // This variables are used by the version code & name generators ext.versionMajor = 1 ext.versionMinor = 6 -ext.versionPatch = 14 +ext.versionPatch = 15 ext.versionClassifier = null ext.isSnapshot = false ext.minimumSdkVersion = androidMinSdkVersion @@ -233,7 +233,7 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") - implementation('org.smartregister:opensrp-client-native-form:3.0.2-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:3.1.1-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' @@ -245,7 +245,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' } - implementation('org.smartregister:opensrp-client-core:6.0.2-PREVIEW-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-core:6.0.0-BETA3-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava'