Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading questionnaire ANR #112

Draft
wants to merge 6 commits into
base: mwcore-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

object Deps {
object sdk_versions {
const val compile_sdk = 34
const val compile_sdk = 35
const val min_sdk = 26
const val target_sdk = 34
const val target_sdk = 35
}

const val build_tool_version = "30.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ data class AddressData(
}
}

internal fun Patient.toPatientItem(configuration: ApplicationConfiguration): PatientItem {
internal suspend fun Patient.toPatientItem(configuration: ApplicationConfiguration): PatientItem {
val phone = if (hasTelecom()) telecom[0].value else "N/A"
val isActive = active
val gender = if (hasGenderElement()) genderElement.valueAsString else ""
Expand Down
1 change: 0 additions & 1 deletion android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ dependencies {
implementation("androidx.cardview:cardview:1.0.0")
implementation("joda-time:joda-time:2.10.14")
implementation("androidx.paging:paging-runtime-ktx:3.3.0")
implementation("com.github.bumptech.glide:glide:4.16.0")
implementation("id.zelory:compressor:3.0.1")

implementation(group = "javax.xml.stream", name = "stax-api", version = "1.0-2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import java.util.Base64
import javax.inject.Inject
import javax.inject.Singleton
import javax.net.ssl.SSLHandshakeException
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.data.remote.auth.OAuthService
import org.smartregister.fhircore.engine.data.remote.model.response.OAuthResponse
Expand Down Expand Up @@ -264,6 +267,14 @@ constructor(

fun sessionActive(): Boolean = isTokenActive(getAccessToken())

suspend fun isSessionActive(): Boolean =
withContext(dispatcherProvider.io()) {
suspendCoroutine {
val active = sessionActive()
it.resume(active)
}
}

fun invalidateSession(onSessionInvalidated: () -> Unit) {
findAccount()?.let { account ->
accountManager.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ package org.smartregister.fhircore.engine.domain.util
*/
interface DataMapper<InputModel, OutputModel> {

fun transformInputToOutputModel(inputModel: InputModel): OutputModel
suspend fun transformInputToOutputModel(inputModel: InputModel): OutputModel
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import com.google.android.fhir.get
import java.util.Date
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.CarePlan
import org.hl7.fhir.r4.model.Encounter.EncounterStatus
Expand Down Expand Up @@ -89,7 +91,9 @@ constructor(val fhirEngine: FhirEngine, val transformSupportServices: TransformS
)
}

fhirPathEngine.evaluateToBoolean(input, null, subject, it.expression.expression)
withContext(Dispatchers.Default) {
fhirPathEngine.evaluateToBoolean(input, null, subject, it.expression.expression)
}
}
) {
val source =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenResumed
import androidx.lifecycle.withResumed
import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.context.FhirVersionEnum
import com.google.android.fhir.datacapture.QuestionnaireFragment
Expand All @@ -43,7 +43,6 @@ import com.google.android.fhir.datacapture.validation.Invalid
import com.google.android.fhir.datacapture.validation.QuestionnaireResponseValidator
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlin.system.measureTimeMillis
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.hl7.fhir.r4.model.Encounter
Expand All @@ -60,11 +59,9 @@ import org.smartregister.fhircore.engine.ui.base.AlertDialogue.showProgressAlert
import org.smartregister.fhircore.engine.ui.base.BaseMultiLanguageActivity
import org.smartregister.fhircore.engine.util.DefaultDispatcherProvider
import org.smartregister.fhircore.engine.util.extension.FieldType
import org.smartregister.fhircore.engine.util.extension.decodeResourceFromString
import org.smartregister.fhircore.engine.util.extension.distinctifyLinkId
import org.smartregister.fhircore.engine.util.extension.encodeResourceToString
import org.smartregister.fhircore.engine.util.extension.find
import org.smartregister.fhircore.engine.util.extension.generateMissingItems
import org.smartregister.fhircore.engine.util.extension.showToast
import timber.log.Timber

Expand Down Expand Up @@ -131,7 +128,7 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
}

updateViews()
fragment.whenResumed { loadProgress.dismiss() }
fragment.withResumed { loadProgress.dismiss() }
}
}

Expand Down Expand Up @@ -169,23 +166,14 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
private suspend fun renderFragment() {
tracer.startTrace(QUESTIONNAIRE_TRACE)
val questionnaireString = parser.encodeResourceToString(questionnaire)
var questionnaireResponse: QuestionnaireResponse?
val questionnaireResponse: QuestionnaireResponse
if (clientIdentifier != null) {
setBarcode(questionnaire, clientIdentifier!!, true)
questionnaireResponse =
questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent)
} else {
questionnaireResponse =
intent
.getStringExtra(QUESTIONNAIRE_RESPONSE)
?.decodeResourceFromString<QuestionnaireResponse>()
?.apply { generateMissingItems([email protected]) }
if (questionnaireType.isReadOnly()) {
requireNotNull(questionnaireResponse)
} else {
questionnaireResponse =
questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent)
}
questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent)
}

val questionnaireFragmentBuilder =
Expand Down Expand Up @@ -294,9 +282,6 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList

questionnaireConfig = resultPair.first
questionnaire = resultPair.second

val t = measureTimeMillis { populateInitialValues(questionnaire) }
Timber.d("populateInitialValues took $t ms : cachedxxx")
}
.onFailure {
Timber.e(it)
Expand Down Expand Up @@ -408,8 +393,6 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
)
}

open fun populateInitialValues(questionnaire: Questionnaire) = Unit

open fun postSaveSuccessful(
questionnaireResponse: QuestionnaireResponse,
extras: List<Resource>? = null,
Expand Down Expand Up @@ -525,7 +508,6 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
groupIdentifier: String? = null,
formName: String,
questionnaireType: QuestionnaireType = QuestionnaireType.DEFAULT,
questionnaireResponse: QuestionnaireResponse? = null,
backReference: String? = null,
launchContexts: Map<String, Resource> = emptyMap(),
populationResources: ArrayList<out Resource> = ArrayList(),
Expand All @@ -538,9 +520,6 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
Pair(QUESTIONNAIRE_BACK_REFERENCE_KEY, backReference),
)
.apply {
questionnaireResponse?.let {
putString(QUESTIONNAIRE_RESPONSE, it.encodeResourceToString())
}
val resourcesList = populationResources.map { it.encodeResourceToString() }
if (resourcesList.isNotEmpty()) {
putStringArrayList(
Expand Down
Loading
Loading