LHNCBC / lforms-fhir-app

A SMART on FHIR app that uses lforms widget to handle Questionnaire and QuestionnaireResponse

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Updating field values using jQuery is not updating the FHIR Json Data

atharwasamantzpaper opened this issue · comments

Hi,

I am trying to set the field values on a table using jQuery, which I was successfully able to do.
$(inputElement).val(fieldValue);

But, the below code which attempts to get the FHIR formatted JSON object for data inserted / updated on the form is not able to see the field values which were updated using jQuery.
var qr = LForms.Util.getFormFHIRData("QuestionnaireResponse", "R4");
var bundle = transformFromQuestionnaireResponseToBundle(qr);
var njs = JSON.stringify(qr, null, 2);

Is there any workaround for this?

Thanks

You might be able to get it to work by firing a change event on the field after setting the value, but it is not intended to be used that way.

If you are trying to set initial values, the Questionnaire specification has an "initial" field you can use for that. Also, the SDC IG (http://hl7.org/fhir/uv/sdc/STU3/) defines "initialExpression" and "calculatedExpression" extensions for setting field values based on calculations.

We are trying to add a modal pop up (instead of an auto complete). In this modal pop up we have have our own filters. When the user selects a row from the result. We are updating the fields on the form.

Using jQuery we are able to set the value on the field, The updated value is visible on the UI, but when we use LForms.Util.getFormFHIRData("QuestionnaireResponse", "R4") to read the form data the updated values are not visible.

We have tried triggering the change event using jQuery and Angular.

triggering change using jQuery
$(ele).trigger('change');

triggering change using angular
angular.element(ele).triggerHandler('change')

Both these method did not work out for us

On approach that would work, but would cause the form to re-render (which might or might not be acceptable) would be get the QuestionnaireRepsonse, modify that data, then merge the QuestionnaireResponse back in the Questionnaire and have LForms render that in place of the original.

I am trying to add a dummy row to the one of the tables on which we have added the modal. But I am not able to able to see the update in the form data.

var qr = LForms.Util.getFormFHIRData("QuestionnaireResponse", "R4");
qr.item.push(qr.item[3])
LForms.Util.mergeFHIRDataIntoLForms("QuestionnaireResponse",qr,fhirQ,"R4");

Does this look right to you?

qr.item should be the array of QuestionnaireResponse items, and qr.item[3] the fourth item in that array. Are there four entries in the qr.item array? Assuming so, then you are appending another reference to the qr.item[3] onto the array. It would be safer to make a copy of qr.item[3] before pushing it. (I am assuming that is just a test; I can't think of any reason to do that normally).

Also, after calling mergeFHIRDataIntoLForms, you will need to render the return value with LForms.Util.addFormToPage.

@plynchnlm , apology for the delay in the response. Your suggesting regarding calling the LForms.Util.addFormToPage. worked.

We also tried another workaround where we are triggering the input event using js. And we are able to see the updated values in the Form Data.

Glad you were able to get it working.

Thanks for your immediate help @plynchnlm :)