Skip to content

Commit 9e0c0ee

Browse files
committed
filter only art
1 parent c00d1d1 commit 9e0c0ee

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/items/CustomQuestItemDataProvider.kt

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@
1616

1717
package org.smartregister.fhircore.engine.ui.questionnaire.items
1818

19+
import ca.uhn.fhir.rest.gclient.TokenClientParam
20+
import ca.uhn.fhir.rest.param.ParamPrefixEnum
1921
import com.google.android.fhir.FhirEngine
2022
import com.google.android.fhir.get
2123
import com.google.android.fhir.search.Operation
2224
import com.google.android.fhir.search.StringFilterModifier
25+
import com.google.android.fhir.search.filter.TokenParamFilterCriterion
2326
import com.google.android.fhir.search.search
2427
import com.google.gson.Gson
2528
import com.google.gson.reflect.TypeToken
2629
import javax.inject.Inject
2730
import org.hl7.fhir.r4.model.Binary
31+
import org.hl7.fhir.r4.model.Coding
32+
import org.hl7.fhir.r4.model.DateTimeType
2833
import org.hl7.fhir.r4.model.Patient
2934
import org.hl7.fhir.r4.model.Reference
35+
import org.smartregister.fhircore.engine.domain.model.HealthStatus
3036
import org.smartregister.fhircore.engine.domain.model.LocationHierarchy
3137
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
3238
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
@@ -35,6 +41,7 @@ import org.smartregister.fhircore.engine.util.extension.asReference
3541
import org.smartregister.fhircore.engine.util.extension.extractAge
3642
import org.smartregister.fhircore.engine.util.extension.extractName
3743
import org.smartregister.fhircore.engine.util.extension.extractOfficialIdentifier
44+
import org.smartregister.fhircore.engine.util.extension.plusYears
3845
import timber.log.Timber
3946

4047
class CustomQuestItemDataProvider
@@ -70,6 +77,13 @@ constructor(
7077
}
7178

7279
suspend fun searchPatients(query: String): List<PickerPatient> {
80+
val codings = listOf(HealthStatus.NEWLY_DIAGNOSED_CLIENT, HealthStatus.CLIENT_ALREADY_ON_ART).map { Coding().apply {
81+
system = SystemConstants.PATIENT_TYPE_FILTER_TAG_VIA_META_CODINGS_SYSTEM
82+
code = it.name.lowercase().replace("_", "-")
83+
} }.map<Coding,
84+
TokenParamFilterCriterion.() -> Unit> { c->
85+
{value = of(c)}
86+
}
7387
val patients =
7488
fhirEngine.search<Patient> {
7589
filter(Patient.ACTIVE, { value = of(true) })
@@ -80,6 +94,7 @@ constructor(
8094
{ value = of("female") },
8195
operation = Operation.OR,
8296
)
97+
filter(TokenClientParam("_tag"), *codings.toTypedArray(), operation = Operation.OR)
8398
if (query.contains(Regex("[0-9]"))) {
8499
filter(Patient.IDENTIFIER, { value = of(query) })
85100
} else {
@@ -114,5 +129,5 @@ data class PickerPatient(
114129
val id: String?,
115130
val gender: String,
116131
val age: String,
117-
val reference: Reference
132+
val reference: Reference,
118133
)

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/items/patient/PatientPicker.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class PatientPicker(
7575
CustomQuestPatientPickerDialogBinding.inflate(LayoutInflater.from(context), null, false)
7676
val dialog = AlertDialog.Builder(context).setView(dialogBinding.root).create()
7777
dialogBinding.submitButton.setOnClickListener {
78-
val inputText = dialogBinding.inputEditText.text.toString()
78+
val inputText = dialogBinding.patientSearchEditText.text.toString()
7979
viewModel.submitText(inputText)
8080
}
8181

@@ -145,7 +145,7 @@ class PatientPicker(
145145

146146
class ItemsAdapter(
147147
private val items: List<PickerPatient>,
148-
val onPatientSelected: (PickerPatient) -> Unit
148+
val onPatientSelected: (PickerPatient) -> Unit,
149149
) : RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
150150

151151
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

android/engine/src/main/res/layout/custom_quest_patient_picker_dialog.xml

+21-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,34 @@
55
android:orientation="vertical"
66
android:padding="16dp">
77

8-
<EditText
9-
android:id="@+id/inputEditText"
8+
<TextView
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:text="Search Patient"
12+
style="?textAppearanceHeadline6"
13+
android:layout_marginBottom="10dp"/>
14+
15+
<com.google.android.material.textfield.TextInputLayout
16+
android:id="@+id/patient_search_input_layout"
17+
style="?attr/questionnaireTextInputLayoutStyle"
1018
android:layout_width="match_parent"
1119
android:layout_height="wrap_content"
12-
android:hint="Enter text" />
20+
android:hint="Enter name or ART number">
21+
22+
<com.google.android.material.textfield.TextInputEditText
23+
android:id="@+id/patient_search_edit_text"
24+
style="?attr/questionnaireMultiLineTextInputEditTextStyle"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:gravity="top" />
28+
29+
</com.google.android.material.textfield.TextInputLayout>
1330

1431
<Button
1532
android:id="@+id/submitButton"
1633
android:layout_width="match_parent"
1734
android:layout_height="wrap_content"
18-
android:text="Submit" />
35+
android:text="Search" />
1936

2037
<ProgressBar
2138
android:id="@+id/progressBar"

0 commit comments

Comments
 (0)