FHIR Chat · Rules on question order · questionnaire

Stream: questionnaire

Topic: Rules on question order


view this post on Zulip Jean Duteau (Nov 18 2020 at 19:37):

I want to implement a set of rules that dictate an ordering of questions. I have an array of rules that are processed in order and if one of the rules fires, it indicates which question to go to next via the linkId. I don't see anything in the SDC that can handle this but I thought before I created an extension, I'd ask if someone has already done something around question logic.

view this post on Zulip Lloyd McKenzie (Nov 19 2020 at 03:10):

At the moment, all items in a questionnaire have a fixed order. You can cause some to turn on and off based on other answers, but you can't change their order of appearance. Can you give an example of where changing order would be necessary?

view this post on Zulip Brian Postlethwaite (Nov 19 2020 at 04:07):

Unless you use the dynamic questionnaire stuff that was part of the Argonaut work, @Lloyd McKenzie wherebis that defined again?

view this post on Zulip Jean Duteau (Nov 19 2020 at 04:09):

We have a questionnaire with branches. I like to think of them as Choose-Your-Adventure questionnaires. :) Our rules can be based on what you just answered as well as characteristics of the submitter or source. We looked at 'enableWhen' but since one question could appear in different branches at different points, the rules for enableWhen would get quite complicated.

view this post on Zulip Elliot Silver (Nov 19 2020 at 04:10):

Take a look at the SDC adaptive questionnaire. I think this allows you to load the "next page" based on the results of the questionnaire so far.

view this post on Zulip Jean Duteau (Nov 19 2020 at 04:11):

i did look at that but didn't find, i'll go take another look

view this post on Zulip Elliot Silver (Nov 19 2020 at 04:11):

http://build.fhir.org/ig/HL7/sdc/adaptive.html

view this post on Zulip Jean Duteau (Nov 19 2020 at 04:16):

right, i remember reading that, but that assumes a server with the question dynamically determined. this is sort of like that except that I want to exchange the rules for determining the next question with the questionnaire itself

view this post on Zulip Elliot Silver (Nov 19 2020 at 04:16):

Hmm, it seems to require a certain amount of support on the server side; I don't see a way to define the full logic in the questionnaire.

view this post on Zulip Elliot Silver (Nov 19 2020 at 04:16):

right.

view this post on Zulip Elliot Silver (Nov 19 2020 at 04:20):

If complex enableWhen conditions are your main block, what about using a variable to factor out those conditions?

view this post on Zulip Elliot Silver (Nov 19 2020 at 04:22):

I just looked at the hidden extension, but that won't do what you want either--it only takes a constant true/false, not a dynamic value.

view this post on Zulip Jean Duteau (Nov 19 2020 at 04:27):

Elliot Silver said:

If complex enableWhen conditions are your main block, what about using a variable to factor out those conditions?

Yes, except that the problem is that I have different branches where the same question occurs in different spots. So if I had a list of questions 1,2,3,4,5, one branch might be 1,3,4,5, another might be 1,2,5,3,4, etc.

view this post on Zulip Lloyd McKenzie (Nov 19 2020 at 12:51):

Can you give a specific example why sometimes 5 needs to be asked before 3 and 4 and sometimes after?

view this post on Zulip Jean Duteau (Nov 19 2020 at 17:25):

i was making that example up out of whole cloth. let me find a real branching example that has behaviour like this

view this post on Zulip Jean Duteau (Nov 19 2020 at 17:39):

okay, the questionnaire that I found had a set of questions for everyone, a set of questions for males, a set of questions for females, and then some wrap-up questions. I can actually reduce the amount of branching by applying some logic, but that wasn't the way that the questionnaire was created in the system.

view this post on Zulip Jean Duteau (Nov 19 2020 at 17:43):

i've abstracted the questions and reordered the branches so that it looks like this:

1) What is your gender?  M/F/O
    if M and age > 40, go to 2
    if M and age <= 40, go to 22
    if F and age > 20, go to 10
    if F and age <= 20, go to 22
    if O, go to 22

2) Have you been screened for prostate cancer? Y/N
    if Y, go to 4
    if N, go to 20

3) Have you been screened for breast cancer? Y/N
    if Y, go to 16
    if N, go to 20

4-10) questions about prostate cancer screening experience with logic based on answers
    last question has go to 16

11-15) questions about breast cancer screening experience with logic based on answers
    last question has go to 16

16-19) general questions about cancer screening experience, potentially with logic

20) Would you like to book a cancer screening appointment? Y/N
    If Y, go to 21
    If N, go to 22

21) (no question, just info about appointment booking)

22) (no question, just thank you slide)

view this post on Zulip Jean Duteau (Nov 19 2020 at 17:44):

this is how the questionnaire was really laid out (again abstracted as it was way more complex):

1) What is your gender?  M/F/O
    if M and age > 40, go to 2
    if M and age <= 40, go to 22
    if F and age > 20, go to 10
    if F and age <= 20, go to 22
    if O, go to 22

2) Have you been screened for prostate cancer? Y/N
    if Y, go to 4
    if N, go to 20

3-9) questions about prostate cancer screening experience with logic based on answers

10-13) general questions about cancer screening experience, potentially with logic
    last question has go to 20

14) Have you been screened for breast cancer? Y/N
    if Y, go to 15
    if N, go to 20

15-19) questions about breast cancer screening experience with logic based on answers
    last question has go to 10

20) Would you like to book a cancer screening appointment? Y/N
    If Y, go to 21
    If N, go to 22

21) (no question, just info about appointment booking)

22) (no question, just thank you slide)

view this post on Zulip Jean Duteau (Nov 19 2020 at 17:49):

Having done the reordering above, I don't actually want to force the users to a) go back and reorder the Questionnaires they have already created and b) reduce branching as much as possible in their new created Questionnaires. I just want to convey the logic that they are creating. I've created an extension for these rules since I couldn't find anything in SDC.

view this post on Zulip Lloyd McKenzie (Nov 19 2020 at 17:54):

This looks like it can be handled without any re-ordering. You just turn off the stuff that's not relevant based on prior answers.

view this post on Zulip Jean Duteau (Nov 19 2020 at 17:57):

Lloyd McKenzie said:

This looks like it can be handled without any re-ordering. You just turn off the stuff that's not relevant based on prior answers.

Sure. We could use 'enableWhen' but the rules will get quite complex. I suspect that the development team (which was developing these before I introduced the notion of FHIR Questionnaires) may have considered that but since the rules got too complex and the idea of a Choose-Your-Adventure Questionnaire seemed simpler, they went with that.

view this post on Zulip Paul Lynch (Nov 19 2020 at 18:47):

Are you showing one question at a time? "go to" might or might not mean hide the others.
enableWhenExpression gives you more flexibility than enableWhen.
The disadvantage of your custom extension is that other systems won't understand it.
You could submit a change request....

view this post on Zulip Jean Duteau (Nov 19 2020 at 19:06):

Yes, I am showing one question at a time. "go to" meant purely skip forward to question with linkId x. I'm going to keep looking at enableWhenExpression and see if I can use that, but the basic problem is that the semantics are the inverse of what I have in my data.

view this post on Zulip Paul Lynch (Nov 19 2020 at 19:18):

Yes, it is inverse, and enableWhen(Expression) has the drawback that if you want to skip from question 1 to question 10 based on question 1's answer, you have to put the enableWhen(Expression) on 8 questions. As Brian said, you could simplify those expressions with a variable, but they still have to be there.
I suppose you could write some code to take a set of "go to" rules and generate the right enableWhenExpressions.
If support for "go to" were added, questionnaire renderers that show the full questionnaire would have to implement that same transformation to enabled states to determine which questions should be visible.

view this post on Zulip Lloyd McKenzie (Nov 19 2020 at 19:20):

You could also point those questions inside a group - but still number them as if they weren't. Then your enableWhen would only need to appear on the group.

view this post on Zulip Brian Postlethwaite (Jan 11 2021 at 00:08):

The simplest answer to this one is the adaptive mode where they only present the questions at each stage.
Jumping about is going to make things very interesting depending on the way that your renderer displays things, and what is practical on the form factor.
Going backwards is always an interesting thing to do - and how would that be handled if you just had a back/next button and showed some content, you'd need to be maintaining an interesting stack of pages/questions?


Last updated: Apr 12 2022 at 19:14 UTC