Skip to content

Commit

Permalink
Merge branch 'fix-register-filters' of github.com:opensrp/fhircore in…
Browse files Browse the repository at this point in the history
…to fix-register-filters
  • Loading branch information
dubdabasoduba committed Sep 19, 2024
2 parents 1629429 + d5d1616 commit 87f412a
Show file tree
Hide file tree
Showing 78 changed files with 1,538 additions and 819 deletions.
4 changes: 1 addition & 3 deletions android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ dependencies {
api(libs.timber)
api(libs.converter.gson)
api(libs.json.path)
api(libs.easy.rules.jexl) {
exclude(group = "commons-logging", module = "commons-logging")
}
api(libs.easy.rules.jexl) { exclude(group = "commons-logging", module = "commons-logging") }
api(libs.data.capture) {
isTransitive = true
exclude(group = "ca.uhn.hapi.fhir")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.util.extension

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.filters.MediumTest
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.FhirEngineConfiguration
import com.google.android.fhir.FhirEngineProvider
import com.google.android.fhir.search.search
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.hl7.fhir.r4.model.Patient
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test

@MediumTest
class FhirEngineExtensionKtTest {

private val context = ApplicationProvider.getApplicationContext<Context>()
private lateinit var fhirEngine: FhirEngine

@Before
fun setUp() {
FhirEngineProvider.init(FhirEngineConfiguration(testMode = true))
fhirEngine = FhirEngineProvider.getInstance(context)

val patients = (0..1000).map { Patient().apply { id = "test-patient-$it" } }
val questionnaires = (0..3).map { Questionnaire().apply { id = "test-questionnaire-$it" } }
runBlocking { fhirEngine.create(*patients.toTypedArray(), *questionnaires.toTypedArray()) }
}

@After
fun tearDown() {
runBlocking { fhirEngine.clearDatabase() }
FhirEngineProvider.cleanup()
}

@Test
fun test_search_time_searches_sequentially_and_short_running_query_waits() {
val fetchedResources = mutableListOf<Resource>()
runBlocking {
launch {
val patients = fhirEngine.search<Patient> {}.map { it.resource }
fetchedResources += patients
}

launch {
val questionnaires = fhirEngine.search<Questionnaire> {}.map { it.resource }
fetchedResources += questionnaires
}
}
val indexOfResultOfShortQuery =
fetchedResources.indexOfFirst { it.resourceType == ResourceType.Questionnaire }
val indexOfResultOfLongQuery =
fetchedResources.indexOfFirst { it.resourceType == ResourceType.Patient }
Assert.assertTrue(indexOfResultOfShortQuery > indexOfResultOfLongQuery)
}

@Test
fun test_batchedSearch_returns_short_running_query_and_long_running_does_not_block() {
val fetchedResources = mutableListOf<Resource>()
runBlocking {
launch {
val patients = fhirEngine.batchedSearch<Patient> {}.map { it.resource }
fetchedResources += patients
}

launch {
val questionnaires = fhirEngine.search<Questionnaire> {}
fetchedResources + questionnaires
}
}

val indexOfResultOfShortQuery =
fetchedResources.indexOfFirst { it.resourceType == ResourceType.Questionnaire }
val indexOfResultOfLongQuery =
fetchedResources.indexOfFirst { it.resourceType == ResourceType.Patient }
Assert.assertTrue(indexOfResultOfShortQuery < indexOfResultOfLongQuery)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ import com.google.android.fhir.get
import com.google.android.fhir.knowledge.KnowledgeManager
import com.google.android.fhir.sync.download.ResourceSearchParams
import dagger.hilt.android.qualifiers.ApplicationContext
import java.io.File
import java.io.FileNotFoundException
import java.io.InputStreamReader
import java.net.UnknownHostException
import java.util.Locale
import java.util.PropertyResourceBundle
import java.util.ResourceBundle
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import okhttp3.RequestBody.Companion.toRequestBody
Expand Down Expand Up @@ -71,15 +80,6 @@ import org.smartregister.fhircore.engine.util.extension.updateLastUpdated
import org.smartregister.fhircore.engine.util.helper.LocalizationHelper
import retrofit2.HttpException
import timber.log.Timber
import java.io.File
import java.io.FileNotFoundException
import java.io.InputStreamReader
import java.net.UnknownHostException
import java.util.Locale
import java.util.PropertyResourceBundle
import java.util.ResourceBundle
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ConfigurationRegistry
Expand Down Expand Up @@ -378,14 +378,18 @@ constructor(
context.assets.list(String.format(BASE_CONFIG_PATH, appId))?.onEach {
if (!supportedFileExtensions.contains(it.fileExtension)) {
filesQueue.addLast(String.format(BASE_CONFIG_PATH, appId) + "/$it")
} else configFiles.add(String.format(BASE_CONFIG_PATH, appId) + "/$it")
} else {
configFiles.add(String.format(BASE_CONFIG_PATH, appId) + "/$it")
}
}
while (filesQueue.isNotEmpty()) {
val currentPath = filesQueue.removeFirst()
context.assets.list(currentPath)?.onEach {
if (!supportedFileExtensions.contains(it.fileExtension)) {
filesQueue.addLast("$currentPath/$it")
} else configFiles.add("$currentPath/$it")
} else {
configFiles.add("$currentPath/$it")
}
}
}
return configFiles
Expand Down Expand Up @@ -507,13 +511,14 @@ constructor(
val resultBundle =
if (isNonProxy()) {
fhirResourceDataSourceGetBundle(resourceType, resourceIdList)
} else
} else {
fhirResourceDataSource.post(
requestBody =
generateRequestBundle(resourceType, resourceIdList)
.encodeResourceToString()
.toRequestBody(NetworkModule.JSON_MEDIA_TYPE),
)
}

processResultBundleEntries(resultBundle.entry)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ enum class LinkIdType : Parcelable {
READ_ONLY,
BARCODE,
LOCATION,
IDENTIFIER,
PREPOPULATION_EXCLUSION,
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import kotlinx.serialization.Serializable
import org.smartregister.fhircore.engine.domain.model.ActionConfig
import org.smartregister.fhircore.engine.util.extension.interpolate


const val ICON_TYPE_LOCAL = "local"
const val ICON_TYPE_REMOTE = "remote"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data class RegisterConfiguration(
val filterDataByRelatedEntityLocation: Boolean = false,
val topScreenSection: TopScreenSectionConfig? = null,
val onSearchByQrSingleResultActions: List<ActionConfig>? = null,
val infiniteScroll: Boolean = true
val infiniteScroll: Boolean = false,
) : Configuration() {
val onSearchByQrSingleResultValidActions =
onSearchByQrSingleResultActions?.filter { it.trigger == ActionTrigger.ON_SEARCH_SINGLE_RESULT }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ data class ButtonProperties(
val interpolated = this.status.interpolate(computedValuesMap)
return if (ServiceStatus.values().map { it.name }.contains(interpolated)) {
ServiceStatus.valueOf(interpolated)
} else ServiceStatus.UPCOMING
} else {
ServiceStatus.UPCOMING
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ fun List<ViewProperties>.retrieveListProperties(): List<ListProperties> {
ViewType.COLUMN -> viewPropertiesQueue.addAll((properties as ColumnProperties).children)
ViewType.ROW -> viewPropertiesQueue.addAll((properties as RowProperties).children)
ViewType.CARD -> viewPropertiesQueue.addAll((properties as CardViewProperties).content)
ViewType.LIST ->
viewPropertiesQueue.addAll((properties as ListProperties).registerCard.views)
ViewType.LIST -> viewPropertiesQueue.addAll((properties as ListProperties).registerCard.views)
else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ object ViewPropertiesSerializer :
): DeserializationStrategy<ViewProperties> {
val jsonObject = element.jsonObject
val viewType = jsonObject[VIEW_TYPE]?.jsonPrimitive?.content
require(viewType != null && ViewType.entries.toTypedArray().contains(ViewType.valueOf(viewType))) {
require(
viewType != null && ViewType.entries.toTypedArray().contains(ViewType.valueOf(viewType)),
) {
"""Ensure that supported `viewType` property is included in your register view properties configuration.
Supported types: ${ViewType.entries.toTypedArray()}
Parsed JSON: $jsonObject
Expand Down
Loading

0 comments on commit 87f412a

Please sign in to comment.