From e6883b596767d16958a0797ee7c934821d409ceb Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:00:15 +0300 Subject: [PATCH 1/4] Remove deleted vaccines from history page --- gradle.properties | 2 +- .../org/smartregister/chw/core/dao/EventDao.java | 12 ++++++++++++ .../chw/core/sync/CoreClientProcessor.java | 15 +++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 03b6b5a328..0b383bc6c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.5.21-SNAPSHOT +VERSION_NAME=1.5.21-test3-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Chw Core Library diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java index 89468b9fd3..b30bc017e4 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java @@ -1,5 +1,6 @@ package org.smartregister.chw.core.dao; +import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; import org.json.JSONException; import org.json.JSONObject; @@ -8,7 +9,9 @@ import org.smartregister.dao.AbstractDao; import org.smartregister.sync.helper.ECSyncHelper; +import java.util.HashMap; import java.util.List; +import java.util.Map; import timber.log.Timber; @@ -78,6 +81,15 @@ private static ECSyncHelper getEcSyncHelper() { } public static void deleteVaccineByFormSubmissionId(String submissionId) { + String sql0 = "delete from visit_details where visit_details_id in ( " + + " select vd.visit_details_id " + + " from visit_details vd " + + " inner join visits v on v.visit_id = vd.visit_id " + + " inner join vaccines va on va.name = visit_key and va.base_entity_id = v.base_entity_id " + + " where va.formSubmissionId = '" + submissionId + "' " + + ")"; + updateDB(sql0); + String sql = "delete from vaccines where formSubmissionId = '" + submissionId + "'"; updateDB(sql); } diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java index 3896d18f32..984d95d018 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/sync/CoreClientProcessor.java @@ -82,7 +82,7 @@ public static void addVaccine(VaccineRepository vaccineRepository, Vaccine vacci } // if its an updated vaccine, delete the previous object - vaccineRepository.deleteVaccine(vaccine.getBaseEntityId(), vaccine.getName()); + //vaccineRepository.deleteVaccine(vaccine.getBaseEntityId(), vaccine.getName()); // Add the vaccine vaccineRepository.add(vaccine); @@ -327,12 +327,15 @@ protected void processEvents(ClientClassification clientClassification, Table va public void processDeleteEvent(Event event) { try { + String formSubmissionId = event.getDetails() == null ? "" : event.getDetails().get("deleted_form_submission_id"); // delete from vaccine table - EventDao.deleteVaccineByFormSubmissionId(event.getFormSubmissionId()); - // delete from visit table - EventDao.deleteVisitByFormSubmissionId(event.getFormSubmissionId()); - // delete from recurring service table - EventDao.deleteServiceByFormSubmissionId(event.getFormSubmissionId()); + if (StringUtils.isNotBlank(formSubmissionId)) { + EventDao.deleteVaccineByFormSubmissionId(formSubmissionId); + // delete from visit table + EventDao.deleteVisitByFormSubmissionId(formSubmissionId); + // delete from recurring service table + EventDao.deleteServiceByFormSubmissionId(formSubmissionId); + } Timber.d("Ending processDeleteEvent: %s", event.getEventId()); } catch (Exception e) { From 0c68970de16cbaea593a3044aedbccf071c0990b Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:00:51 +0300 Subject: [PATCH 2/4] Bump up version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 0b383bc6c9..eb3cf14196 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.5.21-test3-SNAPSHOT +VERSION_NAME=1.5.22-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Chw Core Library From 8f597282ebb4f01676e731981064bdcd534c7c4d Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:29:36 +0300 Subject: [PATCH 3/4] Add core client processor test --- .../smartregister/chw/core/dao/EventDao.java | 3 -- .../core/sync/CoreClientProcessorTest.java | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java index b30bc017e4..e24c1dc139 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/dao/EventDao.java @@ -1,6 +1,5 @@ package org.smartregister.chw.core.dao; -import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; import org.json.JSONException; import org.json.JSONObject; @@ -9,9 +8,7 @@ import org.smartregister.dao.AbstractDao; import org.smartregister.sync.helper.ECSyncHelper; -import java.util.HashMap; import java.util.List; -import java.util.Map; import timber.log.Timber; diff --git a/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java new file mode 100644 index 0000000000..a471203a28 --- /dev/null +++ b/opensrp-chw-core/src/test/java/org/smartregister/chw/core/sync/CoreClientProcessorTest.java @@ -0,0 +1,31 @@ +package org.smartregister.chw.core.sync; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.smartregister.chw.core.BaseUnitTest; +import org.smartregister.immunization.domain.Vaccine; +import org.smartregister.immunization.repository.VaccineRepository; + +public class CoreClientProcessorTest extends BaseUnitTest { + + @Mock + private VaccineRepository vaccineRepository; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testAddVaccine() { + Vaccine vaccine = new Vaccine(); + vaccine.setName("MEASLES 1"); + + CoreClientProcessor.addVaccine(vaccineRepository, vaccine); + Mockito.verify(vaccineRepository).add(vaccine); + Mockito.verify(vaccineRepository).updateFtsSearch(Mockito.any()); + } +} From 0e5720c71b81381e6715b1ea88e2316739f0b4f8 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:54:25 +0300 Subject: [PATCH 4/4] Prevent NPE when generating schedules --- .../org/smartregister/chw/core/utils/VisitVaccineUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java index bc219fe7b8..fc845e9bc0 100644 --- a/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java +++ b/opensrp-chw-core/src/main/java/org/smartregister/chw/core/utils/VisitVaccineUtil.java @@ -53,10 +53,10 @@ public static Map getAllVaccines() { List allVacs = new ArrayList<>(); - List woman = ImmunizationLibrary.getVaccineCacheMap().get("woman").vaccineRepo; + List woman = ImmunizationLibrary.getVaccineCacheMap().get("woman").vaccineRepo; allVacs.addAll(woman); - List child = ImmunizationLibrary.getVaccineCacheMap().get("child").vaccineRepo; + List child = ImmunizationLibrary.getVaccineCacheMap().get("child").vaccineRepo; allVacs.addAll(child); for (VaccineRepo.Vaccine vaccine : allVacs) { @@ -281,6 +281,7 @@ public static List getInMemoryAlerts( try { if (vaccineSchedules != null && vaccineSchedules.containsKey(vaccineCategory)) { for (VaccineSchedule curSchedule : vaccineSchedules.get(vaccineCategory).values()) { + if (curSchedule == null) continue; Alert curAlert = curSchedule.getOfflineAlert(baseEntityId, dob.toDate(), issuedVaccines); if (curAlert != null && curAlert.startDate() != null) { generatedAlerts.add(curAlert);