From fd634ddc92c398a51039c13430702723a58342af Mon Sep 17 00:00:00 2001 From: rishabh-997 Date: Sun, 5 Jul 2020 13:55:19 +0530 Subject: [PATCH] added allergy tabs in the dashoard created layouts for allergies added models and api path resolving conflicts changed modela classes to kotlin added repository and tests AC-804 Updated string values and variable names added tab count in application constatnt removed star imports AC-804 Added allergy module base in the project --- .../PatientDashboardActivity.java | 4 + .../PatientDashboardContract.java | 11 ++ .../PatientDashboardPagerAdapter.java | 22 +++- .../allergy/PatientAllergyFragment.java | 97 ++++++++++++++ .../PatientAllergyRecyclerViewAdapter.java | 95 ++++++++++++++ .../PatientDashboardAllergyPresenter.java | 68 ++++++++++ .../java/org/openmrs/mobile/api/RestApi.java | 4 + .../api/repository/AllergyRepository.java | 61 +++++++++ .../org/openmrs/mobile/models/Allergen.kt | 28 ++++ .../java/org/openmrs/mobile/models/Allergy.kt | 37 ++++++ .../openmrs/mobile/models/AllergyReaction.kt | 28 ++++ .../mobile/utilities/ApplicationConstants.kt | 12 ++ .../res/layout/fragment_patient_allergy.xml | 50 +++++++ .../main/res/layout/list_patient_allergy.xml | 123 ++++++++++++++++++ .../src/main/res/values-hi/strings.xml | 8 ++ .../src/main/res/values/strings.xml | 8 ++ .../openmrs/mobile/test/ACUnitTestBase.java | 16 +++ .../FormAdmissionPresenterTest.java | 14 ++ .../PatientDashboardAllergyPresenterTest.java | 107 +++++++++++++++ 19 files changed, 787 insertions(+), 6 deletions(-) create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyFragment.java create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyRecyclerViewAdapter.java create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientDashboardAllergyPresenter.java create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/api/repository/AllergyRepository.java create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/models/Allergen.kt create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/models/Allergy.kt create mode 100644 openmrs-client/src/main/java/org/openmrs/mobile/models/AllergyReaction.kt create mode 100644 openmrs-client/src/main/res/layout/fragment_patient_allergy.xml create mode 100644 openmrs-client/src/main/res/layout/list_patient_allergy.xml create mode 100644 openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/PatientDashboardAllergyPresenterTest.java diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardActivity.java b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardActivity.java index cbe3f4b438..67796f467b 100644 --- a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardActivity.java +++ b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardActivity.java @@ -40,6 +40,8 @@ import org.openmrs.mobile.R; import org.openmrs.mobile.activities.ACBaseActivity; import org.openmrs.mobile.activities.addeditpatient.AddEditPatientActivity; +import org.openmrs.mobile.activities.patientdashboard.allergy.PatientAllergyFragment; +import org.openmrs.mobile.activities.patientdashboard.allergy.PatientDashboardAllergyPresenter; import org.openmrs.mobile.activities.patientdashboard.charts.PatientChartsFragment; import org.openmrs.mobile.activities.patientdashboard.charts.PatientDashboardChartsPresenter; import org.openmrs.mobile.activities.patientdashboard.details.PatientDashboardDetailsPresenter; @@ -136,6 +138,8 @@ private void attachPresenterToFragment(Fragment fragment) { mPresenter = new PatientDashboardVitalsPresenter(id, ((PatientVitalsFragment) fragment)); } else if (fragment instanceof PatientChartsFragment) { mPresenter = new PatientDashboardChartsPresenter(id, ((PatientChartsFragment) fragment)); + } else if (fragment instanceof PatientAllergyFragment) { + mPresenter = new PatientDashboardAllergyPresenter(id, ((PatientAllergyFragment) fragment)); } } diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardContract.java b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardContract.java index 922d981f83..831fcdc3c4 100644 --- a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardContract.java +++ b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardContract.java @@ -14,8 +14,11 @@ package org.openmrs.mobile.activities.patientdashboard; +import androidx.fragment.app.Fragment; + import org.openmrs.mobile.activities.BasePresenterContract; import org.openmrs.mobile.activities.BaseView; +import org.openmrs.mobile.models.Allergy; import org.openmrs.mobile.models.Encounter; import org.openmrs.mobile.models.Patient; import org.openmrs.mobile.models.Visit; @@ -85,6 +88,10 @@ interface ViewPatientCharts extends ViewPatientMain { void setEmptyListVisibility(boolean visibility); } + interface ViewPatientAllergy extends ViewPatientMain { + void showAllergyList(List allergies); + } + /* * Presenters */ @@ -120,4 +127,8 @@ interface PatientVitalsPresenter extends PatientDashboardMainPresenter { interface PatientChartsPresenter extends PatientDashboardMainPresenter { } + + interface PatientAllergyPresenter extends PatientDashboardMainPresenter { + void getAllergy(Fragment fragment); + } } diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardPagerAdapter.java b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardPagerAdapter.java index f3da5de2af..de6b87044a 100644 --- a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardPagerAdapter.java +++ b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/PatientDashboardPagerAdapter.java @@ -26,6 +26,8 @@ import org.jetbrains.annotations.NotNull; import org.openmrs.mobile.R; +import org.openmrs.mobile.activities.patientdashboard.allergy.PatientAllergyFragment; +import org.openmrs.mobile.activities.patientdashboard.allergy.PatientDashboardAllergyPresenter; import org.openmrs.mobile.activities.patientdashboard.charts.PatientChartsFragment; import org.openmrs.mobile.activities.patientdashboard.charts.PatientDashboardChartsPresenter; import org.openmrs.mobile.activities.patientdashboard.details.PatientDashboardDetailsPresenter; @@ -37,13 +39,15 @@ import org.openmrs.mobile.activities.patientdashboard.vitals.PatientDashboardVitalsPresenter; import org.openmrs.mobile.activities.patientdashboard.vitals.PatientVitalsFragment; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.ALLERGY_TAB_POS; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.CHARTS_TAB_POS; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.DETAILS_TAB_POS; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.DIAGNOSIS_TAB_POS; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.TAB_COUNT; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.VISITS_TAB_POS; +import static org.openmrs.mobile.utilities.ApplicationConstants.PatientDashboardTabs.VITALS_TAB_POS; + class PatientDashboardPagerAdapter extends FragmentPagerAdapter { - private static final int TAB_COUNT = 5; - private static final int DETAILS_TAB_POS = 0; - private static final int DIAGNOSIS_TAB_POS = 1; - private static final int VISITS_TAB_POS = 2; - private static final int VITALS_TAB_POS = 3; - private static final int CHARTS_TAB_POS = 4; private SparseArray registeredFragments = new SparseArray<>(); private String mPatientId; private Context context; @@ -62,6 +66,10 @@ public Fragment getItem(int i) { PatientDetailsFragment patientDetailsFragment = PatientDetailsFragment.newInstance(); new PatientDashboardDetailsPresenter(mPatientId, patientDetailsFragment); return patientDetailsFragment; + case ALLERGY_TAB_POS: + PatientAllergyFragment patientAllergyFragment = PatientAllergyFragment.newInstance(); + new PatientDashboardAllergyPresenter(mPatientId, patientAllergyFragment); + return patientAllergyFragment; case DIAGNOSIS_TAB_POS: PatientDiagnosisFragment patientDiagnosisFragment = PatientDiagnosisFragment.newInstance(); new PatientDashboardDiagnosisPresenter(mPatientId, patientDiagnosisFragment); @@ -89,6 +97,8 @@ public CharSequence getPageTitle(int position) { switch (position) { case DETAILS_TAB_POS: return context.getString(R.string.patient_scroll_tab_details_label); + case ALLERGY_TAB_POS: + return context.getString(R.string.patient_scroll_tab_allergy_label); case DIAGNOSIS_TAB_POS: return context.getString(R.string.patient_scroll_tab_diagnosis_label); case VISITS_TAB_POS: diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyFragment.java b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyFragment.java new file mode 100644 index 0000000000..a6aa886cff --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyFragment.java @@ -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 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(); + } + } + } +} diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyRecyclerViewAdapter.java b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyRecyclerViewAdapter.java new file mode 100644 index 0000000000..6c41b7c1ac --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientAllergyRecyclerViewAdapter.java @@ -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 { + private Context context; + private List list; + + public PatientAllergyRecyclerViewAdapter(Context context, List 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); + } + 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); + } + } +} diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientDashboardAllergyPresenter.java b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientDashboardAllergyPresenter.java new file mode 100644 index 0000000000..5568ee3ce1 --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/allergy/PatientDashboardAllergyPresenter.java @@ -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 allergies) { + mPatientAllergyView.showAllergyList(allergies); + } +} diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/api/RestApi.java b/openmrs-client/src/main/java/org/openmrs/mobile/api/RestApi.java index 30665ceacb..bd380b2583 100644 --- a/openmrs-client/src/main/java/org/openmrs/mobile/api/RestApi.java +++ b/openmrs-client/src/main/java/org/openmrs/mobile/api/RestApi.java @@ -10,6 +10,7 @@ package org.openmrs.mobile.api; +import org.openmrs.mobile.models.Allergy; import org.openmrs.mobile.models.Concept; import org.openmrs.mobile.models.ConceptAnswers; import org.openmrs.mobile.models.Encounter; @@ -174,4 +175,7 @@ Call formCreate(@Path("uuid") String uuid, @POST("provider/{uuid}") Call UpdateProvider(@Path("uuid") String uuid, @Body Provider provider); + + @GET("patient/{uuid}/allergy") + Call> getAllergies(@Path("uuid") String uuid); } diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/api/repository/AllergyRepository.java b/openmrs-client/src/main/java/org/openmrs/mobile/api/repository/AllergyRepository.java new file mode 100644 index 0000000000..487fb6e83a --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/api/repository/AllergyRepository.java @@ -0,0 +1,61 @@ +/* + * 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.api.repository; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; + +import org.jetbrains.annotations.NotNull; +import org.openmrs.mobile.R; +import org.openmrs.mobile.api.RestApi; +import org.openmrs.mobile.application.OpenMRS; +import org.openmrs.mobile.models.Allergy; +import org.openmrs.mobile.models.Results; +import org.openmrs.mobile.utilities.ToastUtil; + +import java.util.List; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class AllergyRepository { + + public AllergyRepository() { + } + + public LiveData> getAllergies(RestApi restApi, String uuid) { + MutableLiveData> allergyLiveData = new MutableLiveData<>(); + + restApi.getAllergies(uuid).enqueue(new Callback>() { + @Override + public void onResponse(@NotNull Call> call, @NotNull Response> response) { + if (response.isSuccessful()) { + allergyLiveData.setValue(response.body().getResults()); + } else { + ToastUtil.error(OpenMRS.getInstance().getString(R.string.unable_to_fetch_allergies)); + allergyLiveData.setValue(null); + } + } + + @Override + public void onFailure(@NotNull Call> call, @NotNull Throwable t) { + ToastUtil.error(OpenMRS.getInstance().getString(R.string.unable_to_fetch_allergies)); + allergyLiveData.setValue(null); + } + }); + return allergyLiveData; + } +} diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/models/Allergen.kt b/openmrs-client/src/main/java/org/openmrs/mobile/models/Allergen.kt new file mode 100644 index 0000000000..c40c6c1ac4 --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/models/Allergen.kt @@ -0,0 +1,28 @@ +/* + * 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.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +class Allergen { + @SerializedName("allergenType") + @Expose + var allergenType: String? = null + + @SerializedName("codedAllergen") + @Expose + var codedAllergen: Resource? = null +} diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/models/Allergy.kt b/openmrs-client/src/main/java/org/openmrs/mobile/models/Allergy.kt new file mode 100644 index 0000000000..ca465c3853 --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/models/Allergy.kt @@ -0,0 +1,37 @@ +/* + * 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.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class Allergy : Resource() { + + @SerializedName("allergen") + @Expose + var allergen: Allergen? = null + + @SerializedName("severity") + @Expose + var severity: Resource? = null + + @SerializedName("comment") + @Expose + var comment: String? = null + + @SerializedName("reactions") + @Expose + var reactions: List = ArrayList() +} diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/models/AllergyReaction.kt b/openmrs-client/src/main/java/org/openmrs/mobile/models/AllergyReaction.kt new file mode 100644 index 0000000000..f138903cf3 --- /dev/null +++ b/openmrs-client/src/main/java/org/openmrs/mobile/models/AllergyReaction.kt @@ -0,0 +1,28 @@ +/* + * 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.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class AllergyReaction { + @SerializedName("reaction") + @Expose + var reaction: Resource? = null + + @SerializedName("reactionNonCoded") + @Expose + var reactionNonCoded: String? = null +} \ No newline at end of file diff --git a/openmrs-client/src/main/java/org/openmrs/mobile/utilities/ApplicationConstants.kt b/openmrs-client/src/main/java/org/openmrs/mobile/utilities/ApplicationConstants.kt index 0831de379f..b4cee290c1 100644 --- a/openmrs-client/src/main/java/org/openmrs/mobile/utilities/ApplicationConstants.kt +++ b/openmrs-client/src/main/java/org/openmrs/mobile/utilities/ApplicationConstants.kt @@ -54,6 +54,8 @@ object ApplicationConstants { const val REPRESENTATION_FULL = "full" const val CAUSE_OF_DEATH = "concept.causeOfDeath" const val MALE = "M"; + const val EMPTY_DASH_REPRESENTATION = "---" + const val COMMA_WITH_SPACE = ", " object OpenMRSSharedPreferenceNames { const val SHARED_PREFERENCES_NAME = "shared_preferences" @@ -167,4 +169,14 @@ object ApplicationConstants { const val ROBOTO_MEDIUM_ITALIC = "fonts/Roboto/Roboto-MediumItalic.ttf" const val ROBOTO_REGULAR = "fonts/Roboto/Roboto-Regular.ttf" } + + object PatientDashboardTabs { + const val DETAILS_TAB_POS = 0 + const val ALLERGY_TAB_POS = 1 + const val DIAGNOSIS_TAB_POS = 2 + const val VISITS_TAB_POS = 3 + const val VITALS_TAB_POS = 4 + const val CHARTS_TAB_POS = 5 + const val TAB_COUNT = 6 + } } \ No newline at end of file diff --git a/openmrs-client/src/main/res/layout/fragment_patient_allergy.xml b/openmrs-client/src/main/res/layout/fragment_patient_allergy.xml new file mode 100644 index 0000000000..735d65397c --- /dev/null +++ b/openmrs-client/src/main/res/layout/fragment_patient_allergy.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + diff --git a/openmrs-client/src/main/res/layout/list_patient_allergy.xml b/openmrs-client/src/main/res/layout/list_patient_allergy.xml new file mode 100644 index 0000000000..7a9c406c28 --- /dev/null +++ b/openmrs-client/src/main/res/layout/list_patient_allergy.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/openmrs-client/src/main/res/values-hi/strings.xml b/openmrs-client/src/main/res/values-hi/strings.xml index 37d3572ff1..0349f5b436 100644 --- a/openmrs-client/src/main/res/values-hi/strings.xml +++ b/openmrs-client/src/main/res/values-hi/strings.xml @@ -145,6 +145,7 @@ डेटाबेस से रोगी लाने में विफल विज़िट शुरू करें विवरण + एलर्जी निदान विज़िट विटल्स @@ -453,4 +454,11 @@ इस सेटिंग के लिए मृत्यु के कोई संभावित कारण नहीं मिले रोगी मृतक चिह्नित है — %1$s मृतक मरीज के लिए निरीक्षण शुरू नहीं कर सकते + + + टिप्पणी + तीव्रता + प्रतिक्रिया + रोगी को अभी तक कोई एलर्जी नहीं है। + एलर्जी लाने में असमर्थ! diff --git a/openmrs-client/src/main/res/values/strings.xml b/openmrs-client/src/main/res/values/strings.xml index 9e7643f7f3..4ba555af75 100644 --- a/openmrs-client/src/main/res/values/strings.xml +++ b/openmrs-client/src/main/res/values/strings.xml @@ -148,6 +148,7 @@ Failed to fetch patient from database Start visit Details + Allergy Diagnosis Visits Vitals @@ -505,4 +506,11 @@ No possible causes of death found for this setting Patient is marked deceased — %1$s Cannot start visit for deceased patient + + + Comment + Severity + Reactions + Patient has no allergies yet. + Unable to fetch Allergies! diff --git a/openmrs-client/src/test/java/org/openmrs/mobile/test/ACUnitTestBase.java b/openmrs-client/src/test/java/org/openmrs/mobile/test/ACUnitTestBase.java index f66d4bda14..d25d0e21c9 100644 --- a/openmrs-client/src/test/java/org/openmrs/mobile/test/ACUnitTestBase.java +++ b/openmrs-client/src/test/java/org/openmrs/mobile/test/ACUnitTestBase.java @@ -28,6 +28,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; +import org.openmrs.mobile.models.Allergen; +import org.openmrs.mobile.models.Allergy; import org.openmrs.mobile.models.Patient; import org.openmrs.mobile.models.PatientIdentifier; import org.openmrs.mobile.models.Person; @@ -168,6 +170,20 @@ protected Provider createProvider(Long id, String identifier){ return provider; } + protected Allergy createAllergy(Long id, String display) { + Allergy allergy = new Allergy(); + allergy.setId(id); + allergy.setUuid("uuid"); + allergy.setDisplay(display); + + allergy.setComment("comment"); + allergy.setAllergen(new Allergen()); + allergy.setReactions(new ArrayList<>()); + allergy.setSeverity(null); + + return allergy; + } + protected Call> mockSuccessCall(List list) { return new MockSuccessResponse<>(list); } diff --git a/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/FormAdmissionPresenterTest.java b/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/FormAdmissionPresenterTest.java index 81e0c2e565..20701c0752 100644 --- a/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/FormAdmissionPresenterTest.java +++ b/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/FormAdmissionPresenterTest.java @@ -1,3 +1,17 @@ +/* + * 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.test.presenters; import android.content.Context; diff --git a/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/PatientDashboardAllergyPresenterTest.java b/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/PatientDashboardAllergyPresenterTest.java new file mode 100644 index 0000000000..6df3f155d6 --- /dev/null +++ b/openmrs-client/src/test/java/org/openmrs/mobile/test/presenters/PatientDashboardAllergyPresenterTest.java @@ -0,0 +1,107 @@ +/* + * 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.test.presenters; + +import androidx.arch.core.executor.testing.InstantTaskExecutorRule; +import androidx.lifecycle.MutableLiveData; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.openmrs.mobile.activities.patientdashboard.PatientDashboardContract; +import org.openmrs.mobile.activities.patientdashboard.allergy.PatientAllergyFragment; +import org.openmrs.mobile.activities.patientdashboard.allergy.PatientDashboardAllergyPresenter; +import org.openmrs.mobile.api.RestApi; +import org.openmrs.mobile.application.OpenMRS; +import org.openmrs.mobile.application.OpenMRSLogger; +import org.openmrs.mobile.models.Allergy; +import org.openmrs.mobile.models.Patient; +import org.openmrs.mobile.test.ACUnitTestBaseRx; +import org.openmrs.mobile.utilities.NetworkUtils; +import org.openmrs.mobile.utilities.ToastUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; + +import java.util.Arrays; +import java.util.List; + +import static org.mockito.Mockito.verify; + +@PrepareForTest({NetworkUtils.class, + ToastUtil.class, + OpenMRS.class, + OpenMRSLogger.class}) +public class PatientDashboardAllergyPresenterTest extends ACUnitTestBaseRx { + @Rule + public InstantTaskExecutorRule taskExecutorRule = new InstantTaskExecutorRule(); + MutableLiveData> allergyLiveData = Mockito.mock(MutableLiveData.class); + List allergyList; + @Mock + private RestApi restApi; + @Mock + private OpenMRSLogger openMRSLogger; + @Mock + private OpenMRS openMRS; + @Mock + private PatientDashboardContract.ViewPatientAllergy viewPatientAllergy; + + private PatientDashboardAllergyPresenter presenter; + private Patient patient; + private PatientAllergyFragment fragment = new PatientAllergyFragment(); + + @Before + public void setUp() { + super.setUp(); + patient = createPatient(1L); + presenter = new PatientDashboardAllergyPresenter(patient, viewPatientAllergy, restApi); + mockStaticMethods(); + } + + private void mockStaticMethods() { + PowerMockito.mockStatic(NetworkUtils.class); + PowerMockito.mockStatic(OpenMRS.class); + PowerMockito.mockStatic(OpenMRSLogger.class); + Mockito.lenient().when(OpenMRS.getInstance()).thenReturn(openMRS); + PowerMockito.when(openMRS.getOpenMRSLogger()).thenReturn(openMRSLogger); + PowerMockito.mockStatic(ToastUtil.class); + } + + @Test + public void shouldGetAllergies_AllOK() { + Allergy allergy = createAllergy(1L, "doctor"); + allergyList = Arrays.asList(allergy); + allergyLiveData.postValue(allergyList); + + Mockito.lenient().when(NetworkUtils.isOnline()).thenReturn(true); + Mockito.lenient().when(restApi.getAllergies("patient_one_uuid" + 1L)).thenReturn(mockSuccessCall(allergyList)); + + presenter.getAllergy(fragment); + presenter.updateViews(allergyList); + + verify(restApi).getAllergies("patient_one_uuid" + 1L); + verify(viewPatientAllergy).showAllergyList(allergyList); + } + + @Test + public void shouldGetAllergies_Error() { + Mockito.lenient().when(NetworkUtils.isOnline()).thenReturn(true); + Mockito.lenient().when(restApi.getAllergies("patient_one_uuid" + 1L)).thenReturn(mockErrorCall(401)); + + presenter.getAllergy(fragment); + verify(restApi).getAllergies("patient_one_uuid" + 1L); + } +}