Skip to content

Commit

Permalink
Merge pull request #2020 from opensrp/lmh1-194
Browse files Browse the repository at this point in the history
LMH1-194: fix due count not matching due family children
  • Loading branch information
LZRS authored Apr 6, 2022
2 parents b363d02 + 29f4e82 commit dba92d3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public boolean hasANC() {

@Override
public boolean syncUsingPost() {
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,9 +38,10 @@ public String getSyncFilterValue() {
if(StringUtils.isBlank(locationId)) locationId = allSharedPreferences().fetchUserLocalityId(providerId);

List<String> locationIds = LocationHelper.getInstance().locationsFromHierarchy(true, null);

if (!isEmptyCollection(locationIds) && locationIds.contains(locationId)) {
int index = locationIds.indexOf(locationId);
List<String> subLocationIds = locationIds.subList(index, locationIds.size());
Set<String> subLocationIds = new HashSet<>(locationIds.subList(index, locationIds.size()));
return StringUtils.join(subLocationIds, ",");
}
return locationId;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BaseUpcomingService> getUpcomingServices(final MemberObject memberObject, final Context ctx){
return getMemberServices(ctx, memberObject);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,8 +78,6 @@ private String getSelectCondition(){

String validMembers(){
List<Pair<String, String>> familyMembers = FamilyMemberDao.getFamilyMembers(this.familyBaseEntityId);
List<VaccineGroup> childVaccineGroups = VaccineScheduleUtil.getVaccineGroups(ChwApplication.getInstance().getApplicationContext(), CoreConstants.SERVICE_GROUPS.CHILD);
List<Vaccine> specialVaccines = VaccinatorUtils.getSpecialVaccines(contextSupplier.get());

StringBuilder joiner = new StringBuilder();
for (Pair<String, String> familyMemberRepr : familyMembers) {
Expand All @@ -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(",");
}
Expand All @@ -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<VaccineGroup> vaccineGroups, List<Vaccine> 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<org.smartregister.immunization.domain.Vaccine> vaccines = CoreChwApplication.getInstance().vaccineRepository()
.findByEntityId(memberObject.getBaseEntityId());

String vaccineCategory = memberObject.getAge() > 5 ? Constants.CHILD_OVER_5 : CoreConstants.SERVICE_GROUPS.CHILD;
List<VaccineRepo.Vaccine> allVacs = VaccineRepo.getVaccines(vaccineCategory);

Map<String, VaccineRepo.Vaccine> vaccinesRepo = new HashMap<>();
for (VaccineRepo.Vaccine vaccine : allVacs) {
vaccinesRepo.put(vaccine.display().toLowerCase().replace(" ", ""), vaccine);
}

Map<VaccineGroup, List<Pair<VaccineRepo.Vaccine, Alert>>> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +71,18 @@ static String getDueServicesState(List<BaseUpcomingService> 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<BaseUpcomingService> upcomingServices = new ChildUpcomingServiceInteractor().getUpcomingServices(memberObject, ctx);
return getDueServicesState(upcomingServices) != null;
}

public static void fetchUpcomingDueServicesState(MemberObject memberObject, Context ctx, Consumer<String> onDueStatusFetched) {
String childGender = ChwChildDao.getChildGender(memberObject.getBaseEntityId());
int childAge = memberObject.getAge();
Expand All @@ -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<BaseUpcomingService> serviceList) {
onDueStatusFetched.accept(getDueServicesState(serviceList));
Expand Down

0 comments on commit dba92d3

Please sign in to comment.