diff --git a/gradle.properties b/gradle.properties index b184fc102..711a29853 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.0.0-SNAPSHOT +VERSION_NAME=1.0.1-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Child Library diff --git a/opensrp-child/build.gradle b/opensrp-child/build.gradle index ae63bbca3..c34ff6a6a 100644 --- a/opensrp-child/build.gradle +++ b/opensrp-child/build.gradle @@ -120,7 +120,7 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6' - api('org.smartregister:opensrp-client-core:6.0.0-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-core:6.1.1-SNAPSHOT@aar') { transitive = true exclude group: 'com.github.bmelnychuk', module: 'atv' exclude group: 'com.google.guava', module: 'guava' @@ -142,7 +142,7 @@ dependencies { exclude group: 'io.ona.rdt-capture', module: 'lib' exclude group: 'com.google.android.gms', module: 'play-services-vision' exclude group: 'com.google.code.gson', module: 'gson' - exclude group: 'com.github.raihan-mpower', module:'FancyAlertDialog-Android' + exclude group: 'com.github.raihan-mpower', module: 'FancyAlertDialog-Android' } implementation 'com.google.code.gson:gson:2.9.0' @@ -187,6 +187,7 @@ dependencies { implementation "androidx.constraintlayout:constraintlayout:2.1.4" testImplementation 'junit:junit:4.13.2' + def robolectricVersion = '4.1' testImplementation("org.robolectric:robolectric:$robolectricVersion") { exclude group: 'com.google.auto.service', module: 'auto-service' diff --git a/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildImmunizationActivity.java b/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildImmunizationActivity.java index e8eb57410..30d684b20 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildImmunizationActivity.java +++ b/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildImmunizationActivity.java @@ -227,8 +227,9 @@ protected void onCreate(Bundle savedInstanceState) { // Get child details from bundled data Bundle extras = this.getIntent().getExtras(); + String caseId = ""; if (extras != null) { - String caseId = extras.getString(Constants.INTENT_KEY.BASE_ENTITY_ID); + caseId = extras.getString(Constants.INTENT_KEY.BASE_ENTITY_ID); childDetails = getChildDetails(caseId); CommonPersonObjectClient cardChildDetails = null; @@ -270,6 +271,12 @@ protected void onCreate(Bundle savedInstanceState) { setLastModified(false); + if (getChildDetails() == null) { + Timber.e("Unable to fetch child details with case id: %s", caseId); + Utils.showToast(this, getString(R.string.error_child_details)); + getActivity().finish(); + return; + } setUpFloatingActionButton(); Utils.refreshDataCaptureStrategyBanner(this, getOpenSRPContext().allSharedPreferences().fetchCurrentLocality()); } @@ -461,7 +468,6 @@ public void updateViews() { } else { Timber.e("fetchCommonPersonObjectClientByBaseEntityId is null, child record is not n the database."); } - } isChildActive = isActiveStatus(childDetails); @@ -479,6 +485,7 @@ public void updateViews() { updateNextAppointmentDateView(); startUpdateViewTask(); + updateFloatingActionButtonBasedOnChildStatus(); } @VisibleForTesting @@ -2142,4 +2149,18 @@ protected void onPostExecute(List list) { showVaccineNotifications(vaccineList, alertList); } } + + protected void updateFloatingActionButtonBasedOnChildStatus() { + if (ChildLibrary.getInstance().getProperties().getPropertyBoolean(ChildAppProperties.KEY.FEATURE_NFC_CARD_ENABLED)) { + if (!Utils.hasCompassRelationshipId(childDetails.getColumnmaps())) { + configureFloatingActionBackground(R.drawable.pill_background_unregistered, getResources().getString(R.string.enroll_caregiver)); + } else { + if (!Utils.isChildHasNFCCard(childDetails.getColumnmaps())) { + configureFloatingActionBackground(R.drawable.pill_background_unregistered, getResources().getString(R.string.activate_new_card)); + } else { + configureFloatingActionBackground(getGenderButtonColor(childDetails.getColumnmaps().get(Constants.KEY.GENDER)), getResources().getString(R.string.write_to_card)); + } + } + } + } } \ No newline at end of file diff --git a/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseAdvancedSearchFragment.java b/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseAdvancedSearchFragment.java index 108d99e3e..d6f57fc5c 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseAdvancedSearchFragment.java +++ b/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseAdvancedSearchFragment.java @@ -651,6 +651,8 @@ public void run() { public void run() { clientAdapter.setTotalcount(totalCount); Timber.i("Total Register Count %d", clientAdapter.getTotalcount()); + updateMatchingResults(totalCount); + clientAdapter.setCurrentlimit(getPageLimit()); clientAdapter.setCurrentoffset(0); } @@ -663,7 +665,6 @@ public void run() { Timber.e(e); } - updateMatchingResults(clientAdapter.getTotalcount()); } @Override diff --git a/opensrp-child/src/main/java/org/smartregister/child/model/BaseChildAdvancedSearchModel.java b/opensrp-child/src/main/java/org/smartregister/child/model/BaseChildAdvancedSearchModel.java index cc2f421d5..29b9d4025 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/model/BaseChildAdvancedSearchModel.java +++ b/opensrp-child/src/main/java/org/smartregister/child/model/BaseChildAdvancedSearchModel.java @@ -57,7 +57,9 @@ public String getMainConditionString(Map editMap) { final String childDetailsTable = Utils.metadata().getRegisterQueryProvider().getChildDetailsTable(); final String motherFirstNameKey = Constants.KEY.MOTHER_FIRST_NAME; + final String motherFirstNameSelect = Constants.KEY.MOTHER + "." + Constants.KEY.FIRST_NAME; final String motherLastNameKey = Constants.KEY.MOTHER_LAST_NAME; + final String motherLastNameSelect = Constants.KEY.MOTHER + "." + Constants.KEY.LAST_NAME; final String startDateKey = START_DATE; final String endDateKey = END_DATE; @@ -105,28 +107,28 @@ public String getMainConditionString(Map editMap) { if (editMap.containsKey(motherFirstNameKey) && editMap.containsKey(motherLastNameKey)) { if (StringUtils.isBlank(mainConditionString)) { - mainConditionString += motherFirstNameKey + " Like '%" + editMap - .get(motherFirstNameKey) + "%' AND " + motherLastNameKey + " Like '%" + editMap + mainConditionString += motherFirstNameSelect + " Like '%" + editMap + .get(motherFirstNameKey) + "%' AND " + motherLastNameSelect + " Like '%" + editMap .get(motherLastNameKey) + "%'"; } else { - mainConditionString += " AND (" + motherFirstNameKey + " Like '%" + editMap - .get(motherFirstNameKey) + "%' AND " + motherLastNameKey + " Like '%" + editMap + mainConditionString += " AND (" + motherFirstNameSelect + " Like '%" + editMap + .get(motherFirstNameKey) + "%' AND " + motherLastNameSelect + " Like '%" + editMap .get(motherLastNameKey) + "%' ) "; } } else if (editMap.containsKey(motherFirstNameKey) && !editMap.containsKey(motherLastNameKey)) { if (StringUtils.isBlank(mainConditionString)) { - mainConditionString += " " + motherFirstNameKey + " Like '%" + editMap + mainConditionString += " " + motherFirstNameSelect + " Like '%" + editMap .get(motherFirstNameKey) + "%'"; } else { - mainConditionString += " AND (" + motherFirstNameKey + " Like '%" + editMap + mainConditionString += " AND (" + motherFirstNameSelect + " Like '%" + editMap .get(motherFirstNameKey) + "%') "; } } else if (!editMap.containsKey(motherFirstNameKey) && editMap.containsKey(motherLastNameKey)) { if (StringUtils.isBlank(mainConditionString)) { - mainConditionString += " " + motherLastNameKey + " Like '%" + editMap + mainConditionString += " " + motherLastNameSelect + " Like '%" + editMap .get(motherLastNameKey) + "%'"; } else { - mainConditionString += " AND (" + motherLastNameKey + " Like '%" + editMap + mainConditionString += " AND (" + motherLastNameSelect + " Like '%" + editMap .get(motherLastNameKey) + "%' ) "; } } diff --git a/opensrp-child/src/main/java/org/smartregister/child/util/DBConstants.java b/opensrp-child/src/main/java/org/smartregister/child/util/DBConstants.java index d9a30c6e9..6e2f3e1b1 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/util/DBConstants.java +++ b/opensrp-child/src/main/java/org/smartregister/child/util/DBConstants.java @@ -24,6 +24,7 @@ public static final class KEY { public static final String LOST_TO_FOLLOW_UP = "lost_to_follow_up"; public static final String MOTHER_FIRST_NAME = "mother_first_name"; public static final String MOTHER_LAST_NAME = "mother_last_name"; + public static final String MOTHER_COMPASS_RELATIONSHIP_ID = "mother_compass_relationship_id"; } public interface RegisterTable { diff --git a/opensrp-child/src/main/java/org/smartregister/child/util/Utils.java b/opensrp-child/src/main/java/org/smartregister/child/util/Utils.java index 8279f8522..d52d52942 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/util/Utils.java +++ b/opensrp-child/src/main/java/org/smartregister/child/util/Utils.java @@ -779,4 +779,8 @@ public static boolean isChildHasNFCCard(Map detailsMap) { return StringUtils.isNotEmpty(detailsMap.get(Constants.KEY.NFC_CARD_IDENTIFIER)) && !Constants.TRUE.equalsIgnoreCase(detailsMap.getOrDefault(Constants.KEY.NFC_CARD_BLACKLISTED, Constants.FALSE)); } + + public static boolean hasCompassRelationshipId(Map detailsMap) { + return StringUtils.isNotBlank(detailsMap.get(DBConstants.KEY.MOTHER_COMPASS_RELATIONSHIP_ID)); + } } \ No newline at end of file diff --git a/opensrp-child/src/main/res/values/strings.xml b/opensrp-child/src/main/res/values/strings.xml index d09093a9a..7f67a10f9 100644 --- a/opensrp-child/src/main/res/values/strings.xml +++ b/opensrp-child/src/main/res/values/strings.xml @@ -391,4 +391,5 @@ %1$s: %2$s %1$s %2$s + Error fetching child details diff --git a/opensrp-child/src/test/java/org/smartregister/child/activity/BaseChildImmunizationActivityTest.java b/opensrp-child/src/test/java/org/smartregister/child/activity/BaseChildImmunizationActivityTest.java index a8f9ebf69..0662b3afd 100644 --- a/opensrp-child/src/test/java/org/smartregister/child/activity/BaseChildImmunizationActivityTest.java +++ b/opensrp-child/src/test/java/org/smartregister/child/activity/BaseChildImmunizationActivityTest.java @@ -1,8 +1,11 @@ package org.smartregister.child.activity; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import android.content.Intent; +import android.content.res.Resources; import android.text.TextUtils; import android.view.View; import android.widget.ImageView; @@ -345,4 +348,53 @@ public void testGetChildsThirdPersonPronounReturnsHerForFemaleGender() { ReflectionHelpers.ClassParameter.from(CommonPersonObjectClient.class, client)); Assert.assertEquals("her", pronoun); } + + @Test + public void onBackActivityShouldReturnThisClass() { + Class backActivity = baseChildImmunizationActivity.onBackActivity(); + Assert.assertEquals(BaseChildRegisterActivity.class, backActivity); + } + + @Test + public void testUpdateFloatingActionButtonBasedOnChildStatusShouldUpdateCorrectValue(){ + CommonPersonObjectClient childDetails = getChildDetails(); + + ReflectionHelpers.setField(baseChildImmunizationActivity, "childDetails", childDetails); + + Mockito.doReturn(true).when(appProperties).getPropertyBoolean(eq("feature.nfc.card.enabled")); + TestChildImmunizationActivity activity = Mockito.spy(baseChildImmunizationActivity); + Mockito.doReturn("Active").when(activity).getString(R.string.active); + + LinearLayout fab = Mockito.mock(LinearLayout.class); + Mockito.doReturn(0).when(fab).getPaddingBottom(); + Mockito.doReturn(0).when(fab).getPaddingLeft(); + Mockito.doReturn(0).when(fab).getPaddingRight(); + Mockito.doReturn(0).when(fab).getPaddingTop(); + + TextView fabText = Mockito.mock(TextView.class); + ImageView fabImage = Mockito.mock(ImageView.class); + Mockito.doReturn(fabText).when(fab).findViewById(R.id.fab_text); + Mockito.doReturn(fabImage).when(fab).findViewById(R.id.fab_image); + + Resources resources = Mockito.mock(Resources.class); + Mockito.doReturn(resources).when(activity).getResources(); + Mockito.doReturn("enroll_caregiver").when(resources).getString(R.string.enroll_caregiver); + Mockito.doReturn("activate_new_card").when(resources).getString(R.string.activate_new_card); + Mockito.doReturn("write_to_card").when(resources).getString(R.string.write_to_card); + + activity.floatingActionButton = fab; + Mockito.doReturn(true).when(activity).isActiveStatus(anyString()); + activity.updateFloatingActionButtonBasedOnChildStatus(); + + Mockito.verify(activity, times(1)).configureFloatingActionBackground(2131231163, "enroll_caregiver"); + + childDetails.getColumnmaps().put("mother_compass_relationship_id", "123"); + activity.updateFloatingActionButtonBasedOnChildStatus(); + Mockito.verify(activity, times(1)).configureFloatingActionBackground(2131231163, "activate_new_card"); + + childDetails.getColumnmaps().put("nfc_card_blacklisted", "false"); + childDetails.getColumnmaps().put("nfc_card_identifier", "0099887711112222"); + activity.updateFloatingActionButtonBasedOnChildStatus(); + Mockito.verify(activity, times(1)).configureFloatingActionBackground(2131231161, "write_to_card"); + } } diff --git a/opensrp-child/src/test/java/org/smartregister/child/model/BaseChildAdvancedSearchModelTest.java b/opensrp-child/src/test/java/org/smartregister/child/model/BaseChildAdvancedSearchModelTest.java index 1fb2de562..8e902c76d 100644 --- a/opensrp-child/src/test/java/org/smartregister/child/model/BaseChildAdvancedSearchModelTest.java +++ b/opensrp-child/src/test/java/org/smartregister/child/model/BaseChildAdvancedSearchModelTest.java @@ -160,37 +160,37 @@ public void testGetMainConditionStringMotherName() { editMap.put("start_date", "26-05-2020"); editMap.put("end_date", "26-05-2020"); mainConditionString = baseChildAdvancedSearchModel.getMainConditionString(editMap); - Assert.assertEquals("ec_client.dob BETWEEN '2020-05-26' AND '2020-05-26' AND (mother_first_name Like '%Mary%' AND mother_last_name Like '%Doe%' ) AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); + Assert.assertEquals("ec_client.dob BETWEEN '2020-05-26' AND '2020-05-26' AND (mother.first_name Like '%Mary%' AND mother.last_name Like '%Doe%' ) AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); editMap = new HashMap<>(); editMap.put(Constants.KEY.MOTHER_FIRST_NAME, "Mary"); editMap.put(Constants.KEY.MOTHER_LAST_NAME, "Doe"); mainConditionString = baseChildAdvancedSearchModel.getMainConditionString(editMap); - Assert.assertEquals("mother_first_name Like '%Mary%' AND mother_last_name Like '%Doe%' AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); + Assert.assertEquals("mother.first_name Like '%Mary%' AND mother.last_name Like '%Doe%' AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); editMap = new HashMap<>(); editMap.put(Constants.KEY.MOTHER_FIRST_NAME, "Mary"); editMap.put("start_date", "26-05-2020"); editMap.put("end_date", "26-05-2020"); mainConditionString = baseChildAdvancedSearchModel.getMainConditionString(editMap); - Assert.assertEquals("ec_client.dob BETWEEN '2020-05-26' AND '2020-05-26' AND (mother_first_name Like '%Mary%') AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); + Assert.assertEquals("ec_client.dob BETWEEN '2020-05-26' AND '2020-05-26' AND (mother.first_name Like '%Mary%') AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); editMap = new HashMap<>(); editMap.put(Constants.KEY.MOTHER_FIRST_NAME, "Mary"); mainConditionString = baseChildAdvancedSearchModel.getMainConditionString(editMap); - Assert.assertEquals("mother_first_name Like '%Mary%' AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); + Assert.assertEquals("mother.first_name Like '%Mary%' AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); editMap = new HashMap<>(); editMap.put(Constants.KEY.MOTHER_LAST_NAME, "Doe"); editMap.put("start_date", "26-05-2020"); editMap.put("end_date", "26-05-2020"); mainConditionString = baseChildAdvancedSearchModel.getMainConditionString(editMap); - Assert.assertEquals("ec_client.dob BETWEEN '2020-05-26' AND '2020-05-26' AND (mother_last_name Like '%Doe%' ) AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); + Assert.assertEquals("ec_client.dob BETWEEN '2020-05-26' AND '2020-05-26' AND (mother.last_name Like '%Doe%' ) AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); editMap = new HashMap<>(); editMap.put(Constants.KEY.MOTHER_LAST_NAME, "Doe"); mainConditionString = baseChildAdvancedSearchModel.getMainConditionString(editMap); - Assert.assertEquals("mother_last_name Like '%Doe%' AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); + Assert.assertEquals("mother.last_name Like '%Doe%' AND (ec_client.date_removed is null AND ec_client.is_closed == '0')", mainConditionString.trim()); } @Test diff --git a/opensrp-child/src/test/java/org/smartregister/child/util/UtilsTest.java b/opensrp-child/src/test/java/org/smartregister/child/util/UtilsTest.java index a472b2945..6b7f7ebfc 100644 --- a/opensrp-child/src/test/java/org/smartregister/child/util/UtilsTest.java +++ b/opensrp-child/src/test/java/org/smartregister/child/util/UtilsTest.java @@ -488,4 +488,44 @@ public void testProcessExtraVaccinesEventObsAddsSelectedVaccinesAndSelectedVacci Assert.assertEquals((obsCount + 1), event.getObs().size()); Assert.assertEquals(Constants.KEY.SELECTED_VACCINES, event.getObs().get(obsCount - 1).getFieldCode()); } + + @Test + public void testHasCompassRelationshipIdShouldReturnTrueIfExists() { + Map childDetails = new HashMap<>(); + childDetails.put("mother_compass_relationship_id", "123"); + + boolean hasCompassRelationshipId = Utils.hasCompassRelationshipId(childDetails); + Assert.assertTrue(hasCompassRelationshipId); + + } + + @Test + public void testHasCompassRelationshipIdShouldReturnFalseIfNotExists() { + Map childDetails = new HashMap<>(); + childDetails.put("mother_compass_relationship_id", ""); + + boolean hasCompassRelationshipId = Utils.hasCompassRelationshipId(childDetails); + Assert.assertFalse(hasCompassRelationshipId); + + } + + @Test + public void testIsChildHasNFCCardShouldReturnTrueIfCardIsNotBlacklisted() { + Map childDetails = new HashMap<>(); + childDetails.put("nfc_card_blacklisted", "false"); + childDetails.put("nfc_card_identifier", "0099887711112222"); + + boolean isChildHasNFCCard = Utils.isChildHasNFCCard(childDetails); + Assert.assertTrue(isChildHasNFCCard); + } + + @Test + public void testIsChildHasNFCCardShouldReturnTrueIfCardIsBlacklisted() { + Map childDetails = new HashMap<>(); + childDetails.put("nfc_card_blacklisted", "true"); + childDetails.put("nfc_card_identifier", "0099887711112222"); + + boolean isChildHasNFCCard = Utils.isChildHasNFCCard(childDetails); + Assert.assertFalse(isChildHasNFCCard); + } } \ No newline at end of file