diff --git a/app/src/main/java/org/smartregister/fhircore/activity/PatientListActivity.kt b/app/src/main/java/org/smartregister/fhircore/activity/PatientListActivity.kt index 8da99697ea..afc329f9e3 100644 --- a/app/src/main/java/org/smartregister/fhircore/activity/PatientListActivity.kt +++ b/app/src/main/java/org/smartregister/fhircore/activity/PatientListActivity.kt @@ -18,9 +18,12 @@ package org.smartregister.fhircore.activity import android.content.Intent import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher import android.util.Log import android.view.View import android.widget.Button +import android.widget.EditText import android.widget.ImageButton import android.widget.TextView import android.widget.Toast @@ -84,6 +87,19 @@ class PatientListActivity : AppCompatActivity() { syncResources() } + findViewById(R.id.edit_text_search) + .addTextChangedListener( + object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + patientListViewModel.getSearchResults(s?.toString()) + } + + override fun afterTextChanged(s: Editable?) {} + } + ) + setupDrawerContent() } diff --git a/app/src/main/java/org/smartregister/fhircore/viewmodel/PatientListViewModel.kt b/app/src/main/java/org/smartregister/fhircore/viewmodel/PatientListViewModel.kt index 9dc44c8093..7a21913ee4 100644 --- a/app/src/main/java/org/smartregister/fhircore/viewmodel/PatientListViewModel.kt +++ b/app/src/main/java/org/smartregister/fhircore/viewmodel/PatientListViewModel.kt @@ -57,7 +57,7 @@ class PatientListViewModel(application: Application, private val fhirEngine: Fhi return liveObservations } - fun getSearchResults() { + fun getSearchResults(query: String? = null) { viewModelScope.launch { val searchResults: List = fhirEngine.search { @@ -65,6 +65,14 @@ class PatientListViewModel(application: Application, private val fhirEngine: Fhi prefix = ParamPrefixEnum.EQUAL value = "NAIROBI" } + apply { + if (query?.isNotBlank() == true) { + filter(Patient.FAMILY) { + prefix = ParamPrefixEnum.EQUAL + value = query.trim() + } + } + } sort(Patient.GIVEN, Order.ASCENDING) count = 100 from = 0