...
As shown above there are different parts of Main grid which can be controlled by implementing SecuredNativeSmartRegisterFragment. TBD explain each in details
- Register Label
- Sort Option
- Filter Option
- Service Mode
- Client Action Handler
- Search Filter Option
- Search Type
- Default Options
- Navigation Options
- Custom Form Handler
- New Record Button
- Adapter
- Client Provider
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public class MyRegisterFragment extends SecuredNativeSmartRegisterFragment { private final ClientActionHandler clientActionHandler = new ClientActionHandler(); public MyRegisterFragment() { super(null); } @SuppressLint("ValidFragment") public MyRegisterFragment(FormController formController) { super(formController); } // Default settings for Sort, Main Filter, Location, Service Mode, Search Filter and Search Type @Override protected SecuredNativeSmartRegisterActivity.DefaultOptionsProvider getDefaultOptionsProvider() { return new SecuredNativeSmartRegisterActivity.DefaultOptionsProvider() { @Override public SearchFilterOption searchFilterOption() { return new MySearchOption(""); } @Override public ServiceModeOption serviceMode() { return new MyServiceModeOption(null, "My Service Mode Label", new int[]{/* Resource ids for each header */ R.id.column1, R.id.column2, /*.....*/}, // Weight for each header. Should bebalance equalthe toweights weight of columns defined in client_record_layout.xml new int[]{6,2,3,2,1}); } @Override public FilterOption villageFilter() { return new CursorCommonObjectFilterOption("no village filter", ""); } @Override public SortOption sortOption() { return new CursorCommonObjectSort(getResources().getString(R.string.alphabetical_sort_text), "sort_column DESC"); } @Override public String nameInShortFormForTitle() { return Context.getInstance().getStringResource(R.string.my_register_title); } @Override public SecuredNativeSmartRegisterActivity.SearchType searchType() { return SecuredNativeSmartRegisterActivity.SearchType.PASSIVE; } }; } @Override protected SecuredNativeSmartRegisterActivity.NavBarOptionsProvider getNavBarOptionsProvider() { return new SecuredNativeSmartRegisterActivity.NavBarOptionsProvider() { @Override public DialogOption[] filterOptions() { return new DialogOption[]{}; } @Override public DialogOption[] serviceModeOptions() { return new DialogOption[]{}; } @Override public DialogOption[] sortingOptions() { return new DialogOption[]{ new CursorCommonObjectSort(getResources().getString(R.string.sort_type1), "my_column1 ASC"), new CursorCommonObjectSort(getResources().getString(R.string.sort_type2), "my_column2 DESC"), new CursorCommonObjectSort(getResources().getString(R.string.sort_dob_age), "my_dob_column DESC") }; } @Override public String searchHint() { return Context.getInstance().getStringResource(R.string.text_to_display_searchbox); } }; } @Override protected void onInitialization(){ // A handler where form submission would be routed for further processing after successful save context.formSubmissionRouter().getHandlerMap().put("my_form1", new MyCustomForm1Handler(getActivity())); } @Override protected void onCreation() { // Custom tasks after fragment creation } // What app should do on click of New Record Button. It can launch QR Code activity or can also open a form directly @Override protected void startRegistration() { // Any fields in form needs to be overriden.. A usecase could be load data from DB and send to form Map<String, String> overrides = new HashMap<>(); overrides.put("my_form_field1", "abc"); startForm("my_form1", "", overrides); } @Override protected SmartRegisterPaginatedAdapter adapter() { // Setup the adapter to /*if(VaccinatorUtils.providerRolesList().toLowerCase().contains("vaccinator")){ setup data. Here it is using CursorAdapter return new SmartRegisterPaginatedCursorAdapter(getActivity(), new SmartRegisterCursorBuilder("mybindType", null, "T", null, new SmartRegisterCursorBuilder("client", null, (CursorSortOption) getDefaultOptionsProvider().sortOption(), "baseEntityId").limit(5), c clientsProvider(), SmartRegisterCursorBuilder.DB.DRISHTI); } @Override protected SmartRegisterClientsProvider , clientsProvider(), SmartRegisterCursorBuilder.DB.OPENSRP); { return new MySmartClientsProvider(getActivity(), clientActionHandler, context.alertService()); } else {* // Client interaction handler. A class that handles any clicks or taps on returndata new SmartRegisterPaginatedCursorAdapter(getActivity(), row's different sections or layouts private class ClientActionHandler implements View.OnClickListener { new SmartRegisterCursorBuilder("pkhousehold", null, "H", @Override public void onClick(View view) { new String[]{"(SELECT count(1) FROM pkindividual WHERE household_id=H.household_id) registeredMembers"},switch (view.getId()) { case (CursorSortOption) getDefaultOptionsProvider().sortOption(), "").limit(5) R.id.column1_layout: // open details fragment ((SmartRegisterSecuredActivity)getActivity()).showDetailFragment((CommonPersonObjectClient) view.getTag(), false); , clientsProvider(), SmartRegisterCursorBuilder.DB.DRISHTI) break; //} } case R.id.column2_button_followup: @Override protected SmartRegisterClientsProvider clientsProvider() { return new HouseholdSmartClientsProvider(getActivity(), clientActionHandler, context.alertService()); } private SmartRegisterClients filterHousehold(String filterString) { setCurrentSearchFilter(new HouseholdIDSearchOption(filterString)); onFilterManual(filterString); return getClientsAdapter().currentPageList(); } private List<CommonPersonObject> filterHouseholdMembers(String householdId) { String memberExistQuery = "select * from pkindividual where household_id = '"+householdId+"' "; return context.allCommonsRepositoryobjects("pkindividual").customQueryForCompleteRow(memberExistQuery, new String[]{}, "pkindividual"); } public CommonPersonObject filterHouseholdMember(String hhMemberId){ String memberExistQuery = "select * from pkindividual where program_client_id = '"+hhMemberId+"' " + " OR id = '"+hhMemberId+"' OR household_member_id = '"+hhMemberId+"'"; List<CommonPersonObject> memberData = context.allCommonsRepositoryobjects("pkindividual").customQueryForCompleteRow(memberExistQuery, new String[]{}, "pkindividual"); CommonPersonObject householdMember; if (memberData.size() == 0) { return null; } else { householdMember = memberData.get(0); String householdId = householdMember.getColumnmaps().get("household_id"); setCurrentSearchFilter(new HouseholdIDSearchOption(householdId)); onFilterManual(householdId); } return householdMember; } public CommonPersonObject vaccinatorTables(String qrCode, String entity){ String q = "select * from "+entity+" where program_client_id = " + qrCode; List<CommonPersonObject> memberData = context.allCommonsRepositoryobjects(entity).customQueryForCompleteRow(q, new String[]{}, entity); if (memberData.size() == 0) { return null; } return memberData.get(0); } private class ClientActionHandler implements View.OnClickListener { private HouseholdSmartRegisterFragment householdSmartRegisterFragment; public ClientActionHandler() { this.householdSmartRegisterFragment = householdSmartRegisterFragment; } @Override public void onClick(View view) { switch (view.getId()) { case R.id.household_profile_info_layout: ((SmartRegisterSecuredActivity)getActivity()).showDetailFragment((CommonPersonObjectClient) view.getTag(), false); break; case R.id.household_add_member: // change the below contains value according to your requirement //if(!Utils.userRoles.contains("Vaccinator")) { final CommonPersonObjectClient client = (CommonPersonObjectClient) view.getTag(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LinearLayout ly = new LinearLayout(getActivity()); ly.setOrientation(LinearLayout.VERTICAL); final RadioButton hasQRCode = new RadioButton(getActivity()); final RadioButton noQRCode = new RadioButton(getActivity()); hasQRCode.setText("Yes, member has a QR code ID"); noQRCode.setText("No, member doesnot have QR code ID"); RadioGroup rG = new RadioGroup(getActivity()); rG.setPadding(10, 10, 10, 5); rG.addView(hasQRCode); rG.addView(noQRCode); final LinearLayout layout = new LinearLayout(getActivity()); layout.setOrientation(LinearLayout.HORIZONTAL); TextView memberCodeQuestion = new TextView(getActivity()); memberCodeQuestion.setText("Has this member ever been registered in any other OpenSRP program and assigned a QR code (A QR code scanner screen will be launched to scan QR Code ID)?"); memberCodeQuestion.setTextSize(20); layout.addView(memberCodeQuestion); ly.addView(layout); ly.addView(rG); builder.setView(ly); final AlertDialog alertDialog = builder.setPositiveButton("OK", null).setNegativeButton("Cancel", null).create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (noQRCode.isChecked()) { HashMap<String, String> map = new HashMap<>(); Map<String, String> m = memberRegistrationOverrides(client, null, filterHouseholdMembers(client.getColumnmaps().get("household_id"))); map.putAll(m); startNewMemberEnrollmentForm(map, client); } else if (hasQRCode.isChecked()) { startMemberRegistration(client.entityId()); } dialog.dismiss(); } }); } }); alertDialog.show(); //} break; } } }//end of method private Map<String, String> memberRegistrationOverrides(CommonPersonObjectClient client , CommonPersonObject existingClient, List<CommonPersonObject> otherMembers){ Map<String, String> map = new HashMap<>(); map.put("relationalid", client.getCaseId()); map.put("existing_full_name_hhh", getValue(client.getColumnmaps(), "first_name", true)); map.put("existing_household_id", getValue(client.getColumnmaps(), "household_id", true)); map.put("existing_num_members", (otherMembers.size()+1)+""); map.put("existing_num_household_members", getValue(client.getColumnmaps(), "num_household_members", false)); map.put("province", getValue(client.getColumnmaps(), "province", false)); map.put("city_village", getValue(client.getColumnmaps(), "city_village", false)); map.put("town", getValue(client.getColumnmaps(), "town", false)); map.put("union_council", getValue(client.getColumnmaps(), "union_council", false)); map.put("address1", getValue(client.getColumnmaps(), "address1", false)); map.put("existing_full_address", getValue(client.getColumnmaps(), "address1", true) +", UC: "+ getValue(client.getColumnmaps(), "union_council", true).replace("Uc", "UC") +", Town: "+ getValue(client.getColumnmaps(), "town", true) +", City: "+ getValue(client.getColumnmaps(), "city_village", true) +", Province: "+ getValue(client.getColumnmaps(), "province", true)); if (existingClient != null) { map.put("first_name", getValue(existingClient.getColumnmaps(), "first_name", false)); map.put("gender", existingClient.getColumnmaps().get("gender")); map.put("birth_date", getValue(existingClient.getColumnmaps(), "dob", false)); // do something map.put("contact_phone_number", getValue(existingClient.getColumnmaps(), "contact_phone_number", false)); else i.e. open another form or open a dialogue etc map.put("ethnicity", getValue(existingClient.getDetails(), "ethnicity", false)); map.put("ethnicity_other", getValue(existingClient.getDetails(), "ethnicity_other", false));break; } return map;} } } |