I'm trying to show if a patient is within a current global period on the patient banner for the doctors to have a quick reference to. The global date and body part are each stored as an obsterm in a form that is entered by the back staff. Once it has been entered in the form, I want it to populate Body Part Surgery Date - Global End Date so it would appear as so:
Right shoulder 11/24/14-2/23/15
One obsterm contains the body part and the surgery date while the second obsterm contains the global end date. I have it in my formula to only show dates where the global end date is on or after today's date (so this is automatically updated).
When I put this in the banner, it is blank, even though I tested it within a form and it worked fine. I'm not sure what I'm doing wrong.
{global dates=""
local final=""
local obsnames=str(OBSPREV("DATE1STVISIT"))
local obsnames2=str(OBSPREV("DATEOFSURG"))
local obs_data = LIST_OBS(obsnames,'signed','delimited','value')
local obs_data2 = LIST_OBS(obsnames2,'signed','delimited','value')
local obsterm_array = getfield(obs_data,"|","")
local obsterm_array2 = getfield(obs_data2,"|","")
for i=1,i<=size(obsterm_array),i=i+1
do
local obs_array = getfield(obsterm_array[i],"^","")
local obs_array2 = getfield(obsterm_array2[i],"^","")
local enddate = durationdays(str(._TODAYSDATE),str(obs_array2[1]))
if val(enddate)>=0 then
if dates<>"" then dates=dates+"," else "" endif
dates=dates+str(obs_array[1])+"-"+str(obs_array2[1])
else "" endif endfor if dates<>"" then final = "Global: " + dates else "" endif}
Any help is appreciated. Thanks!
I just tried it this way as a function and only after putting it in notepad and THEN pasting to the banner did it work.
{!fn obsdatearray(a,b){
local dates=""
local obsnames=(a)
local obsnames2=(b)
local obs_data = LIST_OBS(obsnames,'signed','delimited','value')
local obs_data2 = LIST_OBS(obsnames2,'signed','delimited','value')
local obsterm_array = getfield(obs_data,"|","")
local obsterm_array2 = getfield(obs_data2,"|","")
for i=1,i<=size(obsterm_array),i=i+1
do
local obs_array = getfield(obsterm_array[i],"^","")
local obs_array2 = getfield(obsterm_array2[i],"^","")
if durationdays(str(._TODAYSDATE),str(obs_array2[1]))>=0 then
if dates<>"" then dates=dates+"," else "" endif
dates=dates+str(obs_array[1])+"-"+str(obs_array2[1])
else "" endif
endfor
return str(dates)
}}{obsdatearray("DATE1STVISIT","DATEOFSURG")}