This is my first attempt at trying to write a function and am not sure where I am going wrong. Any help would be welcomed!
There are five variable fields established with radio buttons. Each radio button option can have a value of 0,1,2, or 3. After selecting the five options, I would like the sum of the selections to populate a edit box (or data box if possible). Finally, if the total value is less than or equal to 6, I tried to get a userok to pop up to force the user to acknowledge this value. Needless to say, neither function is working.
Thanks in advance!!!!
/*Calculates the Bishop score.
*/
{! fn fnCalculateBishop()
{
local r1
local r2
local r3
local r4
local r5
!IF (DOCUMENT.POSITION == "") then r1=0
else if (DOCUMENT.POSITION == "Posterior") then r1=0
else if (DOCUMENT.POSITION == "Midposition") then r1=1
else if (DOCUMENT.POSITION == "Anterior") then r1=2
else ""
endif
endif
endif
endif
!IF (DOCUMENT.CONSISTENCY == "") then r2=0
else if (DOCUMENT.CONSISTENCY == "Firm") then r2=0
else if (DOCUMENT.CONSISTENCY == "Medium") then r2=1
else if (DOCUMENT.CONSISTENCY == "Soft") then r2=2
else ""
endif
endif
endif
endif
!IF (DOCUMENT.EFFACEMENT == "") then r3=0
else if (DOCUMENT.EFFACEMENT == "0-30%") then r3=0
else if (DOCUMENT.EFFACEMENT == "40-50%") then r3=1
else if (DOCUMENT.EFFACEMENT == "60-70%") then r3=2
else if (DOCUMENT.EFFACEMENT == "80+%" then r3=3
else ""
endif
endif
endif
endif
endif
!IF (DOCUMENT.DILATION) == "" then r4=0
else if (DOCUMENT.EFFACEMENT == "0 cm") then r4=0
else if (DOCUMENT.EFFACEMENT == "1-2 cm") then r4=1
else if (DOCUMENT.EFFACEMENT == "3-4 cm" then r4=2
else if (DOCUMENT.EFFACEMENT == ">5cm" then r4=3
else ""
endif
endif
endif
endif
endif
!IF (DOCUMENT.STATION == "") then r5=0
else if (DOCUMENT.STATION == "-3") then r5=0
else if (DOCUMENT.STATION == "-2") then r5=1
else if (DOCUMENT.STATION == "-1") then r5=2
else if (DOCUMENT.STATION == "0") then r5=2
else if (DOCUMENT.STATION == "+1") then r5=3
else if (DOCUMENT.STATION == "+2") then r5=3
else ""
endif
endif
endif
endif
endif
endif
endif
!DOCUMENT.BISHOP = r1+r2+r3+r4+r5
}
}
/*
Popup warning for suboptimal Bishop Score
*/
{
if (DOCUMENT.BISHOP = "") then ""
else (DOCUMENT.BISHOP <= "6") then userok("Your patient's Bishop score is less than adequate for induction of labor. Please be sure to document medical necessity.")
endif
}
First, take all the exclamation points out of the body of the function, those are used for either loading a function first so it can be used on form open (which you have also done and is fnie) or forcing a watcher expression to run on form open, which is an expression with only one set of brackets {}. So the only one you should have is the very first one.
How are you calling this function? I would pass the all the variables, i think its cleaner, so the first line of the function make
{! fn fnCalculateBishop(var1,var2,var3,var4,var5)
and then add a line to the code panel
{document.bishop = fnCalculateBishop(DOCUMENT.POSITION, DOCUMENT.CONSISTENCY, DOCUMENT.EFFACEMENT, DOCUMENT.DILATION, DOCUMENT.STATION)}
That way any change in a radio button will force the function to re-evaluate. Also change the last line of the function to
return str(r1 + r2 + r3 + r4 + r5)
and I would initialize the r's to 0, Im not 100% sure its necessary but it may be.
local r1=0
local r2=0
local r3=0
local r4=0
local r5=0
Last for the function, I think you meant to change the EFFACEMENT to DILATION but missed some.
The popup - First thing I notice is that everytime the first option is selected, you will get a popup because the score is always less than 3, you may want to think about adding logic so it only pops-up if less than 6 and all options are filled out.
You're missing an if and an endif, if before you check for less than 6 and endif at the end. The only other thing is you are comparing strings now (or a string to a value before the change to the function I recommended). Do this to compare apples to apples (val(DOCUMENT.BISHOP) <= 6)
Well I was in the ballpark at least! Tried to make those changes but still not getting it to function properly. No MEL errors though either. I was thinking the other option was to populate the DOCUMENT.BISHOP field by firing this with an action key. That way I would not have to worry about the popup. Regardless, I wanted to try using AND to see if it would work but…no. Any furhter thoughts?
/*
Calculates the Bishop score.
*/
{fn fnCalculateBishop(var1,var2,var3,var4,var5)
{DOCUMENT.BISHOP=fnCalculateBishop(DOCUMENT.POSITION,DOCUMENT.CONSISTENCY,DOCUMENT.EFFACEMENT,DOCUMENT.DILATION,DOCUMENT.STATION)
local r1=0
local r2=0
local r3=0
local r4=0
local r5=0
IF (DOCUMENT.POSITION = "") then r1=0
else if (DOCUMENT.POSITION == "Posterior") then r1=0
else if (DOCUMENT.POSITION == "Midposition") then r1=1
else if (DOCUMENT.POSITION == "Anterior") then r1=2
else ""
endif
endif
endif
endif
IF (DOCUMENT.CONSISTENCY = "") then r2=0
else if (DOCUMENT.CONSISTENCY == "Firm") then r2=0
else if (DOCUMENT.CONSISTENCY == "Medium") then r2=1
else if (DOCUMENT.CONSISTENCY == "Soft") then r2=2
else ""
endif
endif
endif
endif
IF (DOCUMENT.EFFACEMENT = "") then r3=0
else if (DOCUMENT.EFFACEMENT == "0-30%") then r3=0
else if (DOCUMENT.EFFACEMENT == "40-50%") then r3=1
else if (DOCUMENT.EFFACEMENT == "60-70%") then r3=2
else if (DOCUMENT.EFFACEMENT == "80+%") then r3=3
else ""
endif
endif
endif
endif
endif
IF (DOCUMENT.DILATION) = "" then r4=0
else if (DOCUMENT.DILATION == "0 cm") then r4=0
else if (DOCUMENT.DILATION == "1-2 cm") then r4=1
else if (DOCUMENT.DILATION == "3-4 cm") then r4=2
else if (DOCUMENT.DILATION == ">5cm") then r4=3
else ""
endif
endif
endif
endif
endif
IF (DOCUMENT.STATION = "") then r5=0
else if (DOCUMENT.STATION == "-3") then r5=0
else if (DOCUMENT.STATION == "-2") then r5=1
else if (DOCUMENT.STATION == "-1") then r5=2
else if (DOCUMENT.STATION == "0") then r5=2
else if (DOCUMENT.STATION == "+1") then r5=3
else if (DOCUMENT.STATION == "+2") then r5=3
else ""
endif
endif
endif
endif
endif
endif
endif
return str(r1 + r2 + r3 + r4 +r5)
}
}
/*
Popup warning for suboptimal Bishop Score
*/
{
if (DOCUMENT.BISHOP = "") then ""
elseif (val(DOCUMENT.BISHOP) > "6") then ""
elseif (val(DOCUMENT.BISHOP) <= "6")
AND
(DOCUMENT.POSITION<>"")
AND
(DOCUMENT.CONSISTENCY<>"")
AND
(DOCUMENT.EFFACEMENT<>"")
AND
(DOCUMENT.DILATION<>"")
AND
(DOCUMENT.STATION<>"")then userok("Your patient's Bishop score is less than adequate for induction of labor. Please be sure to document medical necessity.")
endif
endif
endif
}
Thanks again!
This goes outside the function, so you should have three pieces of code including the popup. Add a closing bracket as well -
{DOCUMENT.BISHOP=fnCalculateBishop(DOCUMENT.POSITION,DOCUMENT.CONSISTENCY,DOCUMENT.EFFACEMENT,DOCUMENT.DILATION,DOCUMENT.STATION)}
Also just noticed, you are missing some closing paranthesis in the function. By the DILATION variable...
The popup, you cant have the quotes on the 6, you want it to compare the value of document.bishop to the value of 6, not the string of 6, writing "6" is the same as "six", MEL wont know what to do with it. The greater than 6 piece is redundant, but its okay. Watch your spaces too, you need one before the 'then userok("...' part and else if needs to be two words in MEL as well.
I caught the the paranthesis issue after I sent my last message and have those cleaned up. I divided all of the code up into three distinct sections. Removed the "" from surrounding the 6 in the pop up code.
Still does not calculate....Thanks for taking the time to help with this Michael. Trying my best to learn this dang language.
Would it help to maybe send the .ckt to you?
Yes I can take a look
Hello,
Our OB providers are asking me to develop a form for the Bishop Score. Are you willing to share?
Thanks,
Jenelle Rabideau
Affinity Health System