Skip to content

Commit

Permalink
Merge pull request #331 from OpenSRP/remove_deleted_vaccines
Browse files Browse the repository at this point in the history
Remove deleted vaccines
  • Loading branch information
rkodev authored Nov 10, 2020
2 parents 0a85679 + 0e5720c commit 05b0d1e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.5.21-SNAPSHOT
VERSION_NAME=1.5.22-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Chw Core Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public static Map<String, VaccineRepo.Vaccine> getAllVaccines() {

List<VaccineRepo.Vaccine> allVacs = new ArrayList<>();

List<VaccineRepo.Vaccine> woman = ImmunizationLibrary.getVaccineCacheMap().get("woman").vaccineRepo;
List<VaccineRepo.Vaccine> woman = ImmunizationLibrary.getVaccineCacheMap().get("woman").vaccineRepo;
allVacs.addAll(woman);

List<VaccineRepo.Vaccine> child = ImmunizationLibrary.getVaccineCacheMap().get("child").vaccineRepo;
List<VaccineRepo.Vaccine> child = ImmunizationLibrary.getVaccineCacheMap().get("child").vaccineRepo;
allVacs.addAll(child);

for (VaccineRepo.Vaccine vaccine : allVacs) {
Expand Down Expand Up @@ -281,6 +281,7 @@ public static List<Alert> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 05b0d1e

Please sign in to comment.