diff --git a/opensrp-chw-hf/build.gradle b/opensrp-chw-hf/build.gradle
index 5c7135c07..38cc1240e 100644
--- a/opensrp-chw-hf/build.gradle
+++ b/opensrp-chw-hf/build.gradle
@@ -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"
@@ -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"}'
@@ -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"}'
@@ -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'
diff --git a/opensrp-chw-hf/src/main/AndroidManifest.xml b/opensrp-chw-hf/src/main/AndroidManifest.xml
index 7fa692d22..c8d50503f 100644
--- a/opensrp-chw-hf/src/main/AndroidManifest.xml
+++ b/opensrp-chw-hf/src/main/AndroidManifest.xml
@@ -137,6 +137,19 @@
+
+
+
+
+
getStockUsageItemReportList(String month, String year) {
+ List 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;
+ }
+}
diff --git a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/activity/ProviderStockUsageReportListActivity.java b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/activity/ProviderStockUsageReportListActivity.java
new file mode 100644
index 000000000..50d80f457
--- /dev/null
+++ b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/activity/ProviderStockUsageReportListActivity.java
@@ -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 getProviderList() {
+ StockUsageReportUtils stockUsageReportUtils = new StockUsageReportUtils();
+ HfStockUsageReportDao hfStockUsageReportDao = new HfStockUsageReportDao();
+ List arrayList = new LinkedList<>();
+ List providers = new ArrayList<>();
+ arrayList.add(this.getString(R.string.all_chw));
+
+ if (stockUsageReportUtils.getPreviousMonths().size() > 0) {
+ for (Map.Entry 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
+ }
+}
diff --git a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/adapter/ProviderStockUsageReportListAdapter.java b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/adapter/ProviderStockUsageReportListAdapter.java
new file mode 100644
index 000000000..aef34be4e
--- /dev/null
+++ b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/adapter/ProviderStockUsageReportListAdapter.java
@@ -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 {
+ protected LayoutInflater inflater;
+ private List providerList;
+ private Context context;
+
+ public ProviderStockUsageReportListAdapter(List 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);
+ }
+
+ }
+}
+
diff --git a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java
index 28a6aaa72..4176622e3 100644
--- a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java
+++ b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/custom_view/HfNavigationMenu.java
@@ -1,8 +1,13 @@
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;
@@ -10,11 +15,11 @@
import java.util.Locale;
public class HfNavigationMenu implements NavigationMenu.Flavour {
-
@Override
public List> getSupportedLanguages() {
return Arrays.asList(Pair.of("English", Locale.ENGLISH), Pair.of("Kiswahili", new Locale("sw")));
}
+
@Override
public HashMap getTableMapValues() {
HashMap tableMap = new HashMap<>();
@@ -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);
}
}
diff --git a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/dao/HfStockUsageReportDao.java b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/dao/HfStockUsageReportDao.java
new file mode 100644
index 000000000..77fea8463
--- /dev/null
+++ b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/dao/HfStockUsageReportDao.java
@@ -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 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 dataMap = cursor -> getCursorValue(cursor, "provider_id");
+ List res = readData(sql, dataMap);
+ if (res == null)
+ return new ArrayList<>();
+
+ return res;
+ }
+
+}
diff --git a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/interactor/LoginInteractor.java b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/interactor/LoginInteractor.java
index 42b9ba860..e68f74957 100644
--- a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/interactor/LoginInteractor.java
+++ b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/interactor/LoginInteractor.java
@@ -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;
@@ -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
@@ -53,5 +58,7 @@ protected void scheduleJobsImmediately() {
PlanIntentServiceJob.scheduleJobImmediately(PlanIntentServiceJob.TAG);
VaccineServiceJob.scheduleJobImmediately(VaccineServiceJob.TAG);
VaccineRecurringServiceJob.scheduleJobImmediately(VaccineRecurringServiceJob.TAG);
+ StockUsageReportJob.scheduleJobImmediately(StockUsageReportJob.TAG);
+
}
}
diff --git a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/repository/HfChwRepository.java b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/repository/HfChwRepository.java
index 1f99e8133..ae9d53953 100644
--- a/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/repository/HfChwRepository.java
+++ b/opensrp-chw-hf/src/main/java/org/smartregister/chw/hf/repository/HfChwRepository.java
@@ -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;
@@ -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;
}
@@ -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);
+ }
+ }
}
diff --git a/opensrp-chw-hf/src/main/res/layout/activity_provider_stock_usage_list_report.xml b/opensrp-chw-hf/src/main/res/layout/activity_provider_stock_usage_list_report.xml
new file mode 100644
index 000000000..22f789cd6
--- /dev/null
+++ b/opensrp-chw-hf/src/main/res/layout/activity_provider_stock_usage_list_report.xml
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/opensrp-chw-hf/src/main/res/layout/provider_stock_usage_items.xml b/opensrp-chw-hf/src/main/res/layout/provider_stock_usage_items.xml
new file mode 100644
index 000000000..0f3082723
--- /dev/null
+++ b/opensrp-chw-hf/src/main/res/layout/provider_stock_usage_items.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/opensrp-chw-hf/src/main/res/values/strings.xml b/opensrp-chw-hf/src/main/res/values/strings.xml
index 4178ff38b..7c41d2659 100644
--- a/opensrp-chw-hf/src/main/res/values/strings.xml
+++ b/opensrp-chw-hf/src/main/res/values/strings.xml
@@ -29,5 +29,4 @@
ANC Danger Signs; Symptoms: %s
Referral %s ago
Update Family planning Registration
-
-
+