Hello,
I have the following MEL code in the whiteboard of a form and it works like it should. This is just a small section of the code, but this pretty much just loops through the patient's Active Problem list and checks to see if they have a Dx of Hypertension, and if so it sets the global variable dxHTN to "y".
I do this same check for a lot of different diagnosis, and I have a couple of different forms that need to know the value of dxHTN for different reasons (visibility regions, button labels, alerts, ect.). This currently works and the other forms can access the global variable, but I want to move this function to the Function Library.
When I take this same piece of code and add it to the function library, it does not work anymore. The function appears to run, but it doesn't seem like I can access the value of the global variables anymore.
To test, at the end of the function I have it setting the value of a text box equal to the value of each global dx variable that I am using, with a HRET separating each variable. When the function runs the textbox has a bunch of HRET, but no values from the variables.
Can I use functions in a function library to set the value of a bunch of global variables that can be accessed by all the forms in an update? Does any one have any ideas why this is not working? If you need any clarification, please let me know.
Thanks!
local getDx = getfield(PROB_AFTER("delimited"),"|","")
local getDxsz = size(getDx)
global dxHTN = ""
FOR count = 1, count <= getDxsz, count = count + 1 do
local getDxInfo = getfield(getDx[count],"^","")
IF getDxInfo[8] <> "" then
if dxHTN == "" and match("I10",replacestr(getDxInfo[8],"ICD10-","")) > 0 then
dxHTN = "y"
endif
ENDIF
ENDFOR
Not sure if this is causing your issue, but it looks like you are creating the local variable getDXInfo multiple times (every time you go through the loop). I would create this variable outside the loop as:
local getDXInfo
Move the global variable definition out of the function. Place it on each form it is required for use in. It should look like the following in the MEL window (white board as you reference it):
{! global dxHTN}
As a side note, since this is a global variable, I would consider renaming it to something more unique. Odds of collision are high for common use names such as what you are using, especially if your content is not entirely constructed by you.
I typically use the letter g to annotate 'global' and include a reference to the library it is in. Example: gDxHTN_Util. This makes it rather unique and provides easy reference down the road when you are attempting to locate where it is being managed.
Thanks for the feedback. I will try this. Just to clarify, I do not need to define the variable at all in the function, I only define it on each form that needs to use the variable?
Thanks.
Thank. I will try this as well.
Correct. The variable is used by the form, not the function, so it must be 'defined' in the form. There are ways to define outside of the form, but they are unreliable and convoluted. The method I described is clean and reliable.
As an alternative, you could simply declare a DOCUMENT. variable on each form as well (IE. DOCUMENT.gDX_HTN_UTIL). Basically, replace your global variable with this variable.
The upside to this approach is that it will preserve the value when the update is put on hold. This will grant more control allowing you to minimize executions. Using this approach, you can fire the function initially and using 'PROB_AFTER()' as an argument to the function, only fire it again if something is changed. Reducing the overhead will optimize the functionality.