Skip to content

Commit

Permalink
Adds search parameters with and / or logic (#57)
Browse files Browse the repository at this point in the history
* Adds search parameters with and / or logic

* Uses inline functions for search query

* Adds filter paramers

* Update Spotless fixes

* Remove unused menu items'
  • Loading branch information
rkodev authored Apr 20, 2021
1 parent 382530f commit eb690f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,6 +87,19 @@ class PatientListActivity : AppCompatActivity() {
syncResources()
}

findViewById<EditText>(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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ class PatientListViewModel(application: Application, private val fhirEngine: Fhi
return liveObservations
}

fun getSearchResults() {
fun getSearchResults(query: String? = null) {
viewModelScope.launch {
val searchResults: List<Patient> =
fhirEngine.search {
filter(Patient.ADDRESS_CITY) {
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
Expand Down

0 comments on commit eb690f8

Please sign in to comment.