diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt index acba6336e1..abccc74501 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/DefaultRepository.kt @@ -1070,14 +1070,20 @@ constructor( if (currentPage != null && pageSize != null) { val fromIndex = currentPage * pageSize val toIndex = (currentPage + 1) * pageSize - with(searchResults.subList(fromIndex, min(toIndex, searchResults.size))) { - mapResourceToRepositoryResourceData( - relatedResourcesConfig = relatedResourcesConfig, - configComputedRuleValues = configComputedRuleValues, - secondaryResourceConfigs = secondaryResourceConfigs, - filterActiveResources = filterActiveResources, - baseResourceConfig = baseResourceConfig, - ) + val maxSublistIndex = min(toIndex, searchResults.size) + + if (fromIndex < maxSublistIndex) { + with(searchResults.subList(fromIndex, maxSublistIndex)) { + mapResourceToRepositoryResourceData( + relatedResourcesConfig = relatedResourcesConfig, + configComputedRuleValues = configComputedRuleValues, + secondaryResourceConfigs = secondaryResourceConfigs, + filterActiveResources = filterActiveResources, + baseResourceConfig = baseResourceConfig, + ) + } + } else { + emptyList() } } else { searchResults.mapResourceToRepositoryResourceData( diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/data/local/register/RegisterRepositoryTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/data/local/register/RegisterRepositoryTest.kt index 1dc0027224..142cebf0f6 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/data/local/register/RegisterRepositoryTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/data/local/register/RegisterRepositoryTest.kt @@ -183,6 +183,50 @@ class RegisterRepositoryTest : RobolectricTest() { } } + @Ignore("Refactor this test") + @Test + fun countRegisterDataWithParamsAndRelatedEntityLocationFilter() { + runTest { + val paramsList = + arrayListOf( + ActionParameter( + key = "paramsName", + paramType = ActionParameterType.PARAMDATA, + value = "testing1", + dataType = DataType.STRING, + linkId = null, + ), + ActionParameter( + key = "paramName2", + paramType = ActionParameterType.PARAMDATA, + value = "testing2", + dataType = DataType.STRING, + linkId = null, + ), + ) + paramsList + .asSequence() + .filter { it.paramType == ActionParameterType.PARAMDATA && it.value.isNotEmpty() } + .associate { it.key to it.value } + val paramsMap = emptyMap() + val searchSlot = slot() + every { + registerRepository.retrieveRegisterConfiguration(PATIENT_REGISTER, emptyMap()) + } returns + RegisterConfiguration( + appId = "app", + id = PATIENT_REGISTER, + fhirResource = fhirResourceConfig(), + filterDataByRelatedEntityLocation = true, + ) + coEvery { fhirEngine.count(capture(searchSlot)) } returns 20 + val recordsCount = + registerRepository.countRegisterData(registerId = PATIENT_REGISTER, paramsMap = paramsMap) + Assert.assertEquals(ResourceType.Group, searchSlot.captured.type) + Assert.assertEquals(20, recordsCount) + } + } + @Test fun testLoadRegisterDataWithForwardAndReverseIncludedResources() = runTest(timeout = 90.seconds) { diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index cc793b5c46..0cc0cac3ef 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -49,7 +49,7 @@ kotlinx-coroutines = "1.9.0" kotlinx-serialization-json = "1.6.0" kt3k-coveralls-ver="2.12.0" ktlint = "0.50.0" -kujaku-library = "0.10.6-2-SNAPSHOT" +kujaku-library = "0.10.7-SNAPSHOT" kujaku-mapbox-sdk-turf = "7.2.0" leakcanary-android = "2.10" lifecycle= "2.8.5" diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/TopScreenSection.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/TopScreenSection.kt index acb6571cc7..58ef9685aa 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/TopScreenSection.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/TopScreenSection.kt @@ -237,9 +237,7 @@ fun TopScreenSection( when { !searchQuery.isBlank() -> { IconButton( - onClick = { - onSearchTextChanged(SearchQuery.emptyText, performSearchOnValueChanged) - }, + onClick = { onSearchTextChanged(SearchQuery.emptyText, true) }, modifier = modifier.testTag(TRAILING_ICON_BUTTON_TEST_TAG), ) { Icon(