Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeating initial values fix #2016

Merged
merged 8 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,11 @@ private fun Questionnaire.QuestionnaireItemComponent.createQuestionnaireResponse
)
}

return mutableListOf(
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
value = initial[0].value
return initial
.map {
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply { value = it.value }
}
)
.toMutableList()
}

internal val Questionnaire.QuestionnaireItemComponent.answerExpression: Expression?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class QuestionnaireViewModelTest {
}

@Test
fun `should set the first of multiple initial values`() {
fun `should set all of multiple initial values`() {
val questionnaire =
Questionnaire().apply {
id = "a-questionnaire"
Expand Down Expand Up @@ -415,6 +415,11 @@ class QuestionnaireViewModelTest {
value = BooleanType(true)
}
)
addAnswer(
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
value = BooleanType(true)
}
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,78 @@ class MoreQuestionnaireItemComponentsTest {
assertThat(questionnaireItem.entryFormat).isNull()
}

@Test
fun `createQuestionnaireResponseItem should set answer for non repeating question initial value`() {
val question =
Questionnaire.QuestionnaireItemComponent(
StringType("phone"),
Enumeration(
Questionnaire.QuestionnaireItemTypeEnumFactory(),
Questionnaire.QuestionnaireItemType.STRING
)
)
.apply {
initial = listOf(Questionnaire.QuestionnaireItemInitialComponent(StringType("000011111")))
}

val responseItem = question.createQuestionnaireResponseItem()

assertThat(responseItem.answer.map { it.value.primitiveValue() }).containsExactly("000011111")
}

@Test
fun `createQuestionnaireResponseItem should set answer for repeating question initial values`() {
val question =
Questionnaire.QuestionnaireItemComponent(
StringType("phones"),
Enumeration(
Questionnaire.QuestionnaireItemTypeEnumFactory(),
Questionnaire.QuestionnaireItemType.STRING
)
)
.apply {
repeats = true
initial =
listOf(
Questionnaire.QuestionnaireItemInitialComponent(StringType("000011111")),
Questionnaire.QuestionnaireItemInitialComponent(StringType("000022222"))
)
}

val responseItem = question.createQuestionnaireResponseItem()

assertThat(responseItem.answer.map { it.value.primitiveValue() })
.containsExactly("000011111", "000022222")
}

@Test
fun `createQuestionnaireResponseItem should throw exception for non repeating question with multiple initial values `() {
val question =
Questionnaire.QuestionnaireItemComponent(
StringType("phones"),
Enumeration(
Questionnaire.QuestionnaireItemTypeEnumFactory(),
Questionnaire.QuestionnaireItemType.STRING
)
)
.apply {
initial =
listOf(
Questionnaire.QuestionnaireItemInitialComponent(StringType("000011111")),
Questionnaire.QuestionnaireItemInitialComponent(StringType("000022222"))
)
}
assertThrows(IllegalArgumentException::class.java) {
question.createQuestionnaireResponseItem()
}
.run {
assertThat(this.message)
.isEqualTo(
"Questionnaire item ${question.linkId} can only have multiple initial values for repeating items. See rule que-13 at https://www.hl7.org/fhir/questionnaire-definitions.html#Questionnaire.item.initial."
)
}
}

@Test
fun `fetchBitmapFromUrl() should return Bitmap from url`() {
val attachment =
Expand Down