Skip to content
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

AC 804 Added Allergy Tab to fetch allergies from server #780

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,6 +88,10 @@ interface ViewPatientCharts extends ViewPatientMain {
void setEmptyListVisibility(boolean visibility);
}

interface ViewPatientAllergy extends ViewPatientMain {
void showAllergyList(List<Allergy> allergies);
}
rishabh-997 marked this conversation as resolved.
Show resolved Hide resolved

/*
* Presenters
*/
Expand Down Expand Up @@ -120,4 +127,8 @@ interface PatientVitalsPresenter extends PatientDashboardMainPresenter {

interface PatientChartsPresenter extends PatientDashboardMainPresenter {
}

interface PatientAllergyPresenter extends PatientDashboardMainPresenter {
void getAllergy(Fragment fragment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Fragment> registeredFragments = new SparseArray<>();
rishabh-997 marked this conversation as resolved.
Show resolved Hide resolved
private String mPatientId;
private Context context;
Expand All @@ -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;
rishabh-997 marked this conversation as resolved.
Show resolved Hide resolved
case DIAGNOSIS_TAB_POS:
PatientDiagnosisFragment patientDiagnosisFragment = PatientDiagnosisFragment.newInstance();
new PatientDashboardDiagnosisPresenter(mPatientId, patientDiagnosisFragment);
Expand Down Expand Up @@ -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:
Expand Down
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();
}
}
}
}
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);
}
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,4 +175,7 @@ Call<FormCreate> formCreate(@Path("uuid") String uuid,
@POST("provider/{uuid}")
Call<Provider> UpdateProvider(@Path("uuid") String uuid,
@Body Provider provider);

@GET("patient/{uuid}/allergy")
Call<Results<Allergy>> getAllergies(@Path("uuid") String uuid);
}
Loading