diff --git a/android/engine/build.gradle.kts b/android/engine/build.gradle.kts index bdca91c203..d3ea5dcbf9 100644 --- a/android/engine/build.gradle.kts +++ b/android/engine/build.gradle.kts @@ -185,7 +185,7 @@ dependencies { exclude(group = "com.google.android.fhir", module = "common") exclude(group = "com.google.android.fhir", module = "engine") } - api("org.smartregister:data-capture:1.1.0-preview11-SNAPSHOT") { + api("org.smartregister:data-capture:1.1.0-preview14-rc2-SNAPSHOT") { isTransitive = true exclude(group = "ca.uhn.hapi.fhir") exclude(group = "com.google.android.fhir", module = "engine") diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivity.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivity.kt index 5e2223f850..fb5da6b0b8 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivity.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivity.kt @@ -60,11 +60,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 @@ -169,23 +167,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() - ?.apply { generateMissingItems(this@QuestionnaireActivity.questionnaire) } - if (questionnaireType.isReadOnly()) { - requireNotNull(questionnaireResponse) - } else { - questionnaireResponse = - questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent) - } + questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent) } val questionnaireFragmentBuilder = @@ -525,7 +514,6 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList groupIdentifier: String? = null, formName: String, questionnaireType: QuestionnaireType = QuestionnaireType.DEFAULT, - questionnaireResponse: QuestionnaireResponse? = null, backReference: String? = null, launchContexts: Map = emptyMap(), populationResources: ArrayList = ArrayList(), @@ -538,9 +526,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( diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/util/extension/ResourceExtension.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/util/extension/ResourceExtension.kt index 6c3e47d3a5..9e7ff8d12d 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/util/extension/ResourceExtension.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/util/extension/ResourceExtension.kt @@ -19,7 +19,6 @@ package org.smartregister.fhircore.engine.util.extension import ca.uhn.fhir.context.FhirContext import ca.uhn.fhir.parser.IParser import ca.uhn.fhir.rest.gclient.ReferenceClientParam -import com.google.android.fhir.datacapture.extensions.createQuestionnaireResponseItem import com.google.android.fhir.datacapture.extensions.logicalId import java.util.Date import java.util.LinkedList @@ -139,20 +138,6 @@ fun JSONObject.updateFrom(updated: JSONObject) { keys.forEach { key -> updated.opt(key)?.run { put(key, this) } } } -fun QuestionnaireResponse.generateMissingItems(questionnaire: Questionnaire) = - questionnaire.item.generateMissingItems(this.item) - -fun List.generateMissingItems( - qrItems: MutableList, -) { - this.forEachIndexed { index, qItem -> - // generate complete hierarchy if response item missing otherwise check for nested items - if (qrItems.isEmpty() || qItem.linkId != qrItems[index].linkId) { - qrItems.add(index, qItem.createQuestionnaireResponseItem()) - } else qItem.item.generateMissingItems(qrItems[index].item) - } -} - /** * Set all questions that are not of type [Questionnaire.QuestionnaireItemType.GROUP] to readOnly if * [readOnly] is true. This also generates the correct FHIRPath population expression for each diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivityTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivityTest.kt index 0bf62d29fd..ff86945d15 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivityTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireActivityTest.kt @@ -187,7 +187,6 @@ class QuestionnaireActivityTest : ActivityRobolectricTest() { clientIdentifier = "1234", formName = "my-form", questionnaireType = QuestionnaireType.READ_ONLY, - questionnaireResponse = questionnaireResponse, populationResources = populationResources, ) Assert.assertEquals("my-form", result.getString(QuestionnaireActivity.QUESTIONNAIRE_ARG_FORM)) @@ -199,12 +198,6 @@ class QuestionnaireActivityTest : ActivityRobolectricTest() { QuestionnaireType.READ_ONLY.name, result.getString(QuestionnaireActivity.QUESTIONNAIRE_ARG_TYPE), ) - Assert.assertEquals( - FhirContext.forCached(FhirVersionEnum.R4) - .newJsonParser() - .encodeResourceToString(questionnaireResponse), - result.getString(QuestionnaireActivity.QUESTIONNAIRE_RESPONSE), - ) Assert.assertEquals( FhirContext.forCached(FhirVersionEnum.R4).newJsonParser().encodeResourceToString(patient), result.getStringArrayList(QuestionnaireActivity.QUESTIONNAIRE_POPULATION_RESOURCES)?.get(0), @@ -379,10 +372,6 @@ class QuestionnaireActivityTest : ActivityRobolectricTest() { putExtra(QuestionnaireActivity.QUESTIONNAIRE_TITLE_KEY, "Patient registration") putExtra(QuestionnaireActivity.QUESTIONNAIRE_ARG_FORM, "patient-registration") putExtra(QuestionnaireActivity.QUESTIONNAIRE_ARG_TYPE, QuestionnaireType.READ_ONLY.name) - putExtra( - QuestionnaireActivity.QUESTIONNAIRE_RESPONSE, - QuestionnaireResponse().encodeResourceToString(), - ) } val questionnaireString = parser.encodeResourceToString(Questionnaire())