-
Notifications
You must be signed in to change notification settings - Fork 427
AC 804 Added Allergy Tab to fetch allergies from server #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
97 changes: 97 additions & 0 deletions
97
...n/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyFragment.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * The contents of this file are subject to the OpenMRS Public License | ||
| * Version 1.0 (the "License"); you may not use this file except in | ||
| * compliance with the License. You may obtain a copy of the License at | ||
| * http://license.openmrs.org | ||
| * | ||
| * Software distributed under the License is distributed on an "AS IS" | ||
| * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing rights and limitations | ||
| * under the License. | ||
| * | ||
| * Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
| */ | ||
|
|
||
| package org.openmrs.mobile.activities.patientdashboard.allergy; | ||
|
|
||
| import android.content.Context; | ||
| import android.os.Bundle; | ||
| import android.view.LayoutInflater; | ||
| import android.view.Menu; | ||
| import android.view.MenuInflater; | ||
| import android.view.MenuItem; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.recyclerview.widget.LinearLayoutManager; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
| import org.openmrs.mobile.activities.patientdashboard.PatientDashboardActivity; | ||
| import org.openmrs.mobile.activities.patientdashboard.PatientDashboardContract; | ||
| import org.openmrs.mobile.activities.patientdashboard.PatientDashboardFragment; | ||
| import org.openmrs.mobile.databinding.FragmentPatientAllergyBinding; | ||
| import org.openmrs.mobile.models.Allergy; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class PatientAllergyFragment extends PatientDashboardFragment implements PatientDashboardContract.ViewPatientAllergy { | ||
| private PatientDashboardActivity mPatientDashboardActivity; | ||
| private FragmentPatientAllergyBinding binding; | ||
|
|
||
| public static PatientAllergyFragment newInstance() { | ||
| return new PatientAllergyFragment(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onAttach(@NotNull Context context) { | ||
| super.onAttach(context); | ||
| mPatientDashboardActivity = (PatientDashboardActivity) context; | ||
| } | ||
|
|
||
| @Override | ||
| public void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| super.setPresenter(mPresenter); | ||
| setHasOptionsMenu(true); | ||
| } | ||
|
|
||
| @Override | ||
| public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| int id = item.getItemId(); | ||
| return super.onOptionsItemSelected(item); | ||
| } | ||
|
|
||
| @Override | ||
| public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| binding = FragmentPatientAllergyBinding.inflate(inflater, container, false); | ||
| ((PatientDashboardAllergyPresenter) mPresenter).getAllergy(this); | ||
| LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); | ||
| binding.recyclerViewAllergy.setHasFixedSize(true); | ||
| binding.recyclerViewAllergy.setLayoutManager(linearLayoutManager); | ||
|
|
||
| return binding.getRoot(); | ||
| } | ||
|
|
||
| @Override | ||
| public void showAllergyList(List<Allergy> allergies) { | ||
| binding.progressBar.setVisibility(View.GONE); | ||
| if (allergies == null) { | ||
| binding.emptyAllergyList.setVisibility(View.VISIBLE); | ||
| } else { | ||
| if (allergies.size() == 0) { | ||
| binding.emptyAllergyList.setVisibility(View.VISIBLE); | ||
| } else { | ||
| binding.emptyAllergyList.setVisibility(View.GONE); | ||
| PatientAllergyRecyclerViewAdapter adapter = new PatientAllergyRecyclerViewAdapter(getContext(), allergies); | ||
| binding.recyclerViewAllergy.setAdapter(adapter); | ||
| adapter.notifyDataSetChanged(); | ||
| } | ||
| } | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
...openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyRecyclerViewAdapter.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * The contents of this file are subject to the OpenMRS Public License | ||
| * Version 1.0 (the "License"); you may not use this file except in | ||
| * compliance with the License. You may obtain a copy of the License at | ||
| * http://license.openmrs.org | ||
| * | ||
| * Software distributed under the License is distributed on an "AS IS" | ||
| * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing rights and limitations | ||
| * under the License. | ||
| * | ||
| * Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
| */ | ||
|
|
||
| package org.openmrs.mobile.activities.patientdashboard.allergy; | ||
|
|
||
| import android.content.Context; | ||
| 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.openmrs.mobile.R; | ||
| import org.openmrs.mobile.models.Allergy; | ||
| import org.openmrs.mobile.utilities.ApplicationConstants; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class PatientAllergyRecyclerViewAdapter extends RecyclerView.Adapter<PatientAllergyRecyclerViewAdapter.ViewHolder> { | ||
| private Context context; | ||
| private List<Allergy> list; | ||
|
|
||
| public PatientAllergyRecyclerViewAdapter(Context context, List<Allergy> list) { | ||
| this.context = context; | ||
| this.list = list; | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public PatientAllergyRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
| View itemView = LayoutInflater.from(context).inflate(R.layout.list_patient_allergy, parent, false); | ||
| return new ViewHolder(itemView); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(@NonNull PatientAllergyRecyclerViewAdapter.ViewHolder holder, int position) { | ||
| Allergy allergy = list.get(position); | ||
| holder.allergen.setText(allergy.getAllergen().getCodedAllergen().getDisplay()); | ||
| if (null == allergy.getComment() || allergy.getComment().isEmpty()) { | ||
| holder.comment.setText(ApplicationConstants.EMPTY_DASH_REPRESENTATION); | ||
| } else { | ||
| holder.comment.setText(allergy.getComment()); | ||
| } | ||
|
|
||
| if (allergy.getReactions().size() == 0) { | ||
| holder.reaction.setText(ApplicationConstants.EMPTY_DASH_REPRESENTATION); | ||
| } else { | ||
| StringBuilder reactions = new StringBuilder(); | ||
| for (int i = 0; i < allergy.getReactions().size() - 1; i++) { | ||
| reactions.append(allergy.getReactions().get(i).getReaction().getDisplay()).append(ApplicationConstants.COMMA_WITH_SPACE); | ||
| } | ||
rishabh-997 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| reactions.append(allergy.getReactions().get(allergy.getReactions().size() - 1).getReaction().getDisplay()); | ||
| holder.reaction.setText(reactions); | ||
| } | ||
|
|
||
| if (allergy.getSeverity() == null) { | ||
| holder.severity.setText(ApplicationConstants.EMPTY_DASH_REPRESENTATION); | ||
| } else { | ||
| holder.severity.setText(allergy.getSeverity().getDisplay()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| return list.size(); | ||
| } | ||
|
|
||
| public class ViewHolder extends RecyclerView.ViewHolder { | ||
| private TextView allergen; | ||
| private TextView reaction; | ||
| private TextView severity; | ||
| private TextView comment; | ||
|
|
||
| public ViewHolder(@NonNull View itemView) { | ||
| super(itemView); | ||
| allergen = itemView.findViewById(R.id.allergy_allergen); | ||
| reaction = itemView.findViewById(R.id.allergy_reaction); | ||
| severity = itemView.findViewById(R.id.allergy_severity); | ||
| comment = itemView.findViewById(R.id.allergy_comment); | ||
| } | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
.../openmrs/mobile/activities/patientdashboard/allergy/PatientDashboardAllergyPresenter.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * The contents of this file are subject to the OpenMRS Public License | ||
| * Version 1.0 (the "License"); you may not use this file except in | ||
| * compliance with the License. You may obtain a copy of the License at | ||
| * http://license.openmrs.org | ||
| * | ||
| * Software distributed under the License is distributed on an "AS IS" | ||
| * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing rights and limitations | ||
| * under the License. | ||
| * | ||
| * Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
| */ | ||
|
|
||
| package org.openmrs.mobile.activities.patientdashboard.allergy; | ||
|
|
||
| import androidx.fragment.app.Fragment; | ||
|
|
||
| import org.openmrs.mobile.activities.patientdashboard.PatientDashboardContract; | ||
| import org.openmrs.mobile.activities.patientdashboard.PatientDashboardMainPresenterImpl; | ||
| import org.openmrs.mobile.api.RestApi; | ||
| import org.openmrs.mobile.api.RestServiceBuilder; | ||
| import org.openmrs.mobile.api.repository.AllergyRepository; | ||
| import org.openmrs.mobile.dao.PatientDAO; | ||
| import org.openmrs.mobile.models.Allergy; | ||
| import org.openmrs.mobile.models.Patient; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class PatientDashboardAllergyPresenter extends PatientDashboardMainPresenterImpl implements PatientDashboardContract.PatientAllergyPresenter { | ||
| private PatientDashboardContract.ViewPatientAllergy mPatientAllergyView; | ||
| private String patientId; | ||
| private PatientDAO patientDAO; | ||
| private RestApi restApi; | ||
| private AllergyRepository allergyRepository; | ||
|
|
||
| public PatientDashboardAllergyPresenter(String patientId, PatientDashboardContract.ViewPatientAllergy mPatientAllergyView) { | ||
| this.mPatientAllergyView = mPatientAllergyView; | ||
| this.patientId = patientId; | ||
| this.patientDAO = new PatientDAO(); | ||
| this.mPatient = patientDAO.findPatientByID(patientId); | ||
| allergyRepository = new AllergyRepository(); | ||
| restApi = RestServiceBuilder.createService(RestApi.class); | ||
| mPatientAllergyView.setPresenter(this); | ||
| } | ||
|
|
||
| public PatientDashboardAllergyPresenter(Patient patient, PatientDashboardContract.ViewPatientAllergy viewPatientAllergy, RestApi restApi) { | ||
| this.mPatientAllergyView = viewPatientAllergy; | ||
| this.mPatient = patient; | ||
| this.restApi = restApi; | ||
| this.mPatientAllergyView.setPresenter(this); | ||
| allergyRepository = new AllergyRepository(); | ||
| } | ||
|
|
||
| @Override | ||
| public void subscribe() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void getAllergy(Fragment fragment) { | ||
| allergyRepository.getAllergies(restApi, mPatient.getUuid()).observe(fragment, this::updateViews); | ||
| } | ||
|
|
||
| public void updateViews(List<Allergy> allergies) { | ||
| mPatientAllergyView.showAllergyList(allergies); | ||
| } | ||
| } |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.