Hi all, I am developing STOP-Bang questionnaire form in VFE. I am missing something because I can't get this function to work
{ IF DOCUMENT.BANGSTORE >2 AND DOCUMENT.BANGSTORE <5 then
DOCUMENT.BANGRESULT = "OSA - Intermediate Risk"
else
IF DOCUMENT.BANGSTORE >=2 AND DOCUMENT.BODYMASS =Yes then
DOCUMENT.BANGRESULT = "OSA - High Risk"
else
IF DOCUMENT.BANGSTORE >=2 AND DOCUMENT.FOR_MALE =Yes then
DOCUMENT.BANGRESULT = "OSA - High Risk"
else ""
endif endif endif}
It is only taking the first statement. it does not recognize the other two statements if other answers are yes.
Any thoughts?
Thanks, Jude
Just thinking a bit about this... and wondering if you need to be doing VAL on those numeric document variables?
{ IF VAL(DOCUMENT.BANGSTORE) >2 AND VAL(DOCUMENT.BANGSTORE) <5 then ...
Also, the text for Yes probably needs to be in quotes "Yes"
Still doing the same thing with VAL or without VAL. It is only recognizing the first IF sentence.
Perhaps simplify - remove the 3rd if, and change the 2nd if to just say "two".
That way, you can make sure it is analyzing to that point.
Once there, use a simple if - like if 2>1 then "TWO"
Simply step through it all.
And one last thing, sometimes manually retyping helps, eliminating a random and unintended character. By the way, assuming you are using the VAL and "quotes", the logic looks correct to me. Although, it is obviously not your true cut/paste.
if document.bangstore is 3 or 4, it will always execute only the first statement and ignore the other two statements
That is correct -> if bangstore is 3 or 4 it will ALWAYS stop there. It meets the first rule so NEVER gets to any succeeding rules. If you want a different result, then perhaps re-order your statements?
Yes, reordering the statements will work . Code the document.bangstore is 3 or 4 as the 3rd if then else statement.
A few things I noticed (my attempt at a re-write is below):
1. Rather than IF/ELSE IF/ELSE IF, I recommend a cond case endcond statement. It really helps simplify the code and makes it easier to think through.
2. By default, I think MEL treats all DOCUMENT. variables as strings, so I think you need to use VAL(DOCUMENT.BANGSTORE) in evaluations.
3. When checking for value = yes, you need to put the Yes in double-quotes. I also use a double == for evaluations like this one, but that could just be personal preference.
{
cond
case VAL(DOCUMENT.BANGSTORE) >2 AND VAL(DOCUMENT.BANGSTORE) =2 AND DOCUMENT.BODYMASS == "Yes": DOCUMENT.BANGRESULT = "OSA – High Risk"
case VAL(DOCUMENT.BANGSTORE) >=2 AND DOCUMENT.FOR_MALE == "Yes": DOCUMENT.BANGRESULT = "OSA – High Risk"
else: //do nothing
endcond
}
So here's what I found about the scoring on a quick web search:
For general population
Low risk of OSA: Yes to 0-2 questions
Intermediate risk of OSA: Yes to 3-4 questions
High risk of OSA: Yes to 5-8 questions
or Yes to 2 or more of 4 STOP questions + male gender
or Yes to 2 or more of 4 STOP questions + BMI > 35 kg/m2
or Yes to 2 or more of 4 STOP questions + neck circumference (17”/43cm in male, 16”/41cm in female)
So I would take Chaddix's suggestion and write this as COND..CASE..ELSE..ENDCOND. Conditional statements like this quit executing as soon as one of the CASE statements is true, so I would do a CASE statement for each High Risk scenarios first, then your Intermediate Risk, and Low Risk would be assigned as the ELSE.