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

Hf stock usage reporting #87

Merged
merged 13 commits into from
Apr 20, 2020
Merged
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
6 changes: 4 additions & 2 deletions opensrp-chw-hf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"'
// buildConfigField "String", 'opensrp_url_debug', '"https://ba-unified-stage.smartregister.org/opensrp/"'
buildConfigField "boolean", 'SUPPORT_QR', 'true'
buildConfigField "int", "DATABASE_VERSION", '5'
buildConfigField "int", "DATABASE_VERSION", '6'
buildConfigField "int", "DATA_SYNC_DURATION_MINUTES", '15'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
Expand All @@ -63,6 +63,7 @@ android {
buildConfigField "int", "PULL_UNIQUE_IDS_MINUTES", '180'
buildConfigField "int", "REPORT_INDICATOR_GENERATION_MINUTES", '15'
buildConfigField "int", "HOME_VISIT_MINUTES", '60'
buildConfigField "int", "STOCK_USAGE_REPORT_MINUTES", '1440'
buildConfigField "boolean", 'SUPPORT_REPORT', 'false'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country","Region","District","Ward" , "Health Facility", "Village", "Village Sublocations"}'
Expand All @@ -81,6 +82,7 @@ android {
buildConfigField "int", "PULL_UNIQUE_IDS_MINUTES", '15'
buildConfigField "int", "REPORT_INDICATOR_GENERATION_MINUTES", '15'
buildConfigField "int", "HOME_VISIT_MINUTES", '60'
buildConfigField "int", "STOCK_USAGE_REPORT_MINUTES", '1440'
buildConfigField "boolean", 'SUPPORT_REPORT', 'false'
buildConfigField "String[]", "ALLOWED_LOCATION_LEVELS", '{"Ward" , "Council", "Facility", "Health Facility", "Village", "Village Sublocations"}'
buildConfigField "String[]", "LOCATION_HIERACHY", '{"Country","Region","District","Ward" ,"Council", "Facility", "Health Facility", "Village", "Village Sublocations"}'
Expand Down Expand Up @@ -118,7 +120,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation ('org.smartregister:opensrp-client-chw-core:1.1.58-SNAPSHOT@aar') {
implementation ('org.smartregister:opensrp-client-chw-core:1.1.60-SNAPSHOT@aar') {
transitive = true
exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
exclude group: 'org.smartregister', module: 'opensrp-client-chw-referral'
Expand Down
13 changes: 13 additions & 0 deletions opensrp-chw-hf/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@
<activity
android:name=".activity.FpRegisterActivity"
android:theme="@style/HFTheme.NoActionBar" />
<activity
android:name=".activity.HfStockInventoryReportActivity"
android:theme="@style/HFTheme.NoActionBar" />
<activity
android:name=".activity.ProviderStockUsageReportListActivity"
android:theme="@style/HFTheme.NoActionBar" />
<activity
android:name="org.smartregister.chw.core.activity.CoreStockInventoryReportActivity"
android:theme="@style/HFTheme.NoActionBar" />

<activity
android:name="org.smartregister.chw.core.activity.CoreStockInventoryItemDetailsReportActivity"
android:theme="@style/HFTheme.NoActionBar" />

<meta-data
android:name="io.fabric.ApiKey"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.smartregister.chw.hf.activity;

import android.content.Intent;

import org.smartregister.chw.core.activity.CoreStockInventoryReportActivity;
import org.smartregister.chw.core.dao.StockUsageReportDao;
import org.smartregister.chw.core.model.StockUsageItemModel;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.hf.R;

import java.util.ArrayList;
import java.util.List;

public class HfStockInventoryReportActivity extends CoreStockInventoryReportActivity {
private String providerName;

@Override
protected void onCreation() {
super.onCreation();
Intent intent = getIntent();
providerName = intent.getStringExtra(CoreConstants.HfStockUsageUtil.PROVIDER_NAME);
}

@Override
public List<StockUsageItemModel> getStockUsageItemReportList(String month, String year) {
List<StockUsageItemModel> stockUsageItemModelsList = new ArrayList<>();
for (String item : getItems()) {
String usage = providerName.equalsIgnoreCase(this.getString(R.string.all_chw)) ? StockUsageReportDao.getAllStockUsageForMonth(month, item, year) : StockUsageReportDao.getStockUsageForMonth(month, item, year, providerName);
stockUsageItemModelsList.add(new StockUsageItemModel(stockUsageReportUtils.getFormattedItem(item), stockUsageReportUtils.getUnitOfMeasure(item), usage, providerName));
}
return stockUsageItemModelsList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.smartregister.chw.hf.activity;

import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.appbar.AppBarLayout;

import org.smartregister.chw.core.utils.StockUsageReportUtils;
import org.smartregister.chw.hf.R;
import org.smartregister.chw.hf.adapter.ProviderStockUsageReportListAdapter;
import org.smartregister.chw.hf.dao.HfStockUsageReportDao;
import org.smartregister.view.activity.SecuredActivity;
import org.smartregister.view.customcontrols.CustomFontTextView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class ProviderStockUsageReportListActivity extends SecuredActivity {
protected AppBarLayout appBarLayout;


private List<String> getProviderList() {
StockUsageReportUtils stockUsageReportUtils = new StockUsageReportUtils();
HfStockUsageReportDao hfStockUsageReportDao = new HfStockUsageReportDao();
List<String> arrayList = new LinkedList<>();
List<String> providers = new ArrayList<>();
arrayList.add(this.getString(R.string.all_chw));

if (stockUsageReportUtils.getPreviousMonths().size() > 0) {
for (Map.Entry<String, String> entry : stockUsageReportUtils.getPreviousMonths().entrySet()) {
providers.addAll(hfStockUsageReportDao.getListOfProviders(stockUsageReportUtils.getMonthNumber(entry.getKey().substring(0, 3)), entry.getValue()));
}
}
arrayList.addAll(new HashSet<>(providers));

return arrayList;
}

@Override
protected void onCreation() {
setContentView(R.layout.activity_provider_stock_usage_list_report);
RecyclerView recyclerView = findViewById(R.id.rv_provider_stock_usage_report);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
ProviderStockUsageReportListAdapter providerStockUsageReportListAdapter = new ProviderStockUsageReportListAdapter(getProviderList(), this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(providerStockUsageReportListAdapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
layoutManager.getOrientation());
recyclerView.addItemDecoration(dividerItemDecoration);


Toolbar toolbar = findViewById(R.id.back_to_nav_toolbar);
CustomFontTextView toolBarTextView = toolbar.findViewById(R.id.toolbar_title);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
final Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
upArrow.setColorFilter(getResources().getColor(R.color.text_blue), PorterDuff.Mode.SRC_ATOP);
upArrow.setVisible(true, true);
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setElevation(0);
}
toolbar.setNavigationOnClickListener(v -> finish());
toolBarTextView.setOnClickListener(v -> finish());
appBarLayout = findViewById(R.id.app_bar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appBarLayout.setOutlineProvider(null);
}
}

@Override
protected void onResumption() {
//override super
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.smartregister.chw.hf.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.smartregister.chw.hf.R;
import org.smartregister.chw.hf.activity.HfStockInventoryReportActivity;

import java.util.List;

public class ProviderStockUsageReportListAdapter extends RecyclerView.Adapter<ProviderStockUsageReportListAdapter.ProviderStockUsageReportListViewHolder> {
protected LayoutInflater inflater;
private List<String> providerList;
private Context context;

public ProviderStockUsageReportListAdapter(List<String> providerList, Context context) {
this.providerList = providerList;
this.context = context;
}

@NonNull
@Override
public ProviderStockUsageReportListAdapter.ProviderStockUsageReportListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
inflater = LayoutInflater.from(parent.getContext());
View v = inflater.inflate(R.layout.provider_stock_usage_items, parent, false);
return new ProviderStockUsageReportListAdapter.ProviderStockUsageReportListViewHolder(v);
}

@Override
public void onBindViewHolder(ProviderStockUsageReportListViewHolder holder, int position) {
String provider = providerList.get(position);
holder.providerName.setText(context.getString(R.string.provider_text, provider));
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String providerName = "providerName";
Intent intent = new Intent(context, HfStockInventoryReportActivity.class);

if (position == 0) {
intent.putExtra(providerName, context.getString(R.string.all_chw));
} else {
intent.putExtra(providerName, provider);
}
context.startActivity(intent);
}
});
}

@Override
public int getItemCount() {
return providerList.size();
}

public static class ProviderStockUsageReportListViewHolder extends RecyclerView.ViewHolder {
private TextView providerName;
private View view;

private ProviderStockUsageReportListViewHolder(View v) {
super(v);
view = v;
providerName = v.findViewById(R.id.provider_name);
}

}
}

Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package org.smartregister.chw.hf.custom_view;

import android.app.Activity;
import android.content.Intent;

import org.apache.commons.lang3.tuple.Pair;
import org.smartregister.chw.core.activity.HIA2ReportsActivity;
import org.smartregister.chw.core.custom_views.NavigationMenu;
import org.smartregister.chw.core.utils.CoreConstants;
import org.smartregister.chw.hf.activity.ProviderStockUsageReportListActivity;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

public class HfNavigationMenu implements NavigationMenu.Flavour {

@Override
public List<Pair<String, Locale>> getSupportedLanguages() {
return Arrays.asList(Pair.of("English", Locale.ENGLISH), Pair.of("Kiswahili", new Locale("sw")));
}

@Override
public HashMap<String, String> getTableMapValues() {
HashMap<String, String> tableMap = new HashMap<>();
Expand All @@ -29,6 +34,16 @@ public boolean hasServiceReport() {

@Override
public boolean hasStockReport() {
return false;
return true;
}

@Override
public Intent getStockReportIntent(Activity activity) {
return new Intent(activity, ProviderStockUsageReportListActivity.class);
}

@Override
public Intent getServiceReportIntent(Activity activity) {
return new Intent(activity, HIA2ReportsActivity.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.smartregister.chw.hf.dao;

import org.smartregister.dao.AbstractDao;

import java.util.ArrayList;
import java.util.List;

public class HfStockUsageReportDao extends AbstractDao {
public List<String> getListOfProviders(String month, String year) {
String sql = "SELECT DISTINCT provider_id FROM stock_usage_report " +
"WHERE month= '" + month + "' " +
"AND year= '" + year + "'" +
"order by provider_id DESC";
AbstractDao.DataMap<String> dataMap = cursor -> getCursorValue(cursor, "provider_id");
List<String> res = readData(sql, dataMap);
if (res == null)
return new ArrayList<>();

return res;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.smartregister.chw.core.job.CoreBasePncCloseJob;
import org.smartregister.chw.core.job.HomeVisitServiceJob;
import org.smartregister.chw.core.job.StockUsageReportJob;
import org.smartregister.chw.core.job.VaccineRecurringServiceJob;
import org.smartregister.chw.hf.BuildConfig;
import org.smartregister.immunization.job.VaccineServiceJob;
Expand Down Expand Up @@ -40,6 +41,10 @@ protected void scheduleJobsPeriodically() {
SyncTaskServiceJob.scheduleJob(SyncTaskServiceJob.TAG, TimeUnit.MINUTES.toMinutes(
BuildConfig.DATA_SYNC_DURATION_MINUTES), getFlexValue(BuildConfig.DATA_SYNC_DURATION_MINUTES));

StockUsageReportJob.scheduleJob(StockUsageReportJob.TAG, TimeUnit.MINUTES.toMinutes(
BuildConfig.STOCK_USAGE_REPORT_MINUTES), getFlexValue(BuildConfig.STOCK_USAGE_REPORT_MINUTES));


}

@Override
Expand All @@ -53,5 +58,7 @@ protected void scheduleJobsImmediately() {
PlanIntentServiceJob.scheduleJobImmediately(PlanIntentServiceJob.TAG);
VaccineServiceJob.scheduleJobImmediately(VaccineServiceJob.TAG);
VaccineRecurringServiceJob.scheduleJobImmediately(VaccineRecurringServiceJob.TAG);
StockUsageReportJob.scheduleJobImmediately(StockUsageReportJob.TAG);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.smartregister.AllConstants;
import org.smartregister.chw.core.application.CoreChwApplication;
import org.smartregister.chw.core.repository.CoreChwRepository;
import org.smartregister.chw.core.repository.StockUsageReportRepository;
import org.smartregister.chw.hf.BuildConfig;
import org.smartregister.domain.db.Column;
import org.smartregister.immunization.repository.RecurringServiceRecordRepository;
Expand Down Expand Up @@ -45,6 +46,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
case 5:
upgradeToVersion5(db);
break;
case 6:
upgradeToVersion6(db);
break;
default:
break;
}
Expand Down Expand Up @@ -116,4 +120,12 @@ private static void upgradeToVersion5(SQLiteDatabase db) {
Timber.e(e, "upgradeToVersion5 ");
}
}

private static void upgradeToVersion6(SQLiteDatabase db) {
try {
StockUsageReportRepository.createTable(db);
} catch (Exception e) {
Timber.e(e);
}
}
}
Loading