From 4f58a52f9857ef6b451fa0deee892b8bfbf04075 Mon Sep 17 00:00:00 2001 From: LZRS <12814349+LZRS@users.noreply.github.com> Date: Mon, 4 Apr 2022 20:26:30 +0300 Subject: [PATCH 1/2] LMH1-194: fix due count not matching due family children --- opensrp-chw/build.gradle | 5 +- .../ChildUpcomingServiceInteractor.java | 17 +++++ .../presenter/FamilyProfileDuePresenter.java | 74 +------------------ .../chw/util/UpcomingServicesUtil.java | 16 +++- 4 files changed, 36 insertions(+), 76 deletions(-) create mode 100644 opensrp-chw/src/main/java/org/smartregister/chw/interactor/ChildUpcomingServiceInteractor.java diff --git a/opensrp-chw/build.gradle b/opensrp-chw/build.gradle index d3794ec1a6..437d7145f3 100644 --- a/opensrp-chw/build.gradle +++ b/opensrp-chw/build.gradle @@ -344,10 +344,11 @@ android { dimension = 'baseDimension' applicationIdSuffix ".lmh" versionCode 2 - versionName "1.1.2" + versionName "2.0.1" buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '100000' buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '50000' - buildConfigField "String", 'opensrp_url', '"https://lmh-liberia.smartregister.org/opensrp/"' + buildConfigField "String", 'opensrp_url', '"https://liberiavts.smartregister.org/opensrp/"' +// buildConfigField "String", 'opensrp_url', '"https://lmh-liberia.smartregister.org/opensrp/"' buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/lmh/"' buildConfigField "String", 'opensrp_url_debug', '"https://lmh-liberia-preview.smartregister.org/opensrp/"' buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country" , "County" , "District", "Clinics", "CHSS", "Village","Commune"}' diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/interactor/ChildUpcomingServiceInteractor.java b/opensrp-chw/src/main/java/org/smartregister/chw/interactor/ChildUpcomingServiceInteractor.java new file mode 100644 index 0000000000..0bf11f6916 --- /dev/null +++ b/opensrp-chw/src/main/java/org/smartregister/chw/interactor/ChildUpcomingServiceInteractor.java @@ -0,0 +1,17 @@ +package org.smartregister.chw.interactor; + +import android.content.Context; + +import org.smartregister.chw.anc.domain.MemberObject; +import org.smartregister.chw.anc.model.BaseUpcomingService; +import org.smartregister.chw.core.interactor.CoreChildUpcomingServiceInteractor; + +import java.util.List; + +public class ChildUpcomingServiceInteractor extends CoreChildUpcomingServiceInteractor { + + public final List getUpcomingServices(final MemberObject memberObject, final Context ctx){ + return getMemberServices(ctx, memberObject); + } + +} diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/presenter/FamilyProfileDuePresenter.java b/opensrp-chw/src/main/java/org/smartregister/chw/presenter/FamilyProfileDuePresenter.java index 5ebf52b7e9..f30c8f3693 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/presenter/FamilyProfileDuePresenter.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/presenter/FamilyProfileDuePresenter.java @@ -3,41 +3,22 @@ import android.content.Context; import android.util.Pair; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.Months; import org.smartregister.chw.anc.domain.MemberObject; import org.smartregister.chw.application.ChwApplication; -import org.smartregister.chw.core.application.CoreChwApplication; import org.smartregister.chw.core.dao.VisitDao; import org.smartregister.chw.core.utils.CoreConstants; -import org.smartregister.chw.core.utils.VaccineScheduleUtil; -import org.smartregister.chw.core.utils.VisitVaccineUtil; import org.smartregister.chw.dao.ChwChildDao; import org.smartregister.chw.model.FamilyKitModel; import org.smartregister.chw.model.WashCheckModel; -import org.smartregister.chw.util.Constants; +import org.smartregister.chw.util.UpcomingServicesUtil; import org.smartregister.dao.AbstractDao; -import org.smartregister.domain.Alert; import org.smartregister.family.contract.FamilyProfileDueContract; import org.smartregister.family.presenter.BaseFamilyProfileDuePresenter; -import org.smartregister.immunization.db.VaccineRepo; -import org.smartregister.immunization.domain.jsonmapping.Vaccine; -import org.smartregister.immunization.domain.jsonmapping.VaccineGroup; -import org.smartregister.immunization.util.VaccinatorUtils; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Locale; -import java.util.Map; import java.util.function.Supplier; -import timber.log.Timber; - public class FamilyProfileDuePresenter extends BaseFamilyProfileDuePresenter { private WashCheckModel washCheckModel; private FamilyKitModel familyKitModel; @@ -97,8 +78,6 @@ private String getSelectCondition(){ String validMembers(){ List> familyMembers = FamilyMemberDao.getFamilyMembers(this.familyBaseEntityId); - List childVaccineGroups = VaccineScheduleUtil.getVaccineGroups(ChwApplication.getInstance().getApplicationContext(), CoreConstants.SERVICE_GROUPS.CHILD); - List specialVaccines = VaccinatorUtils.getSpecialVaccines(contextSupplier.get()); StringBuilder joiner = new StringBuilder(); for (Pair familyMemberRepr : familyMembers) { @@ -109,7 +88,7 @@ String validMembers(){ boolean vaccineCardReceived = VisitDao.memberHasVaccineCard(member.getBaseEntityId()); - if (!vaccineCardReceived || pendingImmunization(member, childVaccineGroups, specialVaccines)) { + if (!vaccineCardReceived || UpcomingServicesUtil.hasUpcomingDueServices(member, contextSupplier.get())) { joiner.append(String.format("'%s'", member.getBaseEntityId())); joiner.append(","); } @@ -121,55 +100,6 @@ String validMembers(){ return joiner.toString(); } - int immunizationCeiling(MemberObject memberObject) { - String gender = ChwChildDao.getChildGender(memberObject.getBaseEntityId()); - - if (gender != null && gender.equalsIgnoreCase("Female")) { - if (memberObject.getAge() >= 9 && memberObject.getAge() <= 11) { - return 132; - } else { - return 60; - } - } - - return 60; - } - - boolean pendingImmunization(MemberObject memberObject, List vaccineGroups, List specialVaccines){ - Date dob = null; - try { - dob = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(memberObject.getDob()); - } catch (ParseException e) { - Timber.e(e); - } - - int ageInMonths = Months.monthsBetween(new LocalDate(dob), new LocalDate()).getMonths(); - if (ageInMonths >= immunizationCeiling(memberObject)) return false; - - List vaccines = CoreChwApplication.getInstance().vaccineRepository() - .findByEntityId(memberObject.getBaseEntityId()); - - String vaccineCategory = memberObject.getAge() > 5 ? Constants.CHILD_OVER_5 : CoreConstants.SERVICE_GROUPS.CHILD; - List allVacs = VaccineRepo.getVaccines(vaccineCategory); - - Map vaccinesRepo = new HashMap<>(); - for (VaccineRepo.Vaccine vaccine : allVacs) { - vaccinesRepo.put(vaccine.display().toLowerCase().replace(" ", ""), vaccine); - } - - Map>> pendingVaccines = VisitVaccineUtil.generateVisitVaccines( - memberObject.getBaseEntityId(), - vaccinesRepo, - new DateTime(dob), - vaccineGroups, - specialVaccines, - vaccines, - null - ); - - return !pendingVaccines.isEmpty(); - } - public boolean saveData(String jsonObject) { return washCheckModel.saveWashCheckEvent(jsonObject); } diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/util/UpcomingServicesUtil.java b/opensrp-chw/src/main/java/org/smartregister/chw/util/UpcomingServicesUtil.java index 0ea2d90d0c..242dd0efff 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/util/UpcomingServicesUtil.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/util/UpcomingServicesUtil.java @@ -11,9 +11,9 @@ import org.smartregister.chw.anc.domain.MemberObject; import org.smartregister.chw.anc.model.BaseUpcomingService; import org.smartregister.chw.application.ChwApplication; -import org.smartregister.chw.core.interactor.CoreChildUpcomingServiceInteractor; import org.smartregister.chw.core.utils.CoreConstants; import org.smartregister.chw.dao.ChwChildDao; +import org.smartregister.chw.interactor.ChildUpcomingServiceInteractor; import java.util.ArrayList; import java.util.HashMap; @@ -71,6 +71,18 @@ static String getDueServicesState(List serviceList) { return hasDue ? CoreConstants.VISIT_STATE.DUE : null; } + public static boolean hasUpcomingDueServices(MemberObject memberObject, Context ctx){ + String childGender = ChwChildDao.getChildGender(memberObject.getBaseEntityId()); + int childAge = memberObject.getAge(); + if (!ChwApplication.getApplicationFlavor().showChildrenAboveTwoDueStatus() + && childAge >= 2 + && !(childGender.equalsIgnoreCase("Female") && childAge >= 9 && childAge <= 11)){ + return false; + } + List upcomingServices = new ChildUpcomingServiceInteractor().getUpcomingServices(memberObject, ctx); + return getDueServicesState(upcomingServices) != null; + } + public static void fetchUpcomingDueServicesState(MemberObject memberObject, Context ctx, Consumer onDueStatusFetched) { String childGender = ChwChildDao.getChildGender(memberObject.getBaseEntityId()); int childAge = memberObject.getAge(); @@ -82,7 +94,7 @@ public static void fetchUpcomingDueServicesState(MemberObject memberObject, Cont return; } - new CoreChildUpcomingServiceInteractor().getUpComingServices(memberObject, ctx, new BaseAncUpcomingServicesContract.InteractorCallBack() { + new ChildUpcomingServiceInteractor().getUpComingServices(memberObject, ctx, new BaseAncUpcomingServicesContract.InteractorCallBack() { @Override public void onDataFetched(List serviceList) { onDueStatusFetched.accept(getDueServicesState(serviceList)); From ce9d678756447cfe5554d868ace7f1e6fc01a91a Mon Sep 17 00:00:00 2001 From: LZRS <12814349+LZRS@users.noreply.github.com> Date: Tue, 5 Apr 2022 20:02:43 +0300 Subject: [PATCH 2/2] sync with using POST request to avoid '414 Request-URI Too Large' --- .../smartregister/chw/application/ChwApplicationFlv.java | 2 +- .../chw/application/ChwSyncConfiguration.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/opensrp-chw/src/lmh/java/org/smartregister/chw/application/ChwApplicationFlv.java b/opensrp-chw/src/lmh/java/org/smartregister/chw/application/ChwApplicationFlv.java index 0713a68b63..052bb0020f 100644 --- a/opensrp-chw/src/lmh/java/org/smartregister/chw/application/ChwApplicationFlv.java +++ b/opensrp-chw/src/lmh/java/org/smartregister/chw/application/ChwApplicationFlv.java @@ -9,7 +9,7 @@ public boolean hasANC() { @Override public boolean syncUsingPost() { - return false; + return true; } @Override diff --git a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java index 690c4ab97a..96dd4564b5 100644 --- a/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java +++ b/opensrp-chw/src/main/java/org/smartregister/chw/application/ChwSyncConfiguration.java @@ -11,7 +11,9 @@ import org.smartregister.repository.AllSharedPreferences; import org.smartregister.view.activity.BaseLoginActivity; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.smartregister.util.Utils.isEmptyCollection; @@ -36,9 +38,10 @@ public String getSyncFilterValue() { if(StringUtils.isBlank(locationId)) locationId = allSharedPreferences().fetchUserLocalityId(providerId); List locationIds = LocationHelper.getInstance().locationsFromHierarchy(true, null); + if (!isEmptyCollection(locationIds) && locationIds.contains(locationId)) { int index = locationIds.indexOf(locationId); - List subLocationIds = locationIds.subList(index, locationIds.size()); + Set subLocationIds = new HashSet<>(locationIds.subList(index, locationIds.size())); return StringUtils.join(subLocationIds, ","); } return locationId; @@ -115,12 +118,12 @@ public String getOauthClientSecret() { @Override public int getConnectTimeout() { - return BuildConfig.MAX_CONNECTION_TIMEOUT * 60000; + return BuildConfig.MAX_CONNECTION_TIMEOUT * 300000; } @Override public int getReadTimeout() { - return BuildConfig.MAX_READ_TIMEOUT * 60000; + return BuildConfig.MAX_READ_TIMEOUT * 300000; } @Override