Skip to content

Commit e91c599

Browse files
committed
AC-625: Check Matching Providers
1 parent 544c0c4 commit e91c599

11 files changed

Lines changed: 220 additions & 53 deletions

openmrs-client/src/main/java/org/openmrs/mobile/activities/providermanagerdashboard/ProviderManagerDashboardFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
8585
refreshUI();
8686

8787
addProviderFab.setOnClickListener(v -> {
88-
startActivityForResult(new Intent(getActivity(), AddProviderActivity.class), ADD_PROVIDER_REQ_CODE);
88+
Intent intent = new Intent(getActivity(),AddProviderActivity.class);
89+
ArrayList<Provider> providerArrayList = new ArrayList<>(providerList);
90+
intent.putExtra(ApplicationConstants.BundleKeys.EXISTING_PROVIDERS_BUNDLE,providerArrayList);
91+
startActivityForResult(intent, ADD_PROVIDER_REQ_CODE);
8992
});
9093

9194
// Font config

openmrs-client/src/main/java/org/openmrs/mobile/activities/providermanagerdashboard/ProviderManagerDashboardRecyclerViewAdapter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openmrs.mobile.utilities.ApplicationConstants;
3333
import org.openmrs.mobile.utilities.FontsUtil;
3434

35+
import java.util.ArrayList;
3536
import java.util.List;
3637

3738
import static org.openmrs.mobile.utilities.ApplicationConstants.RequestCodes.EDIT_PROVIDER_REQ_CODE;
@@ -71,7 +72,9 @@ public void onBindViewHolder(ProviderViewHolder holder, int position) {
7172
});
7273

7374
holder.editIv.setOnClickListener(v -> {
74-
Intent intent = new Intent(fragment.getContext(), AddProviderActivity.class);
75+
Intent intent = new Intent(fragment.getContext(),AddProviderActivity.class);
76+
ArrayList<Provider> providerArrayList = new ArrayList<>(mItems);
77+
intent.putExtra(ApplicationConstants.BundleKeys.EXISTING_PROVIDERS_BUNDLE,providerArrayList);
7578
intent.putExtra(ApplicationConstants.BundleKeys.PROVIDER_ID_BUNDLE, provider);
7679
fragment.startActivityForResult(intent, EDIT_PROVIDER_REQ_CODE);
7780
});

openmrs-client/src/main/java/org/openmrs/mobile/activities/providermanagerdashboard/addprovider/AddProviderContract.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import org.openmrs.mobile.models.Person;
2020
import org.openmrs.mobile.models.Provider;
2121

22+
import java.util.ArrayList;
23+
import java.util.List;
24+
2225
public class AddProviderContract {
2326
public interface View extends BaseView<Presenter> {
2427
boolean validateFields();
@@ -30,5 +33,7 @@ public interface Presenter extends BasePresenterContract {
3033
Provider createNewProvider(Person person, String identifier);
3134

3235
Provider editExistingProvider(Provider provider, Person person, String identifier);
36+
37+
List<Provider> getMatchingProviders(ArrayList<Provider> providers, Provider currentProvider);
3338
}
3439
}

openmrs-client/src/main/java/org/openmrs/mobile/activities/providermanagerdashboard/addprovider/AddProviderFragment.java

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,13 @@
2222

2323
import androidx.annotation.NonNull;
2424
import androidx.annotation.Nullable;
25+
import androidx.appcompat.app.AlertDialog;
26+
import androidx.recyclerview.widget.LinearLayoutManager;
27+
import androidx.recyclerview.widget.RecyclerView;
2528

2629
import com.google.android.material.floatingactionbutton.FloatingActionButton;
2730
import com.google.android.material.textfield.TextInputEditText;
2831
import com.google.android.material.textfield.TextInputLayout;
29-
/*
30-
* The contents of this file are subject to the OpenMRS Public License
31-
* Version 1.0 (the "License"); you may not use this file except in
32-
* compliance with the License. You may obtain a copy of the License at
33-
* http://license.openmrs.org
34-
*
35-
* Software distributed under the License is distributed on an "AS IS"
36-
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
37-
* License for the specific language governing rights and limitations
38-
* under the License.
39-
*
40-
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
41-
*/
4232

4333
import org.openmrs.mobile.R;
4434
import org.openmrs.mobile.activities.ACBaseFragment;
@@ -47,6 +37,8 @@
4737
import org.openmrs.mobile.utilities.ApplicationConstants;
4838
import org.openmrs.mobile.utilities.ViewUtils;
4939

40+
import java.util.ArrayList;
41+
import java.util.List;
5042
import java.util.Objects;
5143

5244
import static android.app.Activity.RESULT_OK;
@@ -59,6 +51,7 @@ public class AddProviderFragment extends ACBaseFragment<AddProviderContract.Pres
5951
TextInputLayout firstNameTIL, lastNameTIL, identifierTIL;
6052

6153
private Provider editProvider = null;
54+
private ArrayList<Provider> existingProviders;
6255

6356
public static AddProviderFragment newInstance() {
6457
return new AddProviderFragment();
@@ -72,6 +65,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
7265

7366
editProvider = (Provider) (Objects.requireNonNull(getActivity()).getIntent()
7467
.getSerializableExtra(ApplicationConstants.BundleKeys.PROVIDER_ID_BUNDLE));
68+
69+
existingProviders = (ArrayList<Provider>) (Objects.requireNonNull(getActivity()).getIntent()
70+
.getSerializableExtra(ApplicationConstants.BundleKeys.EXISTING_PROVIDERS_BUNDLE));
71+
7572
setupUI(root);
7673
return root;
7774
}
@@ -106,15 +103,19 @@ void setupUI(View root) {
106103

107104
if (editProvider == null) {
108105
provider = mPresenter.createNewProvider(person, identifier);
106+
List<Provider> matchingProviders = mPresenter.getMatchingProviders(existingProviders, provider);
107+
108+
if (matchingProviders.size() > 0) {
109+
showMatchingProvidersDialog(matchingProviders, provider);
110+
} else {
111+
setResult(provider);
112+
}
113+
109114
} else {
110115
provider = mPresenter.editExistingProvider(editProvider, person, identifier);
116+
setResult(provider);
111117
}
112118

113-
Intent intent = new Intent();
114-
intent.putExtra(ApplicationConstants.BundleKeys.PROVIDER_ID_BUNDLE, provider);
115-
Objects.requireNonNull(getActivity()).setResult(RESULT_OK, intent);
116-
117-
getActivity().finish();
118119
}
119120

120121
});
@@ -166,4 +167,41 @@ public boolean validateFields() {
166167
}
167168
return true;
168169
}
170+
171+
public void showMatchingProvidersDialog(List<Provider> matchingProviders, Provider provider) {
172+
173+
AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
174+
builder.setTitle(Objects.requireNonNull(getActivity()).getString(R.string.title_dialog_matching_provider));
175+
176+
LayoutInflater inflater = getLayoutInflater();
177+
View dialogView = inflater.inflate(R.layout.custom_matching_provider_alert_dialog, null);
178+
179+
builder.setView(dialogView);
180+
181+
RecyclerView recyclerView = dialogView.findViewById(R.id.custom_matching_provider_rv);
182+
recyclerView.setHasFixedSize(true);
183+
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
184+
recyclerView.setLayoutManager(linearLayoutManager);
185+
186+
MatchingProviderRecyclerViewAdapter adapter = new MatchingProviderRecyclerViewAdapter(getActivity(), matchingProviders);
187+
recyclerView.setAdapter(adapter);
188+
189+
builder.setPositiveButton(getActivity().getString(R.string.dialog_matching_provider_positive_btn), (dialog, which) -> {
190+
setResult(provider);
191+
192+
}).setNegativeButton(getActivity().getString(R.string.dialog_button_cancel), (dialog, which) -> {
193+
// Do nothing and cancel the dialog box
194+
});
195+
AlertDialog dialog = builder.create();
196+
197+
dialog.show();
198+
}
199+
200+
public void setResult(Provider provider) {
201+
Intent intent = new Intent();
202+
intent.putExtra(ApplicationConstants.BundleKeys.PROVIDER_ID_BUNDLE, provider);
203+
Objects.requireNonNull(getActivity()).setResult(RESULT_OK, intent);
204+
205+
getActivity().finish();
206+
}
169207
}

openmrs-client/src/main/java/org/openmrs/mobile/activities/providermanagerdashboard/addprovider/AddProviderPresenter.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ public Provider editExistingProvider(Provider provider, Person person, String id
9292
return provider;
9393
}
9494

95+
/**
96+
* This function finds the matching providers from existing providers list and returns
97+
* a list of matching ones.
98+
* Currently only first name and last name are checked. More fields can be added with more
99+
* attributes checking here.
100+
*
101+
* @param existingProviders
102+
* @param currentProvider
103+
* @return List<Provider>
104+
*/
105+
@Override
106+
public List<Provider> getMatchingProviders(ArrayList<Provider> existingProviders, Provider currentProvider) {
107+
List<Provider> matchingProviders = new ArrayList<>();
108+
for (Provider provider : existingProviders) {
109+
String name = provider.getPerson().getDisplay().toLowerCase();
110+
String fName = currentProvider.getPerson().getName().getGivenName().toLowerCase();
111+
String lName = currentProvider.getPerson().getName().getFamilyName().toLowerCase();
112+
113+
if (name.contains(fName) || name.contains(lName))
114+
matchingProviders.add(provider);
115+
}
116+
return matchingProviders;
117+
}
118+
95119
@Override
96120
public void subscribe() {
97121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.openmrs.mobile.activities.providermanagerdashboard.addprovider;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.TextView;
8+
9+
import androidx.constraintlayout.widget.ConstraintLayout;
10+
import androidx.recyclerview.widget.RecyclerView;
11+
12+
import org.openmrs.mobile.R;
13+
import org.openmrs.mobile.models.Provider;
14+
import org.openmrs.mobile.utilities.FontsUtil;
15+
16+
import java.util.List;
17+
18+
public class MatchingProviderRecyclerViewAdapter extends
19+
RecyclerView.Adapter<MatchingProviderRecyclerViewAdapter.SimilarProviderViewHolder> {
20+
private List<Provider> mItems;
21+
private Context context;
22+
23+
public MatchingProviderRecyclerViewAdapter(Context context, List<Provider> items) {
24+
this.context = context;
25+
this.mItems = items;
26+
}
27+
28+
@Override
29+
public SimilarProviderViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
30+
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_provider_details, parent, false);
31+
FontsUtil.setFont((ViewGroup) itemView);
32+
return new SimilarProviderViewHolder(itemView);
33+
}
34+
35+
@Override
36+
public void onBindViewHolder(SimilarProviderViewHolder holder, int position) {
37+
final Provider provider = mItems.get(position);
38+
if (provider.getPerson().getDisplay() != null) {
39+
holder.mName.setText(provider.getPerson().getDisplay());
40+
}
41+
42+
if (provider.getIdentifier() != null) {
43+
holder.mIdentifier.setText(provider.getIdentifier());
44+
}
45+
46+
// TODO open provider dashboard for clicked provider
47+
holder.providerDetailsCL.setOnClickListener(v -> {
48+
// Action
49+
});
50+
51+
}
52+
53+
@Override
54+
public int getItemCount() {
55+
return mItems.size();
56+
}
57+
58+
59+
class SimilarProviderViewHolder extends RecyclerView.ViewHolder {
60+
private TextView mIdentifier;
61+
private TextView mName;
62+
private ConstraintLayout providerDetailsCL;
63+
64+
public SimilarProviderViewHolder(View itemView) {
65+
super(itemView);
66+
providerDetailsCL = itemView.findViewById(R.id.providerManagementCL);
67+
mIdentifier = itemView.findViewById(R.id.providerManagementIdentifier);
68+
mName = itemView.findViewById(R.id.providerManagementName);
69+
70+
}
71+
}
72+
73+
public void setItems(List<Provider> mItems) {
74+
this.mItems = mItems;
75+
}
76+
}

openmrs-client/src/main/java/org/openmrs/mobile/utilities/ApplicationConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public abstract static class BundleKeys {
8585
public static final String PATIENT_QUERY_BUNDLE = "patientQuery";
8686
public static final String PATIENTS_START_INDEX = "patientsStartIndex";
8787
public static final String PROVIDER_ID_BUNDLE = "providerID";
88+
public static final String EXISTING_PROVIDERS_BUNDLE = "existingProviders";
8889
}
8990

9091
public abstract static class ServiceActions {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<androidx.recyclerview.widget.RecyclerView
7+
android:id="@+id/custom_matching_provider_rv"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"/>
10+
11+
</LinearLayout>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/providerManagementCL"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:padding="@dimen/activity_horizontal_margin"
8+
android:visibility="visible">
9+
10+
<TextView
11+
android:id="@+id/providerManagementName"
12+
android:layout_width="0dp"
13+
android:layout_height="wrap_content"
14+
android:layout_margin="@dimen/margin_short"
15+
android:layout_weight="2"
16+
android:text="Jake Smith"
17+
android:textSize="@dimen/settings_list_text_title_size"
18+
android:textStyle="bold"
19+
app:layout_constraintEnd_toStartOf="@+id/providerManagementIdentifier"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent" />
22+
23+
<TextView
24+
android:id="@+id/providerManagementIdentifier"
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_marginTop="@dimen/margin_short"
28+
android:layout_marginEnd="@dimen/margin_short"
29+
android:layout_marginRight="@dimen/margin_short"
30+
android:layout_weight="1"
31+
android:text="Doctor"
32+
app:layout_constraintEnd_toEndOf="parent"
33+
app:layout_constraintTop_toTopOf="parent" />
34+
35+
36+
</androidx.constraintlayout.widget.ConstraintLayout>

openmrs-client/src/main/res/layout/row_provider_management.xml

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,7 @@
4747
android:layout_width="match_parent"
4848
android:layout_height="wrap_content">
4949

50-
<androidx.constraintlayout.widget.ConstraintLayout
51-
android:layout_width="match_parent"
52-
android:layout_height="wrap_content"
53-
android:padding="@dimen/activity_horizontal_margin"
54-
android:visibility="visible">
55-
56-
<TextView
57-
android:id="@+id/providerManagementName"
58-
android:layout_width="0dp"
59-
android:layout_height="wrap_content"
60-
android:layout_margin="@dimen/margin_short"
61-
android:layout_weight="2"
62-
android:text="Jake Smith"
63-
android:textSize="@dimen/settings_list_text_title_size"
64-
android:textStyle="bold"
65-
app:layout_constraintEnd_toStartOf="@+id/providerManagementIdentifier"
66-
app:layout_constraintStart_toStartOf="parent"
67-
app:layout_constraintTop_toTopOf="parent" />
68-
69-
<TextView
70-
android:id="@+id/providerManagementIdentifier"
71-
android:layout_width="0dp"
72-
android:layout_height="wrap_content"
73-
android:layout_marginTop="@dimen/margin_short"
74-
android:layout_marginEnd="@dimen/margin_short"
75-
android:layout_marginRight="@dimen/margin_short"
76-
android:layout_weight="1"
77-
android:text="Doctor"
78-
app:layout_constraintEnd_toEndOf="parent"
79-
app:layout_constraintTop_toTopOf="parent" />
80-
81-
82-
</androidx.constraintlayout.widget.ConstraintLayout>
50+
<include layout="@layout/row_provider_details"/>
8351
</androidx.cardview.widget.CardView>
8452

8553

0 commit comments

Comments
 (0)