Skip to content

Commit

Permalink
Merge branch 'master' into translations_0507
Browse files Browse the repository at this point in the history
  • Loading branch information
allan-on authored May 10, 2019
2 parents ebe2457 + 79af13c commit 6d16b3f
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 152 deletions.
6 changes: 6 additions & 0 deletions opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ dependencies {
exclude group: 'com.android.support', module: 'appcompat-v7'
}

implementation('org.smartregister:opensrp-client-reporting:1.0.6-SNAPSHOT@aar') {
transitive = true
exclude group: 'org.smartregister', module: 'opensrp-client-core'
exclude group: 'com.android.support', module: 'appcompat-v7'
}

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
Expand Down
14 changes: 14 additions & 0 deletions opensrp-chw/src/main/assets/config/indicator-definitions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
indicators:
- key: "CHW_001"
description: "Total U5 children"
indicatorQuery: "select count(distinct baseEntityId) from event where eventType = 'Child Registration' and eventDate = '%s'"

- key: "CHW_002"
description: "Children (0-11 months) who died in the last year"
indicatorQuery: "select count(distinct event.baseEntityId) from event where eventType = 'Remove Child Under 5' and eventDate = '%s' and event.baseEntityId in (select ec_child.base_entity_id
from ec_child where date(ec_child.dob) >= date('now', '-11 month') and date(ec_child.dod) >= date('now', '-12 month'))"

- key: "CHW_003"
description: "Children (12-59 months) who died in the last year"
indicatorQuery: "select count(distinct event.baseEntityId) from event where eventType = 'Remove Child Under 5' and eventDate = '%s' and event.baseEntityId in (select ec_child.base_entity_id
from ec_child where date(ec_child.dob) >= date('now', '-60 month') and date(ec_child.dob) < date('now', '-11 month') and date(ec_child.dod) >= date('now', '-12 month'))"
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ public void updateImmunizationData() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
layoutMostDueOverdue.setVisibility(View.GONE);
viewMostDueRow.setVisibility(View.GONE);
presenter().fetchVisitStatus(childBaseEntityId);
presenter().fetchUpcomingServiceAndFamilyDue(childBaseEntityId);
presenter().updateChildCommonPerson(childBaseEntityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void parseBundleANdUpdateView() {
if (TextUtils.isEmpty(name)) {
textViewTitle.setVisibility(View.GONE);
} else {
textViewTitle.setText(getString(R.string.medical_title, name + "'s profile"));
textViewTitle.setText(getString(R.string.medical_title, name));
}
textViewLastVisit.setText(getString(R.string.medical_last_visit, Utils.firstCharacterUppercase(lastVisitDays)));
initializePresenter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.smartregister.immunization.util.VaccinatorUtils;
import org.smartregister.location.helper.LocationHelper;
import org.smartregister.receiver.SyncStatusBroadcastReceiver;
import org.smartregister.reporting.ReportingLibrary;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.repository.Repository;
import org.smartregister.sync.ClientProcessorForJava;
Expand Down Expand Up @@ -139,6 +140,9 @@ public void onCreate() {
// init json helper
this.jsonSpecHelper = new JsonSpecHelper(this);

// Init Reporting library
ReportingLibrary.init(context, getRepository(), null, BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION);

//init Job Manager
JobManager.create(this).addJobCreator(new ChwJobCreator());

Expand All @@ -160,7 +164,6 @@ public void onCreate() {
saveLanguage(Locale.FRENCH.getLanguage());
}


private void saveLanguage(String language) {
AllSharedPreferences allSharedPreferences = ChwApplication.getInstance().getContext().allSharedPreferences();
allSharedPreferences.saveLanguagePreference(language);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ public void initializeAdapter(Set<org.smartregister.configurableviews.model.View
@Override
public void countExecute() {
super.countExecute();
int count = clientAdapter.getTotalcount();
final int count = clientAdapter.getTotalcount();
if (getActivity() != null && count != dueCount) {
dueCount = count;
((FamilyProfileActivity) getActivity()).updateDueCount(dueCount);
}

onEmptyRegisterCount(count < 1);
//crash occured after create a child
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {

onEmptyRegisterCount(count < 1);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.smartregister.job.PullUniqueIdsServiceJob;
import org.smartregister.job.SyncServiceJob;
import org.smartregister.login.interactor.BaseLoginInteractor;
import org.smartregister.reporting.job.RecurringIndicatorGeneratingJob;
import org.smartregister.view.contract.BaseLoginContract;

import java.util.concurrent.TimeUnit;
Expand All @@ -29,6 +30,9 @@ protected void scheduleJobsPeriodically() {
PullUniqueIdsServiceJob.scheduleJob(PullUniqueIdsServiceJob.TAG, TimeUnit.MINUTES.toMillis(BuildConfig.PULL_UNIQUE_IDS_MINUTES), getFlexValue
(BuildConfig.PULL_UNIQUE_IDS_MINUTES));

RecurringIndicatorGeneratingJob.scheduleJob(RecurringIndicatorGeneratingJob.TAG,
TimeUnit.MINUTES.toMillis(org.smartregister.reporting.BuildConfig.REPORT_INDICATOR_GENERATION_MINUTES), TimeUnit.MINUTES.toMillis(1));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.smartregister.job.PullUniqueIdsServiceJob;
import org.smartregister.job.SyncServiceJob;
import org.smartregister.job.ValidateSyncDataServiceJob;
import org.smartregister.reporting.job.RecurringIndicatorGeneratingJob;

/**
* Created by keyman on 27/11/2018.
Expand All @@ -34,6 +35,8 @@ public Job create(@NonNull String tag) {
return new VaccineRecurringServiceJob();
case ImageUploadServiceJob.TAG:
return new ImageUploadServiceJob();
case RecurringIndicatorGeneratingJob.TAG:
return new RecurringIndicatorGeneratingJob();
default:
Log.d(ChwJobCreator.class.getCanonicalName(), "Looks like you tried to create a job " + tag + " that is not declared in the Anc Job Creator");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import org.smartregister.immunization.repository.VaccineRepository;
import org.smartregister.immunization.repository.VaccineTypeRepository;
import org.smartregister.immunization.util.IMDatabaseUtils;
import org.smartregister.reporting.ReportingLibrary;
import org.smartregister.reporting.repository.DailyIndicatorCountRepository;
import org.smartregister.reporting.repository.IndicatorQueryRepository;
import org.smartregister.reporting.repository.IndicatorRepository;
import org.smartregister.repository.AlertRepository;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.repository.Repository;
Expand All @@ -35,6 +39,9 @@ public class ChwRepository extends Repository {
protected SQLiteDatabase readableDatabase;
protected SQLiteDatabase writableDatabase;
private Context context;
private String indicatorsConfigFile = "config/indicator-definitions.yml";
private String indicatorDataInitialisedPref = "INDICATOR_DATA_INITIALISED";
private String appVersionCodePref = "APP_VERSION_CODE";

public ChwRepository(Context context, org.smartregister.Context openSRPContext) {
super(context, AllConstants.DATABASE_NAME, BuildConfig.DATABASE_VERSION, openSRPContext.session(), ChwApplication.createCommonFtsObject(), openSRPContext.sharedRepositoriesArray());
Expand All @@ -57,13 +64,28 @@ public void onCreate(SQLiteDatabase database) {

RecurringServiceTypeRepository.createTable(database);
RecurringServiceRecordRepository.createTable(database);

IndicatorRepository.createTable(database);
IndicatorQueryRepository.createTable(database);
DailyIndicatorCountRepository.createTable(database);

//onUpgrade(database, 1, 2);
RecurringServiceTypeRepository recurringServiceTypeRepository = ImmunizationLibrary.getInstance().recurringServiceTypeRepository();
IMDatabaseUtils.populateRecurringServices(context, database, recurringServiceTypeRepository);


onUpgrade(database, 1, BuildConfig.DATABASE_VERSION);

ReportingLibrary reportingLibraryInstance = ReportingLibrary.getInstance();
// Check if indicator data initialised
boolean indicatorDataInitialised = Boolean.parseBoolean(reportingLibraryInstance.getContext()
.allSharedPreferences().getPreference(indicatorDataInitialisedPref));
boolean isUpdated = checkIfAppUpdated();
if (!indicatorDataInitialised || isUpdated) {
reportingLibraryInstance.initIndicatorData(indicatorsConfigFile, database); // This will persist the data in the DB
reportingLibraryInstance.getContext().allSharedPreferences().savePreference(indicatorDataInitialisedPref, "true");
reportingLibraryInstance.getContext().allSharedPreferences().savePreference(appVersionCodePref, String.valueOf(BuildConfig.VERSION_CODE));
}

}

@Override
Expand Down Expand Up @@ -103,19 +125,19 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@Override
public SQLiteDatabase getReadableDatabase() {
String pass = ChwApplication.getInstance().getPassword();
if(StringUtils.isNotBlank(pass)){
if (StringUtils.isNotBlank(pass)) {
return getReadableDatabase(pass);
}else{
} else {
throw new IllegalStateException("Password is blank");
}
}

@Override
public SQLiteDatabase getWritableDatabase() {
String pass = ChwApplication.getInstance().getPassword();
if(StringUtils.isNotBlank(pass)){
if (StringUtils.isNotBlank(pass)) {
return getWritableDatabase(pass);
}else{
} else {
throw new IllegalStateException("Password is blank");
}
}
Expand Down Expand Up @@ -160,6 +182,16 @@ public synchronized void close() {
super.close();
}

private boolean checkIfAppUpdated() {
String savedAppVersion = ReportingLibrary.getInstance().getContext().allSharedPreferences().getPreference(appVersionCodePref);
if (savedAppVersion.isEmpty()) {
return true;
} else {
int savedVersion = Integer.parseInt(savedAppVersion);
return (BuildConfig.VERSION_CODE > savedVersion);
}
}

private void upgradeToVersion2(SQLiteDatabase db) {
try {
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_EVENT_ID_COL);
Expand Down Expand Up @@ -229,15 +261,16 @@ private void upgradeToVersion5(SQLiteDatabase db) {

private void upgradeToVersion6(SQLiteDatabase db) {
try {
if(BuildConfig.BUILD_COUNTRY == Country.TANZANIA){
for (String query: RepositoryUtils.UPGRADE_V6) {
if (BuildConfig.BUILD_COUNTRY == Country.TANZANIA) {
for (String query : RepositoryUtils.UPGRADE_V6) {
db.execSQL(query);
}
}
} catch (Exception e) {
Log.e(TAG, "upgradeToVersion6 " + Log.getStackTraceString(e));
}
}

private void upgradeToVersion7(SQLiteDatabase db) {
try {
db.execSQL(HomeVisitRepository.UPDATE_TABLE_ADD_VACCINE_NOT_GIVEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected Map<String, NamedObject<?>> doInBackground(Void... voids) {
String dobString = Utils.getValue(childDetails.getColumnmaps(), "dob", false);
if (!TextUtils.isEmpty(dobString)) {
DateTime dateTime = new DateTime(dobString);
VaccineSchedule.updateOfflineAlerts(childDetails.entityId(), dateTime, "child");
// VaccineSchedule.updateOfflineAlerts(childDetails.entityId(), dateTime, "child");
ChwServiceSchedule.updateOfflineAlerts(childDetails.entityId(), dateTime);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public static String childAgeLimitFilter(String tableName) {
}

public static String childDueFilter() {
return " ((" + ChildDBConstants.KEY.LAST_HOME_VISIT + " is null OR ((" + ChildDBConstants.KEY.LAST_HOME_VISIT + "/1000) > strftime('%s',datetime('now','start of month')))) AND ((" + ChildDBConstants.KEY.VISIT_NOT_DONE + " is null OR " + ChildDBConstants.KEY.VISIT_NOT_DONE + " = '0') OR ((" + ChildDBConstants.KEY.VISIT_NOT_DONE + "/1000) > strftime('%s',datetime('now','start of month'))))) ";
return "(( " +
"IFNULL(STRFTIME('%Y%m%d%H%M%S', datetime((" + KEY.LAST_HOME_VISIT + ")/1000,'unixepoch')),0) " +
"< STRFTIME('%Y%m%d%H%M%S', datetime('now','start of month')) " +
"AND IFNULL(STRFTIME('%Y%m%d%H%M%S', datetime((" + KEY.VISIT_NOT_DONE + ")/1000,'unixepoch')),0) " +
"< STRFTIME('%Y%m%d%H%M%S', datetime('now','start of month')) " +
" ))";
}

public static String childMainFilter(String mainCondition, String mainMemberCondition, String filters, String sort, int limit, int offset) {
Expand Down
Loading

0 comments on commit 6d16b3f

Please sign in to comment.