I have build a form in VFE which pulls in the appointment history. I have sevral sections. Future appointments pull in ALL appointment detail, while the Appointments kept/No show/Cancelled, I have set to pulll in date only.
This list pulls in oldest to newest dates and I would like to reverse these dates to show the most recent ones first. I'm not having any luck.
Probably a very simple fix, but any suggestions would be most appreciated!!
Thanks, so much.
If you provide the function you are using we can probably fix it for you.
gibsonmi said:
If you provide the function you are using we can probably fix it for you.
Yes, that would surely help!! 🙂
APPTS_BY_STATUS("canceled","DATE")
Try this, add this function to the white space and then change the code in the display to {ReverseList(APPTS_BY_STATUS("canceled","DATE"))}
{fn ReverseList(var){
local temp = getfield(var,"\n","\r")
local hold = ""
for i = size(temp), i>0, i = i - 1 do
if hold <> "" then
hold = hold + hret
endif
hold = temp[i]
endfor
return hold
}}
Has anyone else tried this function?
I keep getting canceled appointments listed from earliest date at top, no matter how I use APPTS_BY_STATUS("canceled"), function or not. The above function is returning the first cancellation in the list only.
It would be really sweet to be able to list dates, latest to earliest... or even the last or last 2 cancellations. Any further help with this issue is appreciated!
This is what I use, I think you would want normal order for future appointments and reverse for past. You could tweak it to limit the number of appointments returned, if you have an old database this can take awhile to load. Also, I really only use it for LIST return method so it may need some additional cleanup.
{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
}}
Here is a sample call within a form
{if SEARCH_APPTS("LIST","CANC") <> "" then SEARCH_APPTS("LIST","CANC") else "<None>" endif}
Michael, thanks for the pointer. I tweaked the following function and am pretty much at what I want for the data display. right now it shows the last canceled appointment in a data display
the function just needs to be named.
{
local appts_list = ""
local return_string = ""
appts_list = getfield(APPTS_BY_STATUS("canceled","FULL"),HRET,"\r")
FOR i=1,i < size(appts_list),i=i+1
DO
if(appts_list[i]<>"")then
if(val(DURATIONDAYS(sub(appts_list[i],1,10),str(._TODAYSDATE))) > 1 )then
return_string = appts_list[i] + HRET
endif
endif
ENDFOR
return return_string
}
I borrowed the base of this function from a similar request - from jrea in the post APPTS_BY_STATUS, list into an array- my thanks to both of you.
To be honest I am a total faker when it comes to VFE, intermediate at best. I barely understand why this function does what it does and I think I would like to tell it to return all cancellations within the last 2 weeks. If anyone has a pointer, it is much appreciated over here!
Thanks again for the help
-richard
This line -
return_string = appts_list[i] + HRET
Needs to be something like
return_string = return_string + appts_list[i] + HRET
Otherwise you are overwriting all of the previous appointments it is writing. That will get you all of them though... To get one week change this
if(val(DURATIONDAYS(sub(appts_list[i],1,10),str(._TODAYSDATE))) > 1 )then
to
if(val(DURATIONDAYS(sub(appts_list[i],1,10),str(._TODAYSDATE))) > 1 ) and (val(DURATIONDAYS(sub(appts_list[i],1,10),str(._TODAYSDATE))) < 8 ) then
Which changes the return from "anything before today" to "anything before today and less than eight days ago"
Oh great! Thank you for the tutorial!!
But here's the thing... what if I only wanted it to show the last appointment canceled before today's date? Because it seems like the function I posted yesterday is doing just that. So, is there a problem that you know of based on that function? I haven't had any issues with it yet, testing-wise...
Thanks again
-richard
rspartos said:
To be honest I am a total faker when it comes to VFE, intermediate at best. I barely understand why this function does what it does and I think I would like to tell it to return all cancellations within the last 2 weeks. If anyone has a pointer, it is much appreciated over here!
Thanks again for the help
-richard
Yeah if its working for you, you dont need to change it, you just mentioned expanding it to fit a time frame, and thats how you would accomplish something like that using your exisiting code.
Yes, I did and all your answers have been very helpful.
It is really appreciated!