Skip to content

Commit

Permalink
Fix nested answer perceived as not having any answer (#3682)
Browse files Browse the repository at this point in the history
  • Loading branch information
FikriMilano authored Jan 15, 2025
1 parent a902176 commit e13ebde
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import org.smartregister.fhircore.engine.task.FhirCarePlanGenerator
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.allItems
import org.smartregister.fhircore.engine.util.extension.appendOrganizationInfo
import org.smartregister.fhircore.engine.util.extension.appendPractitionerInfo
import org.smartregister.fhircore.engine.util.extension.appendRelatedEntityLocation
Expand Down Expand Up @@ -711,19 +712,7 @@ constructor(
questionnaireResponse: QuestionnaireResponse,
questionnaireConfig: QuestionnaireConfig,
) {
val hasPages = questionnaireResponse.item.any { it.hasItem() }
val questionnaireHasAnswer =
questionnaireResponse.item.any {
if (!hasPages) {
it.answer.any { answerComponent -> answerComponent.hasValue() }
} else {
questionnaireResponse.item.any { page ->
page.item.any { pageItem ->
pageItem.answer.any { answerComponent -> answerComponent.hasValue() }
}
}
}
}
val hasAnswer = questionnaireResponse.allItems.any { it.hasAnswer() }
questionnaireResponse.questionnaire =
questionnaireConfig.id.asReference(ResourceType.Questionnaire).reference
if (
Expand All @@ -735,7 +724,7 @@ constructor(
questionnaireConfig.resourceType!!,
)
}
if (questionnaireHasAnswer) {
if (hasAnswer) {
questionnaireResponse.status = QuestionnaireResponse.QuestionnaireResponseStatus.INPROGRESS
defaultRepository.addOrUpdate(
addMandatoryTags = true,
Expand Down

0 comments on commit e13ebde

Please sign in to comment.