Skip to content

Commit

Permalink
added check for vaccines where either can be given
Browse files Browse the repository at this point in the history
Signed-off-by: Ephraim Muhia <emuhia@ona.io>
  • Loading branch information
Ephraim Muhia committed Mar 23, 2018
1 parent 953c5af commit a27278d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
2 changes: 1 addition & 1 deletion 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
Expand Down
Expand Up @@ -147,6 +147,7 @@ public void updateWrapperStatus(VaccineWrapper tag, String type, CommonPersonObj
String dobString = getValue(childDetails.getColumnmaps(), "dob", false);
List<Map<String, Object>> sch = generateScheduleList(type, new DateTime(dobString), recievedVaccines, alertList);


for (Map<String, Object> m : sch) {
VaccineRepo.Vaccine vaccine = (VaccineRepo.Vaccine) m.get("vaccine");
if (tag.getName().toLowerCase().contains(vaccine.display().toLowerCase())) {
Expand Down
Expand Up @@ -302,59 +302,51 @@ private static DateTime getReceivedDate(Map<String, String> received, Vaccine v)
return null;
}

public static List<Map<String, Object>> generateSchedule(String category, DateTime milestoneDate, Map<String, String> received, List<Alert> alerts) {
List<Map<String, Object>> schedule = new ArrayList();
try {
ArrayList<Vaccine> vl = VaccineRepo.getVaccines(category);
for (Vaccine v : vl) {
Map<String, Object> 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<Map<String, Object>> generateScheduleList(String category, DateTime milestoneDate, Map<String, Date> received, List<Alert> alerts) {
return generateScheduleList(category, milestoneDate, received, alerts, false);
}

public static List<Map<String, Object>> generateScheduleList(String category, DateTime milestoneDate, Map<String, Date> received, List<Alert> alerts) {
List<Map<String, Object>> 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<Map<String, Object>> generateScheduleList(String category, DateTime milestoneDate, Map<String, Date> received, List<Alert> alerts, boolean showExpired) {
List<Map<String, Object>> schedule = new ArrayList<>();
boolean m1Given = false;
boolean m2Given = false;
boolean oGiven = false;
try {
ArrayList<Vaccine> 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<String, Object> 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())
Expand Down

0 comments on commit a27278d

Please sign in to comment.