When staff looks for the next appt in thier LOC, they would like to be able to pull the next appt with a quick text that has teh same LOC as they have.
arg 'delim' for '|' & '^'
'' for hret & ','
mine 'mine' for current user's appts
'loc' for current loc's appts
'all' for all users appts
next 'next' for only next appt
'all' for all appts
{fn ListFutureAppointments(arg, mine, next)
{
local rec_delim = ""
local field_delim = ""
local count
local appt = array()
local atype
local book = array()
local bookcount
local loc
local username
local i = 0
local j
local status
local result = ""
if arg=="delim" then
rec_delim = "|"
field_delim = "^"
else
rec_delim = hret
field_delim = ", "
endif
count = getRowCount("_MELCurPatientAppt") // _MEL???? are global variables from mellib.txt
// Loop thru patients appointments and stop after first for current user
while i<count
and (next<>"next"
or (result==""
and next=="next")) do
appt = getRow("_MELCurPatientAppt", i, "ApptDate", "ApptTime", "Appttype", "Booklist", "ApptStatus")
// Check for future appointment
if VAL(appt[1])>=._TODAYSDATE then // doesn't look right
// if DURATIONDAYS(appt[1], str(._TODAYSDATE))>0 then // told doesn't work
// Get the type of appointment … ApptType from _MELApptDef where ID = appt[3]
atype = find("_MELApptDef", "ApptType", "ID", appt[3])
// Get the books associated with appointment
book = getfield(appt[4], ":", "")
bookcount = size(book)
// Loop thru books
j = 2
while j<bookcount do
// Is appointment still scheduled
if appt[5]==0 then
// Get the location of care from the each book
loc = find("_MELBook", "LOCID", "ID", book[j])
loc = find("_MELLoc", "Name", "LOCID", loc)
// Get the user name from the each book
username = find("_MELBook", "UserName", "ID", book[j])
// Build the result if book matches current user
if mine=="all"
or (mine=="mine"
and match(username, 1, user.firstname)>0
and match(username, 1, user.lastname)>0)
or (mine=="loc"
and match(loc, 1, user.curlocationname)>0) then
if result<>"" then
result = result + rec_delim
endif
result = result + appt[1] + field_delim + appttime(appt[2]) + field_delim + loc + field_delim + username
endif
endif
j = j + 1
endwhile
endif
i = i + 1
endwhile
return result
}
}
create a quicktext with ListFutureAppointments("", "loc", "next").
the above function will have to be pasted into usrlib.txt so the quicktext can find it.
this will return the next appt for the current users home LOC.
jjordet,
I placed your function in my usrlib.txt file (at the end), opened up CPS 10 and when the chart loads, I get this pop-up error:
"While attempting to load a definition file the following error occurred:
COMPILER ERROR NEARBY: expect COMMA. Instead had ERROR after STRING
Make sure that the file exists in the application directory is up-to-date"
Any ideas? I'm not seeing where there should have been a comma...
Sorry jjordet,
I realized what I did wrong. I left in your pre-function explanation of the function arguments. Took those out and the chart loads fine. I'll test the quicktext now.
jjordet,
when I call the quick-text, I now get this error:
"
{ListFutureAppointments("", "all", "next") <-FUNCTION DEFINITION IS NOT EXECUTABLE
"
What am I doing wrong now? I exited CPS, closed all windows, reloaded the chart and called this quick text. Any ideas?
Sorry, no ideas.
this function will find the next appointment for a specific LOC.
{fn dn_find_next_appt(limit_loc){
loc_short=change_loc_form(limit_loc)
if loc_short=="not found" then userOK("Sorry, not able to resolve location names. ") return "" else "" endif
local appt_all=dn_FUTURE_APPT("delim") n=""
if appt_all=="" OR (match(appt_all,loc_short)=0 and match(appt_all,limit_loc)=0)then return "You do not have an appointment scheduled at the " + limit_loc + ". If you need to schedule an appointment please give us a call. " else "" endif
if match(appt_all,"|")=0 then appt_all=getfield(appt_all,"^","") return "Your next appointment at the " + limit_loc + " is on " + appt_all[1] + " at " + appt_all[2] + " with " + appt_all[5] + ". " else "" endif
appt_all=getfield(appt_all,"|","")
result_arr=array
for n=1, n<=size(appt_all), n=n+1
do
if (limit_loc=="no" or match(appt_all[n],loc_short)>0 or match(appt_all[n],limit_loc)>0) then result_arr=getfield(appt_all[n],"^","") break else "" endif
endfor
if result_arr[1]<> "" then return "Your next appointment at the " + limit_loc + " is on " + result_arr[1] + " at " + result_arr[2] + " with " + result_arr[5] + ". If you are unable to make this appointment or need to be seen sooner please call the clinic. " else return "" endif
}}
{fn dn_FUTURE_APPT(arg) {
//DN--3-31-04 modified from mellib stock function
local a, b,c, loc, atype, book, i = 0
local result='' field_delim="" rec_delim=""
if arg=="delim" then field_delim="|" rec_delim="^" else field_delim=hret rec_delim="," endif
local j = getRowCount('_MELCurPatientAppt')
if j == 1 then a = getRow("_MELCurPatientAppt",0,"ApptDate","ApptTime","Appttype","Booklist")
if val(a[1]) >= ._TODAYSDATE then
atype = find('_MELApptDef', 'ApptType', 'ID', a[3])
b = getfield(a[4],',',' :')
loc = find('_MELBook', 'LocationAbbrevName', 'ID',b[1])
c = getfield(a[4],',',' :')
book = find('_MELBook', 'Name', 'ID',c[1])
result = a[1] + rec_delim + appttime(a[2]) + rec_delim + atype + rec_delim + loc + rec_delim + book
endif
else if j > 1 then
while i < j do
i = i+1
a = getRow('_MELCurPatientAppt',i, 'ApptDate','ApptTime','Appttype','Booklist')
if val(a[1]) >= ._TODAYSDATE then
atype = find('_MELApptDef', 'ApptType', 'ID', a[3])
b = getfield(a[4],',',' :')
loc = find('_MELBook', 'LocationAbbrevName', 'ID',b[1])
c = getfield(a[4],',',' :')
book = find('_MELBook', 'Name', 'ID',c[1])
if result=="" then
result = result + a[1] + rec_delim + appttime(a[2]) + rec_delim + atype + rec_delim + change_loc_form(loc) + rec_delim + book else result = result + field_delim + a[1] + rec_delim + appttime(a[2]) + rec_delim + atype + rec_delim + loc + rec_delim + book endif endif
endwhile
endif
endif
if size(result)>1999 then return "Sorry, Too Long" else return result endif
}}
It's actually 2 functions I guess.
The function "call" is:
{dn_find_next_appt(user.homelocationname)}