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 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fc5e93f
populate initial with initialExpression result collection
parthfloyd Dec 6, 2024
ac017b3
handle invariant rules for initialExpression
parthfloyd Dec 7, 2024
f158600
convert evaluatedExpressionResult to questionnaireItem.type
parthfloyd Dec 8, 2024
bd7a356
updated answerOptions in test to match initialExpressions' result
parthfloyd Dec 8, 2024
7e80304
added rule url in check message for initial value on group or display…
parthfloyd Dec 12, 2024
0af4de4
added test for invariant rule que-8 & codings without system match in…
parthfloyd Dec 12, 2024
2c0cf8c
Merge branch 'master' into fix-populate-initial-values
parthfloyd Dec 13, 2024
df13034
Merge branch 'master' into fix-populate-initial-values
parthfloyd Dec 23, 2024
d5c4074
Merge branch 'master' into fix-populate-initial-values
parthfloyd Jan 7, 2025
b4e1709
- refactored populateInitialValue
parthfloyd Jan 9, 2025
488e66d
Merge remote-tracking branch 'origin/fix-populate-initial-values' int…
parthfloyd Jan 9, 2025
80694fd
- integrated tests for populateInitialValues
parthfloyd Jan 9, 2025
a31f7b6
- (spotless fix) ResourceMapperTest.kt
parthfloyd Jan 9, 2025
e078ccd
Merge branch 'master' into fix-populate-initial-values
parthfloyd Jan 9, 2025
067c563
- (feedback) added test & refactored code to use variables.
parthfloyd Jan 21, 2025
f1ffc0b
Merge branch 'master' into fix-populate-initial-values
parthfloyd Jan 22, 2025
5c749e0
- (refactor) updated multiline comment
parthfloyd Jan 29, 2025
252f8d8
Merge remote-tracking branch 'origin/fix-populate-initial-values' int…
parthfloyd Jan 29, 2025
3c3846e
Merge branch 'master' into fix-populate-initial-values
parthfloyd Jan 29, 2025
dbb7225
Merge branch 'master' into fix-populate-initial-values
parthfloyd Jan 29, 2025
72f41a2
Merge branch 'master' into fix-populate-initial-values
parthfloyd Jan 31, 2025
3394792
Merge branch 'master' into fix-populate-initial-values
parthfloyd Feb 6, 2025
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
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Google LLC
* Copyright 2022-2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ package com.google.android.fhir.datacapture.mapping
import com.google.android.fhir.datacapture.extensions.createQuestionnaireResponseItem
import com.google.android.fhir.datacapture.extensions.filterByCodeInNameExtension
import com.google.android.fhir.datacapture.extensions.initialExpression
import com.google.android.fhir.datacapture.extensions.initialSelected
import com.google.android.fhir.datacapture.extensions.logicalId
import com.google.android.fhir.datacapture.extensions.questionnaireLaunchContexts
import com.google.android.fhir.datacapture.extensions.targetStructureMap
Expand Down Expand Up @@ -248,22 +249,57 @@ object ResourceMapper {
"QuestionnaireItem item is not allowed to have both initial.value and initial expression. See rule at http://build.fhir.org/ig/HL7/sdc/expressions.html#initialExpression."
}

// Initial values can't be specified for groups or display items
check(
!(questionnaireItem.type == Questionnaire.QuestionnaireItemType.GROUP ||
questionnaireItem.type == Questionnaire.QuestionnaireItemType.DISPLAY) ||
(questionnaireItem.initial.isEmpty() && questionnaireItem.initialExpression == null),
) {
"QuestionnaireItem item is not allowed to have initial value or initial expression for groups or display items. See rule at http://build.fhir.org/ig/HL7/sdc/expressions.html#initialExpression."
}

questionnaireItem.initialExpression
?.let {
evaluateToBase(
questionnaireResponse = null,
questionnaireResponseItem = null,
expression = it.expression,
contextMap = launchContexts,
)
.firstOrNull()
questionnaireResponse = null,
questionnaireResponseItem = null,
expression = it.expression,
contextMap = launchContexts,
)
}
?.let {
// Set initial value for the questionnaire item. Questionnaire items should not have both
// initial value and initial expression.
val value = it.asExpectedType(questionnaireItem.type)
questionnaireItem.initial =
mutableListOf(Questionnaire.QuestionnaireItemInitialComponent().setValue(value))
// Set initial value for the questionnaire item.
if (it.isEmpty()) return@let

// If questionnaireItem.repeats is false only first value is selected from initialExpression
// result set
val evaluatedExpressionResult =
if (questionnaireItem.repeats) {
it.map { it.asExpectedType(questionnaireItem.type) }
} else {
listOf(it.first().asExpectedType(questionnaireItem.type))
}

// For answer options, the initialSelected extension is used to highlight initial values.
// Note: If the initial expression evaluates to 1, 2, 3, 4, 5, but only 3 answer options (1,
// 2, 3) exist,
// then 4 and 5 will be ignored. These values are not added as additional options, nor would
// it make sense to do so.
// This behavior ensures the answer options remain consistent with the defined set.
parthfloyd marked this conversation as resolved.
Show resolved Hide resolved
if (questionnaireItem.answerOption.isNotEmpty()) {
parthfloyd marked this conversation as resolved.
Show resolved Hide resolved
questionnaireItem.answerOption.forEach { answerOption ->
answerOption.initialSelected =
evaluatedExpressionResult.any { answerOption.value.equalsDeep(it) }
parthfloyd marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
questionnaireItem.initial =
evaluatedExpressionResult.map {
Questionnaire.QuestionnaireItemInitialComponent()
.setValue(
it,
)
}
}
}

populateInitialValues(questionnaireItem.item, launchContexts)
Expand Down
Loading
Loading