Skip to content

Commit

Permalink
Clear text to re-generate it from SDK (#3008)
Browse files Browse the repository at this point in the history
* Clear text to re-generate the text with HTML from SDK

* spotlessApply

* spotlessApply

* Update android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt

---------

Co-authored-by: Peter Lubell-Doughtie <[email protected]>
  • Loading branch information
FikriMilano and pld authored Jan 24, 2024
1 parent d35bd17 commit d7cabeb
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.util.extension

import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemComponent

/** Clears the item text in the [QuestionnaireResponse]. */
fun QuestionnaireResponse.clearText() {
this.item.clearText()
}

/** Clears the text of items in the current list. */
private fun List<QuestionnaireResponseItemComponent>.clearText() {
this.forEach { itemToClear ->
itemToClear.text = null
if (itemToClear.hasItem()) {
itemToClear.item.clearText()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2021-2024 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.engine.util.extension

import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class QuestionnaireResponseExtensionTest {
private lateinit var questionnaireResponse: QuestionnaireResponse

@Before
fun setup() {
questionnaireResponse =
QuestionnaireResponse().apply {
addItem().apply {
linkId = "1"
text = "Text 1"
addItem().apply {
linkId = "2"
text = "Text 2"
}
}
}
}

@Test
fun testClearText() {
questionnaireResponse.clearText()
val item1 = questionnaireResponse.itemFirstRep
Assert.assertNull(item1.text)
val item2 = item1.itemFirstRep
Assert.assertNull(item2.text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.smartregister.fhircore.engine.domain.model.isEditable
import org.smartregister.fhircore.engine.domain.model.isReadOnly
import org.smartregister.fhircore.engine.ui.base.AlertDialogue
import org.smartregister.fhircore.engine.ui.base.BaseMultiLanguageActivity
import org.smartregister.fhircore.engine.util.extension.clearText
import org.smartregister.fhircore.engine.util.extension.encodeResourceToString
import org.smartregister.fhircore.engine.util.extension.parcelable
import org.smartregister.fhircore.engine.util.extension.parcelableArrayList
Expand Down Expand Up @@ -203,7 +204,11 @@ class QuestionnaireActivity : BaseMultiLanguageActivity() {
)

val questionnaireResponse =
QuestionnaireResponse().apply { item = latestQuestionnaireResponse?.item }
QuestionnaireResponse().apply {
item = latestQuestionnaireResponse?.item
// Clearing the text prompts the SDK to re-process the content, which includes HTML
clearText()
}

if (viewModel.validateQuestionnaireResponse(questionnaire, questionnaireResponse, this)) {
questionnaireFragmentBuilder.setQuestionnaireResponse(questionnaireResponse.json())
Expand Down

0 comments on commit d7cabeb

Please sign in to comment.