QuestionnaireViewItem

data class QuestionnaireViewItem(val questionnaireItem: Questionnaire.QuestionnaireItemComponent, questionnaireResponseItem: QuestionnaireResponse.QuestionnaireResponseItemComponent, val validationResult: ValidationResult, answersChangedCallback: suspend (Questionnaire.QuestionnaireItemComponent, QuestionnaireResponse.QuestionnaireResponseItemComponent, List<QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent>, Any?) -> Unit, val enabledAnswerOptions: List<Questionnaire.QuestionnaireItemAnswerOptionComponent> = questionnaireItem.answerOption.ifEmpty { emptyList() }, val minAnswerValue: Type? = questionnaireItem.minValue, val maxAnswerValue: Type? = questionnaireItem.maxValue, val draftAnswer: Any? = null, val enabledDisplayItems: List<Questionnaire.QuestionnaireItemComponent> = emptyList(), val questionViewTextConfiguration: QuestionTextConfiguration = QuestionTextConfiguration(), val isHelpCardOpen: Boolean = questionnaireItem.isHelpCode, val helpCardStateChangedCallback: (Boolean, QuestionnaireResponse.QuestionnaireResponseItemComponent) -> Unit = { _, _ -> })

Data item for QuestionnaireItemViewHolder in RecyclerView.

The view should use questionnaireItem, answers, enabledAnswerOptions, validationResult and enabledDisplayItems to render the data item in the UI. The view SHOULD NOT mutate the data using these properties.

The view should use the following answer APIs to update the answer(s):

Updates to the answers using these APIs will invoke answersChangedCallback to notify the view model that the answer(s) have been changed. This will trigger a re-render of the RecyclerView UI.

Parameters

validationResult

the ValidationResult of the answer(s) against the questionnaireItem

answersChangedCallback

the callback to notify the view model that the answers have been changed for the QuestionnaireResponse.QuestionnaireResponseItemComponent

enabledAnswerOptions

the enabled answer options in questionnaireItem

minAnswerValue

the inclusive lower bound on the range of allowed answer values, that may be used for widgets that check for bounds and change behavior based on the min allowed answer value, e.g the Slider widget

maxAnswerValue

the inclusive upper bound on the range of allowed answer values, that may be used for widgets that check for bounds and change behavior based on the max allowed answer value, e.g the Slider widget

draftAnswer

the draft input that cannot be stored in the QuestionnaireResponse.

enabledDisplayItems

the enabled display items in the given questionnaireItem

questionViewTextConfiguration

configuration to show asterisk, required and optional text in the header view.

Constructors

Link copied to clipboard
constructor(questionnaireItem: Questionnaire.QuestionnaireItemComponent, questionnaireResponseItem: QuestionnaireResponse.QuestionnaireResponseItemComponent, validationResult: ValidationResult, answersChangedCallback: suspend (Questionnaire.QuestionnaireItemComponent, QuestionnaireResponse.QuestionnaireResponseItemComponent, List<QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent>, Any?) -> Unit, enabledAnswerOptions: List<Questionnaire.QuestionnaireItemAnswerOptionComponent> = questionnaireItem.answerOption.ifEmpty { emptyList() }, minAnswerValue: Type? = questionnaireItem.minValue, maxAnswerValue: Type? = questionnaireItem.maxValue, draftAnswer: Any? = null, enabledDisplayItems: List<Questionnaire.QuestionnaireItemComponent> = emptyList(), questionViewTextConfiguration: QuestionTextConfiguration = QuestionTextConfiguration(), isHelpCardOpen: Boolean = questionnaireItem.isHelpCode, helpCardStateChangedCallback: (Boolean, QuestionnaireResponse.QuestionnaireResponseItemComponent) -> Unit = { _, _ -> })

Properties

Link copied to clipboard

A read-only list of answers to be rendered in the view.

Link copied to clipboard
val draftAnswer: Any? = null
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Fetches the question title that should be displayed to user. The title is first fetched from Questionnaire.QuestionnaireResponseItemComponent (derived from cqf-expression), otherwise it is derived from localizedTextSpanned of QuestionnaireResponse.QuestionnaireItemComponent

Link copied to clipboard

Functions

Link copied to clipboard
suspend fun addAnswer(questionnaireResponseItemAnswerComponent: QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent)

Adds an answer to the existing answers and removes the draft answer.

Link copied to clipboard
fun answerString(context: Context): String

Returns a given answer (The respondent's answer(s) to the question) along with displayString if question is answered else 'Not Answered'

Link copied to clipboard
suspend fun clearAnswer()

Clears existing answers and any draft answer.

Link copied to clipboard
suspend fun removeAnswer(vararg questionnaireResponseItemAnswerComponent: QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent)

Removes an answer from the existing answers, as well as any draft answer.

Link copied to clipboard
suspend fun setAnswer(vararg questionnaireResponseItemAnswerComponent: QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent)

Updates the answers. This will override any existing answers and removes the draft answer.

Link copied to clipboard
suspend fun setDraftAnswer(draftAnswer: Any? = null)

Updates the draft answer stored in QuestionnaireViewModel. This clears any actual answer for the question.