From a27278dd107d0fd77116db9fce7ba07178655b20 Mon Sep 17 00:00:00 2001 From: Ephraim Muhia Date: Fri, 23 Mar 2018 15:42:03 +0300 Subject: [PATCH] added check for vaccines where either can be given Signed-off-by: Ephraim Muhia --- gradle.properties | 2 +- .../adapter/VaccineCardAdapter.java | 1 + .../immunization/util/VaccinatorUtils.java | 80 +++++++++---------- 3 files changed, 38 insertions(+), 45 deletions(-) diff --git a/gradle.properties b/gradle.properties index 837bab4d..35ab4e7a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.2.3-SNAPSHOT +VERSION_NAME=1.2.4-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/VaccineCardAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java index b41167f8..744fac68 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java @@ -147,6 +147,7 @@ public void updateWrapperStatus(VaccineWrapper tag, String type, CommonPersonObj String dobString = getValue(childDetails.getColumnmaps(), "dob", false); List> sch = generateScheduleList(type, new DateTime(dobString), recievedVaccines, alertList); + for (Map m : sch) { VaccineRepo.Vaccine vaccine = (VaccineRepo.Vaccine) m.get("vaccine"); if (tag.getName().toLowerCase().contains(vaccine.display().toLowerCase())) { diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/VaccinatorUtils.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/VaccinatorUtils.java index 3893f255..915fad6d 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/util/VaccinatorUtils.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/util/VaccinatorUtils.java @@ -302,59 +302,51 @@ private static DateTime getReceivedDate(Map received, Vaccine v) return null; } - public static List> generateSchedule(String category, DateTime milestoneDate, Map received, List alerts) { - List> schedule = new ArrayList(); - try { - ArrayList vl = VaccineRepo.getVaccines(category); - for (Vaccine v : vl) { - Map m = new HashMap<>(); - DateTime recDate = getReceivedDate(received, v); - if (recDate != null) { - m = createVaccineMap("done", null, recDate, v); - } else if (milestoneDate != null && v.expiryDays() > 0 && milestoneDate.plusDays(v.expiryDays()).isBefore(DateTime.now())) { - m = createVaccineMap("expired", null, milestoneDate.plusDays(v.expiryDays()), v); - } else if (alerts.size() > 0) { - for (Alert a : alerts) { - if (a.scheduleName().replaceAll(" ", "").equalsIgnoreCase(v.name()) - || a.visitCode().replaceAll(" ", "").equalsIgnoreCase(v.name())) { - m = createVaccineMap("due", a, new DateTime(a.startDate()), v); - } - } - } - - if (m.isEmpty()) { - if (v.prerequisite() != null) { - DateTime prereq = getReceivedDate(received, v.prerequisite()); - if (prereq != null) { - prereq = prereq.plusDays(v.prerequisiteGapDays()); - m = createVaccineMap("due", null, prereq, v); - } else { - m = createVaccineMap("due", null, null, v); - } - } else if (milestoneDate != null) { - m = createVaccineMap("due", null, milestoneDate.plusDays(v.milestoneGapDays()), v); - } else { - m = createVaccineMap("na", null, null, v); - } - } - - schedule.add(m); - } - } catch (Exception e) { - Log.e(TAG, e.toString(), e); - } - return schedule; + public static List> generateScheduleList(String category, DateTime milestoneDate, Map received, List alerts) { + return generateScheduleList(category, milestoneDate, received, alerts, false); } - public static List> generateScheduleList(String category, DateTime milestoneDate, Map received, List alerts) { - List> schedule = new ArrayList(); + /** + * To use generateSchedule() method just use this method and set showExpired to true + * + * @param category + * @param milestoneDate + * @param received + * @param alerts + * @param showExpired + * @return + */ + public static List> generateScheduleList(String category, DateTime milestoneDate, Map received, List alerts, boolean showExpired) { + List> schedule = new ArrayList<>(); + boolean m1Given = false; + boolean m2Given = false; + boolean oGiven = false; try { ArrayList vl = VaccineRepo.getVaccines(category); for (Vaccine v : vl) { + // Check for vaccines where either can be given - mealses/mr opv0/opv4 + if (m1Given && (VaccineRepo.Vaccine.measles1.equals(v) || VaccineRepo.Vaccine.mr1.equals(v))) { + continue; + } else if (m2Given && (VaccineRepo.Vaccine.measles2.equals(v) || VaccineRepo.Vaccine.mr2.equals(v))) { + continue; + } else if (oGiven && (VaccineRepo.Vaccine.opv0.equals(v)) || VaccineRepo.Vaccine.opv4.equals(v)) { + continue; + } + Map m = new HashMap<>(); Date recDate = received.get(v.display().toLowerCase()); if (recDate != null) { m = createVaccineMap("done", null, new DateTime(recDate), v); + // Check for vaccines where either can be given - mealses/mr opv0/opv4 + if (VaccineRepo.Vaccine.measles1.equals(v) || VaccineRepo.Vaccine.mr1.equals(v)) { + m1Given = true; + } else if (VaccineRepo.Vaccine.measles2.equals(v) || VaccineRepo.Vaccine.mr2.equals(v)) { + m2Given = true; + } else if (VaccineRepo.Vaccine.opv0.equals(v) || VaccineRepo.Vaccine.opv4.equals(v)) { + oGiven = true; + } + } else if (showExpired && milestoneDate != null && v.expiryDays() > 0 && milestoneDate.plusDays(v.expiryDays()).isBefore(DateTime.now())) { + m = createVaccineMap("expired", null, milestoneDate.plusDays(v.expiryDays()), v); } else if (alerts.size() > 0) { for (Alert a : alerts) { if (a.scheduleName().replaceAll(" ", "").equalsIgnoreCase(v.name())