From ef355784a084a56d09976dc5011de77c11724592 Mon Sep 17 00:00:00 2001 From: qaziabubakar-vd Date: Tue, 12 Sep 2023 15:48:54 +0500 Subject: [PATCH 1/6] Add syncing of Basic resource in ConfigurationRegistry Add basic resource in bundle when CQL is executed for zeir growth monitoring --- .../engine/configuration/ConfigurationRegistry.kt | 1 + .../ui/questionnaire/QuestionnaireViewModel.kt | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt index f1686bccce..e247f0d76c 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/configuration/ConfigurationRegistry.kt @@ -382,6 +382,7 @@ constructor( ResourceType.PlanDefinition.name, ResourceType.Library.name, ResourceType.Measure.name, + ResourceType.Basic.name, ) } .forEach { resourceGroup -> diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 07d96e5dc6..89179486d5 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -37,6 +37,7 @@ import javax.inject.Inject import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import org.hl7.fhir.r4.context.IWorkerContext +import org.hl7.fhir.r4.model.Basic import org.hl7.fhir.r4.model.Bundle import org.hl7.fhir.r4.model.Group import org.hl7.fhir.r4.model.IdType @@ -568,9 +569,17 @@ constructor( .all { it is Valid || it is NotValidated } suspend fun executeCql(subject: Resource, bundle: Bundle, questionnaire: Questionnaire) { - questionnaire.cqfLibraryIds().forEach { + questionnaire.cqfLibraryIds().forEach { libraryId -> + if (libraryId == "223758") { //Resource id for Library that calculates Z-score in ZEIR application + //Adding 4 basic resources which contain the Data needed for Z-score calculation + val basicResourceIds = listOf("223754", "223755", "223756", "223757") + basicResourceIds.forEach { resourceId -> + val basicResource = defaultRepository.loadResource(resourceId) as Basic? + bundle.addEntry(Bundle.BundleEntryComponent().setResource(basicResource)) + } + } if (subject.resourceType == ResourceType.Patient) { - libraryEvaluator.runCqlLibrary(it, subject as Patient, bundle) + libraryEvaluator.runCqlLibrary(libraryId, subject as Patient, bundle) } } } From 8ab75ef10283d11c0c7ddf80fa748dfede883b3f Mon Sep 17 00:00:00 2001 From: qaziabubakar-vd Date: Tue, 12 Sep 2023 16:31:41 +0500 Subject: [PATCH 2/6] spotless apply --- .../quest/ui/questionnaire/QuestionnaireViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 89179486d5..92d535ab81 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -570,8 +570,10 @@ constructor( suspend fun executeCql(subject: Resource, bundle: Bundle, questionnaire: Questionnaire) { questionnaire.cqfLibraryIds().forEach { libraryId -> - if (libraryId == "223758") { //Resource id for Library that calculates Z-score in ZEIR application - //Adding 4 basic resources which contain the Data needed for Z-score calculation + if ( + libraryId == "223758" + ) { // Resource id for Library that calculates Z-score in ZEIR application + // Adding 4 basic resources which contain the Data needed for Z-score calculation val basicResourceIds = listOf("223754", "223755", "223756", "223757") basicResourceIds.forEach { resourceId -> val basicResource = defaultRepository.loadResource(resourceId) as Basic? From 7cb236074448d63e85e65280e12e0babb997dd88 Mon Sep 17 00:00:00 2001 From: qaziabubakar-vd Date: Tue, 12 Sep 2023 17:10:34 +0500 Subject: [PATCH 3/6] Update QuestionnaireViewModel to run executeCql on IO Thread --- .../ui/questionnaire/QuestionnaireViewModel.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 92d535ab81..0aed9c8952 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -34,8 +34,10 @@ import dagger.hilt.android.lifecycle.HiltViewModel import java.util.Date import java.util.UUID import javax.inject.Inject +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.hl7.fhir.r4.context.IWorkerContext import org.hl7.fhir.r4.model.Basic import org.hl7.fhir.r4.model.Bundle @@ -234,11 +236,14 @@ constructor( questionnaireConfig = questionnaireConfig, ) - executeCql( - subject = subject, - bundle = newBundle, - questionnaire = questionnaire, - ) + withContext(Dispatchers.IO) { + executeCql( + subject = subject, + bundle = newBundle, + questionnaire = questionnaire, + ) + } + fhirCarePlanGenerator.conditionallyUpdateResourceStatus( questionnaireConfig = questionnaireConfig, subject = subject, From 5044a871f7318be78ffdfffe36bdd19a088fb3a9 Mon Sep 17 00:00:00 2001 From: qaziabubakar-vd Date: Wed, 13 Sep 2023 15:02:26 +0500 Subject: [PATCH 4/6] Add Todo and referenced the issue to keep track --- .../fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 0aed9c8952..8c89b6fff1 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -575,6 +575,7 @@ constructor( suspend fun executeCql(subject: Resource, bundle: Bundle, questionnaire: Questionnaire) { questionnaire.cqfLibraryIds().forEach { libraryId -> + // TODO Refactor/Remove as per the issue: https://github.com/opensrp/fhircore/issues/2747 if ( libraryId == "223758" ) { // Resource id for Library that calculates Z-score in ZEIR application From 0e55ab3614dd82b6743f64e49302bccd468368fd Mon Sep 17 00:00:00 2001 From: qaziabubakar-vd Date: Wed, 13 Sep 2023 15:04:00 +0500 Subject: [PATCH 5/6] update Dispatchers.IO to use 'dispatcherProvider.io()' --- .../fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 8c89b6fff1..4de153ed61 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -236,7 +236,7 @@ constructor( questionnaireConfig = questionnaireConfig, ) - withContext(Dispatchers.IO) { + withContext(dispatcherProvider.io()) { executeCql( subject = subject, bundle = newBundle, From 66eba1c22d0bd654ec936a1827224f67b6e64677 Mon Sep 17 00:00:00 2001 From: qaziabubakar-vd Date: Thu, 14 Sep 2023 11:19:11 +0500 Subject: [PATCH 6/6] Spotless apply --- .../fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 4de153ed61..4a374d2e01 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -34,7 +34,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel import java.util.Date import java.util.UUID import javax.inject.Inject -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import kotlinx.coroutines.withContext