Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement closing of expired referral intent service #206

Merged
merged 22 commits into from
May 19, 2020
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f3ec697
implemented method for fetching tasks with ready status
cozej4 Apr 29, 2020
6187b8b
Added a query for all tasks with business status referred left joined…
cozej4 May 6, 2020
de54bac
Merged changes from master
cozej4 May 6, 2020
5b16c13
Added hiv, tb and gbv task focus constants
cozej4 May 6, 2020
07ced33
Implemented checks for expired and not completed yet referrals
cozej4 May 7, 2020
70b0619
Implemented a method to generate expred and not completed events
cozej4 May 7, 2020
118b743
Implemented methods for saving expired and not yet done referral events
cozej4 May 7, 2020
8dcf569
Code refactoring
cozej4 May 7, 2020
7e29e7c
Implement Updating of tasts
cozej4 May 7, 2020
5facc61
Implemented close expired referrals service job
cozej4 May 7, 2020
5a0ed64
Refactored chw task repository and added implementation for querying …
cozej4 May 7, 2020
e3ee0ed
Updated library version
cozej4 May 7, 2020
f2c6855
Code cleaning
cozej4 May 7, 2020
0e91606
Code cleaning
cozej4 May 7, 2020
b455f4f
Code refactoring
cozej4 May 11, 2020
b57a236
Added child gbv focus in costants
cozej4 May 11, 2020
67c007c
Merge branch 'master' into implement-closing-of-expired-referral-inte…
cozej4 May 11, 2020
9b269e2
Refactored malaria referrals timeouts
cozej4 May 12, 2020
f6ff046
Implemented notifications for not yet done referrals
cozej4 May 12, 2020
523585a
Refactored Referral Not Yet done notification type
cozej4 May 12, 2020
9478859
Code refactoring
cozej4 May 12, 2020
90e2adb
Merge branch 'master' into implement-closing-of-expired-referral-inte…
ellykits May 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented checks for expired and not completed yet referrals
cozej4 committed May 7, 2020
commit 07ced33689e6367647701c01aaf7d099be8e822e
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.1.67-SNAPSHOT
VERSION_NAME=1.1.68-Test-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Chw Core Library
Original file line number Diff line number Diff line change
@@ -2,23 +2,25 @@

import android.content.Intent;

import org.smartregister.CoreLibrary;
import org.smartregister.chw.core.utils.ChwDBConstants;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.core.utils.Utils;
import org.smartregister.chw.referral.util.DBConstants;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.commonregistry.CommonRepository;
import org.smartregister.domain.Task;
import org.smartregister.family.FamilyLibrary;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.TaskRepository;
import org.smartregister.sync.helper.ECSyncHelper;

import java.util.Date;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

import static org.smartregister.chw.core.utils.ChwDBConstants.TaskTable.START;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS.ANC_DANGER_SIGNS;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS.FP_SIDE_EFFECTS;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS.PNC_DANGER_SIGNS;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS.SICK_CHILD;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS.SUSPECTED_MALARIA;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS.SUSPECTED_TB;
import static org.smartregister.chw.referral.util.DBConstants.Key.REFERRAL_APPOINTMENT_DATE;
import static org.smartregister.chw.core.utils.ChwDBConstants.TaskTable;
import static org.smartregister.chw.core.utils.CoreConstants.TASKS_FOCUS;

/**
* Created by cozej4 on 2020-02-08.
@@ -29,11 +31,18 @@ public class CloseExpiredReferralsIntentService extends ChwCoreSyncIntentService

private static final String TAG = CloseExpiredReferralsIntentService.class.getSimpleName();
private final CommonRepository commonRepository;
private final TaskRepository taskRepository;
private AllSharedPreferences sharedPreferences;
private ECSyncHelper syncHelper;


public CloseExpiredReferralsIntentService() {
super(TAG);
commonRepository = Utils.context().commonrepository("task");
taskRepository = CoreLibrary.getInstance().context().getTaskRepository();
sharedPreferences = Utils.getAllSharedPreferences();
syncHelper = FamilyLibrary.getInstance().getEcSyncHelper();

}

@Override
@@ -42,42 +51,62 @@ protected void onHandleIntent(Intent intent) {
String.format(
"SELECT * FROM %s LEFT JOIN %s ON %s.%s = %s.%s WHERE %s = ? ORDER BY %s DESC",
CoreConstants.TABLE_NAME.TASK, CoreConstants.TABLE_NAME.REFERRAL, CoreConstants.TABLE_NAME.TASK, ChwDBConstants.TaskTable.FOR, CoreConstants.TABLE_NAME.REFERRAL, CommonRepository.ID_COLUMN,
ChwDBConstants.TaskTable.BUSINESS_STATUS, START),
ChwDBConstants.TaskTable.BUSINESS_STATUS, TaskTable.START),
new String[]{CoreConstants.BUSINESS_STATUS.REFERRED}, CoreConstants.TABLE_NAME.TASK);

for (CommonPersonObject task : tasks) {
String appointmentDate = task.getColumnmaps().get(REFERRAL_APPOINTMENT_DATE);
String startDate = task.getColumnmaps().get(START);
String appointmentDate = task.getColumnmaps().get(DBConstants.Key.REFERRAL_APPOINTMENT_DATE);
String startDate = task.getColumnmaps().get(TaskTable.START);
String focus = task.getDetails().get(ChwDBConstants.TaskTable.FOCUS);
int timeoutInDays = 0;

if(focus!=null && startDate!=null) {
Date initialDate = null;
switch (focus) {
case ANC_DANGER_SIGNS:
case PNC_DANGER_SIGNS:
timeoutInDays = 1;
initialDate = new Date(Long.parseLong(startDate));
break;
case SICK_CHILD:
case SUSPECTED_MALARIA:
case FP_SIDE_EFFECTS:
timeoutInDays = 7;
initialDate = new Date(Long.parseLong(startDate));
break;
case SUSPECTED_TB:
timeoutInDays = 3;
initialDate = (appointmentDate != null && !appointmentDate.isEmpty()) ? new Date(Long.parseLong(appointmentDate)) : new Date(Long.parseLong(startDate));
default:
timeoutInDays = 7;
initialDate = (appointmentDate != null && !appointmentDate.isEmpty()) ? new Date(Long.parseLong(appointmentDate)) : new Date(Long.parseLong(startDate));
break;
}
if (focus != null && startDate != null) {
Calendar expiredCalendar = Calendar.getInstance();
if (focus.equals(TASKS_FOCUS.ANC_DANGER_SIGNS) || focus.equals(TASKS_FOCUS.PNC_DANGER_SIGNS)) {
expiredCalendar.setTimeInMillis(Long.parseLong(startDate));
expiredCalendar.add(Calendar.HOUR_OF_DAY, 24);
checkIfExpired(expiredCalendar, task);
} else if (focus.equals(TASKS_FOCUS.SICK_CHILD) || focus.equals(TASKS_FOCUS.SUSPECTED_MALARIA) || focus.equals(TASKS_FOCUS.FP_SIDE_EFFECTS)) {
Calendar referralNotYetDoneCalendar = Calendar.getInstance();
referralNotYetDoneCalendar.setTimeInMillis(Long.parseLong(startDate));
referralNotYetDoneCalendar.add(Calendar.DAY_OF_MONTH, 3);

}
expiredCalendar.setTimeInMillis(Long.parseLong(startDate));
expiredCalendar.add(Calendar.DAY_OF_MONTH, 7);

if (Objects.requireNonNull(task.getColumnmaps().get(TaskTable.STATUS)).equals(Task.TaskStatus.READY.name())) {
checkIfNotYetDone(referralNotYetDoneCalendar, task);
} else {
checkIfExpired(expiredCalendar, task);
}
} else if (focus.equals(TASKS_FOCUS.SUSPECTED_TB)) {
expiredCalendar.setTimeInMillis(Long.parseLong(appointmentDate));
expiredCalendar.add(Calendar.DAY_OF_MONTH, 3);

checkIfExpired(expiredCalendar, task);
} else {
if (appointmentDate != null && !appointmentDate.isEmpty()) {
expiredCalendar.setTimeInMillis(Long.parseLong(appointmentDate));
} else {
expiredCalendar.setTimeInMillis(Long.parseLong(startDate));
}
expiredCalendar.add(Calendar.DAY_OF_MONTH, 7);

checkIfExpired(expiredCalendar, task);

}
}
}
}

public void checkIfExpired(Calendar expiredCalendar, CommonPersonObject taskEvent) {
if (Calendar.getInstance().getTime().after(expiredCalendar.getTime())) {
//Implement expired referrals events
}
}

public void checkIfNotYetDone(Calendar referralNotYetDoneCalendar, CommonPersonObject taskEvent) {
if (Calendar.getInstance().getTime().after(referralNotYetDoneCalendar.getTime())) {
//Implement expired referrals events
}
}

}
Original file line number Diff line number Diff line change
@@ -31,5 +31,6 @@ interface TaskTable {
String START = "start";
String FOCUS = "focus";
String REASON_REFERENCE = "reason_reference";
String LOCATION = "location";
}
}
Original file line number Diff line number Diff line change
@@ -125,6 +125,8 @@ public static final class EventType {
public static final String ANC_HOME_VISIT_NOT_DONE_UNDO = "ANC Home Visit Not Done Undo";
public static final String UPDATE_ANC_REGISTRATION = "Update ANC Registration";
public static final String CLOSE_REFERRAL = "Close Referral";
public static final String EXPIRED_REFERRAL = "Expired Referral";
public static final String NOT_YET_DONE_REFERRAL = "Not Yet Done Referral";
public static final String PREGNANCY_OUTCOME = "Pregnancy Outcome";
public static final String PNC_REGISTRATION = "PNC Registration";
public static final String PNC_HOME_VISIT_NOT_DONE = "PNC Home Visit Not Done";
@@ -607,6 +609,7 @@ public static class TABLE_NAME {
public static final String PNC_REFERRAL = "ec_pnc_referral";
public static final String FP_REFERRAL = "ec_fp_referral";
public static final String CLOSE_REFERRAL = "ec_close_referral";
public static final String NOT_YET_DONE_REFERRAL = "ec_not_yet_done_referral";
public static final String SCHEDULE_SERVICE = "schedule_service";
public static final String MALARIA_REFERRAL = "ec_malaria_referral";
public static final String STOCK_USAGE_REPORT = "ec_stock_usage_report";