Skip to content

Commit

Permalink
Update data-capture to custom version 1.1.0-preview14-rc2-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Sep 25, 2024
1 parent 2f9454e commit 1825213
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
2 changes: 1 addition & 1 deletion android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<QuestionnaireResponse>()
?.apply { generateMissingItems(this@QuestionnaireActivity.questionnaire) }
if (questionnaireType.isReadOnly()) {
requireNotNull(questionnaireResponse)
} else {
questionnaireResponse =
questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent)
}
questionnaireViewModel.generateQuestionnaireResponse(questionnaire, intent)
}

val questionnaireFragmentBuilder =
Expand Down Expand Up @@ -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<String, Resource> = emptyMap(),
populationResources: ArrayList<out Resource> = ArrayList(),
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Questionnaire.QuestionnaireItemComponent>.generateMissingItems(
qrItems: MutableList<QuestionnaireResponse.QuestionnaireResponseItemComponent>,
) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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),
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 1825213

Please sign in to comment.