Skip to content

Commit

Permalink
library-evaluator performance
Browse files Browse the repository at this point in the history
  • Loading branch information
maimoonak committed Jan 28, 2022
1 parent 29048fa commit 27de37a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,23 @@ class LibraryEvaluator @Inject constructor() {
private var libEvaluator: LibraryEvaluator? = null
private val bundleLinks = BundleLinks("", null, true, BundleTypeEnum.COLLECTION)
val fhirTypeConverter = FhirTypeConverterFactory().create(fhirContext.version.version)
val cqlFhirParametersConverter by lazy {
CqlFhirParametersConverter(fhirContext, adapterFactory, fhirTypeConverter)
lateinit var cqlFhirParametersConverter: CqlFhirParametersConverter
lateinit var fhirModelResolver: R4FhirModelResolverExt
lateinit var modelManager: ModelManager
var initialized = false

fun initialize() {
if (initialized) return

cqlFhirParametersConverter =
CqlFhirParametersConverter(fhirContext, adapterFactory, fhirTypeConverter)

fhirModelResolver = R4FhirModelResolverExt()
modelManager = ModelManager()

initialized = true
}
val fhirModelResolver by lazy { R4FhirModelResolverExt() }

/**
* This method loads configurations for CQL evaluation
* @param libraryResources Fhir resource type Library
Expand Down Expand Up @@ -206,6 +219,8 @@ class LibraryEvaluator @Inject constructor() {
repository: DefaultRepository,
outputLog: Boolean = false
): List<String> {
initialize()

val library = repository.fhirEngine.load(org.hl7.fhir.r4.model.Library::class.java, libraryId)

val helpers =
Expand Down Expand Up @@ -305,7 +320,7 @@ class LibraryEvaluator @Inject constructor() {

cqlEvaluator =
CqlEvaluator(
LibraryLoaderExt(ModelManager(), listOf(libraryProvider)),
LibraryLoaderExt(modelManager, listOf(libraryProvider)),
mapOf("http://hl7.org/fhir" to CompositeDataProvider(fhirModelResolver, retrieveProvider)),
terminologyProvider
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList

val loadProgress = showProgressAlert(this, R.string.loading)

lifecycleScope.launch { questionnaireViewModel.libraryEvaluator.initialize() }

clientIdentifier = intent.getStringExtra(QUESTIONNAIRE_ARG_PATIENT_KEY)
immunizationId = intent.getStringExtra(ADVERSE_EVENT_IMMUNIZATION_ITEM_KEY)

Expand Down
4 changes: 2 additions & 2 deletions android/engine/src/main/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<string name="loading">Inapakia</string>
<string name="error_loading_form">Hitilafu kounyesha fomu</string>
<string name="error_saving_form">Hitilafu imetokea, haiwezi kuhifadhi fomu</string>
<string name="replace_photo">Replace photo</string>
<string name="take_photo">Take photo</string>
<string name="replace_photo">Badilisha picha</string>
<string name="take_photo">Piga picha</string>
<string name="app_logo">Nembo ya programu</string>
<string name="powered_by">Inatumia</string>
<string name="already_fully_vaccinated">Hawezi kupokea dozi nyingine. Tayari amechanjwa kikamilifu</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import org.smartregister.fhircore.engine.configuration.Configuration

@Serializable
@SerialName("questionnaire")
data class QuestionnaireNavigationAction(val form: String? = null, val readOnly: Boolean? = null) : NavigationAction()
data class QuestionnaireNavigationAction(val form: String? = null, val readOnly: Boolean? = null) :
NavigationAction()

@Serializable
class NavigationConfiguration(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 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.quest.configuration.view

import androidx.compose.runtime.Stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ fun PatientItem.genderFull(): String {
data class QuestResultItem(
val source: Pair<QuestionnaireResponse, Questionnaire>,
val data: List<List<AdditionalData>>
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import org.hl7.fhir.r4.model.Enumerations
import org.hl7.fhir.r4.model.Resource
import org.hl7.fhir.r4.model.ResourceType
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.util.extension.asYyyyMmDd
import org.smartregister.fhircore.engine.util.extension.asYyyyMmDdHHmmss
import org.smartregister.fhircore.quest.configuration.view.Code
import org.smartregister.fhircore.quest.configuration.view.Filter
import org.smartregister.fhircore.quest.configuration.view.PatientRegisterRowViewConfiguration
Expand All @@ -54,11 +52,7 @@ suspend fun loadAdditionalData(
val conditions =
getSearchResults<Condition>("Patient/$patientId", Condition.SUBJECT, filter, fhirEngine)

val sortedByDescending =
conditions.maxByOrNull {
it.meta.lastUpdated?.asYyyyMmDdHHmmss()
?: it.recordedDate?.asYyyyMmDd()?.plus(" 23:60:60") ?: ""
}
val sortedByDescending = conditions.maxByOrNull { it.recordedDate }

sortedByDescending?.category?.forEach { cc ->
cc.coding.firstOrNull { c -> c.code == filter.valueCoding!!.code }?.let {
Expand Down

0 comments on commit 27de37a

Please sign in to comment.