LHNCBC / formbuilder-lhcforms

Build LHC-Forms and FHIR Questionnaires
Other
26 stars 21 forks source link

v8.0.2 missing scoring toggle #51

Closed sjpadgett closed 1 year ago

sjpadgett commented 1 year ago

In previous version of builder a scoring attribute was included for selection in builder. Is this an oversight or was feature removed.

Also noted lforms export from previous builder many time will import in v8 however will not enable the Edit Questions button.

plynchnlm commented 1 year ago

The old form builder had an option "Score calculation" under "Item Attributes- Advanced" for numeric fields. This was a feature of our internal format, and does not have a direct equivalent in FHIR Questionnaires, which is the focus of the new version. The same thing can be achieved using FHIRPath expressions, and we have developed a tool for working with those which we have not yet added to the new form builder, so for now FHIRPath expressions would need to be added to the Questionnaire output by hand (after downloading the form).

I cannot think of any reason why "Edit Questions" should not be enabled, and that sounds like a bug. Could you attach a form definition that causes that condition (and also please mention which browser you are using when you see it, in case that makes a difference)? Thanks for the report.

sjpadgett commented 1 year ago

@plynchnlm

FHIRPath expressions

Okay that's fine and will start converting my questionnaires after pulling down and learning your tool. Really a better way to go anyway.

I cannot think of any reason why "Edit Questions"

Looks like only questionnaires are allowed and not the lform export from previous builder. I'm not too concerned about this and will report after I do some debugging if needed.

Is there a repo for the previous builder or will you be updating the public previous builder to LHC-Forms 33.0.0 which fixed several bugs and works well for my needs so, thanks for that!

I'm an administrator and developer for the OpenEMR project and have recently implement your project. So you can probably expect some pull requests from us in the near future.

That you for quick reply.

sjpadgett commented 1 year ago

I can't seem to get scoring to work using FHIRPaths when questions are contained in a group. Has anyone done this?

plynchnlm commented 1 year ago

If the items with the scores in a group and your total score field is outside of the group, you would need to create variables for each of the individual scores on the group level (assuming the group is at the same level as the total score field) and then use the variables in a FHIRPath calculatedExpression on the total score field. I have two examples not using groups, but using variables, that might be of help.

https://github.com/lhncbc/lforms-fhir-app/blob/master/cypress/fixtures/R4/weight-height-questionnaire.json https://github.com/lhncbc/lforms-fhir-app/blob/master/cypress/fixtures/R4/phq9.json

sjpadgett commented 1 year ago

FHIRPath calculatedExpression on the total score field.

Yep I have the FhirPaths and variables pretty well figured out and working on form without groups. but I'd expect this simple form to work which does outside a group.

sjpadgett commented 1 year ago

@plynchnlm Okay using FHIR paths for scoring is somewhat slow and for longer questionnaires not practical in terms of usability. I'm sure you guys have looked into optimization so I don't know if it would be worth me investigating.

I'd appreciate it if you could update the current 'previous' builder public app to latest LHC-Forms 33.0.0 so my users can contribute questionnaires compatible with my EMR app using same version. I also would like access to the previous LHC-Forms builder repo so I can have a local version to test and debug. I can only find to new LHC-Forms builder x.x.x to 8.0.2 repo. I've also have setup the lforms from that repo so I've every builder running except the public builder.

Thanks for any replies.

plynchnlm commented 1 year ago

In the PHQ-9 form, the FHIRPath expressions evaluate in less than a tenth of a second, and the field with the score updates nearly instantly. Do you have an example where you getting poor performance with the FHIRPath expressions?

We are trying not spend time updating the "previous" version of the formbuilder so we can focus on the new one. However, the "previous" version is running 29.x, and the output should be compatible with version 33 LHC-Forms.

The previous version is also in this repository, version 6.5.3 and earlier.

sjpadgett commented 1 year ago

Hi @plynchnlm Thanks so much for the quick reply and explanation. First concerning previous version: I fully agree and support your position to move to the new builder and primarily using FHIR paths or primarily following the FHIR spec in general. However most clinicians would not know how to design scoring forms with FHIR path calculations but find the lforms builder easy to understand and use. I've received nothing but good feedback and many are very excited about and using this feature in OpenEMR. The more technical and longer questionnaires for our core offering are developed by our engineering team or more knowledgeable vendors. Our EMR is used by many different specialties from Occupational Health to Mental Health both widespread international and domestic. Simplicity is more or less a must for us.

Concerning the calculations performance: My attempted Questionnaire may be unfair as it is composed of 100 questions grouped as 8 quizzes with skip logic and scoring. My original plan was to have the quizzes under a group for each quiz with each having a score. This way I could turn on/off quizzes based on response from other quizzes. This I can not get to work for scores but otherwise works as intended. So my solution was to title with a preceding display item the quiz to separate in the form. This work as I need however rendering is too slow even on my fastest computer. The problem I see is that on form load all the calculations in the form are ran through then form becomes ready to use. This works well when I create questionnaire using the lform model on lforms v33.0.0. There's a problem with combined scoring and skip logic on the previous versions using groups.

Attached are a grouped version and a sectioned version of the questionnaire. Note that because certain versions prior to v33.0.0 the != condition does not work so my skip logic use the = for all potential answers. != works well in v33 but haven't gotten around to changing. This is still work in progress. Any suggestion are appreciated.

You folks have done a great job and service with all your projects and sometime you don't get the thanks you deserve so, thank you! Also I hope to be able to help further your new builder development as I have time.

sjpadgett commented 1 year ago

I gave up on scoring forms using groups unless I modify lhc-forms or I missed something in my usage. I was hoping to get feedback on my past queries here especially concerning my use of FHIR Paths. After converting using drop boxes to radio buttons there is a 150% improvement on render speed.

I'd like to not have the score included as part of the answer but can't find a way to do that. E.g Yes - 1 No-0 Maybe - 2 etc. Is there a way to prevent this as it is very confusing to users when you have numeric answers like 0-0 1-1 2-2 etc.? I've attached a questionnaire for you to test with. I'd attach one using groups if you'd would like to test to look into why lhc-forms won't score using groups. This is an important feature to have on longer forms for skip logic reasons.

Please let me know if you folks aren't interested in what I'm doing so I won't use up time here. Thanks for any feedback offered. Peer_Initial_Pain_Assessment.zip

plynchnlm commented 1 year ago

I am glad you found a way to improve the speed, but I am curious as to what kind of speed you are seeing. The version you attached above is rendering for me in less than 2 s. I tried taking out the itemControl extensions, so the radio buttons became drop-down lists again, and that seemed to render even faster (under 1 s, but it was hard to measure it precisely.) I am testing using the "Load from file" button at https://lhcforms.nlm.nih.gov/lhcforms, in Windows Chrome. If you are getting different times, where are you testing?

The scores are appended to the answer text on line 368 of src/lib/lforms/lhc-common-utils.js in the lforms (LHC-Forms) package. We also prepend sequence numbers, but only if none of the answers is numeric. We could do a similar check before appending scores. Although there isn't a way in the Questionnaire resource itself to control whether or how the score is displayed, we could provide a configuration option in lforms to turn that off. If you would like that, please open an issue on the lforms package (https://github.com/lhncbc/lforms/issues).

I would be interested in seeing what you were trying to do using groups, where the scoring wasn't working. If you'll attach that version, I will take a look.

sjpadgett commented 1 year ago

Thanks, the long form using drop downs was taking up to 50 secs to render on both public builder and my local server on Chrome, Edge and FF. I'm going to rebuild my forms for using groups for you to test and retest my original long form with drop downs to make sure it wasn't a fluke what I was seeing. I'll post up here soon.

Yes having the appended score in answer option should be a feature tuned on and off by default. I don't understand why the user needs to see the score in option as now being sent. I'll open an issue so thanks.

plynchnlm commented 1 year ago

The form builder tool is meant for building forms, not for rendering them for a user to work with, and you can expect that to be slower (especially the "previous" version). Still, even on the "previous" version, I am getting the version with lists to render in about 3-4 s, so I am puzzled as to why you were getting 50 s, unless the form were significantly different than the one you shared above.

sjpadgett commented 1 year ago

Actually the builder renders faster than my implementation of v33 LHC-Forms. Regardless when I say render I should have been more precise in saying the time it takes the form to complete where the score is calculated. The forms I've included below are a long form using drop downs and the a form using group which is the most concern for me. I'm thinking about using contained value sets for answer options but if I can get group working with scoring as configure currently, I'd be happy. And again, I appreciate your support and being a large project administrator I understand how valuable your time is. Grouped_and_Full_Pain_Assessment.zip

plynchnlm commented 1 year ago

I am looking at the grouped one now, and I can see the performance issue. I am not sure of the solution yet. I think you have a FHIRPath expression for nearly every item in the form, to capture its value as a variable to compute the score -- which follows the example of the PHQ-9 form, but there are many more items (131?). When lforms is evaluating the expressions, it runs through them all once, then checks to see if any field or variable was changed. If a field was changed, it has to run through all of the expressions again. If a variable was changed, only the expressions that have the variable in scope (those on or below the item the variable was declared on) get run. So there should be some benefit to having them form broken up into groups, if you put the variables either on the item for the score, or perhaps better, on the group containing the score and the variable's field.

I can see it is running the expressions many, many times when the form is just loading. Unless there is a long chain of variables referencing each (and I would guess there isn't) I can't think why that would be, and we will need to look into that to make sure there isn't a bug in lforms.

As to why the expressions aren't working on the grouped version, there is a flaw in the expressions. The expression "%questionnaire.item.where(linkId = '/PP/PFA23')" won't find anything, because the item with linkId "/PP/PFA23" is not in %questionnaire, but inside %questionnaire.item.where(linkId = '/PP'), so you could write %questionnaire.item.where(linkId = '/PP').item.where(linkId = '/PP/PFA23'), or if we weren't already having performance problems, %questionnaire.repeat('item').where(linkId = '/PP/PFA23'). Each of these expressions is run independently, BTW, there is no caching or reuse of anything found in the previous expressions. However, I think the real problem is the efficiency of one pass through the expressions, but that it doing about 100 passes. I will have to dig into why that is.

plynchnlm commented 1 year ago

Another thought that might help in the interim: Since you are only (I expect) using the variables once, instead of defining the variables separately you could simply add their expressions with + to get the final score. It would be same amount of FHIRPath code, but a single expression per sum. It would not look very nice but I would expect it to run faster.

sjpadgett commented 1 year ago

Great info thanks. I'll look into and try your suggestions.

sjpadgett commented 1 year ago

The path suggestion worked and it makes sense now seeing it. So that's that's a big relief, thanks!

sjpadgett commented 1 year ago

If you want @plynchnlm I can post the working grouped forms. Having group/scoring work I'm going to abandon using a display title to section the quizzes in the form. Your suggestion was of great help and Santa is pleases!:)

sjpadgett commented 1 year ago

but there are many more items (131?)

Correct and was a bug in my builder. I fixed to only include variables for the group being scored instead of the entire form questions(duh) and score rendering is as we'd expect and speed isn't an issue.

So my bad and I'm all set once the new option is in place. I'm closing the issue as resolved due to user errors.

Thanks for helping me get this straight.

plynchnlm commented 1 year ago

Glad to hear things are better now, and if you can share your working form I would like to see it, to check whether there is still a potential problem on our side.

sjpadgett commented 1 year ago

Sure. Do you know if I will be able to enable/disable groups based on score or question from a different group? I'm pretty sure SDC allows however uncertain if lforms will honor? We've recently received our FHIR API ONC certification and Questionnaires is something I've been trying to get to over the last couple years.

This is a long form I'm using. Initial_Assessment.zip

BTW I'm using LHC-Form v33.1.0

plynchnlm commented 1 year ago

Yes, enableWhen on groups should work. It will hide the group when not enabled.