Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

condition works in question, but not in group

More
1 week 4 days ago #272648 by Raymond1612
Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: Version 5.6.68+240625
Own server or LimeSurvey Cloud: own server
Survey theme/template: Fruity
==================
I have a rather complex condition that evaluates a number of answers and counts. The condition looks as follows: 
( ( ( (prot01.NAOK == 1 || prot01.NAOK == 4) && (prot02.NAOK == 2 || prot02.NAOK == 3) ) || ( (prot01.NAOK == 2 || prot01.NAOK == 3) && (prot02.NAOK == 1 || prot02.NAOK == 4) ) ) && (count(that.q00Btest) != 16) ) || ( (prot01.NAOK == 2 || prot01.NAOK == 3) && (prot02.NAOK == 2 || prot02.NAOK == 3) && (count(that.q00Btest) != 32) ) || ( (prot01.NAOK == 2 || prot01.NAOK == 3 || prot02.NAOK == 2 || prot02.NAOK == 3) && ( (!is_empty(pat02a.NAOK) && (pat02a.NAOK == 2 || pat02a.NAOK == 3 || pat02a.NAOK == 4 || pat02a.NAOK == 5)) || (!is_empty(pat02b.NAOK) && (pat02b.NAOK == 2 || pat02b.NAOK == 3 || pat02b.NAOK == 4 || pat02b.NAOK == 5 || pat02b.NAOK == 6 || pat02b.NAOK == 7)) ) ) ) && !( ( (prot01.NAOK == 1 || prot01.NAOK == 4) && (prot02.NAOK == 2 || prot02.NAOK == 3) && (count(that.q00Btest) == 16) ) || ( (prot01.NAOK == 2 || prot01.NAOK == 3) && (prot02.NAOK == 1 || prot02.NAOK == 4) && (count(that.q00Btest) == 16) ) || ( (prot01.NAOK == 2 || prot01.NAOK == 3) && (prot02.NAOK == 2 || prot02.NAOK == 3) && (count(that.q00Btest) == 32) ) )

This condition works fine when I use if for a specific question. But I actually want to use it as a condition for a question group and that doesn't work. So the same condition works for a question, but not for a question group. Can anyone tell me what I'm doing wrong?

Thanks in advance!

Please Log in to join the conversation.

More
1 week 4 days ago #272649 by Joffm
Hi,
you'd better send the lss export of these relevant questions.
And please explain again what's your goal.

Joffm 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 4 days ago #272650 by Raymond1612
Hello,

I thought I'd already uploaded the lss-file, so here's another try.

It's a complex questionnaire, but I will try to explain. Participants will be dentists that have to fill in the status praesens of a patient.
So the array is designed like a schematic representation of the dentition with all elements. First row represents the upper jaw, the second the lower jaw.

There are twelve arrays (q00Btest - q00Mtest) and each of them handles certain health issues. The options that are chosen in the first array are diabled in the following untill there are no options left. So if at a certain point 32 options are chosen (32 is the number of elements in the jaws), but there are still arrays left, they have to be skipped. Hence the count statement in my condition (i.e. count(that.q00Btest) != 32). 

It's possible that the patient hasn't have any elements left in the upper or lower jar. In that case I use the relevance equation to show only relevant subquestions. If question prot01 is 1 or 4 then the first row resresenting the upper jaw is hidden and the other way round if prot02 is 1 or 4, the second subquestion (lower jaw) is hidden. When one of these scenarios are true, the count in my condition is set to 16 (i.e. count(that.q00Btest) != 16).

If the patient has no natural elements at all (prot01 and prot02 are both 1 or 4) the questions q00Btest-q00Mtest can all be skipped.

On top of that one more factor is relevant: the age of the patient. Question pat02a has to have value 2, 3, 4 or 5 or question pat02b has to have value 2, 3, 4, 5, 6 or 7.

In order to get this done, I wrote this condition:
(
  (count(that.q00Btest) != 16 && (prot01.NAOK != 2 && prot01.NAOK != 3 || prot02.NAOK != 2 && prot02.NAOK != 3))
  ||
  (count(that.q00Btest) != 32 && (prot01.NAOK == 2 || prot01.NAOK == 3) && (prot02.NAOK == 2 || prot02.NAOK == 3))
)
&&
(
  (!is_empty(pat02a.NAOK) && (pat02a.NAOK == 2 || pat02a.NAOK == 3 || pat02a.NAOK == 4 || pat02a.NAOK == 5))
  ||
  (!is_empty(pat02b.NAOK) && (pat02b.NAOK == 2 || pat02b.NAOK == 3 || pat02b.NAOK == 4 || pat02b.NAOK == 5 || pat02b.NAOK == 6 || pat02b.NAOK == 7))
)

And it works fine for a question (in this case q00Ctest), but is doesn't work if I use it as a condition for a question group (group relevance).

My question is why won't it work in de group relevance?

 

Please Log in to join the conversation.

More
1 week 4 days ago #272654 by Joffm
Hi,
so here you show a different condition from the one in your lss.
Not seeing this I worked on your sample survey - seeing that the condition contained some unnecessary doubles.  But it worked as group relevance in my environment of version 5.x. (5.6.40).

Now I read this new - shorter - condition.
 
This is the condition if somebody has prothesis both upper and lower

  (count(that.q00Btest) != 32 && (prot01.NAOK == 2 || prot01.NAOK == 3) && (prot02.NAOK == 2 || prot02.NAOK == 3))

and this seems to be if there is a prothesis either in the upper or lower jaw

  (count(that.q00Btest) != 16 && (prot01.NAOK != 2 && prot01.NAOK != 3 || prot02.NAOK != 2 && prot02.NAOK != 3))

But it is also TRUE if the patient doesn't have any or a vollegige.
Is this correct?

Okay, I'll insert this new condition into your survey and have a look.

Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 4 days ago #272656 by Raymond1612
You're right, if the patient doesn't have any elements of his own (prot01=1,4 and prot02=1,4) the groups can be skipped.

So that would mean I need to add an extra argument in the condition:
(prot01.NAOK != 1 && prot01.NAOK != 4 and prot02.NAOK != 1 && prot02.NAOK != 4))

Raymond

Please Log in to join the conversation.

More
1 week 4 days ago - 1 week 4 days ago #272657 by Raymond1612
By the way, I overlooked your other comment regarding the differences between the conditions in the post and in the lss file.

I'd cleaned up the condition a bit in my second post for the purpose of readability. But in any case, the count is written out in full in the lss file. For example, if I enter the following condition (count(that.q00Btest) it would look like this in the lss file (count(q00Btest_Y001_X001, q00Btest_Y001_X002, q00Btest_Y001_X003, q00Btest_Y001_X004, q00Btest_Y001_X005, q00Btest_Y001_X006, q00Btest_Y001_X007, q00Btest_Y001_X008, q00Btest_Y001_X009, q00Btest_Y001_X010, q00Btest_Y001_X011, q00Btest_Y001_X012, q00Btest_Y001_X013, q00Btest_Y001_X014, q00Btest_Y001_X015, q00Btest_Y001_X016, q00Btest_Y002_X001, q00Btest_Y002_X002, q00Btest_Y002_X003, q00Btest_Y002_X004, q00Btest_Y002_X005, q00Btest_Y002_X006, q00Btest_Y002_X007, q00Btest_Y002_X008, q00Btest_Y002_X009, q00Btest_Y002_X010, q00Btest_Y002_X011, q00Btest_Y002_X012, q00Btest_Y002_X013, q00Btest_Y002_X014, q00Btest_Y002_X015, q00Btest_Y002_X016).

Raymond
Last edit: 1 week 4 days ago by Raymond1612.

Please Log in to join the conversation.

More
1 week 3 days ago #272670 by Joffm
Hi,
you have to use "NAOK" in the countings.

Furthermore: q00Btest is not shown for patient "out of age".
So it is sufficient to use the "relevanceStatus" of q00Btest instead of checking the age again and again

Like
(sum(q00Btest_Y001_X001.relevanceStatus,q00Btest_Y002_X001.relevanceStatus)==1  && count(that.q00Btest.NAOK)!=16) ||
(sum(q00Btest_Y001_X001.relevanceStatus,q00Btest_Y002_X001.relevanceStatus)==2  && count(that.q00Btest.NAOK)!=32)


If q00Btest was shown and the count was !16 (1 protesis) resp. !32 (2 protesis), you show q00Ctest

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 2 days ago #272675 by Raymond1612
Hello Joffm,

Thank you very much, you're solution works perfectly!

Do I understand correctly that the crucial error lies primarily in not using "NAOK"? And that the other part (using relevanceStatus) is more of an efficiency improvement although continiously checking prot01 and prot02 does the job as well but in a more cumbersome way?

Raymond

Please Log in to join the conversation.

More
1 week 2 days ago #272677 by Joffm
Yes and yes.
You see. it's a rule in programming "Do not calculate things twice"
If you need a value several times, calculate it, store it and use the stored value later.

By the way:
If you'd coded your age groups better it would be much shorter
Like (I do not remember the correct categories):
Q1
1: 0-3
2: 6-9
3: 15-18
...
0: not in these categories

and
Q2
1: 4-5
2: 10-14
...

Now you avoid the || orgia and the condition is just: Q1.NAOK>1 OR Q2.NAOK>1
Instead of the relevanceStatus you also could have used an equation ("goodage") like {if(Q1.NAOK>1 or Q2.NAOK>1,1,0)}
and use in your conditions "goodage==1"

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 week 2 days ago #272679 by Raymond1612
Hello,

At first glance, the age categories indeed don't seem logical. However, the purpose of the study is to find patients from the age categories in question pat02a. Only if no patients from these categories wish to participate can they also choose the categories in question pat02b.

But I've come across something strange. The condition is being expanded for each subsequent group. So, where the count in group Q00Ctest applies only to q00Btest, in group Q00Dtest it should apply to the count of q00Btest + q00Ctest:

(
  (
    sum(q00Dtest_Y001_X001.relevanceStatus, q00Dtest_Y002_X001.relevanceStatus) == 1
    && count(that.q00Btest.NAOK, that.q00Ctest.NAOK) != 16
  )
  ||
  (
    sum(q00Dtest_Y001_X001.relevanceStatus, q00Dtest_Y002_X001.relevanceStatus) == 2
    && count(that.q00Btest.NAOK, that.q00Ctest.NAOK) != 32
  )
  ||
  (
    (!is_empty(pat02a.NAOK) && (pat02a.NAOK == 2 || pat02a.NAOK == 3 || pat02a.NAOK == 4 || pat02a.NAOK == 5))
    ||
    (!is_empty(pat02b.NAOK) && (pat02b.NAOK == 2 || pat02b.NAOK == 3 || pat02b.NAOK == 4 || pat02b.NAOK == 5 || pat02b.NAOK == 6 || pat02b.NAOK == 7))
  )
)
&&
!(
  (
    sum(q00Dtest_Y001_X001.relevanceStatus, q00Dtest_Y002_X001.relevanceStatus) == 1
    && count(that.q00Btest.NAOK, that.q00Ctest.NAOK) == 16
  )
  ||
  (
    sum(q00Dtest_Y001_X001.relevanceStatus, q00Dtest_Y002_X001.relevanceStatus) == 2
    && count(that.q00Btest.NAOK, that.q00Ctest.NAOK) == 32
  )

When I apply this group condition and check all options for question q00Btest and q00Ctest (relevance=1 and count=16), group Q00Dtest is still shown as an empty group. So the Group is shown whereas the question (q00Dtest) is hidden. Any idea how that is possible? There is no condition set on the question.

Raymond

Please Log in to join the conversation.

More
6 days 21 hours ago - 6 days 21 hours ago #272690 by Raymond1612
Hello,

I managed to solve the problem. The way I added up with count didn’t work:

count(that.q00Btest.NAOK, that.q00Ctest.NAOK)

The count() function in LimeSurvey apparently expects a single array as its argument. If you provide multiple arguments, it leads to strange results. But if you use a separate count for each array and add them together, it works just fine:

(count(that.q00Btest.NAOK) + count(that.q00Ctest.NAOK))

Now I just have to set this up for all 13 arrays 
Hopefully everything will work out now. Thanks for your help and input!

Raymond
Last edit: 6 days 21 hours ago by Raymond1612.

Please Log in to join the conversation.

More
5 days 20 hours ago #272714 by Joffm
Hm,
I do not see any issue.
With none of the several ways. Strange.
 

But one addition:
You should avoid the "+" operator to sum numerical values.

This operator is also used to concatenate text.
Most of the time php guesses the type correctly whether to add to values ao to concatenate.
But sometimes it fails. Then 11+47 is equal 1147.
Therefore it's safer to use the sum()-function.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose