Skip to content

Commit

Permalink
Merge 9fc055f into acf2a3a
Browse files Browse the repository at this point in the history
  • Loading branch information
ekigamba committed Feb 22, 2020
2 parents acf2a3a + 9fc055f commit 129db3f
Show file tree
Hide file tree
Showing 31 changed files with 578 additions and 41 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ This behaviour can be altered via the setting below in your implementation's _ap
```
vaccine.expired.entry.allow=true
```
## Expired vaccine card color

The current default color for expired vaccine when back-data entry is enabled is white. However, this is not intuitive and therefore we provide an option to show the expired vaccines as RED only when vaccine back-data entry is enabled.

```
vaccine.expired.red=true
```

### Vaccine Group

## Gotcha's when using the library

Expand Down
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.41-SNAPSHOT
VERSION_NAME=1.4.42r4-GIZ-0.2.8r1-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 @@ -33,7 +33,7 @@ android {
compileSdkVersion androidCompileSdkVersion
buildToolsVersion androidBuildToolsVersion

defaultPublishConfig !isReleaseBuild() ? "debug" : "release"
//defaultPublishConfig !isReleaseBuild() ? "debug" : "release"

defaultConfig {
minSdkVersion androidMinSdkVersion
Expand All @@ -52,7 +52,7 @@ android {
}

debug {
buildConfigField "int", "VACCINE_SYNC_TIME", '0'
buildConfigField "int", "VACCINE_SYNC_TIME", '12'
testCoverageEnabled true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.smartregister.immunization;

import android.support.annotation.NonNull;

import org.smartregister.Context;
import org.smartregister.commonregistry.CommonFtsObject;
import org.smartregister.immunization.db.VaccineRepo;
Expand All @@ -22,6 +24,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
* Created by keyman on 31/07/17.
Expand All @@ -47,6 +50,8 @@ public class ImmunizationLibrary {
public static List<String> COMBINED_VACCINES = new ArrayList<>();
public static Map<String, String> COMBINED_VACCINES_MAP = new HashMap<>();

private long vaccineSyncTime = -1;

private ImmunizationLibrary(Context context, Repository repository, CommonFtsObject commonFtsObject, int applicationVersion, int databaseVersion) {
this.repository = repository;
this.context = context;
Expand All @@ -62,7 +67,7 @@ public static void init(Context context, Repository repository, CommonFtsObject
allowExpiredVaccineEntry = instance.getProperties().hasProperty(IMConstants.APP_PROPERTIES.VACCINE_EXPIRED_ENTRY_ALLOW) && instance.getProperties().getPropertyBoolean(IMConstants.APP_PROPERTIES.VACCINE_EXPIRED_ENTRY_ALLOW);

Utils.processVaccineCache(context.applicationContext(), IMConstants.VACCINE_TYPE.CHILD);
Utils.processVaccineCache(context.applicationContext(), IMConstants.VACCINE_TYPE.WOMAN);
//Utils.processVaccineCache(context.applicationContext(), IMConstants.VACCINE_TYPE.WOMAN);
}
}

Expand Down Expand Up @@ -172,4 +177,25 @@ public boolean isAllowExpiredVaccineEntry() {
public static Map<String, VaccineCache> getVaccineCacheMap() {
return vaccineCacheMap;
}

public boolean isExpiredVaccineCardRed() {
return getProperties().hasProperty(IMConstants.APP_PROPERTIES.EXPIRED_CARD_AS_RED) && instance.getProperties().getPropertyBoolean(IMConstants.APP_PROPERTIES.EXPIRED_CARD_AS_RED);
}

public long getVaccineSyncTime() {
if (vaccineSyncTime == -1) {
setVaccineSyncTime(BuildConfig.VACCINE_SYNC_TIME);
}

return vaccineSyncTime;
}

public void setVaccineSyncTime(int vaccineSyncTime) {
setVaccineSyncTime(vaccineSyncTime, TimeUnit.HOURS);
}

public void setVaccineSyncTime(int vaccineSyncTime, @NonNull TimeUnit timeUnit) {
this.vaccineSyncTime = timeUnit.toMinutes(vaccineSyncTime);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ public void updateWrapperStatus(VaccineWrapper tag, String type, CommonPersonObj

List<Alert> alertList = getAlertList();

Map<String, Date> recievedVaccines = VaccinatorUtils.receivedVaccines(vaccineList);
Map<String, Date> receivedVaccines = VaccinatorUtils.receivedVaccines(vaccineList);

String dobString = getValue(childDetails.getColumnmaps(), "dob", false);
List<Map<String, Object>> sch = generateScheduleList(type, new DateTime(dobString), recievedVaccines, alertList);
List<Map<String, Object>> sch = generateScheduleList(type, new DateTime(dobString), receivedVaccines, alertList);


for (Map<String, Object> m : sch) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.smartregister.immunization.domain;

import org.joda.time.DateTime;

/**
* Created by Ephraim Kigamba - ekigamba@ona.io on 2020-02-13
*/

public class VaccinationClient {

private String baseEntityId;
private DateTime birthDateTime;

public String getBaseEntityId() {
return baseEntityId;
}

public void setBaseEntityId(String baseEntityId) {
this.baseEntityId = baseEntityId;
}

public DateTime getBirthDateTime() {
return birthDateTime;
}

public void setBirthDateTime(DateTime birthDateTime) {
this.birthDateTime = birthDateTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ private static VaccineSchedule getVaccineSchedule(String vaccineName, String vac
}

VaccineRepo.Vaccine vaccine = VaccineRepo.getVaccine(vaccineName, vaccineCategory);


if (vaccine != null) {
ArrayList<VaccineCondition> conditions = new ArrayList<>();
if (schedule.conditions != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.smartregister.immunization.job;

import java.util.concurrent.TimeUnit;

/**
* Created by Ephraim Kigamba - ekigamba@ona.io on 2020-02-13
*/
class DailyExecutionWindow {

final long startMs;
final long endMs;

/**
* Holds the start end time in ms for a job.
* Will wrap around to next day if currentHour < targetHour.
* If the current time is exactly now it will be forced to 60 seconds in the future.
*
* @param currentHour - current currentHour
* @param currentMinute - current currentMinute
* @param targetHour - currentHour we want to start
* @param targetMinute - currentMinute we want to start
* @param windowLengthInMinutes - number of minutes for the execution window
*/
DailyExecutionWindow(int currentHour, int currentMinute, long targetHour, long targetMinute, long windowLengthInMinutes) {
long hourOffset;
long minuteOffset;

if (targetHour == currentHour && targetMinute < currentMinute) {
hourOffset = TimeUnit.HOURS.toMillis(23);
} else if (targetHour - currentHour == 1) { // if we are less then an hour ahead, but into the next hour
// move forward to 0 minute of next hour
hourOffset = TimeUnit.MINUTES.toMillis(60 - currentMinute);
currentMinute = 0;
} else if (targetHour >= currentHour) {
hourOffset = TimeUnit.HOURS.toMillis(targetHour - currentHour);
} else {
hourOffset = TimeUnit.HOURS.toMillis((24 + targetHour) - currentHour);
}

if (targetMinute >= currentMinute) {
minuteOffset = TimeUnit.MINUTES.toMillis(targetMinute - currentMinute);
} else {
minuteOffset = TimeUnit.MINUTES.toMillis((60 + targetMinute) - currentMinute);
}

this.startMs = Math.max(hourOffset + minuteOffset, 60000);
this.endMs = this.startMs + TimeUnit.MINUTES.toMillis(windowLengthInMinutes);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.smartregister.immunization.job;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;

import com.evernote.android.job.DailyJob;
import com.evernote.android.job.JobRequest;
import com.evernote.android.job.util.support.PersistableBundleCompat;

import org.smartregister.CoreLibrary;
import org.smartregister.immunization.service.intent.VaccineSchedulesUpdateIntentService;
import org.smartregister.immunization.util.IMConstants;

import java.util.concurrent.TimeUnit;

import timber.log.Timber;

/**
* This job starts a service which recalculates the alerts periodically(daily) or ad-hoc
*
* Created by Ephraim Kigamba - ekigamba@ona.io on 2020-02-13
*/

public abstract class VaccineSchedulesUpdateJob extends DailyJob {

public static final String TAG = "VaccineSchedulesUpdateJob";
public static final String SCHEDULE_ADHOC_TAG = "VaccineSchedulesUpdateAdhocJob";

public static void scheduleEverydayAt(@NonNull String jobTag, int hour, int minute) {
JobRequest.Builder jobRequest = new JobRequest.Builder(jobTag);
long startTime = TimeUnit.HOURS.toMillis(hour) + TimeUnit.MINUTES.toMillis(minute);
schedule(jobRequest, startTime, startTime + TimeUnit.MINUTES.toMillis(45));
}

/**
* For jobs that need to be started immediately
*/
public static void scheduleJobImmediately() {
int jobId = startNowOnce(new JobRequest.Builder(SCHEDULE_ADHOC_TAG));
Timber.d("Scheduling job with name " + SCHEDULE_ADHOC_TAG + " immediately with JOB ID " + jobId);
}

@NonNull
@Override
protected DailyJobResult onRunDailyJob(@NonNull Params params) {
Intent intent = new Intent(getContext(), VaccineSchedulesUpdateIntentService.class);
intent.putExtra(IMConstants.IntentKey.VaccineScheduleUpdateIntentService.CLIENT_TABLE_NAME, getClientTableName());

getContext().startService(intent);
updateLastTimeRun();

return DailyJobResult.SUCCESS;
}

@VisibleForTesting
protected void updateLastTimeRun() {
CoreLibrary.getInstance().context().allSharedPreferences().savePreference(IMConstants.Preference.VACCINE_SCHEDULE_UPDATE_LAST_TIME_RUN, String.valueOf(System.currentTimeMillis()));
}

public static long getLastTimeRun() {
String timeString = CoreLibrary.getInstance().context().allSharedPreferences().getPreference(IMConstants.Preference.VACCINE_SCHEDULE_UPDATE_LAST_TIME_RUN);

if (TextUtils.isEmpty(timeString)) {
return 0L;
} else {
try {
return Long.parseLong(timeString);
} catch (NumberFormatException ex) {
Timber.e(ex);
return 0L;
}
}
}

public static boolean isLastTimeRunLongerThan(long hours) {
long lastTimeMillis = getLastTimeRun();

return ((System.currentTimeMillis() - lastTimeMillis)/TimeUnit.HOURS.toMillis(1)) > hours;
}


@NonNull
protected abstract String getClientTableName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import org.smartregister.immunization.domain.ServiceRecord;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.Repository;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import timber.log.Timber;

public class RecurringServiceRecordRepository extends BaseRepository {
public static final String TABLE_NAME = "recurring_service_records";
public static final String ID_COLUMN = "_id";
Expand Down Expand Up @@ -269,12 +270,12 @@ public static String removeHyphen(String s) {
return s;
}

public List<ServiceRecord> findUnSyncedBeforeTime(int hours) {
public List<ServiceRecord> findUnSyncedBeforeTime(int minutes) {
List<ServiceRecord> serviceRecords = new ArrayList<>();
Cursor cursor = null;
try {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY, -hours);
calendar.add(Calendar.MINUTE, -minutes);

Long time = calendar.getTimeInMillis();

Expand All @@ -283,7 +284,7 @@ public List<ServiceRecord> findUnSyncedBeforeTime(int hours) {
new String[] {time.toString(), TYPE_Unsynced}, null, null, null, null);
serviceRecords = readAllServiceRecords(cursor);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
Timber.e(e);
} finally {
if (cursor != null) {
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.jetbrains.annotations.Nullable;
import org.smartregister.immunization.domain.ServiceType;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;

import java.util.ArrayList;
import java.util.Calendar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.smartregister.commonregistry.CommonFtsObject;
import org.smartregister.immunization.domain.VaccineName;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;
import org.smartregister.service.AlertService;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.smartregister.immunization.domain.Vaccine;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.Repository;
import org.smartregister.service.AlertService;

import java.text.ParseException;
Expand All @@ -23,6 +22,8 @@
import java.util.Date;
import java.util.List;

import timber.log.Timber;

public class VaccineRepository extends BaseRepository {
public static final String VACCINE_TABLE_NAME = "vaccines";
public static final String ID_COLUMN = "_id";
Expand Down Expand Up @@ -193,12 +194,12 @@ public static String addHyphen(String s) {
return s;
}

public List<Vaccine> findUnSyncedBeforeTime(int hours) {
public List<Vaccine> findUnSyncedBeforeTime(int minutes) {
List<Vaccine> vaccines = new ArrayList<>();
Cursor cursor = null;
try {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY, -hours);
calendar.add(Calendar.MINUTE, -minutes);

Long time = calendar.getTimeInMillis();

Expand All @@ -207,7 +208,7 @@ public List<Vaccine> findUnSyncedBeforeTime(int hours) {
null, null, null, null);
vaccines = readAllVaccines(cursor);
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
Timber.e(e);
} finally {
if (cursor != null) {
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.smartregister.commonregistry.CommonFtsObject;
import org.smartregister.immunization.domain.VaccineType;
import org.smartregister.repository.BaseRepository;
import org.smartregister.repository.Repository;
import org.smartregister.service.AlertService;

import java.util.ArrayList;
Expand Down

0 comments on commit 129db3f

Please sign in to comment.