FHIR Chat · Questionnaires with Math · questionnaire

Stream: questionnaire

Topic: Questionnaires with Math


view this post on Zulip Raheel Sayeed (Sep 27 2018 at 15:06):

Is it right to embed Math Logic in a questionnaire?
questionItem1 reponse = 3
questionItem2 response= 10

Would there be a place where i could embed the math logic into? Item1 + Item2.
I was thinking about this example: https://www.hl7.org/fhir/questionnaire-example-gcs.json.html It is a math based questionnaire but leaves calculations to the client side perhaps.

view this post on Zulip Lloyd McKenzie (Sep 27 2018 at 15:09):

Take a look at the structured data capture implementation guide. It provides some guidance in this space (though more is still needed). Essentially you're going to use the "variable" extension and the "calculatedExpression" extension

view this post on Zulip Raheel Sayeed (Sep 27 2018 at 15:24):

great. thanks. will check back

view this post on Zulip Raheel Sayeed (Sep 27 2018 at 15:58):

Seems like its not for r3?

view this post on Zulip Lloyd McKenzie (Sep 27 2018 at 16:10):

Correct, though you can adopt the same approach in R3 with a custom extension

view this post on Zulip Grahame Grieve (Sep 28 2018 at 04:33):

@Eric Haas why is argonaut using different extensions than SDC defines:

      <extension url="http://fhir.org/guides/argonaut-questionnaire/StructureDefinition/extension-score">
        <valueDecimal value="17"/>
      </extension>

view this post on Zulip Eric Haas (Sep 28 2018 at 06:13):

1) for STU3
2) There was no extension for option.valueString or for items...which we only fixed for R4

view this post on Zulip Grahame Grieve (Sep 28 2018 at 10:21):

I don't understand why either of those is a reason not to use the SDC extension URL

view this post on Zulip Lloyd McKenzie (Sep 28 2018 at 13:28):

Score shouldn't be an extension - score should be the answer to a question

view this post on Zulip Grahame Grieve (Sep 28 2018 at 13:31):

it should be the calculdated-value extension

view this post on Zulip Lloyd McKenzie (Sep 28 2018 at 15:00):

The calculated-value tells you the calculation. The actual score goes in the item.answer.value

view this post on Zulip Grahame Grieve (Sep 28 2018 at 15:23):

of so that's the ordinal value extension - why not use that one?

view this post on Zulip Lloyd McKenzie (Sep 28 2018 at 15:26):

Ordinal value is for a code or option. It's tied to the choice, it's not dynamic.

view this post on Zulip Grahame Grieve (Sep 28 2018 at 15:29):

so that's what the extension above is?

view this post on Zulip Lloyd McKenzie (Sep 28 2018 at 15:52):

The extension above is the formula, not the value.

view this post on Zulip Lloyd McKenzie (Sep 28 2018 at 15:53):

The value of the score is conveyed as the answer to a question. It can be a hidden question if you don't want the person filling the form to see the score.

view this post on Zulip Eric Haas (Sep 29 2018 at 04:58):

the argonaut extension has nothing to do with a calculated value - it is what value is assigned to the question. I see how the word "score" is confusing and will need to change that. There is no scoring -as in calculating the score and providing that- extensions for the Argo Q - just numbers that can be assigned to any type of question. The total score could be a hidden q-a pair though we don't document that.

view this post on Zulip Grahame Grieve (Sep 29 2018 at 08:23):

I'm not understanding this then. What is 'the score' if it's not the ordinal value?

view this post on Zulip Eric Haas (Sep 29 2018 at 10:40):

see this example. Score=17 is the integer value associated with that question. Its is static number and not calculated - I think you make a good point as to what it means when calculating a total score since is open to interpretation. it could be a weight a, or a max for that question/group etc. Its easier to interpret a score in the second example when is a multiple choice since its easier to intepret each choice having a value or weight that can be used to calculate a total. Screen-Shot-2018-09-29-at-3.23.57-AM.png Screen-Shot-2018-09-29-at-3.40.30-AM.png

view this post on Zulip Eric Haas (Sep 29 2018 at 10:42):

and like I said before the word 'score' here may be confusing. 'weight' or 'integer value associated wth this item' might be better

view this post on Zulip Eric Haas (Sep 29 2018 at 10:44):

here is a score associated with a text answer...

view this post on Zulip Eric Haas (Sep 29 2018 at 10:45):

Screen-Shot-2018-09-29-at-3.44.08-AM.png

view this post on Zulip Grahame Grieve (Sep 29 2018 at 10:51):

so this is the ordinalValue extension then

view this post on Zulip Eric Haas (Sep 29 2018 at 11:00):

yes and it predated the expansion of its context and consolidation of all the various extensions , I plan to update the name of it to align with it. Its the STU3 version of it

view this post on Zulip Grahame Grieve (Sep 29 2018 at 11:01):

well can we do that for this connectathon?

view this post on Zulip Eric Haas (Sep 29 2018 at 11:04):

Its unlikely I will have a chance to change it before then.

view this post on Zulip Eric Haas (Sep 29 2018 at 11:06):

There are other things that predate SDC and will need to be aligned too.

view this post on Zulip Grahame Grieve (Sep 29 2018 at 11:38):

.. all my tooling is SDC based :-(

view this post on Zulip Lloyd McKenzie (Sep 29 2018 at 11:38):

Why is that a frowny-face? ;)

view this post on Zulip Grahame Grieve (Sep 29 2018 at 11:39):

because the questionnaires for the connectathon track are not consistent with SDC, so my tooling isn't applicable

view this post on Zulip Lloyd McKenzie (Sep 29 2018 at 11:41):

I did understand that. And am happy the intention is to align

view this post on Zulip Koray Atalag (Nov 24 2018 at 04:19):

Take a look at the structured data capture implementation guide. It provides some guidance in this space (though more is still needed). Essentially you're going to use the "variable" extension and the "calculatedExpression" extension

@Lloyd McKenzie is there an example using these two extensions?

view this post on Zulip Lloyd McKenzie (Nov 24 2018 at 20:07):

Not yet. I hope to have time to work on examples in December and January in advance of the connectathon.

view this post on Zulip Paul Lynch (Nov 26 2018 at 15:54):

@Koray Atalag I have an example here: https://raw.githubusercontent.com/lhncbc/lforms-fhir-app/master/e2e-tests/data/weight-height-questionnaire.json

which calculates a BMI, though it has a couple of minor problems:

1) In the questionnaire-calculatedExpression, I think the correct FHIRPath would put "%resource.item" where I just have "item".
2) it is still using R3 syntax for the lists ("option" instead of "answerOption")-- but I think that issue is probably not relevant.

You can upload this example into our viewer here: https://apps.smarthealthit.org/app/lforms-questionnaire-app and see it working.

view this post on Zulip Raheel Sayeed (Jan 10 2019 at 18:23):

@Paul Lynch Thanks for the links. I have a related question:
I noticed the QuestionnaireResponse created through the SMART App "LHNCPC SDC Questionnaire App", does not calculate the BMI through FHIRPath, is this because it is a server side step and the QR is autoupdated after upload with the appropriate result?

view this post on Zulip Paul Lynch (Jan 10 2019 at 18:31):

First, I should point out that due to a reorganization of the files, the updated link for the Questionnaire example is at https://raw.githubusercontent.com/lhncbc/lforms-fhir-app/master/e2e-tests/data/R4/weight-height-questionnaire.json .

As you'll see in that example, the BMI is calculated through FHIRPath (search for "BMI calculation"). It is done on the client side. The QuestionnaireResponse ("Show As"->"FHIR QuestionnaireResponse (SDC)") also includes the value that was calculated.

I just updated the system this morning, and of course after the update was live, found a couple of bugs which I am working to fix. But, the above example still works.

view this post on Zulip Raheel Sayeed (Jan 10 2019 at 19:13):

Perfect, thanks.
I couldn't get the calculated BMI item in QR SDC at https://lhncbc.github.io/lforms-fhir-app/
I used both stu3 and the r3 sample through upload.

view this post on Zulip Paul Lynch (Jan 10 2019 at 19:15):

The calculatedExpression extension is for R4, so you would need to use the R4 example.

view this post on Zulip Paul Lynch (Jan 10 2019 at 19:24):

Did you mean R4? I see you wrote both "STU3" and "r3" which are the same. I just tried the R4 example there and it worked.

view this post on Zulip Paul Lynch (Jan 10 2019 at 19:25):

pasted image

view this post on Zulip Raheel Sayeed (Jan 10 2019 at 20:12):

Sorry, I meant R4. For some reason, that isn't working for me when I try it. I'll try again with the right file.

view this post on Zulip Paul Lynch (Jan 10 2019 at 22:44):

@Raheel Sayeed One thing that might be causing confusion is that, while the BMI calculation will run after you upload the form, after you have saved form to the server and pull it back, it will no longer run, because the server is STU3 (and so the resource that is saved and comes back no longer has the R4 extensions).

view this post on Zulip Raheel Sayeed (Jan 15 2019 at 17:34):

Thanks @Paul Lynch that was an issue.

view this post on Zulip Paul Lynch (Feb 20 2019 at 21:01):

@Raheel Sayeed It just (re-)discovered that LHC-Forms somewhat accidentally does support calculatedExpression for STU3 questionnaires, and there are tests in LHC-Forms for that functionality with STU3. This means that support does exist on the NLM SDC Questionnaire SMART app. For an example STU3 form that uses calculatedExpression to do a BMI value, see https://raw.githubusercontent.com/lhncbc/lforms/master/test/data/STU3/weightHeightQuestionnaire.json. You can use the "upload" button on the SMART app to upload it and try it. (Ignore the warning message you get.)

view this post on Zulip Raheel Sayeed (Feb 21 2019 at 20:11):

Whooa, this is great. thanks @Paul Lynch

view this post on Zulip Raheel Sayeed (Feb 28 2019 at 14:53):

@Paul Lynch Have you implemented FHIRPath logic for the calculatedExpression? Can you point me to it in the app?

view this post on Zulip Paul Lynch (Feb 28 2019 at 15:07):

@Raheel Sayeed Did you look at https://raw.githubusercontent.com/lhncbc/lforms/master/test/data/STU3/weightHeightQuestionnaire.json? If you search there for "calculatedExpression" you will see an example.

view this post on Zulip Raheel Sayeed (Feb 28 2019 at 16:19):

I did, I was trying that in the app: https://apps.smarthealthit.org/app/lforms-questionnaire-app ("Try App"), uploaded the resource you mentioned. It does layout the form and upon saving it back, It calculated once, rightly showed the BMI in QR. But I couldn't replicate that behavior.

view this post on Zulip Paul Lynch (Feb 28 2019 at 16:30):

By "replicate", do you mean that when you used calculatdExpression in your own questionnaire, and loaded it into that app, that the calculation didn't work? If you'd like to email me the questionnaire, I'll take a look and see if I can spot the problem. Assuming your questionnaire and expression are correct, it might be that you have run into a bug.

view this post on Zulip Raheel Sayeed (Feb 28 2019 at 16:49):

I meant the same questionnaire ––> https://raw.githubusercontent.com/lhncbc/lforms/master/test/data/STU3/weightHeightQuestionnaire.json . Perhaps some issue with the sandbox its running against.

view this post on Zulip Paul Lynch (Feb 28 2019 at 17:16):

Are you using "upload" to upload the form, or are you using a saved copy from the server? The server's FHIR version is R3, so those copies don't have the calculatedExpression extension.

view this post on Zulip Raheel Sayeed (Feb 28 2019 at 19:31):

Yes, did use upload. and it did work once. later uploads didn't quite work.

view this post on Zulip Paul Lynch (Feb 28 2019 at 19:53):

Which web browser are you using? I just retested with Firefox and Chrome, and it is working for me. I do notice an issue with Edge (but the form there does not even load, so I don't think that is what you are seeing.)

view this post on Zulip Raheel Sayeed (Feb 28 2019 at 20:04):

Totally worked. Safari was the problem. BMI is calculated at client side.

A question though: I see calculation happening client side. Ideally, on R4 servers, is this handled server side? A QR generated with an FHIRPath item, is updated with calculated value after POST.

view this post on Zulip Paul Lynch (Feb 28 2019 at 20:29):

http://hl7.org/fhir/2018Sep/extension-questionnaire-calculatedexpression.html says, "Calculated value is updated as other answers in the QuestionnaireResponse are filled in." So, the intent is that the BMI value updates in response to the user inputting/changing values. After a QR is saved to a server, that BMI value does not automatically get updated based on new heights and weights saved in other resources. (One could pull back a QuestionnaireResponse and edit the height & weight values to get the BMI to update, but again that would be client-side.)

view this post on Zulip Paul Lynch (Feb 28 2019 at 20:55):

(It also sounds like I should find a way to test from Safari.)

view this post on Zulip Paul Lynch (Mar 26 2019 at 18:32):

@Raheel Sayeed I think I have fixed the Safari and Edge issues (which were different problems) in the SDC SMART app. As a side benefit to working on this problem, I now have a Mac in my office.

view this post on Zulip Raheel Sayeed (Apr 17 2019 at 17:31):

@Paul Lynch Great! it works.


Last updated: Apr 12 2022 at 19:14 UTC