I am working on a Surgery Risk calculation and it just isn't calculating... what did i miss: TIA ~ Beth
{!
local localIS_SURGERY_H2
localIS_SURGERY_H2= ""
local localHISTORY_OF_I
localHISTORY_OF_I = ""
local localHISTORY_OF_C
localHISTORY_OF_C = ""
local localHISTORY_OF_C1
localHISTORY_OF_C1 = ""
local localPRE_OPERATIV
localPRE_OPERATIV = ""
local localPRE_OPERATIV1
localPRE_OPERATIV1 = ""
local localTotal
localTotal = ""
if DOCUMENT.IS_SURGERY_H2 = "Yes" then localIS_SURGERY_H2 = "1"
else localIS_SURGERY_H2 = ""
endif
if DOCUMENT.HISTORY_OF_I = "Yes" then localHISTORY_OF_I = "1"
else localHISTORY_OF_I = ""
endif
if DOCUMENT.HISTORY_OF_C = "Yes" then localHISTORY_OF_C = "1"
else localHISTORY_OF_C = ""
endif
if DOCUMENT.HISTORY_OF_C1 = "Yes" then localHISTORY_OF_C1 = "1"
else localHISTORY_OF_C1 = ""
endif
if DOCUMENT.PRE_OPERATIV = "Yes" then localPRE_OPERATIV = "1"
else localPRE_OPERATIV = ""
endif
if DOCUMENT.PRE_OPERATIV1 = "Yes" then localPRE_OPERATIV1 = "1"
else localPRE_OPERATIV1 = ""
endif
localTotal = val(localIS_SURGERY_H2) + val(localHISTORY_OF_I) + val(localHISTORY_OF_C) + val(localHISTORY_OF_C1) + val(localPRE_OPERATIV) + val(localPRE_OPERATIV1)
RSKSCORTOTAL = localTotal
local localREVISED_CARD
localREVISED_CARD = ""
if localTotal = "0" then localREVISED_CARD = " This score belongs to Class I of risk for perioperative cardiac events with a risk percentage of 0.4%.. "
endif
if localTotal = "1" then localREVISED_CARD = " This score belongs to Class II of risk for perioperative cardiac events with a risk percentage of 0.9%."
endif
if localTotal = "2" then localREVISED_CARD = " This score belongs to Class III of risk for perioperative cardiac events with a risk percentage of 6.6%."
endif
if localTotal = "3" then localREVISED_CARD = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%. "
endif
if localTotal = "4" then localREVISED_CARD = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%. "
endif
if localTotal = "5" then localREVISED_CARD = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%. "
endif
if localTotal = "6" then localREVISED_CARD = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%"
endif
DOCUMENT.REVISED_CARD= localREVISED_CARD
}
Hi Beth,
I didn't really review what could be wrong with the code (I suspect the use of local as part of variable - local is a reserved keyword).
I did rewrite the code in a more efficient manner that you hopefully will be able to follow. I broke the workflow down into two separate functions that achieve what it is you desire. I've not tested it, but it should work.
Please let me know and I will work on it some more.
Hope this helps.
{!
DOCUMENT.RSKSCORTOTAL = fnGetCardRiskScore(DOCUMENT.IS_SURGERY_H2,DOCUMENT.HISTORY_OF_I,DOCUMENT.HISTORY_OF_C,DOCUMENT.HISTORY_OF_C1,DOCUMENT.PRE_OPERATIV,DOCUMENT.PRE_OPERATIV1)
}
{! fn fnGetCardRiskScore(strH2,strI,strC,strC1,strPreOp,strPreOp1)
{
local retStr = ""
local i
local nArgs
local nTotal = 0
nArgs = getnargs()
for i = 1, i <= nArgs, i = i + 1 do
if getarg(i) == "" then
retStr = "Incomplete"
break
else
if getarg(i) == "Yes" then
nTotal = nTotal + 1
else ""
endif
endif
endfor
if retStr "Incomplete" then
retStr = str(nTotal)
else
retStr = ""
endif
return retStr
}
}
{!
DOCUMENT.REVISED_CARD = fnGetCardRiskInterp(DOCUMENT.RSKSCORTOTAL)
}
{! fn fnGetCardRiskInterp(strScore)
{
local retStr = ""
cond
case nScore == "0" retStr = " This score belongs to Class I of risk for perioperative cardiac events with a risk percentage of 0.4%.. "
case nScore == "1" retStr = " This score belongs to Class II of risk for perioperative cardiac events with a risk percentage of 0.9%."
case nScore == "2" retStr = " This score belongs to Class III of risk for perioperative cardiac events with a risk percentage of 6.6%."
case nScore == "3" retStr = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%. "
case nScore == "4" retStr = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%. "
case nScore == "5" retStr = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%. "
case nScore == "6" retStr = " This score belongs to Class IV of risk for perioperative cardiac events with a risk percentage of 11%"
else ""
endcond
return retStr
}
}
Beth,
I suspect the reason your code is not working is because you are comparing a numeric value to a string. See the suspected problem lines of code below:
When you calculate the localTotal variable in your code, you properly convert the other variables to numbers prior to performing the calculation - Yay!:
localTotal = val(localIS_SURGERY_H2) + val(localHISTORY_OF_I) + val(localHISTORY_OF_C) + val(localHISTORY_OF_C1) + val(localPRE_OPERATIV) + val(localPRE_OPERATIV1)
However, further down in your code, you are comparing this numeric variable to a string. Remember that localTotal now contains a number and not a string, even though you initialized it with an empty string when you declared the variable. This will result in all of your "if" statement expressions returning false.
if localTotal = “0″ then localREVISED_CARD = ” This score belongs to Class I of risk for perioperative cardiac events with a risk percentage of 0.4%.. ”
As a result, the localREVISED_CARD variable will contain the value that it was assigned when you declared the variable (i.e. an empty string "")
Without knowing your experience level or role within your practice, here are some other suggestions and tips for coding best practices that you might find helpful:
Define all of your local variables at the top of your function and drop the "local" prefix. I originally thought that you had failed to define the localREVISED_CARD variable, but finally found it in the middle of your code. For enhanced readability, you can include a comment after each variable indicating how the variable is used. Trust me, it will make maintaining the code a lot easier when you have to revisit it several months later.
I understand where Lee is coming from with his response about using "local" as a prefix for your variables. However, using "local" as a prefix shouldn't cause errors, even though it is a reserved word in the MEL language. That said, it is highly confusing and makes for longer variable names. If you have adopted this naming convention so that you can identify the locally defined variables throughout your code (as opposed to global variables), then I would suggest using "l_" in front of all local variables and "g_" in front of all global variables. Adopting a consistent naming convention for all your MEL coding will also improve the maintainability of your code.
Finally, take a look at Lee's code and how he compartmentalizes sections of your code with the use of functions. This significantly improves readability and maintainability of your code because it isolates code blocks in a logical fashion making it easier to troubleshoot when things go awry. It also comes in handy when you need similar functionality on a different form. In his function fnGetCardRiskInterp(strScore), note how he used a cond/endcond block to identify the proper condition rather than a series of if/endif statements. This is not only more readable, but more efficient for the computer to process.
I hope you find these tips helpful. Happy coding...
Cheers
Hi Greg,
You actually hit on one of the things I find annoying about MEL. Numerical vs. string representations can actually work in certain conditions (especially with NULL and ZERO) and of course, in others, it fails completely. While the single digit comparison typically will not fail, your advice is spot on - forming good habits is important.
Example from MEL trace of Beth's code:
07/18/2019 11:27:11.147-execute>RSKSCORTOTAL = 0
07/18/2019 11:27:11.147-results>0
07/18/2019 11:27:11.147-execute>LOCALREVISED_CARD = ""
07/18/2019 11:27:11.147-results>""
07/18/2019 11:27:11.147-execute>0 == "0"
07/18/2019 11:27:11.147-results>TRUE
I also 'think' I may have found the issue, there is a missing close parens in the calculation of the score:
val(localIS_SURGERY_H2 +
There should be a close parens after the H2. I do wonder, however, if the forum has stripped it out and it really was there...