My stopbang_or_stob function below is working and displays each score in its own field but my case statement is not working to display the recommendation. If anyone can give me some advice it would be greatly appreciated. I used global variables hoping they would work outside the function but maybe they aren't, or maybe it is a typo?
/*Calculate STOPBANG and STOB scores*/
{fn stopbang_or_stob(i1,i2,i3,i4,i5,i6,i7,i8,op){
global output1 = ""
global output2 = ""
if i1 <> "" and op = "stopbang" then
output1 = 1
else if i1 <> "" and op = "stob" then
output2 = 1
endif
endif
if i2 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i2 <> "" and op = "stob" then
output2 = output2 + 1
endif
endif
if i3 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i3 <> "" and op = "stob" then
output2 = output2 + 1
endif
endif
if i4 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i4 <> "" and op = "stob" then
output2 = output2
endif
endif
if i5 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i5 <> "" and op = "stob" then
output2 = output2 + 1
endif
endif
if i6 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i6 <> "" and op = "stob" then
output2 = output2
endif
endif
if i7 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i7 <> "" and op = "stob" then
output2 = output2
endif
endif
if i8 <> "" and op = "stopbang" then
output1 = output1 + 1
else if i8 <> "" and op = "stob" then
output2 = output2
endif
endif
}}
/*Display recommendation based on scores*/
{!if output1 <>""
then
COND
//HIGH RISK SLEEP APNEA
CASE val output1 > 2
OBSNOW("BANGTOTAL2","This score indicates that the patient is at elevated risk of sleep apnea. Further evaluation with a sleep study is recommended.")
//MEDIUM RISK SLEEP APNEA
CASE val output2 > 1
OBSNOW("BANGTOTAL2","The patient has risk factors for sleep apnea. If clinically indicated, consider ordering a sleep study.")
//NO RISK SLEEP APNEA
CASE val output1 <= 8
OBSNOW("BANGTOTAL2","Screening does not indicate that the patient is at high risk of obstructive sleep apnea.")
ENDCOND
else
OBSNOW("BANGTOTAL2","")
endif
}
you need parentheses around your variable for the VAL function:
CASE val (output1) > 2
Thanks, I just fixed it and tried again. It still doesn't work for some reason though. I am now noticing I get the value FALSE in the fields referencing the function if the last field is not checked, I wonder if I need str(output1) or something similar in there.
you're defining your globals as strings but using them as numbers. try defining as global variable = 0, then check for 0 instead of "". you also have references to output2 = output2. do you want output2 = output2 + 1?
Actually on 4 of the questions for STOB I don't want it to add anything on, the most STOB can ever total is 4. I had originally used a variable called output for both and made them strings and it was working well that way for the display but then I couldn't figure out how to work them into the case statement. This is how the display code works for each one, I use stob at the end of the other one:
{stopbang_or_stob(DOCUMENT.NO1,DOCUMENT.NO2,DOCUMENT.NO3,DOCUMENT.NO4,DOCUMENT.NO5,DOCUMENT.NO6,DOCUMENT.NO7,DOCUMENT.NO8,
"stopbang")}
I've cleaned up your function a bit:
/*Calculate STOPBANG and STOB scores*/
{fn stopbang_or_stob(i1,i2,i3,i4,i5,i6,i7,i8,op)
{
global output1 = 0
global output2 = 0
if i1 <> "" then
if op = "stopbang" then
output1 = output1 + 1
else
if op = "stob" then
output2 = output2 + 1
endif
endif
endif
if i2 <> "" then
if op = "stopbang" then
output1 = output1 + 1
else
if op = "stob" then
output2 = output2 + 1
endif
endif
endif
if i3 <> "" then
if op = "stopbang" then
output1 = output1 + 1
else
if op = "stob" then
output2 = output2 + 1
endif
endif
endif
if i4 <> "" then
if op = "stopbang" then
output1 = output1 + 1
endif
endif
if i5 <> "" then
if op = "stopbang" then
output1 = output1 + 1
else
if op = "stob" then
output2 = output2 + 1
endif
endif
endif
if i6 <> "" then
if op = "stopbang" then
output1 = output1 + 1
endif
endif
if i7 <> "" then
if op = "stopbang" then
output1 = output1 + 1
endif
endif
if i8 <> "" then
if op = "stopbang" then
output1 = output1 + 1
endif
endif
}
}
/*Display recommendation based on scores*/
{!if output1 > 0 then
COND
//HIGH RISK SLEEP APNEA
CASE output1 > 2
OBSNOW("BANGTOTAL2","This score indicates that the patient is at elevated risk of sleep apnea. Further evaluation with a sleep study is recommended.")
//MEDIUM RISK SLEEP APNEA
CASE output2 > 1
OBSNOW("BANGTOTAL2","The patient has risk factors for sleep apnea. If clinically indicated, consider ordering a sleep study.")
//NO RISK SLEEP APNEA
CASE output1 <= 8
OBSNOW("BANGTOTAL2","Screening does not indicate that the patient is at high risk of obstructive sleep apnea.")
ENDCOND
else
OBSNOW("BANGTOTAL2","")
endif
}
but in your case statement...
you referance output1 in the initial IF, but for case 2, you reference output2...guessing should be output1.
3 case conditions should be mutually exclusive...case 3 doesn't make sense...never get there.
The recommendation logic is strange, our sleep doctor wants to look at both STOPBANG and STOB. If it meets case 1 for STOPBANG he wants it to display one message and stop, then if not he wants it to look at STOB and display another message and stop, then display the third message if it doesn't meet either of the first two. I am still getting the FALSE if the last box isn't checked for some reason and STOB is always false. Nothing is popping up in the recommendation box yet, but it never has. This is a really odd one I know, I couldn't even find a consultant to hire that would help me.
/*Display recommendation based on scores*/
{!if output1 > 2 then
//HIGH RISK SLEEP APNEA
OBSNOW("BANGTOTAL2","This score indicates that the patient is at elevated risk of sleep apnea. Further evaluation with a sleep study is recommended.")
else
if output2 > 1 then
//MEDIUM RISK SLEEP APNEA
OBSNOW("BANGTOTAL2","The patient has risk factors for sleep apnea. If clinically indicated, consider ordering a sleep study.")
else
//NO RISK SLEEP APNEA
OBSNOW("BANGTOTAL2","Screening does not indicate that the patient is at high risk of obstructive sleep apnea.")
endif
endif}
Great, I am getting closer, thanks. Now the third message always displays no matter what is checked, none ever have before. I see I was using a Case Statement when if/then is best. The only problem now is that the STOB display always says FALSE, and STOPBANG only displays if i8 is checked, otherwise it says FALSE.
= means assignment
== is for comparison
sorry didn't catch that before
/*Calculate STOPBANG and STOB scores*/
{fn stopbang_or_stob(i1,i2,i3,i4,i5,i6,i7,i8,op)
{
global output1 = 0
global output2 = 0
if i1 <> "" then
if op == "stopbang" then
output1 = output1 + 1
else
if op == "stob" then
output2 = output2 + 1
endif
endif
endif
if i2 <> "" then
if op == "stopbang" then
output1 = output1 + 1
else
if op == "stob" then
output2 = output2 + 1
endif
endif
endif
if i3 <> "" then
if op == "stopbang" then
output1 = output1 + 1
else
if op == "stob" then
output2 = output2 + 1
endif
endif
endif
if i4 <> "" then
if op == "stopbang" then
output1 = output1 + 1
endif
endif
if i5 <> "" then
if op == "stopbang" then
output1 = output1 + 1
else
if op == "stob" then
output2 = output2 + 1
endif
endif
endif
if i6 <> "" then
if op == "stopbang" then
output1 = output1 + 1
endif
endif
if i7 <> "" then
if op == "stopbang" then
output1 = output1 + 1
endif
endif
if i8 <> "" then
if op == "stopbang" then
output1 = output1 + 1
endif
endif
}
}
It finally works, thanks for all of the ideas, I couldn't have figured this out without you. This is what I ended up using. I don't really need to display the scores, just a recommendation so this ends up working out perfectly
/*Calculate*/
{
global output1 = 0
global output2 = 0
if DOCUMENT.NO1 <> "" then
output1 = output1 + 1
output2 = output2 + 1
endif
if DOCUMENT.NO2 <> "" then
output1 = output1 + 1
output2 = output2 + 1
endif
if DOCUMENT.NO3 <> "" then
output1 = output1 + 1
output2 = output2 + 1
endif
if DOCUMENT.NO4 <> "" then
output1 = output1 + 1
endif
if DOCUMENT.NO5 <> "" then
output1 = output1 + 1
output2 = output2 + 1
endif
if DOCUMENT.NO6 <> "" then
output1 = output1 + 1
endif
if DOCUMENT.NO7 <> "" then
output1 = output1 + 1
endif
if DOCUMENT.NO8 <> "" then
output1 = output1 + 1
endif
}
/*Display recommendation based on scores*/
{fn calc(){
if output1 > 2 then
//HIGH RISK SLEEP APNEA
OBSNOW("BANGTOTAL2","This score indicates that the patient is at elevated risk of sleep apnea. Further evaluation with a sleep study is recommended.")
else
if output2 > 1 then
//MEDIUM RISK SLEEP APNEA
OBSNOW("BANGTOTAL2","The patient has risk factors for sleep apnea. If clinically indicated, consider ordering a sleep study.")
else
//NO RISK SLEEP APNEA
OBSNOW("BANGTOTAL2","Screening does not indicate that the patient is at high risk of obstructive sleep apnea.")
endif
endif}}