Skip to content

Commit

Permalink
Merge a283130 into 51d3704
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Oct 17, 2019
2 parents 51d3704 + a283130 commit 8986462
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 173 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.4.27-SNAPSHOT
VERSION_NAME=1.4.28-SNAPSHOT
VERSION_CODE=2
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
4 changes: 2 additions & 2 deletions opensrp-immunization/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ tasks.withType(Test) {
}

dependencies {
implementation('org.smartregister:opensrp-client-core:1.7.28-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-core:1.7.35-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
}

implementation('org.smartregister:opensrp-client-native-form:1.6.44-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-native-form:1.6.51-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -38,7 +39,7 @@ public ServiceSchedule(ServiceTrigger dueTrigger, ServiceTrigger expiryTrigger)
}

public static ServiceSchedule getServiceSchedule(JSONObject schedule)
throws JSONException {
throws JSONException {
ServiceTrigger dueTrigger = ServiceTrigger.init(schedule.getJSONObject("due"));
ServiceTrigger expiryTrigger = ServiceTrigger.init(schedule.optJSONObject("expiry"));
return new ServiceSchedule(dueTrigger, expiryTrigger);
Expand Down Expand Up @@ -104,7 +105,7 @@ public static void updateOfflineAlerts(String type, String baseEntityId, DateTim
}
}

if (!exists) {
if (!exists && !AlertStatus.complete.equals(curAlert.status())) {
// Insert alert into table
newAlerts.add(curAlert);
alertService.create(curAlert);
Expand All @@ -126,13 +127,13 @@ public static Alert getOfflineAlert(ServiceType serviceType, List<ServiceRecord>
DateTime dueDateTime = VaccinatorUtils.getServiceDueDate(serviceType, dateOfBirth, issuedServices);
DateTime expiryDateTime = VaccinatorUtils.getServiceExpiryDate(serviceType, dateOfBirth);

// Use the trigger date as a reference, since that is what is mostly used
AlertStatus alertStatus = calculateAlertStatus(dueDateTime);

AlertStatus alertStatus = isServiceIssued(serviceType.getName(), issuedServices) ? AlertStatus.complete : calculateAlertStatus(dueDateTime);

if (alertStatus != null) {
Date startDate = dueDateTime == null ? dateOfBirth.toDate() : dueDateTime.toDate();
Date expiryDate = expiryDateTime == null ? null : expiryDateTime.toDate();
return new Alert(baseEntityId, serviceType.getName(), serviceType.getName().toLowerCase().replace(" ", ""),
return new Alert(baseEntityId, serviceType.getName(), serviceType.getName().toLowerCase(Locale.ENGLISH).replace(" ", ""),
alertStatus, startDate == null ? null : DateUtil.yyyyMMdd.format(startDate),
expiryDate == null ? null : DateUtil.yyyyMMdd.format(expiryDate), true);
}
Expand All @@ -143,6 +144,23 @@ public static Alert getOfflineAlert(ServiceType serviceType, List<ServiceRecord>
}
}

protected static boolean isServiceIssued(String currentVaccine, List<ServiceRecord> serviceRecords) {

for (ServiceRecord serviceRecord : serviceRecords) {
if (currentVaccine.equalsIgnoreCase(serviceRecord.getName())) {
return true;
}
}

return false;
}

/**
* Use the trigger date as a reference, since that is what is mostly used
*
* @param referenceDate trigger date
* @return evaluated alert status
*/
private static AlertStatus calculateAlertStatus(DateTime referenceDate) {
if (referenceDate != null) {
Calendar refCalendarDate = Calendar.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -178,7 +179,7 @@ public static List<String> updateOfflineAlerts(String baseEntityId,
}
}

if (!exists) {
if (!exists && !AlertStatus.complete.equals(curAlert.status())) {
// Insert alert into table
newAlerts.add(curAlert);
alertService.create(curAlert);
Expand Down Expand Up @@ -259,14 +260,17 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth,
Date dueDate = getDueDate(issuedVaccines, dateOfBirth);
Date expiryDate = getExpiryDate(issuedVaccines, dateOfBirth);
Date overDueDate = getOverDueDate(dueDate);

// Use the trigger date as a reference, since that is what is mostly used
AlertStatus alertStatus = calculateAlertStatus(dueDate, overDueDate);
// Generate only if its not in issued vaccines

AlertStatus alertStatus = isVaccineIssued(vaccine.name(), issuedVaccines) ? AlertStatus.complete : calculateAlertStatus(dueDate, overDueDate);

if (alertStatus != null) {

Alert offlineAlert = new Alert(baseEntityId,
vaccine.display(),
vaccine.name(),
vaccine.name().toLowerCase(Locale.ENGLISH).replace(" ", ""),
alertStatus,
dueDate == null ? null : DateUtil.yyyyMMdd.format(dueDate),
expiryDate == null ? null : DateUtil.yyyyMMdd.format(expiryDate),
Expand All @@ -278,6 +282,18 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth,
return defaultAlert;
}


protected boolean isVaccineIssued(String currentVaccine, List<Vaccine> issuedVaccines) {

for (Vaccine vaccine : issuedVaccines) {
if (currentVaccine.equalsIgnoreCase(vaccine.getName().replaceAll(" ", ""))) {
return true;
}
}

return false;
}

public Date getDueDate(List<Vaccine> issuedVaccines, Date dob) {
Date dueDate = null;
for (VaccineTrigger curTrigger : dueTriggers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,117 +297,6 @@ public static boolean addDialogHookCustomFilter(VaccineWrapper tag) {

}

public static String previousStateKey(String category, Vaccine v) {
if (v == null || category == null) {
return null;
}
ArrayList<VaccineRepo.Vaccine> vaccines = VaccineRepo.getVaccines(category);

VaccineRepo.Vaccine vaccine = null;
for (VaccineRepo.Vaccine vrp : vaccines) {
if (vrp.display().toLowerCase().equalsIgnoreCase(v.getName().toLowerCase())) {
vaccine = vrp;
}
}

if (vaccine == null) {
return null;
} else {
String stateKey = stateKey(vaccine);
if ("at birth".equals(stateKey)) {
stateKey = "Birth";
}
return stateKey;
}
}

public static String stateKey(VaccineRepo.Vaccine vaccine) {
String key;
switch (vaccine) {
case opv0:
case bcg:
case HepB:
key = "at birth";
break;
case opv1:
case penta1:
case pcv1:
case rota1:
key = "6 weeks";
break;

case opv2:
case penta2:
case pcv2:
case rota2:
key = "10 weeks";
break;

case opv3:
case penta3:
case pcv3:
case ipv:
case rota3:
key = "14 weeks";
break;

case mv1:
key = "5 Months";
break;

case mv2:
key = "6 Months";
break;

case mv3:
key ="7 Months";
break;

case measles1:
case mr1:
case opv4:
case yellowfever:
case mcv1:
case rubella1:
case menA:
case meningococcal:
key = "9 months";
break;

case mcv2:
case rubella2:
key = "15 months";
break;
case measles2:
case mr2:
key = "18 months";
break;
case tt1:
key = "After LMP";
break;
case tt2:
key = "4 Weeks after TT 1";
break;
case tt3:
key = "26 Weeks after TT 2";
break;
case tt4:
key = " 1 Year after TT 3 ";
break;
case tt5:
key = " 1 Year after TT 4 ";
break;
case mv4:
key ="22 Months";
break;
default:
key = "";
break;
}

return key;
}

public static String[] allAlertNames(String category) {
if (category == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* Created by real on 31/10/17.
*/

@PrepareForTest ({FormUtils.class, VaccinatorUtils.class, ImmunizationLibrary.class})
@PrepareForTest({FormUtils.class, VaccinatorUtils.class, ImmunizationLibrary.class})
public class VaccinateActionUtilsTest extends BaseUnitTest {

public static final String WOMAN = "woman";
Expand Down Expand Up @@ -210,54 +210,6 @@ public void assertUpdateJsonAndFindTestReturnsJsonObject() throws Exception {

}

@Test
public void assertPreviousStateKeyTestWithVariousVaccineNames() {
Assert.assertNull(VaccinateActionUtils.previousStateKey(null, null));
Vaccine vaccine = new Vaccine();
vaccine.setName(magicBCG);
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName(magicNULL);
Assert.assertNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("OPV 0");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("OPV 1");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("OPV 2");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("OPV 3");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("OPV 4");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MR 1");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MR 2");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("IPV");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MV 1");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MV 2");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MV 3");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MV 4");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("MCV 2");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("Rubella 2");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(magicChild, vaccine));
vaccine.setName("TT 2");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(WOMAN, vaccine));
vaccine.setName("TT 3");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(WOMAN, vaccine));
vaccine.setName("TT 4");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(WOMAN, vaccine));
vaccine.setName("TT 5");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(WOMAN, vaccine));
vaccine.setName("TT 1");
Assert.assertNotNull(VaccinateActionUtils.previousStateKey(WOMAN, vaccine));
}

@Test
public void assertHyphenTestReturnsHyphenatedString() {
Assert.assertNotNull(VaccinateActionUtils.addHyphen(""));
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ android {

dependencies {

implementation('org.smartregister:opensrp-client-core:1.7.28-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-core:1.7.35-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
}

implementation('org.smartregister:opensrp-client-native-form:1.6.44-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-native-form:1.6.51-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
Expand Down

0 comments on commit 8986462

Please sign in to comment.