Skip to content

Commit 68f50ca

Browse files
author
Ephraim (Keyman) Muhia
authored
Merge pull request #30 from OpenSRP/issue29
added check for vaccines where either can be given
2 parents 953c5af + a27278d commit 68f50ca

File tree

3 files changed

+38
-45
lines changed

3 files changed

+38
-45
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=1.2.3-SNAPSHOT
1+
VERSION_NAME=1.2.4-SNAPSHOT
22
VERSION_CODE=2
33
GROUP=org.smartregister
44
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization

opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/VaccineCardAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public void updateWrapperStatus(VaccineWrapper tag, String type, CommonPersonObj
147147
String dobString = getValue(childDetails.getColumnmaps(), "dob", false);
148148
List<Map<String, Object>> sch = generateScheduleList(type, new DateTime(dobString), recievedVaccines, alertList);
149149

150+
150151
for (Map<String, Object> m : sch) {
151152
VaccineRepo.Vaccine vaccine = (VaccineRepo.Vaccine) m.get("vaccine");
152153
if (tag.getName().toLowerCase().contains(vaccine.display().toLowerCase())) {

opensrp-immunization/src/main/java/org/smartregister/immunization/util/VaccinatorUtils.java

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -302,59 +302,51 @@ private static DateTime getReceivedDate(Map<String, String> received, Vaccine v)
302302
return null;
303303
}
304304

305-
public static List<Map<String, Object>> generateSchedule(String category, DateTime milestoneDate, Map<String, String> received, List<Alert> alerts) {
306-
List<Map<String, Object>> schedule = new ArrayList();
307-
try {
308-
ArrayList<Vaccine> vl = VaccineRepo.getVaccines(category);
309-
for (Vaccine v : vl) {
310-
Map<String, Object> m = new HashMap<>();
311-
DateTime recDate = getReceivedDate(received, v);
312-
if (recDate != null) {
313-
m = createVaccineMap("done", null, recDate, v);
314-
} else if (milestoneDate != null && v.expiryDays() > 0 && milestoneDate.plusDays(v.expiryDays()).isBefore(DateTime.now())) {
315-
m = createVaccineMap("expired", null, milestoneDate.plusDays(v.expiryDays()), v);
316-
} else if (alerts.size() > 0) {
317-
for (Alert a : alerts) {
318-
if (a.scheduleName().replaceAll(" ", "").equalsIgnoreCase(v.name())
319-
|| a.visitCode().replaceAll(" ", "").equalsIgnoreCase(v.name())) {
320-
m = createVaccineMap("due", a, new DateTime(a.startDate()), v);
321-
}
322-
}
323-
}
324-
325-
if (m.isEmpty()) {
326-
if (v.prerequisite() != null) {
327-
DateTime prereq = getReceivedDate(received, v.prerequisite());
328-
if (prereq != null) {
329-
prereq = prereq.plusDays(v.prerequisiteGapDays());
330-
m = createVaccineMap("due", null, prereq, v);
331-
} else {
332-
m = createVaccineMap("due", null, null, v);
333-
}
334-
} else if (milestoneDate != null) {
335-
m = createVaccineMap("due", null, milestoneDate.plusDays(v.milestoneGapDays()), v);
336-
} else {
337-
m = createVaccineMap("na", null, null, v);
338-
}
339-
}
340-
341-
schedule.add(m);
342-
}
343-
} catch (Exception e) {
344-
Log.e(TAG, e.toString(), e);
345-
}
346-
return schedule;
305+
public static List<Map<String, Object>> generateScheduleList(String category, DateTime milestoneDate, Map<String, Date> received, List<Alert> alerts) {
306+
return generateScheduleList(category, milestoneDate, received, alerts, false);
347307
}
348308

349-
public static List<Map<String, Object>> generateScheduleList(String category, DateTime milestoneDate, Map<String, Date> received, List<Alert> alerts) {
350-
List<Map<String, Object>> schedule = new ArrayList();
309+
/**
310+
* To use generateSchedule() method just use this method and set showExpired to true
311+
*
312+
* @param category
313+
* @param milestoneDate
314+
* @param received
315+
* @param alerts
316+
* @param showExpired
317+
* @return
318+
*/
319+
public static List<Map<String, Object>> generateScheduleList(String category, DateTime milestoneDate, Map<String, Date> received, List<Alert> alerts, boolean showExpired) {
320+
List<Map<String, Object>> schedule = new ArrayList<>();
321+
boolean m1Given = false;
322+
boolean m2Given = false;
323+
boolean oGiven = false;
351324
try {
352325
ArrayList<Vaccine> vl = VaccineRepo.getVaccines(category);
353326
for (Vaccine v : vl) {
327+
// Check for vaccines where either can be given - mealses/mr opv0/opv4
328+
if (m1Given && (VaccineRepo.Vaccine.measles1.equals(v) || VaccineRepo.Vaccine.mr1.equals(v))) {
329+
continue;
330+
} else if (m2Given && (VaccineRepo.Vaccine.measles2.equals(v) || VaccineRepo.Vaccine.mr2.equals(v))) {
331+
continue;
332+
} else if (oGiven && (VaccineRepo.Vaccine.opv0.equals(v)) || VaccineRepo.Vaccine.opv4.equals(v)) {
333+
continue;
334+
}
335+
354336
Map<String, Object> m = new HashMap<>();
355337
Date recDate = received.get(v.display().toLowerCase());
356338
if (recDate != null) {
357339
m = createVaccineMap("done", null, new DateTime(recDate), v);
340+
// Check for vaccines where either can be given - mealses/mr opv0/opv4
341+
if (VaccineRepo.Vaccine.measles1.equals(v) || VaccineRepo.Vaccine.mr1.equals(v)) {
342+
m1Given = true;
343+
} else if (VaccineRepo.Vaccine.measles2.equals(v) || VaccineRepo.Vaccine.mr2.equals(v)) {
344+
m2Given = true;
345+
} else if (VaccineRepo.Vaccine.opv0.equals(v) || VaccineRepo.Vaccine.opv4.equals(v)) {
346+
oGiven = true;
347+
}
348+
} else if (showExpired && milestoneDate != null && v.expiryDays() > 0 && milestoneDate.plusDays(v.expiryDays()).isBefore(DateTime.now())) {
349+
m = createVaccineMap("expired", null, milestoneDate.plusDays(v.expiryDays()), v);
358350
} else if (alerts.size() > 0) {
359351
for (Alert a : alerts) {
360352
if (a.scheduleName().replaceAll(" ", "").equalsIgnoreCase(v.name())

0 commit comments

Comments
 (0)