FHIR Chat · variable scope when populating in repeating groups · questionnaire

Stream: questionnaire

Topic: variable scope when populating in repeating groups


view this post on Zulip Diane (Oct 20 2021 at 03:05):

I see that Brian Postlethwaite has a separate thread about variable scope when populating in repeating groups.

I didn't want to hijack that one. I don't know how to confine my variable to one iteration of the group.

In Link ID 1.1, the user chooses between site type A or site type B. This selection is stored in variable %siteType.

In Link ID 1.2, there is a answerExpression extension with iif in the value expression
such as iif(%siteType = 'A', 'X', 'Y')

In Link ID 1.3, there is another answerExpression extension with iif in the value expression
such as iif(%siteType = 'A', 'C', 'D')"

In Link ID 1.4, there is another answerExpression extension with iif in the value expression
such as iif(%siteType = 'A', 'E', 'F')

These are the results that I want to populate:

Parent Link ID 1 Sites

Link ID 1.1 Site Type A
Link ID 1.2 X
Link ID 1.3 C
Link ID 1.4 E

Link ID 1.1 Site Type B
Link ID 1.2 Y
Link ID 1.3 D
Link ID 1.4 F

Link ID 1.1 Site Type B
Link ID 1.2 Y
Link ID 1.3 D
Link ID 1.4 F

I have tried putting the variable against the parent link ID 1, but that is obviously visible to all of the repeating groups, so every time a new site (group iteration) is added, the variable value causes the previously added sites (group iterations) to repopulate (incorrectly).

I have also tried making an unneeded group nesting and putting the variable against it like this:

Parent Link ID 1 Sites

Unneeded grouping 1.1 to store variable %siteType
Link ID 1.1.1 Site Type A
Link ID 1.1.2 X
Link ID 1.1.3 C
Link ID 1.1.4 E

Unneeded grouping 1.1 to store variable %siteType
Link ID 1.1.1 Site Type B
Link ID 1.1.2 Y
Link ID 1.1.3 D
Link ID 1.1.4 F

Unneeded grouping 1.1 to store variable %siteType
Link ID 1.1.1 Site Type B
Link ID 1.1.2 Y
Link ID 1.1.3 D
Link ID 1.1.4 F

But, the variable still seems to be "seen" and modified by any of the group iterations.

How do I contain the variable scope to only the one iteration of the repeating group?

Do I need to add the extension for itemPopulationContext to Unneeded grouping 1.1?

view this post on Zulip Lloyd McKenzie (Oct 20 2021 at 04:31):

To clarify linkId "1" is a repeating group and declares the %siteType variable? If so, then my belief is that the value of the %siteType value should be managed separately for each repetition of the group. @Paul Lynch ?

view this post on Zulip Brian Postlethwaite (Oct 20 2021 at 08:25):

That is how I've interpreted it too, and implementing in my renderer.

view this post on Zulip Brian Postlethwaite (Oct 20 2021 at 08:26):

The variable is only visible down the tree, not up.

view this post on Zulip Diane (Oct 20 2021 at 13:46):

Yes. linkid "1" is the repeating group and declares the %siteType variable. As an alternative, I also tried adding a linkid "1.1" to declare %siteType.

view this post on Zulip Paul Lynch (Oct 20 2021 at 13:47):

I agree that each repetition of a group should get its own instance of the group's variables. I will double-check LHC-Forms' behavior.

view this post on Zulip Paul Lynch (Oct 20 2021 at 14:53):

LHC-Forms seems to be behaving correctly. I just created a repeating BMI panel, and and the BMI calculation for each instance is only affected by the weight & height in the group instance. @Diane , if you will email me your Questionnaire, I will take a look and see if I can spot the problem.

view this post on Zulip Diane (Oct 20 2021 at 16:30):

I just sent the questionnaire to @Paul Lynch

view this post on Zulip Diane (Oct 22 2021 at 04:44):

In case anyone else is looking for the solution to this type of problem, the answer (thanks to @Paul Lynch is in the fhirpath. If your fhirpath expression refers to the entire resource, such as %resource.descendants().where(linkId = '1.1'), then the variable will keep getting updated and wiping out the previous iterations. The fhirpath expression should be local to the instance of the group. In my case, using item.descendants().where(linkId = '1.1') fixed the problem.

To answer my question "How do I contain the variable scope to only the one iteration of the repeating group?" Contain your fhirpath expression to the one iteration of the repeating group.


Last updated: Apr 12 2022 at 19:14 UTC