Skip to content

Commit c8e7131

Browse files
author
Janardhan Vignarajan
committed
Refactor QR Item ID handling across form components
- Introduced `getQRItemId` utility function to manage QR Item IDs, ensuring that IDs generated from calculated expressions are unique. - Updated multiple form components (AttachmentItem, BooleanItem, ChoiceAutocompleteItem, etc.) to utilize `getQRItemId` for initializing answer keys. - This change enhances the reliability of ID handling in components that rely on QR Item answers, particularly in scenarios involving calculated expressions.
1 parent 8dff8db commit c8e7131

27 files changed

+64
-51
lines changed

packages/smart-forms-renderer/src/components/FormComponents/AttachmentItem/AttachmentItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import React, { useCallback, useState } from 'react';
1919
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2020
import debounce from 'lodash.debounce';
21-
import { createEmptyQrItem } from '../../../utils/qrItem';
21+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2222
import { DEBOUNCE_DURATION } from '../../../utils/debounce';
2323
import useReadOnly from '../../../hooks/useReadOnly';
2424
import AttachmentFieldWrapper from './AttachmentFieldWrapper';
@@ -45,7 +45,7 @@ function AttachmentItem(props: BaseItemProps) {
4545
} = props;
4646

4747
// Init input value
48-
const answerKey = qrItem?.answer?.[0]?.id;
48+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
4949
let valueString = '';
5050
if (qrItem?.answer && qrItem?.answer[0].valueString) {
5151
valueString = qrItem.answer[0].valueString;

packages/smart-forms-renderer/src/components/FormComponents/BooleanItem/BooleanItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import useReadOnly from '../../../hooks/useReadOnly';
2020
import useValidationFeedback from '../../../hooks/useValidationFeedback';
2121
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2222
import { useQuestionnaireStore } from '../../../stores';
23-
import { createEmptyQrItem } from '../../../utils/qrItem';
23+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2424
import { FullWidthFormComponentBox } from '../../Box.styles';
2525
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
2626
import ItemLabel from '../ItemParts/ItemLabel';
@@ -46,7 +46,7 @@ function BooleanItem(props: BaseItemProps) {
4646
const feedback = useValidationFeedback(qItem, feedbackFromParent);
4747

4848
// Init input value
49-
const answerKey = qrItem?.answer?.[0]?.id;
49+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
5050
let valueBoolean: boolean | undefined = undefined;
5151
if (qrItem?.answer?.[0]?.valueBoolean !== undefined) {
5252
valueBoolean = qrItem.answer[0].valueBoolean;

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceAutocompleteItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import useValidationFeedback from '../../../hooks/useValidationFeedback';
2626
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2727
import { useQuestionnaireStore } from '../../../stores';
2828
import { AUTOCOMPLETE_DEBOUNCE_DURATION } from '../../../utils/debounce';
29-
import { createEmptyQrItem } from '../../../utils/qrItem';
29+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
3030
import { FullWidthFormComponentBox } from '../../Box.styles';
3131
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
3232
import ItemLabel from '../ItemParts/ItemLabel';
@@ -48,7 +48,7 @@ function ChoiceAutocompleteItem(props: BaseItemProps) {
4848
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();
4949

5050
// Init input value
51-
const answerKey = qrItem?.answer?.[0]?.id;
51+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
5252
const qrChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);
5353

5454
let valueCoding: Coding | undefined;

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerOptionItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import useValidationFeedback from '../../../hooks/useValidationFeedback';
2121
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2222
import { useQuestionnaireStore } from '../../../stores';
2323
import { updateChoiceCheckboxAnswers } from '../../../utils/choice';
24-
import { createEmptyQrItem } from '../../../utils/qrItem';
24+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2525
import { FullWidthFormComponentBox } from '../../Box.styles';
2626
import DisplayInstructions from '../DisplayItem/DisplayInstructions';
2727
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
@@ -44,7 +44,7 @@ function ChoiceCheckboxAnswerOptionItem(props: BaseItemProps) {
4444
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();
4545

4646
// Init input value
47-
const answerKey = qrItem?.answer?.[0]?.id;
47+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
4848
const qrChoiceCheckbox = qrItem ?? createEmptyQrItem(qItem, answerKey);
4949
const answers = qrChoiceCheckbox.answer ?? [];
5050

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import useValueSetCodings from '../../../hooks/useValueSetCodings';
2323
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2424
import { useQuestionnaireStore } from '../../../stores';
2525
import { convertCodingsToAnswerOptions, updateChoiceCheckboxAnswers } from '../../../utils/choice';
26-
import { createEmptyQrItem } from '../../../utils/qrItem';
26+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2727
import { FullWidthFormComponentBox } from '../../Box.styles';
2828
import DisplayInstructions from '../DisplayItem/DisplayInstructions';
2929
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
@@ -46,7 +46,7 @@ function ChoiceCheckboxAnswerValueSetItem(props: BaseItemProps) {
4646
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();
4747

4848
// Init input value
49-
const answerKey = qrItem?.answer?.[0]?.id;
49+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
5050
const qrChoiceCheckbox = qrItem ?? createEmptyQrItem(qItem, answerKey);
5151
const answers = qrChoiceCheckbox.answer ?? [];
5252

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerOptionItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ChoiceItemControl } from '../../../interfaces/choice.enum';
2424
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2525
import { useQuestionnaireStore } from '../../../stores';
2626
import { findInAnswerOptions, getChoiceControlType, getQrChoiceValue } from '../../../utils/choice';
27-
import { createEmptyQrItem } from '../../../utils/qrItem';
27+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2828
import ChoiceRadioAnswerOptionView from './ChoiceRadioAnswerOptionView';
2929
import ChoiceSelectAnswerOptionView from './ChoiceSelectAnswerOptionView';
3030

@@ -44,7 +44,7 @@ function ChoiceRadioAnswerOptionItem(props: BaseItemProps) {
4444
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();
4545

4646
// Init input value
47-
const answerKey = qrItem?.answer?.[0]?.id;
47+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
4848
const qrChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);
4949
const valueChoice = getQrChoiceValue(qrChoice);
5050

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import useValueSetCodings from '../../../hooks/useValueSetCodings';
2323
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2424
import { useQuestionnaireStore } from '../../../stores';
2525
import { convertCodingsToAnswerOptions, findInAnswerOptions } from '../../../utils/choice';
26-
import { createEmptyQrItem } from '../../../utils/qrItem';
26+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2727
import { FullWidthFormComponentBox } from '../../Box.styles';
2828
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
2929
import ItemLabel from '../ItemParts/ItemLabel';
@@ -44,7 +44,7 @@ function ChoiceRadioAnswerValueSetItem(props: BaseItemProps) {
4444
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();
4545

4646
// Init input value
47-
const answerKey = qrItem?.answer?.[0]?.id;
47+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
4848
const qrChoiceRadio = qrItem ?? createEmptyQrItem(qItem, answerKey);
4949

5050
let valueRadio: string | null = null;

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import useValidationFeedback from '../../../hooks/useValidationFeedback';
2222
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2323
import { useQuestionnaireStore } from '../../../stores';
2424
import { findInAnswerOptions, getQrChoiceValue } from '../../../utils/choice';
25-
import { createEmptyQrItem } from '../../../utils/qrItem';
25+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2626
import ChoiceSelectAnswerOptionView from './ChoiceSelectAnswerOptionView';
2727

2828
function ChoiceSelectAnswerOptionItem(props: BaseItemProps) {
@@ -46,7 +46,7 @@ function ChoiceSelectAnswerOptionItem(props: BaseItemProps) {
4646
const feedback = useValidationFeedback(qItem, feedbackFromParent);
4747

4848
// Init input value
49-
const answerKey = qrItem?.answer?.[0]?.id;
49+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
5050
const qrChoice = qrItem ?? createEmptyQrItem(qItem, answerKey);
5151
const valueChoice = getQrChoiceValue(qrChoice);
5252

packages/smart-forms-renderer/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import useValidationFeedback from '../../../hooks/useValidationFeedback';
2424
import useValueSetCodings from '../../../hooks/useValueSetCodings';
2525
import type { BaseItemProps } from '../../../interfaces/renderProps.interface';
2626
import { useQuestionnaireStore } from '../../../stores';
27-
import { createEmptyQrItem } from '../../../utils/qrItem';
27+
import { createEmptyQrItem, getQRItemId } from '../../../utils/qrItem';
2828
import { FullWidthFormComponentBox } from '../../Box.styles';
2929
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
3030
import ItemLabel from '../ItemParts/ItemLabel';
@@ -46,7 +46,7 @@ function ChoiceSelectAnswerValueSetItem(props: BaseItemProps) {
4646
const onFocusLinkId = useQuestionnaireStore.use.onFocusLinkId();
4747

4848
// Init input value
49-
const answerKey = qrItem?.answer?.[0]?.id;
49+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
5050
const qrChoiceSelect = qrItem ?? createEmptyQrItem(qItem, answerKey);
5151

5252
let valueCoding: Coding | null = null;

packages/smart-forms-renderer/src/components/FormComponents/DateTimeItems/CustomDateItem/CustomDateItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import useDateValidation from '../../../../hooks/useDateValidation';
2020
import useReadOnly from '../../../../hooks/useReadOnly';
2121
import type { BaseItemProps } from '../../../../interfaces/renderProps.interface';
2222
import { useQuestionnaireStore } from '../../../../stores';
23-
import { createEmptyQrItem } from '../../../../utils/qrItem';
23+
import { createEmptyQrItem, getQRItemId } from '../../../../utils/qrItem';
2424
import { FullWidthFormComponentBox } from '../../../Box.styles';
2525
import ItemFieldGrid from '../../ItemParts/ItemFieldGrid';
2626
import ItemLabel from '../../ItemParts/ItemLabel';
@@ -49,7 +49,7 @@ function CustomDateItem(props: BaseItemProps) {
4949
const { displayPrompt, entryFormat } = renderingExtensions;
5050

5151
// Init input value
52-
const answerKey = qrItem?.answer?.[0]?.id;
52+
const answerKey = getQRItemId(qrItem?.answer?.[0]?.id);
5353
const qrDate = qrItem ?? createEmptyQrItem(qItem, answerKey);
5454
let valueDate: string = '';
5555
if (qrDate.answer) {

0 commit comments

Comments
 (0)