I have the MEL below in a form our sleep specialist needed called the STOP BANG form with 8 sleep questions and a recommendation button. This works fine if the same user asks the questions and presses the recommendation button but if another user opens the form the recommendation changes, as though none of the eight check boxes are checked any longer. What should I be looking for?
/*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}}
Maybe you need to put a ! in the MEL for your Calculate so it recalcs when the form opens?
/*Calculate*/ { ! global output1 = 0 global output2 = 0 if DOCUMENT.NO1 <> "" then.....
David is right, since you saved the output to global variables and declared them inside the form they will die when you put the document on hold. You can do what David suggested and that will work fine, the other option to replace the global variables output1 and output2 with document variables document.output1 and document.output2. That way you will not need to do the extra calculation when you open the form. I always declare document variables seperately so I would do it like this
/*Calculate*/
{!document.output1}
{!document.output2}
{if DOCUMENT.NO1 <> "" then
document.output1 = document.output1 + 1
document.output2 = document.output2 + 1
endif
if DOCUMENT.NO2 <> "" then ....
Running less code always speeds things up, the time savings is very marginal in this case but it can add up quickly.
Thank you both so much, I really learn a lot from this forum. I am going to fix this right now.