I am using the below function to pull in lab values from the last year. It works beautifully, but is there any way to add a sort to it so it shows the most recent values last? Right now, it displays like this:
CALCIUM
07/16/2012 : 9.2
10/23/2012 : 9.2
01/24/2013 : 9.1
04/16/2012 : 9.0
Any help would be appreciated.
{! fn fnGetFlowSheetValues_LC(strFlowSheetName)
{
local retStr = ""
local strTemp = ""
local strBuf = ""
local strToday = ""
local strVals = ""
local lTab = ""
local strObsName = ""
local strObsDate = ""
local strObsValue = ""
local strOffSet = ""
local strList = ""
local strRes = ""
local i
if strFlowSheetName == "" then return "Flowsheet Name Not Specified" endif
strVals = GET_FLOWSHEET_VALUES(strFlowSheetName,"DELIM")
// format: obsterm name^result value^result date|
if strVals == "" then return "No results." endif
lTab = numtoascii(9)
if DOCUMENT.CLINICALDATE == "" then
strToday = str(._TODAYSDATE)
else
strToday = str(sub(str(DOCUMENT.CLINICALDATE),1,10))
endif
strTemp = getfield(strVals,"|","")
for i = 1, i <= size(strTemp), i = i + 1 do
if strTemp[i] <> "" then
// build exception patterns to strip out delimiters from data that will offset the index
cond
case match(strTemp[i],"m^2^")>0 strTemp[i] = fnReplStr_LC(strTemp[i], "m^2^", "m2^")
else ""
endcond
strTemp[i] = getfield(strTemp[i],"^","")
strObsDate = strTemp[i][3]
if durationdays(strObsDate,strToday)<=366 then
strObsName = strTemp[i][1]
if match(strList,strObsName)==0 then
strList = strList + strObsName + "|"
endif
strBuf = lTab + strTemp[i][3] + ": " + strTemp[i][2]
strRes = strRes + strObsName + "^" + strBuf + "|"
else ""
endif
else ""
endif
endfor
if strRes == "" then
return "No results."
endif
strTemp = getfield(strList,"|","")
for i = 1, i <= size(strTemp), i = i + 1 do
if strTemp[i] <> "" then
retStr = retStr + strTemp[i] + HRET + fnGrpResults_LC(strTemp[i],strRes)
else ""
endif
endfor
return retStr
}
}
{! fn fnGrpResults_LC(strObsName,strResults)
{
local retStr = ""
local strTemp = ""
local strBuf = ""
local i
strTemp = getfield(strResults,"|","")
for i = 1, i <= size(strTemp), i = i + 1 do
if strTemp[i] <> "" then
strTemp[i] = getfield(strTemp[i],"^","")
if strObsName == strTemp[i][1] then
strBuf = strTemp[i][2]
retStr = retStr + strBuf + HRET
else ""
endif
else ""
endif
endfor
return retStr
}
}
{! fn fnReplStr_LC(strBuf, strTarget, strReplacement)
{
local nMatch = match(strBuf, strTarget)
while (nMatch > 0) do
strBuf = remove(strBuf, nMatch, size(strTarget))
strBuf = insert(strBuf, nMatch, strReplacement)
nMatch = match(strBuf, nMatch + size(strReplacement), strTarget)
endwhile
return (strBuf)
}
}{fnGetFlowSheetValues_LC("Enterprise\Interfaces\CCD\Diagnostic Results")}