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

populate initial with initialExpression result collection #2751

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

parthfloyd
Copy link
Collaborator

@parthfloyd parthfloyd commented Dec 6, 2024

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #2750

Description
Updated populateInitialValue() function in ResourceMapper.kt of the SDC module to populate questionnaireItem.initial with values of collection instead of just the first value of the collection.

Alternative(s) considered
None | Looking forward to feedback

Type
Bug fix

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@parthfloyd parthfloyd requested a review from a team as a code owner December 6, 2024 06:31
@parthfloyd parthfloyd requested a review from jingtang10 December 6, 2024 06:31
@LZRS
Copy link
Collaborator

LZRS commented Dec 6, 2024

To support multiple initially selected options from the dropdown, not quite sure populating the Questionnaire.item.initial would work.
From this Questionnaire.item.initial invariant

que-11 Rule If one or more answerOption is present, initial cannot be present. Use answerOption.initialSelected instead answerOption.empty() or initial.empty()

I would suggest maybe using Questionnaire.item.answerOption.initialSelected instead

@parthfloyd
Copy link
Collaborator Author

@LZRS Thank you so much for your feedback!
I've pushed code & now it's conforming with the invariant rules. Please feel free if any changes or optimizations are required in the code.

Invariant:

que-8 Rule Initial values can't be specified for groups or display items

que-13 Rule Can only have multiple initial values for repeating items

que-11 Rule If one or more answerOption is present, initial cannot be present. Use answerOption.initialSelected instead

cc: @jingtang10 , @icrc-jofrancisco

Copy link
Collaborator

@LZRS LZRS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@parthfloyd parthfloyd requested a review from jingtang10 January 9, 2025 10:07
Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good test cases! Thanks @parthfloyd!

A few comments below

@@ -2973,6 +2979,414 @@ class ResourceMapperTest {
)
}

@Test
fun `populate() should fail with IllegalStateException when QuestionnaireItem of group or display item has a initial value`():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you split this into 2 smaller test cases one for group one for display item?

In each questionnaire just include a single questionnaire item.

In general, for tests, it's much better to keep tests small and focused. So when a test fails from the test name you'll immediately figure out what's the problem, instead of having to debug.

val questionnaireResponse =
ResourceMapper.populate(questionnaire, mapOf("observations" to observationBundle))

assertThat((questionnaireResponse.item[0].answer[0].value as Coding).code)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract questionnaireResponse.item[0].answer[0].value as a variable. or use kotlin's with:

with(questionnaireResponse.item[0].answer[0].value) {
  assert(this.code...)
  assert(this.system...)
}

Comment on lines +3191 to +3218
val observation1 =
Observation().apply {
status = Observation.ObservationStatus.FINAL
value =
CodeableConcept().apply {
coding =
mutableListOf(
Coding().apply {
code = "correct-code-val"
display = "correct-display-val"
},
)
}
}
val observation2 =
Observation().apply {
status = Observation.ObservationStatus.FINAL
value =
CodeableConcept().apply {
coding =
mutableListOf(
Coding().apply {
code = "correct-code-val"
display = "correct-display-val"
},
)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the significance of having 2 observations in this test case? it seems that's not really being tested?

is the point you would collapse the 2 choices? would it be better to give the second observation a different coding and show that the first one is chosen?

Comment on lines +3326 to +3333
assertThat((questionnaireResponse.item[0].answer[0].value as Coding).code)
.isEqualTo("correct-code-val")
assertThat((questionnaireResponse.item[0].answer[0].value as Coding).display)
.isEqualTo("correct-display-val")
assertThat((questionnaireResponse.item[0].answer[1].value as Coding).code)
.isEqualTo("correct2-code-val")
assertThat((questionnaireResponse.item[0].answer[1].value as Coding).display)
.isEqualTo("correct2-display-val")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly extract local variables instead of repeating

}

@Test
fun `populate() should select a single initial answer for non repeating question without answerOption`() =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think a missing test case here is that if there's no answer option but the expression evaluates to multiple values?

you should test in that case only the first value is used. right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SDC library] initialExpression with multiple values as result rendering incorrectly.
3 participants