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

Issue#1970 WCARO In-app reporting #2015

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 11 additions & 11 deletions opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -293,37 +293,37 @@ android {
togo {
dimension = 'baseDimension'
applicationIdSuffix ".togo"
versionCode 26
versionName "1.2.7"
versionCode 27
versionName "1.2.8"
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '1000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '500'
buildConfigField "String", 'opensrp_url', '"https://wcaro-tg.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/togo/"'
buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"'
buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-tg.smartregister.org/opensrp/"'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village" }'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"National", "Regional" , "District" , "Formation sanitaire", "Supervisor", "Village"}'
buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"Village"'
buildConfigField "String", 'DEFAULT_LOCATION', '"Village"'
buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '10'
buildConfigField "int", "MAX_READ_TIMEOUT", '10'
buildConfigField "int", "DATABASE_VERSION", '21'
buildConfigField "int", "DATABASE_VERSION", '23'
}
liberia {
dimension = 'baseDimension'
versionCode 8
versionName "1.0.1"
versionCode 9
versionName "1.1.0"
buildConfigField "String", 'opensrp_url', '"https://wcaro-lr.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/liberia/"'
buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-stage.smartregister.org/opensrp/"'
buildConfigField "String", 'opensrp_url_debug', '"https://wcaro-lr-preview.smartregister.org/opensrp/"'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Clinic" , "CHSS" , "CHA"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Country" , "County" , "District", "Clinics", "CHSS", "Village"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Clinic" , "CHSS" , "CHA"}'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS_DEBUG", '{"Country" , "County" , "District", "Clinics", "CHSS", "Village"}'
buildConfigField "String", 'DEFAULT_LOCATION', '"Village"'
buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"CHA"'
buildConfigField "String", 'DEFAULT_LOCATION_DEBUG', '"Village"'
buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5'
buildConfigField "int", "MAX_READ_TIMEOUT", '5'
buildConfigField "int", "DATABASE_VERSION", '8'
buildConfigField "int", "DATABASE_VERSION", '9'
}
lmh {
dimension = 'baseDimension'
Expand All @@ -348,7 +348,7 @@ android {
}

dependencies {
implementation('org.smartregister:opensrp-client-chw-core:2.1.3-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-chw-core:2.1.4-alpha-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'androidx.legacy', module: 'legacy-support-v4'
Expand Down
7 changes: 7 additions & 0 deletions opensrp-chw/src/liberia/assets/ec_client_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
"json_mapping": {
"field": "entityType"
}
},
{
"column_name": "provider_id",
"type": "Event",
"json_mapping": {
"field": "providerId"
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.sqlcipher.database.SQLiteDatabase;

import org.smartregister.chw.anc.repository.VisitRepository;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.util.RepositoryUtils;
import org.smartregister.domain.db.Column;
import org.smartregister.immunization.repository.RecurringServiceRecordRepository;
Expand Down Expand Up @@ -49,6 +50,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 8:
upgradeToVersion8(db);
break;
case 9:
upgradeToVersion9(db);
break;
default:
break;
}
Expand Down Expand Up @@ -91,14 +95,16 @@ private static void upgradeToVersion2(Context context, SQLiteDatabase db) {
db.execSQL(VaccineRepository.UPDATE_TABLE_ADD_CHILD_LOCATION_ID_COL);
db.execSQL(RecurringServiceRecordRepository.UPDATE_TABLE_ADD_CHILD_LOCATION_ID_COL);

// setup reporting
ReportingLibrary reportingLibrary = ReportingLibrary.getInstance();
String childIndicatorsConfigFile = "config/child-reporting-indicator-definitions.yml";
String ancIndicatorConfigFile = "config/anc-reporting-indicator-definitions.yml";
String pncIndicatorConfigFile = "config/pnc-reporting-indicator-definitions.yml";
for (String configFile : Collections.unmodifiableList(
Arrays.asList(childIndicatorsConfigFile, ancIndicatorConfigFile, pncIndicatorConfigFile))) {
reportingLibrary.readConfigFile(configFile, db);
// Set up reporting for CHW users only
if (!((ChwApplication)ChwApplication.getInstance()).isSupervisor()) {
ReportingLibrary reportingLibrary = ReportingLibrary.getInstance();
String childIndicatorsConfigFile = "config/child-reporting-indicator-definitions.yml";
String ancIndicatorConfigFile = "config/anc-reporting-indicator-definitions.yml";
String pncIndicatorConfigFile = "config/pnc-reporting-indicator-definitions.yml";
for (String configFile : Collections.unmodifiableList(
Arrays.asList(childIndicatorsConfigFile, ancIndicatorConfigFile, pncIndicatorConfigFile))) {
reportingLibrary.readConfigFile(configFile, db);
}
}

} catch (Exception e) {
Expand Down Expand Up @@ -142,7 +148,6 @@ private static void upgradeToVersion6(SQLiteDatabase db) {
}
}


private static void upgradeToVersion7(SQLiteDatabase db) {
try {
db.execSQL("ALTER TABLE ec_family_member ADD COLUMN marital_status VARCHAR;");
Expand All @@ -152,6 +157,20 @@ private static void upgradeToVersion7(SQLiteDatabase db) {
}

private static void upgradeToVersion8(SQLiteDatabase db) {
RepositoryUtils.updateNullEventIds(db);
RepositoryUtils.updateNullEventIds(db);
}

private static void upgradeToVersion9(SQLiteDatabase db) {
if (((ChwApplication) ChwApplication.getInstance()).isSupervisor()) {
try {
// setup reporting
ReportingLibrary reportingLibrary = ReportingLibrary.getInstance();
String supervisorIndicatorDefinitionsFile = "config/supervisor-reporting-indicator-definitions.yml";
reportingLibrary.readConfigFile(supervisorIndicatorDefinitionsFile, db);
} catch (Exception e) {
Timber.e(e, "upgradeToVersion9");
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
indicators:
- key: "supervisor_catchment_task_completion_rate"
description: "Task Completion Rate for Entire Catchment Area"
indicatorQuery: ""

- key: "supervisor_synced_count"
description: "Sync Completion Rate for Entire Catchment Area"
indicatorQuery: "SELECT count(distinct json_extract(json, '$.providerId')) FROM event where syncStatus = 'Synced'"

- key: "supervisor_unsynced_count"
description: "Sync Not Completed Rate for Entire Catchment Area"
indicatorQuery: "SELECT count(distinct json_extract(json, '$.providerId')) FROM event where syncStatus = 'Unsynced'"

- key: "supervisor_households_with_open_tasks_for_month"
description: "Households with open tasks remaining for the month by CHW"
indicatorQuery: "SELECT f.provider_id as provider, (select count(distinct ecf.base_entity_id) from ec_family ecf where ecf.provider_id = f.provider_id and ecf.is_closed = 0)
as total_households, count(distinct f.base_entity_id) as count
FROM schedule_service sc INNER JOIN ec_family_member fm ON sc.base_entity_id = fm.base_entity_id
COLLATE NOCASE INNER JOIN ec_family f ON fm.relational_id = f.base_entity_id COLLATE NOCASE
WHERE (sc.completion_date IS NULL OR sc.completion_date = '') AND
f.is_closed = 0 AND fm.is_closed = 0
AND sc.created_at between date('now', 'start of month') and date('now') GROUP BY provider"
isMultiResult: true

- key: "supervisor_incomplete_tasks_for_month"
description: "Tasks remaining incomplete for the month by CHW"
indicatorQuery: "SELECT
CASE WHEN sc.completion_date IS NULL THEN 'open_tasks'
ELSE 'closed_tasks' END tasks, f.provider_id as provider, count(distinct f.base_entity_id) as households, count(*)
FROM
schedule_service sc
INNER JOIN ec_family_member fm ON sc.base_entity_id = fm.base_entity_id COLLATE NOCASE
INNER JOIN ec_family f ON fm.relational_id = f.base_entity_id COLLATE NOCASE
WHERE f.is_closed = 0 AND fm.is_closed = 0 AND sc.created_at between date('now', 'start of month') and date('now')
GROUP BY tasks, provider"
isMultiResult: true

- key: "supervisor_chw_last_sync"
description: "CHW by date of last sync"
indicatorQuery: "SELECT
json_extract(json, '$.providerId') as provider,
strftime('%Y-%m-%d',date(max(updatedAt))) as last_sync_date, count(*) as count
FROM event
where syncStatus = 'Synced'
group by provider
order by last_sync_date desc"
isMultiResult: true
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import org.smartregister.chw.R;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.chw.core.job.ChwIndicatorGeneratingJob;
import org.smartregister.chw.fragment.JobAidsDashboardFragment;
import org.smartregister.chw.fragment.GuideBooksFragment;
import org.smartregister.chw.fragment.JobAidsDashboardFragment;
import org.smartregister.chw.fragment.SupervisorDashboardFragment;
import org.smartregister.chw.listener.JobsAidsBottomNavigationListener;
import org.smartregister.chw.util.Utils;
import org.smartregister.helper.BottomNavigationHelper;
Expand Down Expand Up @@ -84,6 +85,9 @@ public SectionsPagerAdapter(FragmentManager fm) {
public Fragment getItem(int position) {
switch (position) {
case 0:
if (((ChwApplication) ChwApplication.getInstance()).isSupervisor()) {
return SupervisorDashboardFragment.newInstance();
}
return JobAidsDashboardFragment.newInstance();
case 1:
return GuideBooksFragment.newInstance();
Expand All @@ -102,6 +106,8 @@ public int getCount() {
public int getItemPosition(Object object) {
if (object instanceof JobAidsDashboardFragment) {
((JobAidsDashboardFragment) object).loadIndicatorTallies();
} else if ((object instanceof SupervisorDashboardFragment)) {
((SupervisorDashboardFragment) object).loadIndicatorTallies();
}
return super.getItemPosition(object);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.smartregister.chw.application;

import static org.koin.core.context.GlobalContext.getOrNull;

import android.Manifest;
import android.content.Intent;
import android.content.IntentFilter;
Expand All @@ -9,6 +11,7 @@

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.crashlytics.android.Crashlytics;
import com.evernote.android.job.JobManager;
import com.mapbox.mapboxsdk.Mapbox;
import com.vijay.jsonwizard.NativeFormLibrary;
Expand Down Expand Up @@ -54,6 +57,7 @@
import org.smartregister.chw.malaria.MalariaLibrary;
import org.smartregister.chw.model.NavigationModelFlv;
import org.smartregister.chw.pnc.PncLibrary;
import org.smartregister.chw.processor.ChwMultiResultsProcessor;
import org.smartregister.chw.referral.ReferralLibrary;
import org.smartregister.chw.repository.ChwRepository;
import org.smartregister.chw.schedulers.ChwScheduleTaskExecutor;
Expand Down Expand Up @@ -93,11 +97,10 @@
import java.util.Locale;
import java.util.Map;

import io.fabric.sdk.android.Fabric;
import io.ona.kujaku.KujakuLibrary;
import timber.log.Timber;

import static org.koin.core.context.GlobalContext.getOrNull;

public class ChwApplication extends CoreChwApplication implements SyncStatusBroadcastReceiver.SyncStatusListener, P2pProcessingStatusBroadcastReceiver.StatusUpdate {

private static Flavor flavor = new ChwApplicationFlv();
Expand Down Expand Up @@ -171,6 +174,7 @@ public CommonFtsObject getCommonFtsObject() {

@Override
public void onCreate() {
Fabric.with(this, new Crashlytics());
super.onCreate();

mInstance = this;
Expand All @@ -186,7 +190,6 @@ public void onCreate() {
NavigationMenu.setupNavigationMenu(this, new NavigationMenuFlv(), new NavigationModelFlv(),
getRegisteredActivities(), flavor.hasP2P());


initializeLibraries();

// init json helper
Expand Down Expand Up @@ -256,8 +259,11 @@ private void initializeLibraries() {
PncLibrary.init(context, getRepository(), BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION);
MalariaLibrary.init(context, getRepository(), BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION);
FpLibrary.init(context, getRepository(), BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION);

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

GrowthMonitoringConfig growthMonitoringConfig = new GrowthMonitoringConfig();
growthMonitoringConfig.setWeightForHeightZScoreFile("weight_for_height.csv");
GrowthMonitoringLibrary.init(context, getRepository(), BuildConfig.VERSION_CODE, BuildConfig.DATABASE_VERSION, growthMonitoringConfig);
Expand Down Expand Up @@ -403,6 +409,9 @@ public void onVisitEvent(Visit visit) {
ChildAlertService.updateAlerts(visit.getBaseEntityId());
}
}
public boolean isSupervisor() {
return "Supervisor".equals(CoreLibrary.getInstance().context().allSharedPreferences().getUserPractitionerRole());
}

public AppExecutors getAppExecutors() {
if (appExecutors == null) {
Expand Down Expand Up @@ -614,6 +623,7 @@ public interface Flavor {
Map<String, String[]> getFTSSearchMap();

Map<String, String[]> getFTSSortMap();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,5 @@ public Map<String, String[]> getFTSSortMap() {
public boolean showsPhysicallyDisabledView() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_job_aids_dashboard, container, false);
View rootView = inflater.inflate(R.layout.fragment_indicators_dashboard, container, false);
progressBar = rootView.findViewById(R.id.progress_bar);
visualizationsViewGroup = rootView.findViewById(R.id.dashboard_content);
return rootView;
Expand Down
Loading