diff --git a/gradle.properties b/gradle.properties index 605c069d..f4cbe66a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.0.4-SNAPSHOT +VERSION_NAME=3.0.5-SNAPSHOT VERSION_CODE=2 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Immunization diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 4cec537d..c7e3aa8f 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -264,7 +264,25 @@ protected VaccineWrapper doInBackground(Void... params) { protected void onPostExecute(VaccineWrapper vaccineWrapper) { vaccineCard.setVaccineWrapper(vaccineWrapper); vaccineGroup.toggleRecordAllTV(); - notifyDataSetChanged(); + if (vaccineWrapper.getStatus() == null) { + removeVaccine(vaccineName); + } else { + notifyDataSetChanged(); + } + } + } + + private void removeVaccine(String vaccineName) { + vaccineCards.remove(vaccineName); + for (int i = 0; i < vaccineGroup.getVaccineData().vaccines.size(); i++) { + org.smartregister.immunization.domain.jsonmapping.Vaccine vaccine = vaccineGroup.getVaccineData().vaccines + .get(i); + if (vaccine.getName().equalsIgnoreCase(vaccineName)) { + vaccineGroup.getVaccineData().vaccines + .remove(i); + } } + notifyDataSetChanged(); + vaccineGroup.getVaccinesGV().invalidateViews(); } } diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java index 33f2d2f6..95ac0ec3 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java @@ -159,7 +159,7 @@ public void updateWrapper(ServiceWrapper tag) { if (!serviceRecordList.isEmpty()) { for (ServiceRecord serviceRecord : serviceRecordList) { - if (tag.getName().toLowerCase().contains(serviceRecord.getName().toLowerCase()) && serviceRecord + if (tag.getName().equalsIgnoreCase(serviceRecord.getName()) && serviceRecord .getDate() != null) { long diff = serviceRecord.getUpdatedAt() - serviceRecord.getDate().getTime(); if (diff > 0 && TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) > 1) { diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 343ff2d6..eb36aee6 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -10,10 +10,12 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.Alert; import org.smartregister.domain.AlertStatus; @@ -81,6 +83,11 @@ public void setDataForTest(String dateTimeString) { wrapper.setName(VaccineRepo.Vaccine.measles2.display()); wrapper.setVaccine(VaccineRepo.Vaccine.measles2); wrappers.add(wrapper); + wrapper.setDbKey(0l); + wrapper.setName(VaccineRepo.Vaccine.opv0.display()); + wrapper.setVaccine(VaccineRepo.Vaccine.opv0); + wrapper.setStatus(null); + wrappers.add(wrapper); Type listType = new TypeToken>() { }.getType(); @@ -141,8 +148,20 @@ public void assertGetViewReturnsVaccineGroup() { ImmunizationRowAdapter immunizationRowAdapter = new ImmunizationRowAdapter(RuntimeEnvironment.application, view, true, vaccinelist, alertlist); - Assert.assertEquals(immunizationRowAdapter.getView(0, null, null) != null, true); + Assert.assertNotNull(immunizationRowAdapter.getView(0, null, null)); + + } + + @Test + public void assertVaccineRemovedWithNullStatus() { + ImmunizationRowAdapter mockAdapter = Mockito + .spy(new ImmunizationRowAdapter(context, view, true, vaccinelist, alertlist)); + + ReflectionHelpers.callInstanceMethod(mockAdapter, "removeVaccine", + ReflectionHelpers.ClassParameter.from(String.class, "OPV 0")); + + Assert.assertEquals(view.getVaccineData().vaccines.size(), 1); } } diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java index 4794efa2..d1968fb8 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java @@ -75,6 +75,14 @@ public void assertConstructorsNotNull() { //Assert.assertNotNull(activity.getInstance3()); } + @Test + public void testConstructors() { + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application)); + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build())); + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build(), 0)); + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build(), 0, 0)); + } + @After public void tearDown() { destroyController();