Skip to content

Commit

Permalink
Adds filter paramers
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Apr 19, 2021
1 parent 4d6bc6e commit 7148d18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ 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.ImageButton
import android.widget.TextView
import android.widget.Toast
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.GravityCompat
Expand Down Expand Up @@ -84,6 +83,16 @@ 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 7148d18

Please sign in to comment.