We just upgraded to CPS12 and my Upcoming Appts function (found on CHUG, Thanks!) no longer works. We were on EMR9.5 and CPS10, and this is the first time on a combined product. Can anyone help me tweak this one, or have another that will display any scheduled appts from the current date forward? Below is what I used in EMR9.5\CPS10, it just says <none> all the time now. Thanks for any help
{fn APPT_DISPLAY(){
local a, b, c, d, loc, atype, book, stat
local i = 0
local result=""
local j = getRowCount('_MELCurPatientAppt')
// Loop thru patients appointments
while i < j do
i = i+1
a = getRow('_MELCurPatientAppt',i,'ApptDate','ApptTime','Appttype','Booklist','ApptStatus')
// Find the next scheduled appointment
If val(a[1]) >= ._TODAYSDATE then
// Get the type of appointment
atype = find('_MELApptDef','ApptType','ID', a[3])
if atype = "" then
atype = "UNKNOWN"
endif
// Get the location of care from the first book
if a[4] == "" then
loc = "UNKNOWN"
else
b = getfield(a[4],',',' :')
loc = find('_MELBook', 'LocationAbbrevName','ID',b[1])
endif
// Get the Book Name
if a[4] == "" then
book = "UNKNOWN"
else c = getfield(a[4],',',' :')
book = find('_MELBook', 'Name','ID',c[1])
endif
// Get the Status 0 Scheduled, 1 No Show, 2 Cancelled, 3 Arrived
d = a[5]
cond
case d == 0 stat = "Scheduled"
case d == 1 stat = "No Show"
case d == 2 stat = "Cancelled"
case d == 3 stat = "Arrived"
endcond
// Build the rest if status is 0 Scheduled or 3 Arrived
if stat == "Scheduled" then
result = result + a[1] + " at " + appttime(a[2]) + ", " + atype + " with " + book + HRET
else result = ""
endif
endif
endwhile
return result}}
{if APPT_DISPLAY()<>"" then APPT_DISPLAY() else "<none>
" endif}
Thanks
Kelly
Below is the one I use in 12, you probably want to call it with {SEARCH_APPTS("LIST","NEXT")}
I also got this from CHUG originally, Im pretty sure the field names changed at some point in the object that this function references and thats why it doesnt work anymore
{fn SEARCH_APPTS(returnMethod,type){
//Valid types are NEXT, PREV, and CANC
if (toUpper(returnMethod) <> "DELIMITED" AND toUpper(returnMethod) <> "LIST" AND toUpper(returnMethod) <> "COMMA" AND toUpper(returnMethod) <> "FORMATTEDLONG") then
// Default Return Method if no value passed edit this if you want to change the default
returnMethod = "LIST"
endif
// initialize local variables
local retVal = ""
local z = getRowCount("_MELCurPatientAppt")
// loop through rows in _MELCurPatientAppt data object
for iq=1, iq<=z, iq=iq+1 do
local a = (getRow("_MELCurPatientAppt",iq,"AppointmentsId","ApptStart","ApptTypeId","FacilityId","DoctorID","ResourceId","Status","Canceled"))
if (val(durationdays(datestamp(),a[2]))>0 and a[8]=="" and toupper(type) == "NEXT") or (val(durationdays(datestamp(),a[2]))<0 and a[8]=="" and toupper(type) = "PREV") or (a[8]<>"" and toupper(type) == "CANC") then
// Appointment type lookup in _MELApptType data object
if (find("_MELApptType","Name","ApptTypeID",a[3]) <> "") then
a[3] = find("_MELApptType","Name","ApptTypeID",a[3])
endif
// Facility lookup in _MELLocation data object
if (find("_MELLocation","ListName","DoctorFacilityID",a[4]) <> "") then
a[4] = find("_MELLocation","ListName","DoctorFacilityID",a[4])
endif
// Doctor lookup in _DoctorFacilityForPatAppt data object
if (find("_DoctorFacilityForPatAppt","ListName","DoctorFacilityID",a[5]) <> "") then
a[5] = find("_DoctorFacilityForPatAppt","ListName","DoctorFacilityID",a[5])
endif
// Resource lookup in _DoctorFacilityForPatAppt data object
if (find("_DoctorFacilityForPatAppt","ListName","DoctorFacilityID",a[6]) <> "") then
a[6] = find("_DoctorFacilityForPatAppt","ListName","DoctorFacilityID",a[6])
endif
// ApptStatus is actually a combination of two fields, Canceled or ApptStatus. If Canceled <> "" then write Canceled, else write contents of ApptStatus
if (a[8] <> "") then
a[7] = "Canceled"
endif
cond
case toUpper(returnMethod) == "DELIMITED"
// Don't add pipe before first element
if (retVal <> "") then
retVal = "|" + retVal
endif
retVal = str(a[2],"^",a[3],"^",a[4],"^",a[6]) + retVal
case toUpper(returnMethod) == "LIST"
// Don't add HRET before first element
if (retVal <> "") then
retVal = retVal + HRET
endif
retVal = retVal + str(a[2],", ",a[3],", ",a[4],", ",a[6])
case toUpper(returnMethod) == "COMMA"
// Don't add comma before first element
if (retVal <> "") then
retVal = "," + retVal
endif
// Need to replace commas in elements with semicolon to prevent errors in comma separated list
retVal = str(ReplaceStr(a[2], ",",";")," ",ReplaceStr(a[3], ",",";")," ",ReplaceStr(a[4], ",",";")," ",ReplaceStr(a[6], ",",";")) + retVal
case toUpper(returnMethod) == "FORMATTEDLONG"
// Don't add new lines before first element
if (retVal <> "") then
retVal = HRET + HRET + retVal
endif
// Need to replace commas in elements with semicolon to prevent errors in comma separated list
retVal = str("ApptTime: ",ReplaceStr(a[2], ",",";"),HRET,"ApptType: ",ReplaceStr(a[3], ",",";"),HRET,"FacilityID: ",ReplaceStr(a[4], ",",";"),HRET,"ResourceID: ",ReplaceStr(a[6], ",",";")) + retVal
endcond
endif
endfor
return retVal
}}
This is working PERFECT! Thank you soo much
Kelly