In the example below, in the (Most Current Result & date column) I want the most recent lab results. {LastObsValue("")} works fine. However, in the (Prior Result & Date column) none of the functions shown produce the result for previous lab results. Why am I unable to get the results I am seeking?
I am writing with the results of your recent blood work.
(Most Current Result & date)
|
(Prior Result & Date) | ||
Total cholesterol: | {LastObsValue("CHOLESTEROL")}
{LastObsDate("CHOLESTEROL")} |
{OBSPREV("CHOLESTEROL")}
{OBSTAGANY("CHOLESTEROL")} {OBSTAGPREV("CHOLESTEROL")} |
Less than 200 |
It is more or less working correctly (from what is presented).
Lastobsvalue returns the last observation recorded, either the obsnow value if an update is active with a new value, or the last signed obsvalue if no 'obsnow' value exists.
The same goes for the obstag values as well.
What you need to do is create a custom function that parses the LIST_OBS data symbol and captures the most recent and second most recent values for each obsterm. A bit more code and a different approach is required than what you are using.
Note: Using LIST_OBS, you can get all the desired information from the array, so a loop routine will allow you to capture it all and display it, if present. Consult the EMR Help File under using data symbols for specifics on how to use the array.
Hope this helps.
That helps some what, but not really getting me any closer to my solution. I'm a novice when it comes to writing out and creating functions with code. When I refer to the EMR Help file, it provides me with the functions I've already tried. I need specific direction.
The following function will get you what you want, but you may need to adjust to your specific needs.
Understand that you are introducing a level of complexity beyond simple MEL coding in that you are adding this to a handout. This means that the handout must contain or have access to the function too. Unless you have experience with that, it is a bit difficult to walk you through the process here on the forum, so if you find yourself struggling, let me know and we might be able to set up a remote session.
The function below is what you need and it allows you to define which value to return. For example:
fnGetObsVals("WEIGHT",1) will return the most recent value in the weight obsterm
fnGetObsVals("WEIGHT",2) will return the second most recent value in the weight obsterm.
{! fn fnGetObsVals(strObsName,nVal)
{
local retStr = ""
local strTemp = ""
local strBuf = ""
local i
strBuf = LIST_OBS(strObsName,"pencil","delimited","value")
strTemp = getfield(strBuf,"|","")
if nVal > size(strTemp) then
return ""
endif
for i = 1, i <= size(strTemp), i = i + 1 do
strTemp[i] = getfield(strTemp[i],"^","")
if i == nVal then
// Format: Date: Value (tag/flag)
retStr = strTemp[i][2] + ": " + strTemp[i][1] + " (" + strTemp[i][6] + ")"
break
else ""
endif
endfor
return retStr
}
}
Hope this at least gets you started.