A simple code to pull an array from PROB_PRIOR and match the ICD code then extract the date. Done this many times but for some reason I just can't get it this time. This will crash the form every time when you end the visit or discard and I get no return value. Appreciate the help.
/* Function finds active depression diagnosis */
{!fn fnDiagnosis() {
local DAnswer
local DList = ""
local DAray =""
local DMax
local DCode = "ICD-296.30"
DList = PROB_PRIOR('DELIMITED')
DAray = getfield(DList,"|","")
DMax = size(DAray)
local DCount
local DRow
DAnswer = ""
for DCount=1, DCount<=DMax, DCount=DCount+1 do
DRow = getfield(DAray(DCount),"^","")
If (str(DRow[3])= DCode) then DAnswer = val(aRow[30])
else DAnswer = ""
endif
Endfor
return DAnswer
}
}
1. always check for null array or your system will crash. Suggest,
if DList<>"" then
(code)
endif
2. in line Drow=getfield, must y0u [] instead of () for row counter
3. esthetic issue, can use DAray to contain row variables,
DAray[DCount]=getfield(DAray[DCount],"^","")
4. field Onset Date is row 5 of your array DRow, not 30 which doesn't exit
5. DRow[3], the problem code, is a string value, do not need str()
Good luck!
I really appreciate the help and tips. The 30 I knew about i just copied the wrong code to the site but it was the dang brackets on the Drow line. It has driven me nuts and I called myself looking for format errors. Thanks again.
Cecil