Skip to content

Commit

Permalink
Merge pull request #104 from OpenSRP/issue103
Browse files Browse the repository at this point in the history
Overdue and expiry alert issues
  • Loading branch information
ndegwamartin committed Nov 11, 2019
2 parents ec4e818 + 0ac24ec commit f883106
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 36 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.28-SNAPSHOT
VERSION_NAME=1.4.29-SNAPSHOT
VERSION_CODE=2
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ public static Alert getOfflineAlert(ServiceType serviceType, List<ServiceRecord>
DateTime dueDateTime = VaccinatorUtils.getServiceDueDate(serviceType, dateOfBirth, issuedServices);
DateTime expiryDateTime = VaccinatorUtils.getServiceExpiryDate(serviceType, dateOfBirth);

AlertStatus alertStatus = null;
alertStatus = expiryDateTime != null && expiryDateTime.isBeforeNow() ? AlertStatus.expired : null; //Check if expired first

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

if (alertStatus != null) {
Date startDate = dueDateTime == null ? dateOfBirth.toDate() : dueDateTime.toDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth,
// Use the trigger date as a reference, since that is what is mostly used
// Generate only if its not in issued vaccines

AlertStatus alertStatus = isVaccineIssued(vaccine.name(), issuedVaccines) ? AlertStatus.complete : calculateAlertStatus(dueDate, overDueDate);
AlertStatus alertStatus = null;
alertStatus = expiryDate != null && expiryDate.before(Calendar.getInstance().getTime()) ? AlertStatus.expired : null; //Check if expired first

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

if (alertStatus != null) {

Expand Down Expand Up @@ -344,7 +349,10 @@ public Date getOverDueDate(Date dueDate) {
dueDateCalendar.setTime(dueDate);
standardiseCalendarDate(dueDateCalendar);

return addOffsetToCalendar(dueDateCalendar, window).getTime();
Calendar overDueOffsetCalendar = addOffsetToCalendar(dueDateCalendar, window);
overDueOffsetCalendar.add(Calendar.DATE, 1); //Add date it should actually be expired

return overDueOffsetCalendar.getTime();
}

return null;
Expand Down Expand Up @@ -374,8 +382,7 @@ private AlertStatus calculateAlertStatus(Date referenceDate, Date overDueDate) {
standardiseCalendarDate(today);


if (overDueDate != null
&& overDueCalendarDate.getTimeInMillis() <= today.getTimeInMillis()) { //OverDue
if (overDueDate != null && overDueCalendarDate.getTimeInMillis() <= today.getTimeInMillis()) { //OverDue
return AlertStatus.urgent;
} else if (refCalendarDate.getTimeInMillis() <= today.getTimeInMillis()) { // Due
return AlertStatus.normal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.smartregister.immunization.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
Expand Down Expand Up @@ -39,7 +39,7 @@
import java.util.Calendar;
import java.util.List;

@SuppressLint ("ValidFragment")
@SuppressLint("ValidFragment")
public class ServiceEditDialogFragment extends DialogFragment {
public static final String DIALOG_TAG = "ServiceEditDialogFragment";
private final ServiceWrapper tag;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void run() {
}

@Override
public void onAttach(Activity activity) {
public void onAttach(Context activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
Expand Down Expand Up @@ -220,7 +220,7 @@ public void onClick(View view) {
earlierDatePicker.setVisibility(View.VISIBLE);
set.setVisibility(View.VISIBLE);

DatePickerUtils.themeDatePicker(earlierDatePicker, new char[] {'d', 'm', 'y'});
DatePickerUtils.themeDatePicker(earlierDatePicker, new char[]{'d', 'm', 'y'});


}
Expand Down Expand Up @@ -272,8 +272,7 @@ public void onClick(View view) {
/**
* This method updates the allowed date ranges in the views
*
* @param datePicker
* Date picker for selecting a previous date for a vaccine
* @param datePicker Date picker for selecting a previous date for a vaccine
*/
private void updateDateRanges(DatePicker datePicker, Button set) {
if (tag == null || tag.getDob() == null || tag.getServiceType() == null || issuedServices == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.smartregister.immunization.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Point;
import android.os.Bundle;
Expand Down Expand Up @@ -29,7 +29,7 @@

import java.io.Serializable;

@SuppressLint ("ValidFragment")
@SuppressLint("ValidFragment")
public class UndoServiceDialogFragment extends DialogFragment {
public static final String DIALOG_TAG = "UndoServiceDialogFragment";
public static final String WRAPPER_TAG = "tag";
Expand Down Expand Up @@ -98,7 +98,7 @@ public void run() {
}

@Override
public void onAttach(Activity activity) {
public void onAttach(Context activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.smartregister.immunization.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Point;
import android.os.Bundle;
Expand Down Expand Up @@ -30,7 +30,7 @@

import java.io.Serializable;

@SuppressLint ("ValidFragment")
@SuppressLint("ValidFragment")
public class UndoVaccinationDialogFragment extends DialogFragment {
public static final String DIALOG_TAG = "UndoVaccinationDialogFragment";
public static final String WRAPPER_TAG = "tag";
Expand Down Expand Up @@ -101,7 +101,7 @@ public void run() {
}

@Override
public void onAttach(Activity activity) {
public void onAttach(Context activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.smartregister.immunization.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.Point;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void run() {
}

@Override
public void onAttach(Activity activity) {
public void onAttach(Context activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.smartregister.immunization.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;
Expand Down Expand Up @@ -43,7 +42,7 @@
import java.util.Date;
import java.util.List;

@SuppressLint ("ValidFragment")
@SuppressLint("ValidFragment")
public class VaccinationEditDialogFragment extends DialogFragment {
private final Context context;
private final ArrayList<VaccineWrapper> tags;
Expand Down Expand Up @@ -141,7 +140,7 @@ public void run() {
}

@Override
public void onAttach(Activity activity) {
public void onAttach(Context activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
Expand Down Expand Up @@ -290,7 +289,7 @@ public void onClick(View view) {
earlierDatePicker.setVisibility(View.VISIBLE);
set.setVisibility(View.VISIBLE);

DatePickerUtils.themeDatePicker(earlierDatePicker, new char[] {'d', 'm', 'y'});
DatePickerUtils.themeDatePicker(earlierDatePicker, new char[]{'d', 'm', 'y'});

// dismiss();
//
Expand Down Expand Up @@ -448,8 +447,7 @@ private VaccineWrapper searchWrapperByName(String name) {
/**
* This method updates the allowed date ranges in the views
*
* @param datePicker
* Date picker for selecting a previous date for a vaccine
* @param datePicker Date picker for selecting a previous date for a vaccine
*/
private void updateDateRanges(DatePicker datePicker, Button set) {
Calendar today = Calendar.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -431,10 +432,10 @@ public static List<Map<String, Object>> generateScheduleList(String category, Da
return schedule;
}

private static Map<String, Object> createVaccineMap(String status, Alert a, DateTime
date, Vaccine v) {
private static Map<String, Object> createVaccineMap(String status, Alert a, DateTime date, Vaccine v) {

Map<String, Object> m = new HashMap<>();
m.put("status", status);
m.put("status", a != null && !TextUtils.isEmpty(a.status().name()) && a.status().name().equals("expired") ? a.status().name() : status);
m.put("alert", a);
m.put("date", date);
m.put("vaccine", v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void updateStateUi() {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_white);
undoB.setVisibility(INVISIBLE);
nameTV.setText(getVaccineName());
StatusTV.setText("Expired");
StatusTV.setText(context.getResources().getString(R.string.expired));
StatusTV.setTextColor(context.getResources().getColor(R.color.silver));
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ServiceCard(Context context, AttributeSet attrs, int defStyleAttr) {
init(context);
}

@TargetApi (Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ServiceCard(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
Expand Down Expand Up @@ -224,7 +224,7 @@ private void updateStateUi() {
undoB.setVisibility(GONE);
nameTV.setVisibility(VISIBLE);
nameTV.setTextColor(context.getResources().getColor(R.color.silver));
nameTV.setText("Expired: " + getServiceName());
nameTV.setText(context.getResources().getString(R.string.expired_colon, getServiceName()));
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void updateStateUi() {
statusIV.setBackgroundResource(R.drawable.vaccine_card_background_white);
undoB.setVisibility(INVISIBLE);
nameTV.setText(getVaccineName());
StatusTV.setText("Expired");
StatusTV.setText(context.getResources().getString(R.string.expired));
StatusTV.setTextColor(context.getResources().getColor(R.color.silver));
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void updateStateUi() {
undoB.setVisibility(GONE);
nameTV.setVisibility(VISIBLE);
nameTV.setTextColor(context.getResources().getColor(R.color.silver));
nameTV.setText("Expired: " + getVaccineName());
nameTV.setText(context.getResources().getString(R.string.expired_colon,getVaccineName()));
break;
default:
break;
Expand Down
3 changes: 3 additions & 0 deletions opensrp-immunization/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@
<string name="_9_months">9 أشهر</string>
<string name="_18_months">18 شهرا</string>

<string name="expired">تنقضي</string>
<string name="expired_colon">%1$s
تنقضي:</string>

</resources>
3 changes: 3 additions & 0 deletions opensrp-immunization/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@
<string name="_9_months">9 mois</string>
<string name="_18_months">18 mois</string>

<string name="expired">Expiré</string>
<string name="expired_colon">Expiré: %1$s</string>


</resources>
3 changes: 3 additions & 0 deletions opensrp-immunization/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@
<string name="_9_months">9 Months</string>
<string name="_18_months">18 Months</string>

<string name="expired">Expired</string>
<string name="expired_colon">Expired: %1$s</string>


</resources>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.smartregister.immunization.fragment.mock;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void onStart() {
}

@Override
public void onAttach(Activity activity) {
public void onAttach(Context activity) {
super.onAttach(activity);
}

Expand Down

0 comments on commit f883106

Please sign in to comment.