Skip to content

Commit

Permalink
fix date of birth tracing filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenreup committed Apr 3, 2024
1 parent c27f054 commit b06c830
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,40 +172,43 @@ abstract class TracingRegisterDao(
}
.map { it.resource }
.filter {
if (filters.age != null) {
val today = LocalDate.now().atStartOfDay(ZoneId.systemDefault())
when (filters.age) {
TracingAgeFilterEnum.ZERO_TO_2 -> {
val date = Date.from(today.minusYears(2L).toInstant())
it.birthDate.after(date)
}
TracingAgeFilterEnum.ZERO_TO_18 -> {
val date = Date.from(today.minusYears(18L).toInstant())
it.birthDate.after(date)
}
TracingAgeFilterEnum.PLUS_18 -> {
val date = Date.from(today.minusYears(18L).toInstant())
it.birthDate.time <= date.time
val isInRange =
if (filters.age != null) {
val today = LocalDate.now().atStartOfDay(ZoneId.systemDefault())
when (filters.age) {
TracingAgeFilterEnum.ZERO_TO_2 -> {
val date = Date.from(today.minusYears(2L).toInstant())
it.birthDate?.after(date)
}
TracingAgeFilterEnum.ZERO_TO_18 -> {
val date = Date.from(today.minusYears(18L).toInstant())
it.birthDate?.after(date)
}
TracingAgeFilterEnum.PLUS_18 -> {
val date = Date.from(today.minusYears(18L).toInstant())
it.birthDate?.before(date)
}
}
} else {
true
}
} else {
true
}

isInRange ?: false
}

val patientrefs =
val patientRefs =
patients
.map<Patient, (ReferenceParamFilterCriterion.() -> Unit)> {
return@map { value = it.referenceValue() }
}
.toTypedArray()

val tasks: List<Task> =
if (patientrefs.isNotEmpty()) {
if (patientRefs.isNotEmpty()) {
fhirEngine
.search<Task> {
filtersForValidTask()
filter(Task.SUBJECT, *patientrefs, operation = Operation.OR)
filter(Task.SUBJECT, *patientRefs, operation = Operation.OR)
}
.map { it.resource }
.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ sealed class ProfileData(open val logicalId: String, open val name: String) {
val identifier: String? = null,
val givenName: String = "",
val familyName: String = "",
val birthdate: Date,
val birthdate: Date?,
val age: String = birthdate.toAgeDisplay(),
val gender: Enumerations.AdministrativeGender,
val address: String,
Expand All @@ -109,7 +109,7 @@ sealed class ProfileData(open val logicalId: String, open val name: String) {
data class TracingProfileData(
override val logicalId: String,
override val name: String,
val birthdate: Date,
val birthdate: Date?,
val dueDate: Date?,
val address: String,
val identifier: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ package org.smartregister.fhircore.engine.ui.components.register
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.Chip
import androidx.compose.material.ExperimentalMaterialApi
Expand All @@ -49,29 +46,28 @@ const val SEARCH_HEADER_TEXT_TAG = "searchHeaderTestTag"
fun RegisterHeader(
modifier: Modifier = Modifier,
resultCount: Int,
activeFilters: List<FilterOption> = listOf()
activeFilters: List<FilterOption> = listOf(),
) {
val scrollState = rememberScrollState()
Row(
horizontalArrangement = Arrangement.spacedBy(2.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.background(color = PersonalDataBackgroundColor)
.fillMaxWidth()
.horizontalScroll(scrollState),
modifier =
modifier
.background(color = PersonalDataBackgroundColor)
.fillMaxWidth()
.horizontalScroll(scrollState),
) {
if (resultCount != -1) {
Text(
text = stringResource(id = R.string.search_result, resultCount),
color = GreyTextColor,
modifier =
modifier
.testTag(SEARCH_HEADER_TEXT_TAG)
.padding(horizontal = 16.dp, vertical = 8.dp),
modifier.testTag(SEARCH_HEADER_TEXT_TAG).padding(horizontal = 16.dp, vertical = 8.dp),
)
}
repeat(activeFilters.size) {
Chip(onClick = { /*TODO*/ }) {
Chip(onClick = { /*TODO*/}) {
Text(
text = activeFilters[it].text(),
color = GreyTextColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fun PageRegisterScreen(
iModifier = Modifier.padding(top = 32.dp)
RegisterHeader(
resultCount = if (searchText.isEmpty()) -1 else pagingItems.itemCount,
activeFilters = activeFilters
activeFilters = activeFilters,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ProfileViewDataMapper @Inject constructor(@ApplicationContext val context:
else -> "ART Number"
}

private fun Date.formatDob(): String = simpleDateFormat.format(this)
private fun Date?.formatDob(): String = if (this == null) "" else simpleDateFormat.format(this)

companion object {
const val DEFAULT_TASKS_COUNT = 5 // TODO Configure tasks to display
Expand Down

0 comments on commit b06c830

Please sign in to comment.