Skip to content

Commit

Permalink
Evaluate enable when with newly created repeated groups (#2597)
Browse files Browse the repository at this point in the history
* Update enablement evaluator

* Add test case for calculating enable when with new repeated group

* Add tests for shouldHaveNestedItemsUnderAnswers
  • Loading branch information
jingtang10 authored Jul 4, 2024
1 parent fc6e299 commit 445cf3f
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
Any?,
) -> Unit =
{ questionnaireItem, questionnaireResponseItem, answers, draftAnswer ->
// TODO(jingtang10): update the questionnaire response item pre-order list and the parent map
questionnaireResponseItem.answer = answers.toList()
when {
(questionnaireResponseItem.answer.isNotEmpty()) -> {
Expand All @@ -363,6 +362,19 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
}
if (questionnaireItem.shouldHaveNestedItemsUnderAnswers) {
questionnaireResponseItem.addNestedItemsToAnswer(questionnaireItem)

// If nested items are added to the answer, the enablement evaluator needs to be
// reinitialized in order for it to rebuild the pre-order map and parent map of
// questionnaire response items to reflect the new structure of the questionnaire response
// to correctly calculate calculate enable when statements.
enablementEvaluator =
EnablementEvaluator(
questionnaire,
questionnaireResponse,
questionnaireItemParentMap,
questionnaireLaunchContextMap,
xFhirQueryResolver,
)
}
modifiedQuestionnaireResponseItemSet.add(questionnaireResponseItem)

Expand All @@ -380,7 +392,7 @@ internal class QuestionnaireViewModel(application: Application, state: SavedStat
xFhirQueryResolver,
)

private val enablementEvaluator: EnablementEvaluator =
private var enablementEvaluator: EnablementEvaluator =
EnablementEvaluator(
questionnaire,
questionnaireResponse,
Expand Down
Loading

0 comments on commit 445cf3f

Please sign in to comment.