Skip to content

Commit

Permalink
Flyover text added for open choice view (#1625)
Browse files Browse the repository at this point in the history
* Flyover text added for open choice view

* Flyover text added for Modal Component

* test case added

* Flyover text added for open choice view

* Flyover text added for Modal Component

* test case added

* review comment addressed

* spotless check applied
  • Loading branch information
PallaviGanorkar authored Oct 12, 2022
1 parent c4cea20 commit da1b5b3
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 15 deletions.
20 changes: 20 additions & 0 deletions catalog/src/main/assets/component_modal.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
"type": "choice",
"repeats": true,
"text": "Specific health concern for today’s visit",
"item": [
{
"linkId": "1.2",
"text": "Health concern",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover"
}
]
}
}
]
}
],
"answerOption": [
{
"valueCoding": {
Expand Down
20 changes: 20 additions & 0 deletions catalog/src/main/assets/component_modal_with_validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
"repeats": true,
"text": "Specific health concern for today’s visit",
"required": true,
"item": [
{
"linkId": "1.2",
"text": "Health concern",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover"
}
]
}
}
]
}
],
"answerOption": [
{
"valueCoding": {
Expand Down
22 changes: 21 additions & 1 deletion catalog/src/main/assets/component_open_choice.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "choice",
"repeats": true,
"extension": [
Expand All @@ -19,8 +20,27 @@
}
}
],
"linkId": "1",
"text": "Do you have any pre-existing health conditions?",
"item": [
{
"linkId": "1.1",
"text": "Health conditions",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover"
}
]
}
}
]
}
],
"answerOption": [
{
"valueCoding": {
Expand Down
26 changes: 22 additions & 4 deletions catalog/src/main/assets/component_open_choice_with_validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,35 @@
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "open-choice",
"display": "Open choice"
"code": "open-choice"
}
],
"text": "Open choice"
]
}
}
],
"linkId": "1",
"text": "Do you have any pre-existing health conditions?",
"required": true,
"item": [
{
"linkId": "1.1",
"text": "Health conditions",
"type": "display",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "flyover"
}
]
}
}
]
}
],
"answerOption": [
{
"valueCoding": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ import android.widget.FrameLayout
import android.widget.TextView
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import com.google.android.fhir.datacapture.DisplayItemControlType
import com.google.android.fhir.datacapture.EXTENSION_ITEM_CONTROL_SYSTEM
import com.google.android.fhir.datacapture.EXTENSION_ITEM_CONTROL_URL
import com.google.android.fhir.datacapture.R
import com.google.android.fhir.datacapture.TestActivity
import com.google.android.fhir.datacapture.utilities.assertQuestionnaireResponseAtIndex
import com.google.android.fhir.datacapture.utilities.clickOnText
import com.google.android.fhir.datacapture.utilities.clickOnTextInDialog
import com.google.android.fhir.datacapture.utilities.endIconClickInTextInputLayout
import com.google.android.fhir.datacapture.validation.NotValidated
import com.google.android.material.textfield.TextInputLayout
import com.google.common.truth.StringSubject
import com.google.common.truth.Truth.assertThat
import org.hl7.fhir.r4.model.CodeableConcept
import org.hl7.fhir.r4.model.Coding
import org.hl7.fhir.r4.model.Extension
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.junit.Before
Expand Down Expand Up @@ -180,6 +186,44 @@ class QuestionnaireItemDialogMultiSelectViewHolderFactoryEspressoTest {
assertThat(questionnaireItemViewItem.answers).isEmpty()
}

@Test
fun bindView_setHintText() {
val questionnaireItemViewItem =
QuestionnaireItemViewItem(
answerOptions(false, "Coding 1", "Coding 2", "Coding 3", "Coding 4", "Coding 5")
.addItem(
Questionnaire.QuestionnaireItemComponent().apply {
linkId = "1.1"
text = "Select code"
type = Questionnaire.QuestionnaireItemType.DISPLAY
addExtension(
Extension()
.setUrl(EXTENSION_ITEM_CONTROL_URL)
.setValue(
CodeableConcept()
.addCoding(
Coding()
.setCode(DisplayItemControlType.FLYOVER.extensionCode)
.setSystem(EXTENSION_ITEM_CONTROL_SYSTEM)
)
)
)
}
),
responseOptions(),
validationResult = NotValidated,
answersChangedCallback = { _, _, _ -> },
)
runOnUI { viewHolder.bind(questionnaireItemViewItem) }

assertThat(
viewHolder.itemView
.findViewById<TextInputLayout>(R.id.multi_select_summary_holder)
.hint.toString()
)
.isEqualTo("Select code")
}

@Test
fun singleOption_select_clickCancel_shouldSaveNothing() {
val questionnaireItemViewItem =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.google.android.fhir.datacapture.R
import com.google.android.fhir.datacapture.common.datatype.asStringValue
import com.google.android.fhir.datacapture.displayString
import com.google.android.fhir.datacapture.itemControl
import com.google.android.fhir.datacapture.localizedFlyoverSpanned
import com.google.android.fhir.datacapture.localizedTextSpanned
import com.google.android.fhir.datacapture.validation.Invalid
import com.google.android.fhir.datacapture.validation.NotValidated
Expand Down Expand Up @@ -57,6 +58,8 @@ internal object QuestionnaireItemDialogSelectViewHolderFactory :

override fun bind(questionnaireItemViewItem: QuestionnaireItemViewItem) {
cleanupOldState()
holder.summaryHolder.hint =
questionnaireItemViewItem.questionnaireItem.localizedFlyoverSpanned
val activity =
requireNotNull(holder.header.context.tryUnwrapContext()) {
"Can only use dialog select in an AppCompatActivity context"
Expand Down Expand Up @@ -108,7 +111,8 @@ internal object QuestionnaireItemDialogSelectViewHolderFactory :
override fun displayValidationResult(validationResult: ValidationResult) {
holder.summaryHolder.error =
when (validationResult) {
is NotValidated, Valid -> null
is NotValidated,
Valid -> null
is Invalid -> validationResult.getSingleStringValidationMessage()
}
}
Expand All @@ -123,17 +127,19 @@ internal object QuestionnaireItemDialogSelectViewHolderFactory :

private fun updateAnswers(selectedOptions: SelectedOptions) {
questionnaireItemViewItem.clearAnswer()
selectedOptions.options.filter { it.selected }.map { option ->
val answer =
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
value = option.item.value
selectedOptions.options
.filter { it.selected }
.map { option ->
val answer =
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
value = option.item.value
}
if (questionnaireItemViewItem.questionnaireItem.repeats) {
questionnaireItemViewItem.addAnswer(answer)
} else {
questionnaireItemViewItem.setAnswer(answer)
}
if (questionnaireItemViewItem.questionnaireItem.repeats) {
questionnaireItemViewItem.addAnswer(answer)
} else {
questionnaireItemViewItem.setAnswer(answer)
}
}
selectedOptions.otherOptions.map { otherOption ->
val otherAnswer =
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
Expand Down

0 comments on commit da1b5b3

Please sign in to comment.