LHNCBC / lforms

See the project website at http://lhncbc.github.io/lforms/, or view the demo website at https://lhcforms.nlm.nih.gov/lhcforms.
Other
103 stars 56 forks source link

Validation rule definition in a demo form #10

Closed dattachandan closed 5 years ago

dattachandan commented 5 years ago

Is there any example of how to specify and validate field rules in any of the elements of the SDC profile? http://hl7.org/fhir/us/sdc/sdc-questionnaire.html https://github.com/lhncbc/lforms-fhir-app

For example, if we have a string element in a combo-box and we want to specify the minLength/maxLength or a regex pattern that will also be used represented in the form builder generated code.

"type": "choice", "extension": [ { "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl", "valueCodeableConcept": { "coding": [ { "system": "http://hl7.org/fhir/questionnaire-item-control", "code": "Combo-box", "display": "Combo-box" } ], "text": "Combo-box" } } ]

plynchnlm commented 5 years ago

First, be advised that: 1) There is a new version of SDC being balloted (ballot closing on April 29th) at http://hl7.org/fhir/uv/sdc/2019May/index.html 2) Our item-control codes that we output are outdated (or maybe just wrong). I was actually planning to work on fixing that today.

Now, to your question. If I understood correctly, you are using the LHC Form Builder (https://lhcformbuilder.nlm.nih.gov/) to create a form, and you want to add something like minLength. Steps for doing that:

1) From the left pane, select the item to which you want to add the field validation. 2) In the middle pane for editing the item, there are two tabs, "Build Basic Properties" and "Build Advanced Properties." Click the advanced one. 3) Change the value of "Add restrictions" to "Yes". The form builder calls field validation rules "restrictions". A new section should open under than question when you choose "Yes". 4) Under "type" select "Minimum Length" 5) Enter the length you want in "Value". 6) In the pane on the right, which has the form preview, click the "JSON Output" tab. You should see that an extension has been added to the item like: "extension": [ { "url": "http://hl7.org/fhir/StructureDefinition/minLength", "valueInteger": 3 }

dattachandan commented 5 years ago

Thanks.

I can see it now.

image

I tried SMART-on-FHIR app client here to understand the form definition language and the FHIR questionnaire response which seem to be a combination of the form UI and the logic: https://apps.smarthealthit.org/app/lforms-questionnaire-app

image

image

{ "name": "NewTestFormCD", "items": [ { "question": "Patient Demographics", "questionCodeSystem": "Custom", "questionCode": "[Q1]", "questionCardinality": { "min": "1", "max": "1" }, "header": true, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "items": [ { "question": "Patient Name", "questionCodeSystem": "Custom", "questionCode": "[Q1.1]", "questionCardinality": { "min": "1", "max": "1" }, "header": true, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "displayControl": { "questionLayout": "horizontal" }, "items": [ { "question": "Patient Name Prefix", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": false, "editable": "1", "answerCardinality": { "min": "1", "max": "1" }, "dataType": "CNE", "answers": null, "defaultAnswer": "Mr" }, { "question": "Patient First Name", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": false, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "dataType": "ST" }, { "question": "Patient Last Name", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": false, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "dataType": "ST" }, { "question": "Patient Name Postfix", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": false, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "dataType": "ST" } ] }, { "question": "Patient Office Telephone", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": false, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "dataType": "ST" }, { "question": "Patient Home Telephone", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": false, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "dataType": "ST" } ] }, { "question": "Patient Medications", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": true, "editable": "1", "answerCardinality": { "min": "0", "max": "1" }, "items": [ { "question": "Patient Regular Medications", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": true, "editable": "1", "answerCardinality": { "min": "0", "max": "1" } }, { "question": "Patient PRN medications", "questionCodeSystem": "Custom", "questionCardinality": { "min": "1", "max": "1" }, "header": true, "editable": "1", "answerCardinality": { "min": "0", "max": "1" } } ] } ] }

image image

image

image

plynchnlm commented 5 years ago

If you are interested in FHIR and FHIR servers, I would not advise working with the LForms internal form definition format, which predates the FHIR support we've added.

* Is there any example code of pre-populating a form defined using the json Form Definition Format(https://github.com/lhncbc/lforms/blob/master/form_definition.md) from a FHIR server and validating the response on the form using the validation rules defined?

Prepopulation is only support is only available for FHIR Questionnaire, and we have not yet added those settings to the Form Builder. So, the path would be to first build a form using the form builder, then export it as FHIR Questionnaire, version R4, (possibly saving that to a FHIR server, but keep your own copy), and then editing the JSON to add the FHIR prepopulation stuff.

Form population is described here: http://hl7.org/fhir/uv/sdc/2019May/populate.html

At present, LForms supports observation-based prepopulation, and part of the FHIRPath-based prepopulation (launchContext, initialExpression, variable, and calculatedExpression). The only FHIR queries that happen in LForms are in launchContext and observationLinkPeriod, and although launchContext can provide the patient, there isn't yet in LForms support getting to other resources like Medication. Basically, we can pull in information about the patient resource, and from the patient's observations, and we can do calculations on those, but that is as far as we have gotten to date.

* Does the FHIR questionnaire  or the Form Definition Format allow more complex UI controls to be defined such as a DatePicker (as shown below for DoB) or RadioButtons?

Yes. Radio buttons and date pickers can be created by selected the appropriate data type in the item's "type" field in the form builder.

* Then on selecting an option on a radio button, it displays further options as shown below when the Yes option in cardiovascular disease is selected and error options when user selection is not correct.

The first could be done by adding skip logic (under "advanced properties", see "show logic") for the checkbox question so that it is hidden until the user chooses "yes" in the previous question.

Although I have not tested a required field with checkboxes, I would expect LForms to only complain (as with string required fields) if the user field enters a value and then changes it to blank.

We don't yet support selected files for inclusion in the response. (FHIR does, but we haven't gotten to it yet.)

We don't have an online converter (except the Form Builder) but if you had a collections of form definitions in our internal format, you could use the LForms APIs to convert them to FHIR... although now that I think about it, you might have to do that in a browser. Although LForms in an npm package, I haven't tried loading into Node.js for server side processing.

dattachandan commented 5 years ago

Thanks for those responses.

Is there any work on a lform framework with possible integration with standard UI JS libs such as react or angular so that complex biz logic forms can be built and represented with the FHIR questionnaire and then programmed using that framework. For example, controls for selecting more medications on some biz logic being true or on a button click? The FHIR questionnaire now can represent some of the UI components and the data model, but is there any ongoing work for a reusable backend framework to help developers build apps for app stores such as SMART-on-FHIR for readily consuming FHIR resources from supported FHIR servers?

image

plynchnlm commented 5 years ago

Our focus at present is on improving support for the SDC Questionnaire specification, which includes FHIRPath-popoulation and definition-based extraction, which would handle your use case of showing a patient's medication records and allowing edits.

dattachandan commented 5 years ago

Thanks for that. Will wait for the ballot review and some samples then