From 8aa37f415b66c830e6ed2851a202dfef93dcbd62 Mon Sep 17 00:00:00 2001 From: mib-iqbal Date: Thu, 16 Nov 2017 17:38:56 +0800 Subject: [PATCH] MI | add Mother register #6 Signed-off-by: mib-iqbal --- opensrp-gizi/build.gradle | 2 +- .../gizi/activity/GiziHomeActivity.java | 6 +- .../controller/GiziNavigationController.java | 10 +- .../GiziIbuSmartRegisterFragment.java | 630 ++++++++++++++++++ .../gizi/giziIbu/IbuDateSort.java | 72 ++ .../gizi/giziIbu/IbuSearchOption.java | 36 + .../gizi/giziIbu/IbuServiceModeOption.java | 77 +++ .../gizi/giziIbu/IbuSmartClientsProvider.java | 249 +++++++ .../giziIbu/IbuSmartRegisterActivity.java | 433 ++++++++++++ .../giziIbu/KICommonObjectFilterOption.java | 41 ++ .../provider/ChildSmartClientsProvider.java | 4 +- .../gizi/utils/AllConstantsINA.java | 9 +- .../res/layout/smart_registers_gizi_home.xml | 4 +- 13 files changed, 1554 insertions(+), 19 deletions(-) create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/fragment/GiziIbuSmartRegisterFragment.java create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuDateSort.java create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSearchOption.java create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuServiceModeOption.java create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartClientsProvider.java create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartRegisterActivity.java create mode 100644 opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/KICommonObjectFilterOption.java diff --git a/opensrp-gizi/build.gradle b/opensrp-gizi/build.gradle index 8c6b20d..af3d0f6 100644 --- a/opensrp-gizi/build.gradle +++ b/opensrp-gizi/build.gradle @@ -33,7 +33,7 @@ android { multiDexEnabled true buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l" buildConfigField "boolean", "TIME_CHECK", "false" - resValue "string", 'opensrp_url', '"http://118.91.130.18:9090/opensrp"' + resValue "string", 'opensrp_url', '"http://192.168.1.253:8080/opensrp"' } dexOptions { diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java index 3dea596..f27a0a5 100644 --- a/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java @@ -138,7 +138,7 @@ protected void onCreation() { private void setupViews() { findViewById(R.id.btn_gizi_register).setOnClickListener(onRegisterStartListener); - + findViewById(R.id.btn_gizi_ibu_register).setOnClickListener(onRegisterStartListener); findViewById(R.id.btn_reporting).setOnClickListener(onButtonsClickListener); @@ -364,7 +364,9 @@ public void onClick(View view) { case R.id.btn_gizi_register: navigationController.startChildSmartRegistry(); break; - + case R.id.btn_gizi_ibu_register: + navigationController.startECSmartRegistry(); + break; } diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/controller/GiziNavigationController.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/controller/GiziNavigationController.java index d4b1dec..4a9c0d0 100644 --- a/opensrp-gizi/src/main/java/org/smartregister/gizi/controller/GiziNavigationController.java +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/controller/GiziNavigationController.java @@ -9,6 +9,7 @@ //import org.ei.opensrp.gizi.test.TestSmartRegisterActivity; import org.smartregister.gizi.R; import org.smartregister.gizi.activity.GiziSmartRegisterActivity; +import org.smartregister.gizi.giziIbu.IbuSmartRegisterActivity; import org.smartregister.view.controller.ANMController; import org.json.JSONObject; @@ -33,14 +34,7 @@ public GiziNavigationController(Activity activity, ANMController anmController, @Override public void startECSmartRegistry() { - // activity.startActivity(new Intent(activity, TestSmartRegisterActivity.class)); - /// activity.startActivity(new Intent(activity, HouseHoldSmartRegisterActivity.class)); - SharedPreferences sharedPreferences = getDefaultSharedPreferences(this.activity); - - if(sharedPreferences.getBoolean("firstlauch",true)) { - sharedPreferences.edit().putBoolean("firstlauch",false).commit(); - // activity.startActivity(new Intent(activity, tutorialCircleViewFlow.class)); - } + activity.startActivity(new Intent(activity, IbuSmartRegisterActivity.class)); } @Override diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/fragment/GiziIbuSmartRegisterFragment.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/fragment/GiziIbuSmartRegisterFragment.java new file mode 100644 index 0000000..822ba01 --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/fragment/GiziIbuSmartRegisterFragment.java @@ -0,0 +1,630 @@ +package org.smartregister.gizi.fragment; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Parcelable; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.View; +import android.widget.EditText; + +import com.flurry.android.FlurryAgent; + +import org.smartregister.Context; +import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.commonregistry.CommonPersonObjectController; +import org.smartregister.commonregistry.CommonRepository; +import org.smartregister.cursoradapter.CursorCommonObjectFilterOption; +import org.smartregister.cursoradapter.CursorCommonObjectSort; +import org.smartregister.cursoradapter.CursorSortOption; +import org.smartregister.cursoradapter.SecuredNativeSmartRegisterCursorAdapterFragment; +import org.smartregister.cursoradapter.SmartRegisterPaginatedCursorAdapter; +import org.smartregister.cursoradapter.SmartRegisterQueryBuilder; +import org.smartregister.gizi.R; +import org.smartregister.gizi.giziIbu.IbuServiceModeOption; +import org.smartregister.gizi.giziIbu.IbuSmartRegisterActivity; +import org.smartregister.gizi.giziIbu.KICommonObjectFilterOption; +import org.smartregister.gizi.provider.ChildSmartClientsProvider; +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.sync.ClientProcessor; +import org.smartregister.util.StringUtil; +import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity; +import org.smartregister.view.contract.ECClient; +import org.smartregister.view.contract.SmartRegisterClient; +import org.smartregister.view.contract.SmartRegisterClients; +import org.smartregister.view.controller.VillageController; +import org.smartregister.view.dialog.AllClientsFilter; +import org.smartregister.view.dialog.DialogOption; +import org.smartregister.view.dialog.DialogOptionMapper; +import org.smartregister.view.dialog.DialogOptionModel; +import org.smartregister.view.dialog.EditOption; +import org.smartregister.view.dialog.FilterOption; +import org.smartregister.view.dialog.NameSort; +import org.smartregister.view.dialog.ServiceModeOption; +import org.smartregister.view.dialog.SortOption; +import org.opensrp.api.domain.Location; +import org.opensrp.api.util.EntityUtils; +import org.opensrp.api.util.LocationTree; +import org.opensrp.api.util.TreeNode; + +import java.util.ArrayList; +import java.util.Map; + +import util.AsyncTask; + +import static android.view.View.INVISIBLE; +import static android.view.View.VISIBLE; +import static org.apache.commons.lang3.StringUtils.isEmpty; + +/** + * Created by koros on 10/12/15. + */ +public class GiziIbuSmartRegisterFragment extends SecuredNativeSmartRegisterCursorAdapterFragment { + + private static final String TAG = GiziIbuSmartRegisterFragment.class.getSimpleName(); + + private SmartRegisterClientsProvider clientProvider = null; + private CommonPersonObjectController controller; + private VillageController villageController; + private DialogOptionMapper dialogOptionMapper; + private ClientProcessor clientProcessor; + private final ClientActionHandler clientActionHandler = new ClientActionHandler(); + private String locationDialogTAG = "locationDialogTAG"; + + public static String criteria; + + @Override + protected void onCreation() { + // + } + +// @Override +// protected SmartRegisterPaginatedAdapter adapter() { +// return new SmartRegisterPaginatedAdapter(clientsProvider()); +// } + + @Override + protected SecuredNativeSmartRegisterActivity.DefaultOptionsProvider getDefaultOptionsProvider() { + return new SecuredNativeSmartRegisterActivity.DefaultOptionsProvider() { + + @Override + public ServiceModeOption serviceMode() { + return new IbuServiceModeOption(clientsProvider()); + } + + @Override + public FilterOption villageFilter() { + return new AllClientsFilter(); + } + + @Override + public SortOption sortOption() { + return new NameSort(); + + } + + @Override + public String nameInShortFormForTitle() { + return Context.getInstance().getStringResource(R.string.gizi_ibu); + } + }; + } + + @Override + protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { + return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { + + @Override + public DialogOption[] filterOptions() { + // FlurryFacade.logEvent("click_filter_option_on_kohort_ibu_dashboard"); + ArrayList dialogOptionslist = new ArrayList(); + + dialogOptionslist.add(new CursorCommonObjectFilterOption(getString(R.string.filter_by_all_label),filterStringForAll())); + // dialogOptionslist.add(new CursorCommonObjectFilterOption(getString(R.string.hh_no_mwra),filterStringForNoElco())); + // dialogOptionslist.add(new CursorCommonObjectFilterOption(getString(R.string.hh_has_mwra),filterStringForOneOrMoreElco())); + + String locationjson = context().anmLocationController().get(); + LocationTree locationTree = EntityUtils.fromJson(locationjson, LocationTree.class); + + Map> locationMap = + locationTree.getLocationsHierarchy(); + //addChildToList(dialogOptionslist,locationMap); + DialogOption[] dialogOptions = new DialogOption[dialogOptionslist.size()]; + for (int i = 0;i < dialogOptionslist.size();i++){ + dialogOptions[i] = dialogOptionslist.get(i); + } + + return dialogOptions; + } + + @Override + public DialogOption[] serviceModeOptions() { + return new DialogOption[]{}; + } + + @Override + public DialogOption[] sortingOptions() { + // FlurryFacade.logEvent("click_sorting_option_on_kohort_ibu_dashboard"); + return new DialogOption[]{ +// new HouseholdCensusDueDateSort(), + + + new CursorCommonObjectSort(getResources().getString(R.string.sort_by_name_label),KiSortByNameAZ()), + new CursorCommonObjectSort(getResources().getString(R.string.sort_by_name_label_reverse),KiSortByNameZA()), + }; + } + + @Override + public String searchHint() { + return getResources().getString(R.string.hh_search_hint); + } + }; + } + + + + @Override + protected SmartRegisterClientsProvider clientsProvider() { +// if (clientProvider == null) { +// clientProvider = new HouseHoldSmartClientsProvider( +// getActivity(),clientActionHandler , context().alertService()); +// } + return null; + } + + private DialogOption[] getEditOptions() { + return ((IbuSmartRegisterActivity)getActivity()).getEditOptions(); + } + + @Override + protected void onInitialization() { + // context().formSubmissionRouter().getHandlerMap().put("census_enrollment_form", new CensusEnrollmentHandler()); + } + + @Override + public void setupViews(View view) { + getDefaultOptionsProvider(); + + super.setupViews(view); + view.findViewById(R.id.btn_report_month).setVisibility(INVISIBLE); + view.findViewById(R.id.service_mode_selection).setVisibility(View.GONE); + clientsView.setVisibility(View.VISIBLE); + clientsProgressView.setVisibility(View.INVISIBLE); +// list.setBackgroundColor(Color.RED); + // initializeQueries(getCriteria()); + } + private String filterStringForAll(){ + return ""; + } + private String sortByAlertmethod() { + return " CASE WHEN alerts.status = 'urgent' THEN '1'" + + + "WHEN alerts.status = 'upcoming' THEN '2'\n" + + "WHEN alerts.status = 'normal' THEN '3'\n" + + "WHEN alerts.status = 'expired' THEN '4'\n" + + "WHEN alerts.status is Null THEN '5'\n" + + "Else alerts.status END ASC"; + } + + private void initializeQueries() { + String tableName = "ec_ibu"; + // String parentTableName = PathConstants.MOTHER_TABLE_NAME; + + ChildSmartClientsProvider hhscp = new ChildSmartClientsProvider(getActivity(), + clientActionHandler, context().alertService(), context().commonrepository(tableName)); + clientAdapter = new SmartRegisterPaginatedCursorAdapter(getActivity(), null, hhscp, context().commonrepository(tableName)); + clientsView.setAdapter(clientAdapter); + + setTablename(tableName); + SmartRegisterQueryBuilder countqueryBUilder = new SmartRegisterQueryBuilder(); + countqueryBUilder.SelectInitiateMainTableCounts(tableName); + mainCondition = " is_closed = 0 "; + countSelect = countqueryBUilder.mainCondition(mainCondition); + super.CountExecute(); + + /* queryBUilder.SelectInitiateMainTable("ec_ibu", new String[]{"ec_ibu.relationalid","ec_ibu.is_closed", "ec_ibu.details", "ec_kartu_ibu.namalengkap","ec_kartu_ibu.namaSuami"}); + queryBUilder.customJoin("LEFT JOIN ec_kartu_ibu on ec_kartu_ibu.id = ec_ibu.id");*/ + + SmartRegisterQueryBuilder queryBUilder = new SmartRegisterQueryBuilder(); + queryBUilder.SelectInitiateMainTable(tableName, new String[]{ + tableName + ".relationalid", + tableName + ".details", + tableName + ".is_closed", + tableName + ".relational_id", + tableName + ".details", + tableName + ".namalengkap", + tableName + ".namaSuami", + + }); + + queryBUilder.customJoin("LEFT JOIN " + "ec_kartu_ibu" + " ON " + tableName + ".id = " + "ec_kartu_ibu" + ".id"); + mainSelect = queryBUilder.mainCondition(mainCondition); + Sortqueries = ((CursorSortOption) getDefaultOptionsProvider().sortOption()).sort(); + + currentlimit = 20; + currentoffset = 0; + + super.filterandSortInInitializeQueries(); + + updateSearchView(); + refresh(); + } + + + @Override + public void startRegistration() { +// FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); +// Fragment prev = getActivity().getFragmentManager().findFragmentByTag(locationDialogTAG); +// if (prev != null) { +// ft.remove(prev); +// } +// ft.addToBackStack(null); +// LocationSelectorDialogFragment +// .newInstance((GiziSmartRegisterActivity) getActivity(), new EditDialogOptionModel(), context().anmLocationController().get(), "registrasi_jurim") +// .show(ft, locationDialogTAG); + } + + private class ClientActionHandler implements View.OnClickListener { + public void onClick(View view) { + switch (view.getId()) { +// case R.id.profile_info_layout: +// CharSequence selections[] = new CharSequence[] {"Detail View", "Charts"}; +// GiziDetailActivity.childclient = (CommonPersonObjectClient) view.getTag(); +// GiziGrowthChartActivity.client = (CommonPersonObjectClient)view.getTag(); +// final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); +// builder.setTitle(""); +// builder.setItems(selections, new DialogInterface.OnClickListener() { +// @Override +// public void onClick(DialogInterface dialog, int which) { +// // the user clicked on colors[which] +// if(which == 0) +// { +// Intent intent = new Intent(getActivity(),GiziDetailActivity.class); +// startActivity(intent); +// getActivity().finish(); +// } +// else if(which == 1){ +// Intent intent = new Intent(getActivity(),GiziGrowthChartActivity.class); +// startActivity(intent); +// getActivity().finish(); +// } +// } +// }); +// builder.show(); +// // FlurryFacade.logEvent("click_detail_picture_vaksinator"); +// +// break; + //untuk follow up button + case R.id.btn_edit: + // FlurryFacade.logEvent("click_button_edit_vaksinator"); + showFragmentDialog(new EditDialogOptionModel(), view.getTag()); + break; + } + } + + private void showProfileView(ECClient client) { + navigationController.startEC(client.entityId()); + } + } + + + + private String KiSortByNameAZ() { + return "namalengkap ASC"; + } + private String KiSortByNameZA() { + return "namalengkap DESC"; + } + + private String KiSortByAge() { + return "umur DESC"; + } + private String KiSortByNoIbu() { + return "noIbu ASC"; + } + + private String KiSortByEdd() { + return "htp IS NULL, htp"; + } + + + private class EditDialogOptionModel implements DialogOptionModel { + @Override + public DialogOption[] getDialogOptions() { + return getEditOptions(); + } + @Override + public void onDialogOptionSelection(DialogOption option, Object tag) { + + + /*if(option.name().equalsIgnoreCase(getString(R.string.str_register_anc_form)) ) { + CommonPersonObjectClient pc = KIDetailActivity.kiclient; + if(pc.getDetails().get("ibu.type")!= null) { + if (pc.getDetails().get("ibu.type").equals("anc") || pc.getDetails().get("ibu.type").equals("pnc")) { + Toast.makeText(getActivity().getApplicationContext(), getString(R.string.mother_already_registered), Toast.LENGTH_SHORT).show(); + return; + } + } + }*/ + onEditSelection((EditOption) option, (SmartRegisterClient) tag); + } + } + + @Override + protected void onResumption() { +// super.onResumption(); + getDefaultOptionsProvider(); + if(isPausedOrRefreshList()) { + // initializeQueries("!"); + } + // updateSearchView(); +// + try{ + // LoginActivity.setLanguage(); + }catch (Exception e){ + + } + + } +// @Override +// public void setupSearchView(View view) { +// searchView = (EditText) view.findViewById(org.smartregister.R.id.edt_search); +// searchView.setHint(getNavBarOptionsProvider().searchHint()); +// searchView.addTextChangedListener(new TextWatcher() { +// @Override +// public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { +// } +// +// @Override +// public void onTextChanged(final CharSequence cs, int start, int before, int count) { +// +// (new AsyncTask() { +// SmartRegisterClients filteredClients; +// +// @Override +// protected Object doInBackground(Object[] params) { +//// currentSearchFilter = +//// setCurrentSearchFilter(new HHSearchOption(cs.toString())); +//// filteredClients = getClientsAdapter().getListItemProvider() +//// .updateClients(getCurrentVillageFilter(), getCurrentServiceModeOption(), +//// getCurrentSearchFilter(), getCurrentSortOption()); +//// +// filters = cs.toString(); +// joinTable = ""; +// mainCondition = " namaBayi !='' "; +// return null; +// } +// +// @Override +// protected void onPostExecute(Object o) { +//// clientsAdapter +//// .refreshList(currentVillageFilter, currentServiceModeOption, +//// currentSearchFilter, currentSortOption); +//// getClientsAdapter().refreshClients(filteredClients); +//// getClientsAdapter().notifyDataSetChanged(); +// getSearchCancelView().setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); +// CountExecute(); +// filterandSortExecute(); +// super.onPostExecute(o); +// } +// }).execute(); +// } +// +// @Override +// public void afterTextChanged(Editable editable) { +// } +// }); +// searchCancelView = view.findViewById(org.smartregister.R.id.btn_search_cancel); +// searchCancelView.setOnClickListener(searchCancelHandler); +// } +// + public void updateSearchView(){ + getSearchView().addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void onTextChanged(final CharSequence cs, int start, int before, int count) { + (new AsyncTask() { + SmartRegisterClients filteredClients; + + @Override + protected Object doInBackground(Object[] params) { +// currentSearchFilter = +// setCurrentSearchFilter(new HHSearchOption(cs.toString())); +// filteredClients = getClientsAdapter().getListItemProvider() +// .updateClients(getCurrentVillageFilter(), getCurrentServiceModeOption(), +// getCurrentSearchFilter(), getCurrentSortOption()); +// + + filters = cs.toString(); + joinTable = ""; + mainCondition = " namaBayi !='' "; + return null; + } + + @Override + protected void onPostExecute(Object o) { +// clientsAdapter +// .refreshList(currentVillageFilter, currentServiceModeOption, +// currentSearchFilter, currentSortOption); +// getClientsAdapter().refreshClients(filteredClients); +// getClientsAdapter().notifyDataSetChanged(); + getSearchCancelView().setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); + filterandSortExecute(); + super.onPostExecute(o); + } + }).execute(); +// currentSearchFilter = new HHSearchOption(cs.toString()); +// clientsAdapter +// .refreshList(currentVillageFilter, currentServiceModeOption, +// currentSearchFilter, currentSortOption); +// +// searchCancelView.setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); + + + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }); + } + /* public void addChildToList(ArrayList dialogOptionslist,Map> locationMap){ + for(Map.Entry> entry : locationMap.entrySet()) { + + if(entry.getValue().getChildren() != null) { + addChildToList(dialogOptionslist,entry.getValue().getChildren()); + + }else{ + StringUtil.humanize(entry.getValue().getLabel()); + String name = StringUtil.humanize(entry.getValue().getLabel()); + dialogOptionslist.add(new KICommonObjectFilterOption(name,"desa", name)); + + } + } + }*/ + + // WD + public void setCriteria(String criteria) { + this.criteria = criteria; + } + + public static String getCriteria() { + return criteria; + } + + // WD + @Override + public void setupSearchView(final View view) { + searchView = (EditText) view.findViewById(org.smartregister.R.id.edt_search); + searchView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CharSequence selections[] = new CharSequence[]{"Name", "Photo"}; + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle("Please Choose one, Search by"); + builder.setItems(selections, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int opt) { + if (opt == 0) searchTextChangeListener(""); + // else getFacialRecord(view); + } + }); + builder.show(); + } + }); + + searchCancelView = view.findViewById(org.smartregister.R.id.btn_search_cancel); + searchCancelView.setOnClickListener(searchCancelHandler); + } + + /*public void getFacialRecord(View view) { + FlurryAgent.logEvent(TAG+" search_by_face", true); + Log.e(TAG, "getFacialRecord: "); + SmartShutterActivity.kidetail = (CommonPersonObjectClient) view.getTag(); + FlurryAgent.logEvent(TAG + " search_by_face", true); + + Intent intent = new Intent(getActivity(), SmartShutterActivity.class); + intent.putExtra("org.sid.sidface.ImageConfirmation.origin", GiziIbuSmartRegisterFragment.class.getSimpleName()); + intent.putExtra("org.sid.sidface.ImageConfirmation.identify", true); + intent.putExtra("org.sid.sidface.ImageConfirmation.kidetail", (Parcelable) SmartShutterActivity.kidetail); + startActivityForResult(intent, 2); + }*/ + + public void searchTextChangeListener(String s) { + Log.e(TAG, "searchTextChangeListener: " + s); + if (s != null) { + filters = s; + } else { + searchView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { + } + + @Override + public void onTextChanged(final CharSequence cs, int start, int before, int count) { + + Log.e(TAG, "onTextChanged: " + searchView.getText()); + (new AsyncTask() { +// SmartRegisterClients filteredClients; + + @Override + protected Object doInBackground(Object[] params) { +// currentSearchFilter = +// setCurrentSearchFilter(new HHSearchOption(cs.toString())); +// filteredClients = getClientsAdapter().getListItemProvider() +// .updateClients(getCurrentVillageFilter(), getCurrentServiceModeOption(), +// getCurrentSearchFilter(), getCurrentSortOption()); +// + + filters = cs.toString(); + joinTable = ""; + mainCondition = "nama_bayi !=''"; + Log.e(TAG, "doInBackground: " + filters); + return null; + } +// +// @Override +// protected void onPostExecute(Object o) { +//// clientsAdapter +//// .refreshList(currentVillageFilter, currentServiceModeOption, +//// currentSearchFilter, currentSortOption); +//// getClientsAdapter().refreshClients(filteredClients); +//// getClientsAdapter().notifyDataSetChanged(); +// getSearchCancelView().setVisibility(isEmpty(cs) ? INVISIBLE : VISIBLE); +// CountExecute(); +// filterandSortExecute(); +// super.onPostExecute(o); +// } + }).execute(); + } + + @Override + public void afterTextChanged(Editable editable) { + } + }); + } + } + +// @Override +// public void onActivityResult(int requestCode, int resultCode, Intent data){ +// super.onActivityResult(requestCode, resultCode, data); +// +// Intent myIntent = new Intent(getActivity(), IbuSmartRegisterActivity.class); +// if (data != null) { +// myIntent.putExtra("org.smartregister.indonesia.face.face_mode", true); +// myIntent.putExtra("org.smartregister.indonesia.face.base_id", data.getStringExtra("org.smartregister.indonesia.face.base_id")); +// } +// getActivity().startActivity(myIntent); +// +// } + + + @Override + + public void onActivityResult(int requestCode, int resultCode, Intent data){ + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == 2 ) { + if (resultCode != 0) { + Intent myIntent = new Intent(getActivity(), IbuSmartRegisterActivity.class); + if (data != null) { + myIntent.putExtra("org.smartregister.indonesia.face.face_mode", true); + myIntent.putExtra("org.smartregister.indonesia.face.base_id", data.getStringExtra("org.smartregister.indonesia.face.base_id")); + } + getActivity().startActivity(myIntent); + } else { + Log.e(TAG, "onActivityResult: "+ resultCode ); + } + } + +} + + + +} diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuDateSort.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuDateSort.java new file mode 100644 index 0000000..650346d --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuDateSort.java @@ -0,0 +1,72 @@ +package org.smartregister.gizi.giziIbu; + +import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.view.contract.SmartRegisterClient; +import org.smartregister.view.contract.SmartRegisterClients; +import org.smartregister.view.dialog.SortOption; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; + +/** + * Created by Iq on 30/03/16. + */ +public class IbuDateSort implements SortOption { + String field; + ByColumnAndByDetails byColumnAndByDetails; + + public enum ByColumnAndByDetails{ + byColumn,byDetails; + } + + public IbuDateSort() { + + } + + @Override + public String name() { + return "Due Status"; + } + + @Override + public SmartRegisterClients sort(SmartRegisterClients allClients) { + Collections.sort(allClients, commoncomparator); + return allClients; + } + + Comparator commoncomparator = new Comparator() { + @Override + public int compare(SmartRegisterClient oneClient, SmartRegisterClient anotherClient2) { + CommonPersonObjectClient commonPersonObjectClient = (CommonPersonObjectClient)oneClient; + CommonPersonObjectClient commonPersonObjectClient2 = (CommonPersonObjectClient)anotherClient2; + switch (byColumnAndByDetails){ + case byColumn: + try { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date1 = dateFormat.parse(commonPersonObjectClient.getColumnmaps().get(field)); + Date date2 = dateFormat.parse(commonPersonObjectClient2.getColumnmaps().get(field)); + + return date1.compareTo(date2); + }catch (Exception e){ + break; + } + + + case byDetails: + try { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date1 = dateFormat.parse(commonPersonObjectClient.getDetails().get(field)); + Date date2 = dateFormat.parse(commonPersonObjectClient2.getDetails().get(field)); + return date1.compareTo(date2); + }catch (Exception e){ + break; + } + + } + return 0; + } + }; +} diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSearchOption.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSearchOption.java new file mode 100644 index 0000000..b65a341 --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSearchOption.java @@ -0,0 +1,36 @@ +package org.smartregister.gizi.giziIbu; + +import org.smartregister.Context; +import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.gizi.R; +import org.smartregister.view.contract.SmartRegisterClient; +import org.smartregister.view.dialog.FilterOption; + +public class IbuSearchOption implements FilterOption { + private final String criteria; + + public IbuSearchOption(String criteria) { + this.criteria = criteria; + } + + @Override + public String name() { + return Context.getInstance().applicationContext().getResources().getString(R.string.hh_search_hint); + } + + @Override + public boolean filter(SmartRegisterClient client) { + boolean result = false; + CommonPersonObjectClient currentclient = (CommonPersonObjectClient) client; +// AllCommonsRepository allElcoRepository = new AllCommonsRepository("elco"); + if(!result) { + if(currentclient.getDetails().get("namaLengkap") != null) { + if (currentclient.getDetails().get("namaLengkap").toLowerCase().contains(criteria.toLowerCase())) { + result = true; + } + } + } + + return result; + } +} diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuServiceModeOption.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuServiceModeOption.java new file mode 100644 index 0000000..5c57881 --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuServiceModeOption.java @@ -0,0 +1,77 @@ +package org.smartregister.gizi.giziIbu; + +import android.view.View; + +import org.smartregister.Context; +import org.smartregister.gizi.R; +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.view.contract.ANCSmartRegisterClient; +import org.smartregister.view.contract.ChildSmartRegisterClient; +import org.smartregister.view.contract.FPSmartRegisterClient; +import org.smartregister.view.contract.pnc.PNCSmartRegisterClient; +import org.smartregister.view.dialog.ServiceModeOption; + +import static org.smartregister.view.activity.SecuredNativeSmartRegisterActivity.ClientsHeaderProvider; + +public class IbuServiceModeOption extends ServiceModeOption { + + public IbuServiceModeOption(SmartRegisterClientsProvider provider) { + super(provider); + } + + @Override + public String name() { + return Context.getInstance().getStringResource(R.string.test_register); + } + + @Override + public ClientsHeaderProvider getHeaderProvider() { + return new ClientsHeaderProvider() { + @Override + public int count() { + return 6; + } + + @Override + public int weightSum() { + return 200; + } + + @Override + public int[] weights() { + return new int[]{20,42,40,39,45,14}; + } + + @Override + public int[] headerTextResourceIds() { + return new int[]{ + R.string.header_edit,R.string.detail_ibu,R.string.anthopometri,R.string.hasil_lab,R.string.post_partum_care,R.string.header_edit + }; + } + }; + } + + /* @Override + public void setupListView(ChildSmartRegisterClient client, + NativeChildSmartRegisterViewHolder viewHolder, + View.OnClickListener clientSectionClickListener) { + + } + + @Override + public void setupListView(ANCSmartRegisterClient client, NativeANCSmartRegisterViewHolder viewHolder, View.OnClickListener clientSectionClickListener) { + + } + + @Override + public void setupListView(FPSmartRegisterClient client, NativeFPSmartRegisterViewHolder viewHolder, View.OnClickListener clientSectionClickListener) { + + } + + @Override + public void setupListView(PNCSmartRegisterClient client, NativePNCSmartRegisterViewHolder viewHolder, View.OnClickListener clientSectionClickListener) { + + }*/ + + +} diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartClientsProvider.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartClientsProvider.java new file mode 100644 index 0000000..558b1a8 --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartClientsProvider.java @@ -0,0 +1,249 @@ +package org.smartregister.gizi.provider; + +import android.content.Context; +import android.database.Cursor; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.os.AsyncTask; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.AbsListView; +import android.widget.ImageView; +import android.widget.TextView; + +import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.smartregister.commonregistry.AllCommonsRepository; +import org.smartregister.commonregistry.CommonPersonObject; +import org.smartregister.commonregistry.CommonPersonObjectClient; +import org.smartregister.commonregistry.CommonRepository; +import org.smartregister.cursoradapter.SmartRegisterCLientsProviderForCursorAdapter; +import org.smartregister.domain.Alert; +import org.smartregister.gizi.R; +import org.smartregister.repository.DetailsRepository; +import org.smartregister.service.AlertService; +import org.smartregister.util.DateUtil; +import org.smartregister.util.OpenSRPImageLoader; +import org.smartregister.util.Utils; +import org.smartregister.view.activity.DrishtiApplication; +import org.smartregister.view.contract.SmartRegisterClient; +import org.smartregister.view.contract.SmartRegisterClients; +import org.smartregister.view.dialog.FilterOption; +import org.smartregister.view.dialog.ServiceModeOption; +import org.smartregister.view.dialog.SortOption; +import org.smartregister.view.viewholder.OnClickFormLauncher; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import util.GiziConstants; +import util.formula.Support; + +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; +import static org.smartregister.util.Utils.fillValue; +import static org.smartregister.util.Utils.getName; +import static org.smartregister.util.Utils.getValue; + +/** + * Created by soran on 08/11/17. + */ + +public class IbuSmartClientsProvider implements SmartRegisterCLientsProviderForCursorAdapter { + private final LayoutInflater inflater; + private final Context context; + private final View.OnClickListener onClickListener; + private final AlertService alertService; + + private Drawable iconPencilDrawable; + private final AbsListView.LayoutParams clientViewLayoutParams; + private final CommonRepository commonRepository; + + public IbuSmartClientsProvider(Context context, View.OnClickListener onClickListener, + AlertService alertService, CommonRepository commonRepository) { + this.onClickListener = onClickListener; + this.context = context; + this.alertService = alertService; + this.commonRepository = commonRepository; + this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + clientViewLayoutParams = new AbsListView.LayoutParams(MATCH_PARENT, (int) context.getResources().getDimension(org.smartregister.R.dimen.list_item_height)); + } + + @Override + public void getView(Cursor cursor, SmartRegisterClient client, final View convertView) { + CommonPersonObjectClient pc = (CommonPersonObjectClient) client; + if (iconPencilDrawable == null) { + iconPencilDrawable = context.getResources().getDrawable(R.drawable.ic_pencil); + } + //convertView.findViewById(R.id.btn_edit).setBackgroundDrawable(iconPencilDrawable); + convertView.findViewById(R.id.btn_edit).setTag(client); + convertView.findViewById(R.id.btn_edit).setOnClickListener(onClickListener); + + convertView.findViewById(R.id.profile_info_layout).setTag(client); + convertView.findViewById(R.id.profile_info_layout).setOnClickListener(onClickListener); + + DetailsRepository detailsRepository = org.smartregister.Context.getInstance().detailsRepository(); + detailsRepository.updateDetails(pc); + + String firstName = getValue(pc.getColumnmaps(), "namaBayi", true); + fillValue((TextView) convertView.findViewById(R.id.txt_child_name), firstName); + + // get parent + AllCommonsRepository childRepository = org.smartregister.Context.getInstance().allCommonsRepositoryobjects("ec_anak"); + CommonPersonObject childobject = childRepository.findByCaseID(pc.entityId()); + // Log.d("IDssssssssssssss",pc.entityId()); + AllCommonsRepository kirep = org.smartregister.Context.getInstance().allCommonsRepositoryobjects("ec_kartu_ibu"); + final CommonPersonObject kiparent = kirep.findByCaseID(getValue(pc.getColumnmaps(), "relational_id", true)); + + if(kiparent != null) { + detailsRepository.updateDetails(kiparent); + // String namaayah = getValue(kiparent.getColumnmaps(), "namaSuami", true); + String namaibu = getValue(kiparent.getColumnmaps(), "namalengkap", true); + fillValue((TextView) convertView.findViewById(R.id.ParentName), namaibu); + String subVillages = getValue(kiparent.getDetails(), "address1", true); + fillValue((TextView) convertView.findViewById(R.id.txt_child_subVillage), subVillages); + } + String dob= pc.getColumnmaps().get("tanggalLahirAnak").substring(0, pc.getColumnmaps().get("tanggalLahirAnak").indexOf("T")); + String age = ""+monthRangeToToday(dob); + //get child detail value +/* +* viewHolder.namaLengkap.setText(getColumnMaps("namalengkap", pc)); + viewHolder.namaSuami.setText(getColumnMaps("namaSuami", pc)); + viewHolder.dusun.setText(getDetails("posyandu", pc)); + viewHolder.tanggalLahir.setText(getDetails("tanggalLahir",pc).length()>10?getDetails("tanggalLahir",pc).substring(0,10) : "-"); + viewHolder.umur.setText(String.format("%s %s", getDetails("umur", pc), context.getString(R.string.years_unit))); + + viewHolder.lastANCVisit.setText(String.format("%s: %s", context.getString(R.string.kunjunganTerakhir), getDetails("ancDate", pc))); + int usiaKandungan = usiaKandungan(getDetails("tanggalHPHT",pc),getDetails("ancDate",pc)); + viewHolder.HPHT.setText(String.format("%s: %s%s", context.getString(R.string.usiaKandungan), usiaKandungan != -1 + ? Integer.toString(usiaKandungan) + : "-", context.getString(R.string.str_weeks))); + viewHolder.lila.setText(String.format("%s: %s cm", context.getString(R.string.lila), getDetails("hasilPemeriksaanLILA", pc))); + viewHolder.hbLevel.setText(String.format("%s: %s", context.getString(R.string.hb_level), getDetails("laboratoriumPeriksaHbHasil", pc))); + viewHolder.weight.setText(String.format("%s %s %s", context.getString(R.string.str_weight), getDetails("bbKg", pc), context.getString(R.string.weight_unit))); + + viewHolder.sistolik.setText(String.format("%s: %s", context.getString(R.string.sistolik), getDetails("tandaVitalTDSistolik", pc))); + viewHolder.diastolik.setText(String.format("%s: %s", context.getString(R.string.diastolik), getDetails("tandaVitalTDDiastolik", pc))); + + + viewHolder.vitaminA2.setText(String.format("%s%s", context.getString(R.string.vitamin_a_pnc_2), getDetails("vitaminA2jamPP", pc))); + viewHolder.vitaminA24.setText(String.format("%s%s", context.getString(R.string.vitamin_a_pnc_24), getDetails("vitaminA24jamPP", pc))); + */ + + // String ages = getValue(pc.getColumnmaps(), "namaBayi", true); + String dateOfBirth = getValue(pc.getColumnmaps(), "tanggalLahirAnak", true); + String gender = getValue(pc.getDetails(), "gender", true); + String visitDate = getValue(pc.getDetails(), "tanggalPenimbangan", true); + String height = getValue(pc.getDetails(), "tinggiBadan", true); + + String weight = getValue(pc.getDetails(), "beratBadan", true); + String underweight = getValue(pc.getDetails(), "underweight", true); + String stunting_status = getValue(pc.getDetails(), "stunting", true); + String wasting_status = getValue(pc.getDetails(), "wasting", true); + + //set child detail value + + fillValue((TextView) convertView.findViewById(R.id.txt_child_age), age); + fillValue((TextView) convertView.findViewById(R.id.txt_child_date_of_birth), "DOB :"+dob); + fillValue((TextView) convertView.findViewById(R.id.txt_child_gender), gender); + + + fillValue((TextView) convertView.findViewById(R.id.txt_child_visit_date),context.getString(R.string.tanggal)+ visitDate); + fillValue((TextView) convertView.findViewById(R.id.txt_child_height),context.getString(R.string.height)+ height); + fillValue((TextView) convertView.findViewById(R.id.txt_child_weight),context.getString(R.string.weight)+ weight); + + if (pc.getDetails().get("tanggalPenimbangan") != null) { + fillValue((TextView) convertView.findViewById(R.id.txt_child_underweight), context.getString(R.string.wfa) + setStatus(underweight)); + fillValue((TextView) convertView.findViewById(R.id.txt_child_stunting), context.getString(R.string.stunting) + setStatus(stunting_status)); + fillValue((TextView) convertView.findViewById(R.id.txt_child_wasting), context.getString(R.string.wasting) + setStatus(wasting_status)); + } + else{ + fillValue((TextView) convertView.findViewById(R.id.txt_child_underweight), context.getString(R.string.wfa)); + fillValue((TextView) convertView.findViewById(R.id.txt_child_stunting), context.getString(R.string.stunting)); + fillValue((TextView) convertView.findViewById(R.id.txt_child_wasting), context.getString(R.string.wasting)); + } + + } + + + private String setStatus(String status){ + switch (status.toLowerCase()){ + case "underweight" : + return context.getString(R.string.underweight); + case "severely underweight" : + return context.getString(R.string.s_underweight); + case "normal": + return context.getString(R.string.normal); + case "overweight": + return context.getString(R.string.overweight); + case "severely stunted" : + return context.getString(R.string.s_stunted); + case "stunted" : + return context.getString(R.string.stunted); + case "tall" : + return context.getString(R.string.tall); + case "severely wasted" : + return context.getString(R.string.s_wasted); + case "wasted" : + return context.getString(R.string.wasted); + default: + return ""; + } + } + public void setVitAVisibility(){ + int month = Integer.parseInt(new SimpleDateFormat("MM").format(new java.util.Date())); + int visibility = month == 2 || month == 8 ? View.VISIBLE : View.INVISIBLE; +// vitALogo.setVisibility(visibility); +// vitAText.setVisibility(visibility); + } + + private int monthRangeToToday(String lastVisitDate){ + String currentDate[] = new SimpleDateFormat("yyyy-MM").format(new java.util.Date()).substring(0,7).split("-"); + return ((Integer.parseInt(currentDate[0]) - Integer.parseInt(lastVisitDate.substring(0,4)))*12 + + (Integer.parseInt(currentDate[1]) - Integer.parseInt(lastVisitDate.substring(5,7)))); + } + + @Override + public SmartRegisterClients updateClients(FilterOption villageFilter, ServiceModeOption + serviceModeOption, FilterOption searchFilter, SortOption sortOption) { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void onServiceModeSelected(ServiceModeOption serviceModeOption) { + + } + + @Override + public OnClickFormLauncher newFormLauncher(String formName, String entityId, String + metaData) { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public View inflatelayoutForCursorAdapter() { + return inflater().inflate(R.layout.smart_register_gizi_client, null); + } + + public LayoutInflater inflater() { + return inflater; + } + + + + + + + + + + +} + diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartRegisterActivity.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartRegisterActivity.java new file mode 100644 index 0000000..a2a60bd --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/IbuSmartRegisterActivity.java @@ -0,0 +1,433 @@ +package org.smartregister.gizi.giziIbu; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.util.Log; + +import com.flurry.android.FlurryAgent; + +import org.smartregister.domain.form.FieldOverrides; +import org.smartregister.domain.form.FormSubmission; +import org.smartregister.gizi.activity.LoginActivity; +import org.smartregister.gizi.R; +import org.smartregister.gizi.fragment.GiziIbuSmartRegisterFragment; +import org.smartregister.gizi.pageradapter.BaseRegisterActivityPagerAdapter; +import org.smartregister.gizi.utils.KmsHandler; +import org.smartregister.provider.SmartRegisterClientsProvider; +import org.smartregister.service.ZiggyService; +import org.smartregister.sync.ClientProcessor; +import org.smartregister.util.FormUtils; +import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity; +import org.smartregister.view.dialog.DialogOption; +import org.smartregister.view.dialog.LocationSelectorDialogFragment; +import org.smartregister.view.dialog.OpenFormOption; +import org.smartregister.view.fragment.SecuredNativeSmartRegisterFragment; +import org.smartregister.view.viewpager.OpenSRPViewPager; +import org.json.JSONException; +import org.json.JSONObject; + +import org.smartregister.enketo.view.fragment.DisplayFormFragment; +import org.smartregister.view.fragment.SecuredNativeSmartRegisterFragment; +import org.smartregister.view.viewpager.OpenSRPViewPager; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import butterknife.Bind; +import butterknife.ButterKnife; + +//import org.smartregister.gizi.fragment.HouseHoldSmartRegisterFragment; + +public class IbuSmartRegisterActivity extends SecuredNativeSmartRegisterActivity implements + LocationSelectorDialogFragment.OnLocationSelectedListener{ + + SimpleDateFormat timer = new SimpleDateFormat("hh:mm:ss"); + + public static final String TAG = "GiziIbuActivity"; + @Bind(R.id.view_pager) + OpenSRPViewPager mPager; + private FragmentPagerAdapter mPagerAdapter; + private int currentPage; + private ClientProcessor clientProcessor; + private String[] formNames = new String[]{}; + private android.support.v4.app.Fragment mBaseFragment = null; + + ZiggyService ziggyService; + + GiziIbuSmartRegisterFragment nf = new GiziIbuSmartRegisterFragment(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + ButterKnife.bind(this); + + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + String GiziStart = timer.format(new Date()); + Map Gizi = new HashMap(); + Gizi.put("start", GiziStart); +// FlurryAgent.logEvent("Gizi_dashboard",Gizi, true ); + // FlurryFacade.logEvent("Gizi_dashboard"); + + formNames = this.buildFormNameList(); + + // WD + Bundle extras = getIntent().getExtras(); + if (extras != null) { + boolean mode_face = extras.getBoolean("org.smartregister.indonesia.face.face_mode"); + String base_id = extras.getString("org.smartregister.indonesia.face.base_id"); + double proc_time = extras.getDouble("org.smartregister.indonesia.face.proc_time"); +// Log.e(TAG, "onCreate: "+proc_time ); + + if (mode_face) { + nf.setCriteria(base_id); + mBaseFragment = new GiziIbuSmartRegisterFragment(); + + Log.e(TAG, "onCreate: id " + base_id); +// showToast("id "+base_id); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Is it Right Person ?"); +// builder.setTitle("Is it Right Clients ?" + base_id); +// builder.setTitle("Is it Right Clients ?"+ pc.getName()); + + // TODO : get name by base_id +// builder.setMessage("Process Time : " + proc_time + " s"); + + builder.setNegativeButton("CANCEL", listener ); + builder.setPositiveButton("YES", listener ); + builder.show(); + } + } else { + mBaseFragment = new GiziIbuSmartRegisterFragment(); + } + + + // Instantiate a ViewPager and a PagerAdapter. + mPagerAdapter = new BaseRegisterActivityPagerAdapter(getSupportFragmentManager(), formNames, mBaseFragment); + mPager.setOffscreenPageLimit(formNames.length); + mPager.setAdapter(mPagerAdapter); + mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + currentPage = position; + onPageChanged(position); + } + }); + + ziggyService = context().ziggyService(); + } + public void onPageChanged(int page){ + setRequestedOrientation(page == 0 ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + LoginActivity.setLanguage(); + } + + @Override + protected DefaultOptionsProvider getDefaultOptionsProvider() {return null;} + + @Override + protected void setupViews() { + + + } + + @Override + protected void onResumption(){} + + @Override + protected NavBarOptionsProvider getNavBarOptionsProvider() {return null;} + + @Override + protected SmartRegisterClientsProvider clientsProvider() {return null;} + + @Override + protected void onInitialization() { + context().formSubmissionRouter().getHandlerMap().put("kunjungan_gizi", new KmsHandler()); + } + + @Override + public void startRegistration() { + } + + public DialogOption[] getEditOptions() { + return new DialogOption[]{ + new OpenFormOption("Kunjungan Per Bulan ", "kunjungan_gizi", formController), + new OpenFormOption("Edit Registrasi Gizi ", "edit_registrasi_gizi", formController), + new OpenFormOption("Close Form","close_form",formController) + }; + } + + + @Override + public void saveFormSubmission(String formSubmission, String id, String formName, JSONObject fieldOverrides){ + Log.v("fieldoverride", fieldOverrides.toString()); + // save the form + try{ + FormUtils formUtils = FormUtils.getInstance(getApplicationContext()); + FormSubmission submission = formUtils.generateFormSubmisionFromXMLString(id, formSubmission, formName, fieldOverrides); + ziggyService.saveForm(getParams(submission), submission.instance()); + ClientProcessor.getInstance(getApplicationContext()).processClient(); + + context().formSubmissionService().updateFTSsearch(submission); + context().formSubmissionRouter().handleSubmission(submission, formName); + //switch to forms list fragment + switchToBaseFragment(formSubmission); // Unnecessary!! passing on data + + }catch (Exception e){ + // TODO: show error dialog on the formfragment if the submission fails + DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(currentPage); + if (displayFormFragment != null) { + displayFormFragment.hideTranslucentProgressDialog(); + } + e.printStackTrace(); + } + // KMSCalculation(); + } + + /*@Override + public void saveFormSubmission(String formSubmission, String id, String formName, JSONObject fieldOverrides){ + Log.v("fieldoverride", fieldOverrides.toString()); + // save the form + try{ + FormUtils formUtils = FormUtils.getInstance(getApplicationContext()); + FormSubmission submission = formUtils.generateFormSubmisionFromXMLString(id, formSubmission, formName, fieldOverrides); + + ziggyService.saveForm(getParams(submission), submission.instance()); + + //switch to forms list fragment + switchToBaseFragment(formSubmission); // Unnecessary!! passing on data + + }catch (Exception e){ + // TODO: show error dialog on the formfragment if the submission fails + DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(currentPage); + if (displayFormFragment != null) { + displayFormFragment.hideTranslucentProgressDialog(); + } + e.printStackTrace(); + } + *//* if(formName.equals("registrasi_gizi")) { + saveuniqueid(); + }*//* + //end capture flurry log for FS + String end = timer.format(new Date()); + Map FS = new HashMap(); + FS.put("end", end); + FlurryAgent.logEvent(formName,FS, true); + + } +*/ + @Override + public void OnLocationSelected(String locationJSONString) { + JSONObject combined = null; + + try { + JSONObject locationJSON = new JSONObject(locationJSONString); + // JSONObject uniqueId = new JSONObject(context().uniqueIdController().getUniqueIdJson()); + + combined = locationJSON; + // Iterator iter = uniqueId.keys(); + + /* while (iter.hasNext()) { + String key = iter.next(); + combined.put(key, uniqueId.get(key)); + } +*/ + } catch (JSONException e) { + e.printStackTrace(); + } + + if (combined != null) { + FieldOverrides fieldOverrides = new FieldOverrides(combined.toString()); + startFormActivity("registrasi_gizi", null, fieldOverrides.getJSONString()); + } + } + + /* public void saveuniqueid() { + try { + JSONObject uniqueId = new JSONObject(context().uniqueIdController().getUniqueIdJson()); + String uniq = uniqueId.getString("unique_id"); + context().uniqueIdController().updateCurrentUniqueId(uniq); + + } catch (JSONException e) { + e.printStackTrace(); + } + }*/ + + @Override + public void startFormActivity(String formName, String entityId, String metaData) { + // FlurryFacade.logEvent(formName); +// Log.v("fieldoverride", metaData); + try { + int formIndex = FormUtils.getIndexForFormName(formName, formNames) + 1; // add the offset + if (entityId != null || metaData != null){ + String data = null; + //check if there is previously saved data for the form + data = getPreviouslySavedDataForForm(formName, metaData, entityId); + if (data == null){ + data = FormUtils.getInstance(getApplicationContext()).generateXMLInputForFormWithEntityId(entityId, formName, metaData); + } + + DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(formIndex); + if (displayFormFragment != null) { + displayFormFragment.setFormData(data); + displayFormFragment.setRecordId(entityId); + displayFormFragment.setFieldOverides(metaData); + } + } + + mPager.setCurrentItem(formIndex, false); //Don't animate the view on orientation change the view disapears + + }catch (Exception e){ + e.printStackTrace(); + } + + } + + /*@Override + public void startFormActivity(String formName, String entityId, String metaData) { + // Log.v("fieldoverride", metaData); + String start = timer.format(new Date()); + Map FS = new HashMap(); + FS.put("start", start); + FlurryAgent.logEvent(formName,FS, true ); + //FlurryFacade.logEvent(formName); + try { + int formIndex = FormUtils.getIndexForFormName(formName, formNames) + 1; // add the offset + if (entityId != null || metaData != null){ + String data = null; + //check if there is previously saved data for the form + data = getPreviouslySavedDataForForm(formName, metaData, entityId); + if (data == null){ + data = FormUtils.getInstance(getApplicationContext()).generateXMLInputForFormWithEntityId(entityId, formName, metaData); + } + + DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(formIndex); + if (displayFormFragment != null) { + displayFormFragment.setFormData(data); + displayFormFragment.loadFormData(); + displayFormFragment.setRecordId(entityId); + displayFormFragment.setFieldOverides(metaData); + } + } + + mPager.setCurrentItem(formIndex, false); //Don't animate the view on orientation change the view disapears + + }catch (Exception e){ + e.printStackTrace(); + } + + }*/ + + public void switchToBaseFragment(final String data){ + final int prevPageIndex = currentPage; + runOnUiThread(new Runnable() { + @Override + public void run() { + mPager.setCurrentItem(0, false); + SecuredNativeSmartRegisterFragment registerFragment = (SecuredNativeSmartRegisterFragment) findFragmentByPosition(0); + if (registerFragment != null && data != null) { + registerFragment.refreshListView(); + } + + //hack reset the form + DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(prevPageIndex); + if (displayFormFragment != null) { + displayFormFragment.hideTranslucentProgressDialog(); + displayFormFragment.setFormData(null); + + } + + displayFormFragment.setRecordId(null); + } + }); + + } + + public android.support.v4.app.Fragment findFragmentByPosition(int position) { + FragmentPagerAdapter fragmentPagerAdapter = mPagerAdapter; + return getSupportFragmentManager().findFragmentByTag("android:switcher:" + mPager.getId() + ":" + fragmentPagerAdapter.getItemId(position)); + } + + public DisplayFormFragment getDisplayFormFragmentAtIndex(int index) { + return (DisplayFormFragment)findFragmentByPosition(index); + } + + @Override + public void onBackPressed() { + nf.setCriteria(""); + if (currentPage != 0) { + switchToBaseFragment(null); + } else if (currentPage == 0) { + super.onBackPressed(); // allow back key only if we are + } + } + + private String[] buildFormNameList(){ + List formNames = new ArrayList(); + formNames.add("registrasi_gizi"); + formNames.add("kunjungan_gizi"); + formNames.add("edit_registrasi_gizi"); + formNames.add("close_form"); + + + // formNames.add("census_enrollment_form"); +// DialogOption[] options = getEditOptions(); +// for (int i = 0; i < options.length; i++){ +// formNames.add(((OpenFormOption) options[i]).getFormName()); +// } + return formNames.toArray(new String[formNames.size()]); + } + + @Override + protected void onPause() { + super.onPause(); + retrieveAndSaveUnsubmittedFormData(); + /* String GiziEnd = timer.format(new Date()); + Map Gizi = new HashMap(); + Gizi.put("end", GiziEnd); + FlurryAgent.logEvent("Gizi_dashboard",Gizi, true );*/ + } + + public void retrieveAndSaveUnsubmittedFormData(){ + if (currentActivityIsShowingForm()){ + DisplayFormFragment formFragment = getDisplayFormFragmentAtIndex(currentPage); + formFragment.saveCurrentFormData(); + } + } + + private boolean currentActivityIsShowingForm(){ + return currentPage != 0; + } + + private DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + if (which == -1 ){ + nf.setCriteria("!"); + currentPage = 0; + Log.e(TAG, "onClick: YES " + currentPage); + FlurryAgent.logEvent(TAG+"search_by_face OK", true); + + } else { + nf.setCriteria(""); + onBackPressed(); + Log.e(TAG, "onClick: NO " + currentPage); + FlurryAgent.logEvent(TAG + "search_by_face NOK", true); + + Intent intent= new Intent(IbuSmartRegisterActivity.this, IbuSmartRegisterActivity.class); + startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); + } + + + } + }; + +} diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/KICommonObjectFilterOption.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/KICommonObjectFilterOption.java new file mode 100644 index 0000000..f7c093a --- /dev/null +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/giziIbu/KICommonObjectFilterOption.java @@ -0,0 +1,41 @@ +package org.smartregister.gizi.giziIbu; + +import org.apache.commons.lang3.StringUtils; +import org.smartregister.cursoradapter.CursorFilterOption; +import org.smartregister.view.contract.SmartRegisterClient; + +public class KICommonObjectFilterOption implements CursorFilterOption { + public final String criteria; + public final String fieldname; + private final String filterOptionName; + private final String tablename; + + @Override + public String filter() { + if(StringUtils.isNotBlank(fieldname) && !fieldname.equals("location_name")){ + return " AND " + tablename+ ".base_entity_id IN (SELECT DISTINCT base_entity_id FROM ec_details WHERE key MATCH '"+fieldname+"' INTERSECT SELECT DISTINCT base_entity_id FROM ec_details WHERE value MATCH '"+criteria+"' ) "; + } else{ + return " AND " + tablename+ ".base_entity_id IN (SELECT DISTINCT base_entity_id FROM ec_details WHERE value MATCH '"+criteria+"' ) "; + } + } + + + + public KICommonObjectFilterOption(String criteria, String fieldname, String filteroptionname, String tablename) { + this.criteria = criteria; + this.fieldname = fieldname; + this.filterOptionName = filteroptionname; + this.tablename = tablename; + } + + @Override + public String name() { + return filterOptionName; + } + + @Override + public boolean filter(SmartRegisterClient client) { + + return false; + } +} diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/provider/ChildSmartClientsProvider.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/provider/ChildSmartClientsProvider.java index b5dc484..a24cd1c 100644 --- a/opensrp-gizi/src/main/java/org/smartregister/gizi/provider/ChildSmartClientsProvider.java +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/provider/ChildSmartClientsProvider.java @@ -104,9 +104,9 @@ public void getView(Cursor cursor, SmartRegisterClient client, final View conver if(kiparent != null) { detailsRepository.updateDetails(kiparent); - String namaayah = getValue(kiparent.getColumnmaps(), "namaSuami", true); + // String namaayah = getValue(kiparent.getColumnmaps(), "namaSuami", true); String namaibu = getValue(kiparent.getColumnmaps(), "namalengkap", true); - fillValue((TextView) convertView.findViewById(R.id.ParentName), namaibu+","+namaayah); + fillValue((TextView) convertView.findViewById(R.id.ParentName), namaibu); String subVillages = getValue(kiparent.getDetails(), "address1", true); fillValue((TextView) convertView.findViewById(R.id.txt_child_subVillage), subVillages); } diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/utils/AllConstantsINA.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/utils/AllConstantsINA.java index 42b262c..86d33a2 100644 --- a/opensrp-gizi/src/main/java/org/smartregister/gizi/utils/AllConstantsINA.java +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/utils/AllConstantsINA.java @@ -29,10 +29,11 @@ public static class CloudantSync { public static final String REPLICATION_ERROR = "REPLICATION_ERROR"; public static final String DOCUMENTS_REPLICATED = "DOCUMENTS_REPLICATED"; public static final String BATCHES_REPLICATED = "BATCHES_REPLICATED"; - public static final String COUCHDB_PORT = "5983"; - public static final String COUCH_DATABASE_NAME = "opensrp"; - public static final String COUCH_DATABASE_USER = "rootuser"; - public static final String COUCH_DATABASE_PASS = "Satu23456"; + public static final String COUCHDB_PORT = "COUCHDB_PORT"; + public static final String COUCH_DATABASE_NAME = "COUCH_DATABASE_NAME"; + public static final String COUCH_DATABASE_USER = "COUCH_DATABASE_USER"; + public static final String COUCH_DATABASE_PASS = "COUCH_DATABASE_PASS"; + } } \ No newline at end of file diff --git a/opensrp-gizi/src/main/res/layout/smart_registers_gizi_home.xml b/opensrp-gizi/src/main/res/layout/smart_registers_gizi_home.xml index 8caccfd..c177de5 100644 --- a/opensrp-gizi/src/main/res/layout/smart_registers_gizi_home.xml +++ b/opensrp-gizi/src/main/res/layout/smart_registers_gizi_home.xml @@ -87,7 +87,7 @@ - +