-
-
Save MamboBryan/65099bcc78402cd04eb0eb5c720f35a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PatientSeenSummaryFragment extends Fragment { | |
private static final String TAG = "PatientSeenSummaryFragm"; | |
private String apiBaseUrl; | |
private String authToken; | |
private ConstraintLayout content; | |
private ConstraintLayout loading; | |
private CardView cashPatientsCardView; | |
private CardView insurancePatientsCardView; | |
private TextView cashPatientsSummary; | |
private TextView insurancePatientsSummary; | |
private PatientSeenSummaryData mSummaryData; | |
private List<PatientFacility> patientFacilitiesList = new ArrayList<>(); | |
private List<PatientDepartment> patientDepartmentsList = new ArrayList<>(); | |
private List<PatientPaymentMode> patientPaymentModeList = new ArrayList<>(); | |
private List<String> facilities = new ArrayList<>(); | |
private List<String> visists = new ArrayList<>(); | |
private PatientSeenFacilitiesRecyclerAdapter facilitiesAdapter; | |
private View rootView; | |
private PatientsSeenDepartmentsRecyclerAdapter departmentAdapter; | |
public PatientSeenSummaryFragment() { | |
// Required empty public constructor | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
rootView = inflater.inflate(R.layout.fragment_patient_seen_summary, | |
container, false); | |
content = rootView.findViewById(R.id.pateint_seen_summary_content); | |
loading = rootView.findViewById(R.id.patient_seen_summary_loading); | |
cashPatientsCardView = rootView.findViewById(R.id.cardView_patients_seen_summary_cash); | |
insurancePatientsCardView = rootView.findViewById(R.id.cardView_patients_seen_summary_insurance); | |
cashPatientsSummary = rootView.findViewById(R.id.patients_seen_cash_summary); | |
insurancePatientsSummary = rootView.findViewById(R.id.patients_seen_insurance_summary); | |
displayLoading(); | |
return rootView; | |
} | |
private void initFacilitiesRecyclerView(View rootView) { | |
RecyclerView facilitiesView = rootView.findViewById(R.id.recycleView_patients_seen_facilities); | |
facilitiesAdapter = new PatientSeenFacilitiesRecyclerAdapter(getContext(), | |
patientFacilitiesList); | |
facilitiesView.setAdapter(facilitiesAdapter); | |
facilitiesView.setLayoutManager(new LinearLayoutManager(getContext())); | |
} | |
public void initDepartmentRecycleView(View rootView) { | |
RecyclerView departmentView = rootView.findViewById(R.id.recyclerView_patients_seen_departments); | |
departmentAdapter = new | |
PatientsSeenDepartmentsRecyclerAdapter(getContext(), patientDepartmentsList); | |
departmentView.setAdapter(departmentAdapter); | |
departmentView.setLayoutManager(new LinearLayoutManager(getContext())); | |
} | |
@Override | |
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
getBaseApiUrl(); | |
Filters filters = new Filters(); | |
CustomViewModelFactory factory = new | |
CustomViewModelFactory(apiBaseUrl, authToken); | |
PatientsSeenViewModel patientsSeenViewModel = ViewModelProviders.of(this, factory) | |
.get(PatientsSeenViewModel.class); | |
patientsSeenViewModel.getPatientsSeenSummaryData(filters).observe(getViewLifecycleOwner(), | |
new Observer<PatientSeenSummaryData>() { | |
@Override | |
public void onChanged(PatientSeenSummaryData patientSeenSummaryData) { | |
Toast.makeText(getContext(), "Summary changed", Toast.LENGTH_SHORT).show(); | |
Log.i(TAG, "SummaryData onChanged: data has been changed"); | |
if (patientSeenSummaryData != null) { | |
mSummaryData = patientSeenSummaryData; | |
displayContent(); | |
getSummaryData(); | |
facilitiesAdapter.notifyDataSetChanged(); | |
departmentAdapter.notifyDataSetChanged(); | |
} | |
} | |
}); | |
patientsSeenViewModel.getPatientsSeen(filters).observe(getViewLifecycleOwner(), | |
new Observer<PatientsSeenData>() { | |
@Override | |
public void onChanged(PatientsSeenData patientsSeenData) { | |
if (patientsSeenData != null) { | |
displayContent(); | |
facilitiesAdapter.notifyDataSetChanged(); | |
departmentAdapter.notifyDataSetChanged(); | |
} | |
} | |
}); | |
} | |
private void displayContent() { | |
loading.setVisibility(View.INVISIBLE); | |
content.setVisibility(View.VISIBLE); | |
Log.i("Patient Summary", "Displaying content"); | |
getSummaryData(); | |
PatientPaymentMode mode = patientPaymentModeList.get(0); | |
PatientPaymentMode mode1 = patientPaymentModeList.get(1); | |
cashPatientsSummary.setText(String.valueOf(mode.getVisits())); | |
insurancePatientsSummary.setText(String.valueOf(mode1.getVisits())); | |
initFacilitiesRecyclerView(rootView); | |
initDepartmentRecycleView(rootView); | |
} | |
private void getSummaryData() { | |
patientFacilitiesList = mSummaryData.getFacilities(); | |
patientDepartmentsList = mSummaryData.getDepartments(); | |
patientPaymentModeList = mSummaryData.getPaymentMode(); | |
} | |
private void displayLoading() { | |
loading.setVisibility(View.VISIBLE); | |
content.setVisibility(View.INVISIBLE); | |
Log.i("Loading", "Displaying loading"); | |
} | |
/** | |
* Gets api base url and sets to variable | |
* Generates service with api url | |
*/ | |
private void getBaseApiUrl() { | |
//Restore shared preferences | |
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); | |
apiBaseUrl = prefs.getString(BASE_API_URL, ""); | |
String token = prefs.getString(ACCESS_TOKEN, "No string gotten"); | |
authToken = "Bearer " + token; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment