I am having trouble getting the scheduled appt's to pull in. I can get all of the scheduled appt's to pull in but it pulls in everything listed as scheduled and I only want from today foward to pull in. Here is what I am using.
{
apptschd = APPTS_BY_STATUS("scheduled",["FULL"])
appts = ""
if apptschd = "<None>" then
else
appts = appts + apptschd
endif
tody = str(._todaysdate)
if appts <> "" then
apptslist
[]
= getfield(appts, "\n", "")
sz = size(apptslist)
list = ""
for i = 1, i <= sz, i = i + 1 do
dt = ""
dur = ""
appt = apptslist[i]
apptsize = size(appt)
if apptsize > 0 then
dt = sub(appt, 1, 10)
dur = durationdays(tody, dt)
if dur > 0 then
list = list + appt + "\n\r"
endif
endif
endfor
if list <> "" then list else "No appointments scheduled." endif
else
"No appointments."
endif
}
You have a lot of syntactical errors in there...
-Declare your variables before you use them like so:
local appts
-Use globally unique variable names if this is in a watcher function.
-Use double equals signs to test for equality in an IF statement:
if val1==val2 then ...
-Don't have a empty value between "then" and "else". Just invert your IF statement:
if apptschd<>"<None>" then
appts=apptschd
endif
-Don't use empty brackets when assigning an array to a variable. Just overwrite the variable:
apptslist=getfield(appts,"\n","")
-You probably don't need brackets around ["Full"] when you pass it to APPTS_BY_STATUS(...)
Here is the function I use to pull in future appointments:
(I didn't write this from scratch; I took what someone else posted and tweaked it to meet my needs)
/*
Function to display details of future appointments.
*/
!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 result if status is 0 Scheduled or 3 Arrived
if stat == "Scheduled" OR stat == "Arrived" then
result = result + a[1] + " at " + appttime(a[2]) + " " + atype + " with " + book + HRET
endif
endif
endwhile
return result
}
Jennifer Gardner said:
Here is the function I use to pull in future appointments:
(I didn't write this from scratch; I took what someone else posted and tweaked it to meet my needs)
/*
Function to display details of future appointments.
*/!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 result if status is 0 Scheduled or 3 Arrived
if stat == "Scheduled" OR stat == "Arrived" then
result = result + a[1] + " at " + appttime(a[2]) + " " + atype + " with " + book + HRET
endif
endif
endwhile
return result
}
Hey Jennifer,
I've tried to work with your appt function without success. I've placed your function in a letter (wrapped in "{}" of coarse) and then called the function in the letter as such: "{APPT_DISPLAY()}" and I get back nothing. No errors, just blank space.
Any ideas? BTW I'm using CPS 10
I'm using EMR 9.6 - we're not on CPS. I'm not sure if that explains the difference. Also, I use the function in forms, but haven't tried it in a letter. Maybe someone else has other ideas?
Thanks, Jennifer.
I'll try your function in a form. Are you attaching it to a data display?
Yep. Good luck!
if you need a "letter" to be able to use a function, the best place to place it is the usrlib. Then it will be usable in any MEL space.