@lhncbc/expression-editor
v5.1.0
Published
A widget to add and edit FHIRPath expressions to a given FHIR Questionnaire.
Keywords
Readme
The LHC Expression Editor
A widget to add and edit FHIRPath expressions to a given FHIR Questionnaire.
Usage
The Lister Hill Center (LHC) Expression Editor can be used both as an Angular Component or a Web Component.
Attributes available
Note: To use the attributes for Web Components change the camel case below to
kebab case (with a dash). This does not apply to the keys of the lhcStyle
object.
fhirQuestionnaire- The FHIR Questionnaire the user will edit using the widget.itemLinkId- The linkID on which the FHIRPath expression will be stored. If the FHIRPath expression is to be stored at the Questionnaire root level rather than at the item levels, then an empty 'itemLinkId' should be passed in.save- Callback called after the user clickssaveinside the widget. The callback passes in the new version of the FHIR Questionnaire the user entered as a parameter.expressionUri- By default the widget modifies the calculatedExpression. You can specify any expression URI here; it is preserved unchanged in the result. The target Questionnaire or item's extensions and sub-extensions are searched, and an existing expression is saved back to its original parent. At the Questionnaire root, the Output Expression section is available for a recognized SDC extraction expression; otherwise root mode edits Questionnaire variables andexpressionUriis not needed.expressionValueType- Controls how the output expression is stored. UsevalueExpression(the default) for the FHIR Expression datatype orvalueStringfor string-backed extraction expressions.expressionParentIndex- Optional index in the target Questionnaire or item'sextensionarray of thedefinitionExtractortemplateExtractextension that owns a bundle field such asfullUrl. It is only needed when that target contains more than one extract extension. Without it, a missing bundle field is added to the target's only extract extension; the target is rejected if it has no extract extension, more than one, or one that does not define the field (for example,resourceIdindefinitionExtract).itemVariablesReadOnly- In the standard expression context, whentrue, variables declared on the current item are shown with the other read-only variables in scope instead of in the editable Item Variables section. Defaults tofalse. Extraction expressions exclude ordinary Questionnaire variables regardless of this setting.expressionLabel- Heading name to use to show user when entering the expression.titleName- Main widget heading shown to the user.advancedInterface- Show options to edit FHIRPath and x-fhir-query directly in dropdowns. This mode is automatically enabled for complex Questionnaires. This attribute sets the default which can be overridden by the user.doNotAskToCalculateScore- Do not ask the user if they would like to calculate a score.userExpressionChoices- Choices of expression type to output. Array of objects withnameandurivalues of choices to present to the user in a dropdown. If no value is provided the dropdown will not be present.lhcStyle(object) - Specify custom CSS to be used by the widget for:- h1 - Main heading
- h2 - Secondary headings
- previewArea - FHIRPath preview area
- variableHeader - Variable section table header
- variableRow - Variable section table row
- buttonPrimary - Button style for primary action
- buttonSecondary - Button style for secondary actions
- buttonDanger - Button style for delete, etc
- input - Input forms
- select - Input forms
- description - Instructions presented to the user
Use as an Angular Component
- Install in your project using
npm install --save-prod @lhncbc/expression-editor - Make sure your application has
@angular/animations,@angular/cdk,@angular/common,@angular/coreand@angular/materialas dependencies since they are needed as peer dependencies by the Expression Editor. - Add the
lhc-expression-editorand required tags similar to the example below:
Angular Component Example
Note that the attribute names need to be surrounded by square brackets.
The only required attributes are [fhirQuestionnaire] and [itemLinkId].
If the FHIRPath expression is to be stored at the Questionnaire root level,
only the [fhirQuestionnaire] is the requied attribute. An empty [itemLinkId]
can be passed in or omitted altogether in that case.
To retrieve data use the (save) attribute.
<lhc-expression-editor
[fhirQuestionnaire]="fhir[questionnaire]"
[itemLinkId]="linkId"
(save)="onSave(fhirResult)"
[submitButtonName]="'Save'"
[titleName]="'My Expression Editor'"
[expressionLabel]="'My Expression'"
[expressionUri]="'http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression'"
[lhcStyle]="{
buttonPrimary: { backgroundColor: 'blue' },
buttonSecondary: { backgroundColor: 'blue', color: 'white' },
input: { backgroundColor: 'lightblue' },
select: { backgroundColor: 'lightblue' }
}">
</lhc-expression-editor>Use as a Web Component
- Install in your project using
npm install --save-prod @lhncbc/expression-editor - Import jQuery.
- Import the JavaScript file
dist/expression-editor/expression-editor.json the page or integrate it as part of your build process (webpack, etc.) - Add the tag along with necessary attributes to the HTML.
- Add event handlers for the
saveevent.
Web Component Example
To retrieve data add an event listener for save.
<lhc-expression-editor
id="editor"
title-name="Test Expression Editor"
submit-button-name="Test Submit">
</lhc-expression-editor>
<pre id="output"></pre>
<script src="/expression-editor/expression-editor.js"></script>
<script src="mock-data.js"></script>
<script>
const editor = document.getElementById('editor');
const output = document.getElementById('output');
editor.fhirQuestionnaire = fhir.phq9;
editor.itemLinkId = '/39156-5';
editor.titlename = 'test';
editor.addEventListener('save', (data) => {
output.innerText = JSON.stringify(data.detail, null, 2);
});
</script>Build
Run npm run build to build the project. The build artifacts will be stored
in the dist/ directory. Use the --prod flag for a production build.
Demo project
Run npm start after building to see the two ways to use the widget:
- The Angular Library can be used at http://localhost:4202.
- The Web Component can be used at http://localhost:4202/web-component.html.
Running tests
Run npm test to execute the unit tests via Karma
and the end-to-end tests via Protractor.
