1- import { Expression } from 'fhir/r4b' ;
2- import fhirpath from 'fhirpath' ;
31import _ from 'lodash' ;
42import isEqual from 'lodash/isEqual' ;
53import React , { PropsWithChildren , useEffect , useContext , useMemo , useRef , useState } from 'react' ;
@@ -9,7 +7,13 @@ import { FCEQuestionnaireItem } from './fce.types';
97import { useQuestionnaireResponseFormContext } from '.' ;
108import { QRFContext } from './context' ;
119import { FormAnswerItems , ItemContext , QRFContextData , QuestionItemProps , QuestionItemsProps } from './types' ;
12- import { calcContext , getBranchItems , getEnabledQuestions , wrapAnswerValue } from './utils.js' ;
10+ import {
11+ calcContext ,
12+ evaluateQuestionItemExpression ,
13+ getBranchItems ,
14+ getEnabledQuestions ,
15+ wrapAnswerValue ,
16+ } from './utils.js' ;
1317
1418function usePreviousValue < T = any > ( value : T ) {
1519 const prevValue = useRef < T | undefined > ( value ) ;
@@ -61,7 +65,7 @@ export function QuestionItem(props: QuestionItemProps) {
6165 ? branchItems . qrItems . map ( ( curQRItem ) =>
6266 calcContext ( initialContext , variable , branchItems . qItem , curQRItem ) ,
6367 )
64- : calcContext ( initialContext , variable , branchItems . qItem , branchItems . qrItems [ 0 ] ! ) ;
68+ : calcContext ( initialContext , variable , branchItems . qItem , branchItems . qrItems [ 0 ] ) ;
6569 const prevAnswers : FormAnswerItems [ ] | undefined = usePreviousValue ( _ . get ( formValues , fieldPath ) ) ;
6670
6771 const itemContext = isGroupItem ( questionItem , context ) ? context [ 0 ] : context ;
@@ -218,20 +222,3 @@ function isGroupItem(
218222) : context is ItemContext [ ] {
219223 return questionItem . type === 'group' ;
220224}
221-
222- function evaluateQuestionItemExpression ( linkId : string , path : string , context : ItemContext , expression ?: Expression ) {
223- if ( ! expression ) {
224- return [ ] ;
225- }
226-
227- if ( expression . language !== 'text/fhirpath' ) {
228- console . error ( 'Only fhirpath expression is supported' ) ;
229- return [ ] ;
230- }
231-
232- try {
233- return fhirpath . evaluate ( context . context ?? { } , expression . expression ! , context , undefined , { async : false } ) ;
234- } catch ( err : unknown ) {
235- throw Error ( `FHIRPath expression evaluation failure for ${ linkId } .${ path } : ${ err } ` ) ;
236- }
237- }
0 commit comments