Skip to content

Commit

Permalink
Main | Performance improvements (#3586)
Browse files Browse the repository at this point in the history
* Test single transaction save for questionnaires

* Caching questionnaires and their SM

* spotless ran

* Fetch search results in batches for when loading all

* Fix infinite loop for mocks with FhirEngine#search in tests

* [WIP] FhirEngine search integration tests

* spotless ran

* updated tests

* WIP tests updated

* resolved feedback

* spotess ran

* Upgrade FHIR SDK depenencies ⬆️

* Upragde SDC library

* Replace JWT token parser library

* Fix CQL Content Test

* Fix unit tests ✅

* Refactor to remove Dispatch Provider

* Fix unit test ✅

* Refactor Knowledge Manager Resources Persistance

* Refactor CQL Content tests

* Fix AppSettingModel unit tests  ✅

* Refactor Cancel previous worflow to use native commands

* Upgrade CI API level to 34

* Clean up Translations

* Fix measure reporting

* Fix Workflow Configuration

* Fix QuestionnaireViewModel unit tests ✅

* Clean up WorkManager after running unit tests

* Remove skyscreamer test dependency

* Fix build 💚

* Clean up gradle dependencies configuration

* Move measure reporting evaluation to BG thread

* Fix MeasureReportRepositoryTest

* Fix MeasureReportRepositoryTest

* Fix MeasureReportViewModel unit tests ✅

Co-authored-by: Roy Munge <[email protected]>

* Fix Measure Reporting

* Migrate Engine and Workflow libraries
- Fix Measure reporting
- Optimization PRs added

* Refactor register filter with REL tags

Signed-off-by: Elly Kitoto <[email protected]>

* Update default pageSize to 15

Signed-off-by: Elly Kitoto <[email protected]>

* Fix loading locations on map

Signed-off-by: Elly Kitoto <[email protected]>

* Refactor data structure used on base resource search results

Signed-off-by: Elly Kitoto <[email protected]>

* Process saveCredentials in the background

* Refactor code

Signed-off-by: Elly Kitoto <[email protected]>

* Delete unnecessary code

Signed-off-by: Elly Kitoto <[email protected]>

* Refactor retrieving related resources

Signed-off-by: Elly Kitoto <[email protected]>

* Optimize data structures and perform parallel processing

Signed-off-by: Elly Kitoto <[email protected]>

* Use recent version of rules engine library

Signed-off-by: Elly Kitoto <[email protected]>

* Refactor implementation for decoding image resources to bitmap

Signed-off-by: Elly Kitoto <[email protected]>

* Fix related resource count on register

Signed-off-by: Elly Kitoto <[email protected]>

* Fix loading related resources

This fix ensures all the nested related resources are loaded too.

Signed-off-by: Elly Kitoto <[email protected]>

* Batch related resource queries

Signed-off-by: Elly Kitoto <[email protected]>

* Map resources to RepositoryResourceData with async map

Signed-off-by: Elly Kitoto <[email protected]>

* Make infinite scroll the default register behavior

Signed-off-by: Elly Kitoto <[email protected]>

* Disable automatic intialization of emoji2

A lot of memory was used in heap during the allocation. Emojis are not
used in the app so intializing them automatically is unnecessary.

Signed-off-by: Elly Kitoto <[email protected]>

* Run spotlessApply

Signed-off-by: Elly Kitoto <[email protected]>

* Update tests for displaying images (#3506)

* Refactor load images tests for different views.

Signed-off-by: Lentumunai-Mark <[email protected]>

* Remove unutilized imports.

Signed-off-by: Lentumunai-Mark <[email protected]>

* Run spotlessApply

Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Lentumunai-Mark <[email protected]>

* Refactor load images tests for different views.

Signed-off-by: Lentumunai-Mark <[email protected]>

* Resolve conflicts.

Signed-off-by: Lentumunai-Mark <[email protected]>

---------

Signed-off-by: Lentumunai-Mark <[email protected]>
Signed-off-by: Elly Kitoto <[email protected]>

* Refactor navigation to GeowidgetLauncher workflow

Signed-off-by: Elly Kitoto <[email protected]>

* Use dipatcher IO to handle questionnaire submission

* Hotfix space_asterisk

* Upgrade engine to v1.0.0-preview14.1-SNAPSHOT

* Update infiniteScroll to not be default

* Update sdk versions

* Update integration Faker to fix error

* Revert upgrade on workflow and knowledge libs

* Upgrade FHIR SDK depenencies ⬆️

* Upragde SDC library

* Replace JWT token parser library

* Fix CQL Content Test

* Fix unit tests ✅

* Refactor to remove Dispatch Provider

* Fix unit test ✅

* Refactor Knowledge Manager Resources Persistance

* Refactor CQL Content tests

* Fix AppSettingModel unit tests  ✅

* Refactor Cancel previous worflow to use native commands

* Upgrade CI API level to 34

* Clean up Translations

* Fix measure reporting

* Fix Workflow Configuration

* Fix QuestionnaireViewModel unit tests ✅

* Clean up WorkManager after running unit tests

* Remove skyscreamer test dependency

* Fix build 💚

* Clean up gradle dependencies configuration

* Move measure reporting evaluation to BG thread

* Fix MeasureReportRepositoryTest

* Fix MeasureReportRepositoryTest

* Fix MeasureReportViewModel unit tests ✅

Co-authored-by: Roy Munge <[email protected]>

* Fix Measure Reporting

* Migrate Engine and Workflow libraries
- Fix Measure reporting
- Optimization PRs added

* Update Workflow library
- Fix build
- Fix reporting NPE

* Fix evaluate Population Measure

* Update SDC snapshot to 14.1

* Remove unrecommended forced portrait format

* Refactor from using deprecated KnowledgeManager methods loadResources

* Clean up TOML catalog file

* Revert Knowledge Manager and Workflow Library Upgrades

* Display symbol instead of unicode

* Refactor usage of FHIR JSONParser to support concurrency

* Update FHIR SDK library versions

* Geowidget configuration
- Update Kujaku library version
- Revert offline map downloads configuration via Kujaku network change receiver

* Fix build 💚
- Fix code coverage reporting

* SDK Engine to RC3

* Fix build

* Fix failing ci tests

* Update data-capture lib to v1.1.0-preview14-rc2-SNAPSHOT

* Fix errors in tests

* 🐛 Readd the eusm mg and bi flavour

* 🔥 Remove unnecessary files

* 🍻 Removing double flavour defination

* Fix failing QuestionnaireViewModel tests

* rename content cache to util.helper.CacheHelper

* only 2 dots

* remove unused cache var

* use assign if null operator

* format fixes

* remove left over cache

* update signature to require resourcetype

* fix test call and remove dup test

* refactor with setup and teardown

* Revert "Caching questionnaires and their SM"

This reverts commit 8129afd.

* Clean up 🗑

* Clean up caching to reset to main brach state

---------

Signed-off-by: Elly Kitoto <[email protected]>
Signed-off-by: Lentumunai-Mark <[email protected]>
Co-authored-by: L≡ZRS <[email protected]>
Co-authored-by: Aurangzaib Umer <[email protected]>
Co-authored-by: aurangzaibumer <[email protected]>
Co-authored-by: Martin Ndegwa <[email protected]>
Co-authored-by: Roy Munge <[email protected]>
Co-authored-by: Elly Kitoto <[email protected]>
Co-authored-by: Simon Njoroge <[email protected]>
Co-authored-by: Lentumunai Mark <[email protected]>
Co-authored-by: fikrimilano <[email protected]>
Co-authored-by: Simon Kiarie <[email protected]>
Co-authored-by: Peter Lubell-Doughtie <[email protected]>
  • Loading branch information
12 people authored Nov 18, 2024
1 parent f5e64b8 commit 512c010
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 227 deletions.
5 changes: 3 additions & 2 deletions android/buildSrc/src/main/kotlin/BuildConfigs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ object BuildConfigs {
const val compileSdk = 34
const val targetSdk = 34
const val versionCode = 11
const val versionName = "2.0.0"
const val versionName = "2.0.1"
const val applicationId = "org.smartregister.opensrp"
const val jvmToolchain = 17
const val kotlinCompilerExtensionVersion = "1.5.8"
const val jacocoVersion ="0.8.11"
const val ktLintVersion = "0.49.0"
const val enableUnitTestCoverage = true
const val enableAndroidTestCoverage = false
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ constructor(
fhirEngine.update(resource)
}

suspend fun applyDbTransaction(block: suspend () -> Unit) {
fhirEngine.withTransaction { block.invoke() }
}

suspend fun loadManagingEntity(group: Group) =
group.managingEntity?.let { reference ->
fhirEngine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import java.util.Base64
import javax.inject.Inject
import javax.inject.Singleton
import javax.net.ssl.SSLHandshakeException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.data.remote.auth.OAuthService
Expand Down Expand Up @@ -215,8 +217,11 @@ constructor(
addAccountExplicitly(newAccount, oAuthResponse.refreshToken, null)
setAuthToken(newAccount, AUTH_TOKEN_TYPE, oAuthResponse.accessToken)
}

// Save credentials
secureSharedPreference.saveCredentials(username, password)
CoroutineScope(dispatcherProvider.io()).launch {
secureSharedPreference.saveCredentials(username, password)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.RequestBody.Companion.toRequestBody
import org.apache.commons.lang3.StringUtils
import org.hl7.fhir.r4.model.Binary
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.Composition
import org.hl7.fhir.r4.model.ResourceType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,73 +195,93 @@ constructor(
context = context,
)

saveExtractedResources(
bundle = bundle,
questionnaire = questionnaire,
questionnaireConfig = questionnaireConfig,
questionnaireResponse = currentQuestionnaireResponse,
context = context,
defaultRepository.applyDbTransaction {
performSave(
bundle,
questionnaire,
questionnaireConfig,
currentQuestionnaireResponse,
context,
actionParameters,
)
}

val idTypes =
bundle.entry?.map { IdType(it.resource.resourceType.name, it.resource.logicalId) }
?: emptyList()

onSuccessfulSubmission(
idTypes,
currentQuestionnaireResponse,
)
}
}

updateResourcesLastUpdatedProperty(actionParameters)
private suspend fun performSave(
bundle: Bundle,
questionnaire: Questionnaire,
questionnaireConfig: QuestionnaireConfig,
currentQuestionnaireResponse: QuestionnaireResponse,
context: Context,
actionParameters: List<ActionParameter>,
) {
saveExtractedResources(
bundle = bundle,
questionnaire = questionnaire,
questionnaireConfig = questionnaireConfig,
questionnaireResponse = currentQuestionnaireResponse,
context = context,
)

// Important to load subject resource to retrieve ID (as reference) correctly
val subjectIdType: IdType? =
if (currentQuestionnaireResponse.subject.reference.isNullOrEmpty()) {
null
} else {
IdType(currentQuestionnaireResponse.subject.reference)
}
updateResourcesLastUpdatedProperty(actionParameters)

if (subjectIdType != null) {
val subject =
loadResource(
ResourceType.valueOf(subjectIdType.resourceType),
subjectIdType.idPart,
)
// Important to load subject resource to retrieve ID (as reference) correctly
val subjectIdType: IdType? =
if (currentQuestionnaireResponse.subject.reference.isNullOrEmpty()) {
null
} else {
IdType(currentQuestionnaireResponse.subject.reference)
}

if (subject != null && !questionnaireConfig.isReadOnly()) {
val newBundle = bundle.copyBundle(currentQuestionnaireResponse)
if (subjectIdType != null) {
val subject =
loadResource(
ResourceType.valueOf(subjectIdType.resourceType),
subjectIdType.idPart,
)

val extractedResources = newBundle.entry.map { it.resource }
validateWithFhirValidator(*extractedResources.toTypedArray())
if (subject != null && !questionnaireConfig.isReadOnly()) {
val newBundle = bundle.copyBundle(currentQuestionnaireResponse)

generateCarePlan(
subject = subject,
bundle = newBundle,
questionnaireConfig = questionnaireConfig,
)
val extractedResources = newBundle.entry.map { it.resource }
validateWithFhirValidator(*extractedResources.toTypedArray())

withContext(dispatcherProvider.io()) {
executeCql(
subject = subject,
bundle = newBundle,
questionnaire = questionnaire,
questionnaireConfig = questionnaireConfig,
)
}
generateCarePlan(
subject = subject,
bundle = newBundle,
questionnaireConfig = questionnaireConfig,
)

fhirCarePlanGenerator.conditionallyUpdateResourceStatus(
questionnaireConfig = questionnaireConfig,
withContext(dispatcherProvider.io()) {
executeCql(
subject = subject,
bundle = newBundle,
questionnaire = questionnaire,
questionnaireConfig = questionnaireConfig,
)
}
}

softDeleteResources(questionnaireConfig)

retireUsedQuestionnaireUniqueId(questionnaireConfig, currentQuestionnaireResponse)
fhirCarePlanGenerator.conditionallyUpdateResourceStatus(
questionnaireConfig = questionnaireConfig,
subject = subject,
bundle = newBundle,
)
}
}

val idTypes =
bundle.entry?.map { IdType(it.resource.resourceType.name, it.resource.logicalId) }
?: emptyList()
softDeleteResources(questionnaireConfig)

onSuccessfulSubmission(
idTypes,
currentQuestionnaireResponse,
)
}
retireUsedQuestionnaireUniqueId(questionnaireConfig, currentQuestionnaireResponse)
}

fun validateWithFhirValidator(vararg resource: Resource) {
Expand Down Expand Up @@ -642,27 +662,25 @@ constructor(
): Bundle =
kotlin
.runCatching {
withContext(dispatcherProvider.default()) {
if (extractByStructureMap) {
ResourceMapper.extract(
questionnaire = questionnaire,
questionnaireResponse = questionnaireResponse,
structureMapExtractionContext =
StructureMapExtractionContext(
transformSupportServices = transformSupportServices,
structureMapProvider = { structureMapUrl: String?, _: IWorkerContext ->
structureMapUrl?.substringAfterLast("/")?.let { structureMapId ->
defaultRepository.loadResourceFromCache<StructureMap>(structureMapId)
}
},
),
)
} else {
ResourceMapper.extract(
questionnaire = questionnaire,
questionnaireResponse = questionnaireResponse,
)
}
if (extractByStructureMap) {
ResourceMapper.extract(
questionnaire = questionnaire,
questionnaireResponse = questionnaireResponse,
structureMapExtractionContext =
StructureMapExtractionContext(
transformSupportServices = transformSupportServices,
structureMapProvider = { structureMapUrl: String?, _: IWorkerContext ->
structureMapUrl?.substringAfterLast("/")?.let { structureMapId ->
defaultRepository.loadResourceFromCache<StructureMap>(structureMapId)
}
},
),
)
} else {
ResourceMapper.extract(
questionnaire = questionnaire,
questionnaireResponse = questionnaireResponse,
)
}
}
.onFailure { exception ->
Expand Down
Loading

0 comments on commit 512c010

Please sign in to comment.