Skip to content

Commit

Permalink
Add mimeType extension support (#1678)
Browse files Browse the repository at this point in the history
* Implement mimeType extension

* Add tests for mimeType

* Trigger CI

* Trigger CI checks

* Trigger CI checks

* Trigger CI checks
  • Loading branch information
FikriMilano authored Dec 5, 2022
1 parent c55276d commit 51a7057
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 51a7057

Please sign in to comment.