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
105 stars 56 forks source link

Prepopulating forms #132

Closed whollervi closed 1 year ago

whollervi commented 1 year ago

I am trying to find a generic way of prepopulating a form with answers e.g. by linkid/value pairs

I couldn't find functionality in the LForms API to prepopulate answers? Something like lforms.Utils.setFHIRItemValue(linkID, value)

Reading the FHIR SDC (Form Population) document and without looking too much into the lforms code, LForms.Util.setFHIRContext(fhirContext, fhirContextVars) looks like a candidate to me.

In order to use that mechanism, would I need to write a local FHIR client wrapper (fhirContext), providing the values to prepopulate? Reading the documentation of LForms.Util.setFHIRContext() it sounds like it could be enough to simply provide a map of name, value pairs in the fhirContextVars parameter, but currently I don't know how that map would look like.

Would this be a reasonable approach? And if yes, are there any examples?

plynchnlm commented 1 year ago

That kind of loading of data would normally be done by loading data from a QuestionnaireResponse. See http://lhncbc.github.io/lforms/#merge-fhir-data.

whollervi commented 1 year ago

Ok thanks, that’s what I do when reloading a form that already has a QuestionnaireResponse.

So after loading (before rendering) the FHIR Questionnaire, I would need to first retrieve the empty QuestionnaireResponse LForms.Util.getFormFHIRData() then prepopulate the answers using linkids and merge the lform with the prepopulated QuestionnaireResponse, right? One problem I see with this approach is, that there seems to be no option with getFormFHIRData() to also retrieve empty answers like it’s the default with getFormData() (see noEmptyValue option).

On 3. Jul 2023, at 19:20, plynchnlm @.***> wrote:



That kind of loading of data would normally be done by loading data from a QuestionnaireResponse. See http://lhncbc.github.io/lforms/#merge-fhir-data.

— Reply to this email directly, view it on GitHubhttps://github.com/lhncbc/lforms/issues/132#issuecomment-1618911783, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BA6NLU5YMCBJHWURT7G3A7LXOL5NJANCNFSM6AAAAAAZ4V7UYI. You are receiving this because you authored the thread.Message ID: @.***>

plynchnlm commented 1 year ago

That is true-- QuestionnaireResponses don't contain empty answers. Are you trying to pre-populate with data from the patient's record? LHC-Forms supports populating from FHIR Observations (https://build.fhir.org/ig/HL7/sdc/populate.html#obs-pop) and also from the Patient resource via the launchContext extension (https://build.fhir.org/ig/HL7/sdc/populate.html#exp-pop).

whollervi commented 1 year ago

Thanks for pointing me to the launchContext extension, which looks promising.

For now I'll create a QuestionnaireResponse out out the original Questionnaire and prepopulate it before merging with the Questionnaire ...

Thanks for your help!

plynchnlm commented 1 year ago

If you are going to do that, you could also just work with LHC-Forms' internal data structure, in which the answers and form definition are together. The call would be LForms.Util.convertFHIRQuestionnaireToLForms(fhirData, fhirVersion) (see http://lhncbc.github.io/lforms/#convert-fhir-data), where fhirData is the Questionnaire, and the return is the internal format form definition which can have 'value' fields placed in items. The drawback is that this internal format might change some day, and the 'value' field is not documented, since we only documented the definition part of the format, and not the user data part.