Skip to main content

// todo link to source

This documentation covers files located at: Questionnaire Item Choice

Questionnaire Item Choice Component

The Questionnaire Item Choice Component is a little more complex than the other questionnaire item components. It needs to handle the answerOptions and therefore it must retrieve them from the QuestionnaireItem.answerOption property.

Choice Item Handling & Option Matching

Concept

A critical requirement for Choice items is that the QuestionnaireResponseItem.answer property must be matched against available options before the patching process occurs. This ensures that only valid values, consistent with the current Questionnaire definition, are set.

Initialization Workflow

To achieve this, option retrieval must be completed before the answer FormArray is initialized. Consequently, the setup must occur prior to the QuestionnaireItemBaseComponent.ngOnInit call:

  1. We override ngOnInit.
  2. We set up and filter for our options.
  3. Finally, we call super.ngOnInit() to proceed with the standard lifecycle.

Special Case: itemValueKey

In standard items, the itemValueKey is mapped directly to a specific FHIR key (e.g., valueString or valueInteger), as detailed in the Questionnaire Item Base Component.

However, Choice elements present a unique challenge because they support polymorphic value types within their options (e.g., valueString, valueInteger, or valueCoding). To handle this flexibility without hardcoding a single FHIR key, we use a specialized approach:

  • Dedicated Wrapper: We use a custom key called CHOICE_ANSWER_WRAPPER.
  • Object-Level Handling: Instead of managing primitive values, the Choice element handles the entire Response object.
  • Custom Comparison: We implemented a custom comparison function to ensure that objects are compared by their internal structure/identity rather than just primitive equality.

Dynamic Response Building

When the final response is constructed, the QuestionnaireLogicService unpacks the value stored under the CHOICE_ANSWER_WRAPPER. This architecture allows us to:

  1. Keep FormGroups consistent and simple.
  2. Remain dynamic across different value types.
  3. Theoretically support a mix of different "value" types within the same set of options.

Supported Item Features

FeatureConfig KeyLogic
Label Textitem.textThis component
Answer Optionsitem.answerOptionThis component
Enable Whenitem.enableWhenItem Renderer
Enable When Behaviouritem.enableWhenBehaviourItem Renderer
Requireditem.requiredItem Renderer
Repeatsitem.repeatsItem Renderer

Extension Features

FeatureExtension URLKey / Value Type
Translationhttp://hl7.org/fhir/StructureDefinition/translationComplex Type
Min Occurrenceshttp://hl7.org/fhir/StructureDefinition/questionnaire-minOccursvalueInteger
Max Occurrenceshttp://hl7.org/fhir/StructureDefinition/questionnaire-maxOccursvalueInteger
SDC Enable Whenhttp://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpressionvalueExpression
Item Controlhttp://hl7.org/fhir/StructureDefinition/questionnaire-itemControlvalueCodeableConcept: radio-button
Choice Orientationhttp://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientationvalueCode: horizontal | vertical

Technical Implementation Details

For detailed information regarding technical implementation, please refer to the following:

  • Questionnaire Base Component
  • Questionnaire Item Renderer
  • Questionnaire-Enable-When Service