Skip to content

Commit

Permalink
Add cqf-expression
Browse files Browse the repository at this point in the history
  • Loading branch information
atuonufure committed Nov 3, 2024
1 parent bf715cd commit b56be7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
19 changes: 18 additions & 1 deletion sdc-qrf/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export function QuestionItem(props: QuestionItemProps) {
} = useContext(QRFContext);
const { formValues, setFormValues } = useQuestionnaireResponseFormContext();

const { type, linkId, calculatedExpression, variable, repeats, itemControl } = questionItem;
const { type, linkId, calculatedExpression, variable, repeats, itemControl, cqfExpression } =
questionItem;
const fieldPath = useMemo(() => [...parentPath, linkId!], [parentPath, linkId]);

// TODO: how to do when item is not in QR (e.g. default element of repeatable group)
Expand Down Expand Up @@ -116,10 +117,26 @@ export function QuestionItem(props: QuestionItemProps) {
}
}
}
if (!isGroupItem(questionItem, context) && cqfExpression) {
try {
if (cqfExpression.language === 'text/fhirpath') {
questionItem.text = fhirpath.evaluate(
context.context || {},
cqfExpression.expression!,
context as ItemContext,
)[0];
}
} catch (err: unknown) {
throw Error(
`FHIRPath expression evaluation failure for "cqfExpression" in ${questionItem.linkId}: ${err}`,
);
}
}
}, [
setFormValues,
formValues,
calculatedExpression,
cqfExpression,
context,
parentPath,
repeats,
Expand Down
4 changes: 4 additions & 0 deletions sdc-qrf/src/converter/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum ExtensionIdentifier {
SliderStepValue = 'http://hl7.org/fhir/StructureDefinition/questionnaire-sliderStepValue',
Unit = 'http://hl7.org/fhir/StructureDefinition/questionnaire-unit',
ReferenceResource = 'http://hl7.org/fhir/StructureDefinition/questionnaire-referenceResource',
CqfExpression = 'http://hl7.org/fhir/StructureDefinition/cqf-expression',

ItemPopulationContext = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemPopulationContext',
InitialExpression = 'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression',
Expand Down Expand Up @@ -74,6 +75,9 @@ export const extensionTransformers: ExtensionTransformer = {
},
},
},
[ExtensionIdentifier.CqfExpression]: {
path: { extension: 'valueExpression', questionnaire: 'cqfExpression' },
},

[ExtensionIdentifier.ItemPopulationContext]: {
path: { extension: 'valueExpression', questionnaire: 'itemPopulationContext' },
Expand Down
3 changes: 3 additions & 0 deletions shared/src/contrib/aidbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14366,6 +14366,9 @@ export interface QuestionnaireItem {
/** An invariant that must be satisfied before responses to the questionnaire can be considered "complete". */
constraint?: QuestionnaireItemConstraint[];
/** ElementDefinition - details for the item */
/** NOTE: from extension http://hl7.org/fhir/StructureDefinition/cqf-expression */
/** An expression that, when evaluated, provides the value for the element on which it appears. */
cqfExpression: Expression;
definition?: uri;
/** all | any */
enableBehavior?: code;
Expand Down

0 comments on commit b56be7a

Please sign in to comment.