diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt index f6a98a72ed..a4740c0bc1 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponents.kt @@ -175,6 +175,17 @@ internal val Questionnaire.QuestionnaireItemComponent.choiceOrientation: ChoiceO return ChoiceOrientationTypes.values().firstOrNull { it.extensionCode == code } } +internal const val EXTENSION_MIME_TYPE = "http://hl7.org/fhir/StructureDefinition/mimeType" + +/** Identifies the kinds of attachment allowed to be sent for an element. */ +internal val Questionnaire.QuestionnaireItemComponent.mimeTypes: List + get() { + return extension + .filter { it.url == EXTENSION_MIME_TYPE } + .map { (it.value as CodeType).valueAsString } + .filter { !it.isNullOrEmpty() } + } + /** UI controls relevant to rendering questionnaire items. */ internal enum class DisplayItemControlType(val extensionCode: String) { FLYOVER("flyover"), diff --git a/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt b/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt index ca4ab3248d..0d10efbece 100644 --- a/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt +++ b/datacapture/src/test/java/com/google/android/fhir/datacapture/MoreQuestionnaireItemComponentsTest.kt @@ -462,6 +462,31 @@ class MoreQuestionnaireItemComponentsTest { assertThat(questionnaire.choiceOrientation).isNull() } + @Test + fun mimeTypes_shouldReturnMimeTypes() { + val questionnaire = + Questionnaire.QuestionnaireItemComponent().apply { + addExtension(EXTENSION_MIME_TYPE, CodeType("image/jpg")) + addExtension(EXTENSION_MIME_TYPE, CodeType("application/pdf")) + } + assertThat(questionnaire.mimeTypes).isEqualTo(listOf("image/jpg", "application/pdf")) + } + + @Test + fun mimeTypes_missingMimeType_shouldReturnEmpty() { + val questionnaire = + Questionnaire.QuestionnaireItemComponent().apply { + addExtension(EXTENSION_MIME_TYPE, CodeType("")) + } + assertThat(questionnaire.mimeTypes).isEmpty() + } + + @Test + fun mimeTypes_missingExtension_shouldReturnNull() { + val questionnaire = Questionnaire.QuestionnaireItemComponent() + assertThat(questionnaire.mimeTypes).isEmpty() + } + @Test fun localizedTextSpanned_noText_shouldReturnNull() { assertThat(Questionnaire.QuestionnaireItemComponent().localizedTextSpanned).isNull()