diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemExtensions.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemExtensions.kt index c096be22e9..2f4c07eec3 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemExtensions.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemExtensions.kt @@ -19,6 +19,8 @@ package com.google.android.fhir.datacapture import com.google.fhir.r4.core.Questionnaire internal const val ITEM_CONTROL_DROP_DOWN = "drop-down" +internal const val ITEM_CONTROL_RADIO_BUTTON = "radio-button" + internal const val EXTENSION_ITEM_CONTROL_URL = "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl" internal const val EXTENSION_ITEM_CONTROL_SYSTEM = @@ -35,6 +37,7 @@ internal val Questionnaire.Item.itemControl: String? }?.code?.value ) { ITEM_CONTROL_DROP_DOWN -> ITEM_CONTROL_DROP_DOWN + ITEM_CONTROL_RADIO_BUTTON -> ITEM_CONTROL_RADIO_BUTTON else -> null } } diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt index d7c18714a4..e65f0bcc09 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt @@ -106,6 +106,8 @@ internal class QuestionnaireItemAdapter : QuestionnaireItemViewHolderType { if (questionnaireItem.itemControl == ITEM_CONTROL_DROP_DOWN) { return QuestionnaireItemViewHolderType.DROP_DOWN + } else if (questionnaireItem.itemControl == ITEM_CONTROL_RADIO_BUTTON) { + return QuestionnaireItemViewHolderType.RADIO_GROUP } else if ( questionnaireItem.answerOptionCount >= MINIMUM_NUMBER_OF_ANSWER_OPTIONS_FOR_DROP_DOWN) { diff --git a/datacapture/src/main/res/layout/questionnaire_item_drop_down_view.xml b/datacapture/src/main/res/layout/questionnaire_item_drop_down_view.xml index 511938828c..6241caadae 100644 --- a/datacapture/src/main/res/layout/questionnaire_item_drop_down_view.xml +++ b/datacapture/src/main/res/layout/questionnaire_item_drop_down_view.xml @@ -14,7 +14,7 @@ { repeat(QuestionnaireItemAdapter.MINIMUM_NUMBER_OF_ANSWER_OPTIONS_FOR_DROP_DOWN) { @@ -281,7 +281,31 @@ class QuestionnaireItemAdapterTest { } @Test - fun getItemViewType_choiceItemType_shouldReturnDropDownViewHolderTypeWithExtension() { + fun getItemViewType_choiceItemType_itemControlExtensionWithRadioButton_shouldReturnRadioGroupViewHolder() { // ktlint-disable max-line-length + val answerOptions = Iterable { + iterator { + repeat(QuestionnaireItemAdapter.MINIMUM_NUMBER_OF_ANSWER_OPTIONS_FOR_DROP_DOWN) { + yield( + Questionnaire.Item.AnswerOption.newBuilder() + .setValue( + Questionnaire.Item.AnswerOption.ValueX.newBuilder() + .setCoding( + Coding.newBuilder() + .setCode( + Code.newBuilder() + .setValue("test-code") + ) + .setDisplay( + String.newBuilder() + .setValue("Test Code") + ) + ) + ) + .build() + ) + } + } + } val questionnaireItemAdapter = QuestionnaireItemAdapter() questionnaireItemAdapter.submitList( listOf( @@ -291,6 +315,7 @@ class QuestionnaireItemAdapterTest { Questionnaire.Item.TypeCode.newBuilder() .setValue(QuestionnaireItemTypeCode.Value.CHOICE) ) + .addAllAnswerOption(answerOptions) .addExtension( Extension.newBuilder() .setUrl( @@ -305,7 +330,59 @@ class QuestionnaireItemAdapterTest { Coding.newBuilder() .setCode( Code.newBuilder() - .setValue("drop-down") + .setValue(ITEM_CONTROL_RADIO_BUTTON) + ) + .setDisplay( + String.newBuilder() + .setValue("Radio Button") + ) + .setSystem( + Uri.newBuilder() + .setValue( + EXTENSION_ITEM_CONTROL_SYSTEM + ) + ) + ) + ) + ) + ) + .build(), + QuestionnaireResponse.Item.newBuilder() + ) {} + ) + ) + + assertThat(questionnaireItemAdapter.getItemViewType(0)) + .isEqualTo(QuestionnaireItemViewHolderType.RADIO_GROUP.value + ) + } + + @Test + fun getItemViewType_choiceItemType_itemControlExtensionWithDropDown_shouldReturnDropDownViewHolderType() { // ktlint-disable max-line-length + val questionnaireItemAdapter = QuestionnaireItemAdapter() + questionnaireItemAdapter.submitList( + listOf( + QuestionnaireItemViewItem( + Questionnaire.Item.newBuilder() + .setType( + Questionnaire.Item.TypeCode.newBuilder() + .setValue(QuestionnaireItemTypeCode.Value.CHOICE) + ) + .addExtension( + Extension.newBuilder() + .setUrl( + Uri.newBuilder() + .setValue(EXTENSION_ITEM_CONTROL_URL) + ) + .setValue( + Extension.ValueX.newBuilder() + .setCodeableConcept( + CodeableConcept.newBuilder() + .addCoding( + Coding.newBuilder() + .setCode( + Code.newBuilder() + .setValue(ITEM_CONTROL_DROP_DOWN) ) .setDisplay( String.newBuilder() @@ -329,7 +406,7 @@ class QuestionnaireItemAdapterTest { assertThat(questionnaireItemAdapter.getItemViewType(0)) .isEqualTo(QuestionnaireItemViewHolderType.DROP_DOWN.value - ) + ) } // TODO: test errors thrown for unsupported types