/* * Copyright 2025 Commonwealth Scientific and Industrial Research * Organisation (CSIRO) ABN 41 687 119 230. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import Typography from '@mui/material/Typography'; import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4'; import { useCalculatedExpressionUpdated } from '../../../hooks/useCalculatedExpressionUpdated'; import type { PropsWithFeedbackFromParentAttribute, PropsWithIsRepeatedAttribute, PropsWithIsTabledAttribute, PropsWithParentIsReadOnlyAttribute, PropsWithParentStylesAttribute, PropsWithQrItemChangeHandler, PropsWithRenderingExtensionsAttribute } from '../../../interfaces/renderProps.interface'; import { useQuestionnaireStore } from '../../../stores'; import { isSpecificItemControl } from '../../../utils'; import AttachmentItem from '../AttachmentItem/AttachmentItem'; import BooleanItem from '../BooleanItem/BooleanItem'; import ChoiceItemSwitcher from '../ChoiceItems/ChoiceItemSwitcher'; import CustomDateItem from '../DateTimeItems/CustomDateItem/CustomDateItem'; import CustomDateTimeItem from '../DateTimeItems/CustomDateTimeItem/CustomDateTimeItem'; import DecimalItem from '../DecimalItem/DecimalItem'; import DisplayItem from '../DisplayItem/DisplayItem'; import IntegerItem from '../IntegerItem/IntegerItem'; import OpenChoiceItemSwitcher from '../OpenChoiceItems/OpenChoiceItemSwitcher'; import QuantityItem from '../QuantityItem/QuantityItem'; import SliderItem from '../SliderItem/SliderItem'; import StringItem from '../StringItem/StringItem'; import TextItem from '../TextItem/TextItem'; import TimeItem from '../TimeItem/TimeItem'; import UrlItem from '../UrlItem/UrlItem'; interface SingleItemSwitcherProps extends PropsWithQrItemChangeHandler, PropsWithIsRepeatedAttribute, PropsWithIsTabledAttribute, PropsWithRenderingExtensionsAttribute, PropsWithParentIsReadOnlyAttribute, PropsWithFeedbackFromParentAttribute, PropsWithParentStylesAttribute { qItem: QuestionnaireItem; qrItem: QuestionnaireResponseItem | null; } function SingleItemSwitcher(props: SingleItemSwitcherProps) { const { qItem, qrItem, isRepeated, isTabled, renderingExtensions, parentIsReadOnly, feedbackFromParent, parentStyles, onQrItemChange } = props; // Get answer key from the qrItem.answer, if it exists // This is used to force re-rendering of the component when the answer changes via an external event i.e. calculatedExpression const answerKey = qrItem?.answer?.[0]?.id; const calcExpUpdated = useCalculatedExpressionUpdated(answerKey); const qItemOverrideComponents = useQuestionnaireStore.use.qItemOverrideComponents(); const QItemOverrideComponent = qItemOverrideComponents[qItem.linkId]; // If a qItem override component is defined for this item, render it // Don't get too strict with the "typeof" checks for now if (QItemOverrideComponent && typeof QItemOverrideComponent === 'function') { return ( {}} // Not needed for single items, use empty function /> ); } // Otherwise, render the default form component based on the item type switch (qItem.type) { case 'display': return ( ); case 'boolean': return ( ); case 'decimal': return ( ); case 'integer': if (isSpecificItemControl(qItem, 'slider')) { return ( ); } return ( ); case 'date': return ( ); case 'dateTime': return ( ); case 'time': return ( ); case 'string': return ( ); case 'text': return ( ); case 'url': return ( ); case 'choice': return ( ); case 'open-choice': return ( ); case 'attachment': return ( ); case 'reference': // FIXME reference item uses the same component as string item currently return ( ); case 'quantity': return ( ); default: return ( Item type {qItem.type} not supported yet, or something has went wrong. If your questionnnaire is not a FHIR R4 resource, there might be issues rendering it. ); } } export default SingleItemSwitcher;