Well it took some trial and error but we got it to work:
You are currently scheduled for a new patient appointment {! fn APPT_NEXT_PCP(PCP){
local retVal = ""
local i = getRowCount("_MELCurPatientAppt")
local t1Hour
local t1Minute
local t1AMPM
local t2Hour
local t2Minute
local t2AMPM
local currentTime
local apptDateTime
local temp
local PCPName
while i > 0 do
i = i-1
local a = getRow("_MELCurPatientAppt",i,"AppointmentsId","ApptStart","ApptTypeId","FacilityId","DoctorID","ResourceId","Status","Canceled","ApptKind")
if (a[8] <> "" or a[9] <> 1) then
continue
endif
/* Doctor lookup in _DoctorFacilityForPatAppt data object */
if (find("_DoctorFacilityForPatAppt","ListName","DoctorFacilityID",a[5]) <> "") then
a[5] = find("_DoctorFacilityForPatAppt","ListName","DoctorFacilityID",a[5])
endif
/* Make sure the appt is with the PCP */
if a[5] <> PCP then
continue
endif
/* Build PCP name */
if match(a[5],",")>0 then
temp = getfield(a[5],",","")
PCPName = temp[2] + " " + temp[1]
else
PCPName = a[5]
endif
/* Facility lookup in _MELLocation data object */
if (find("_MELLocation","ListName","DoctorFacilityID",a[4]) <> "") then
a[4] = find("_MELLocation","ListName","DoctorFacilityID",a[4])
endif
//Set up the time values for comparison
if size(TIMESTAMP()) == 7 then
currentTime = "0" + TIMESTAMP()
else
currentTime = TIMESTAMP()
endif
if sub(str(a[2]),13,1) == ":" then
apptDateTime = "0" + sub(str(a[2]),12,7)
else
apptDateTime = sub(str(a[2]),12,8)
endif
t1Hour = sub(currentTime, 1, 2)
t1Minute = sub(currentTime, 4, 2)
t1AMPM = sub(currentTime, 7, 2)
t2Hour = sub(apptDateTime, 1, 2)
t2Minute = sub(apptDateTime, 4, 2)
t2AMPM = sub(apptDateTime, 7, 2)
// Build the result if date is in the future
if
(
DURATIONDAYS(sub(str(a[2]),1,10),str(._TODAYSDATE)) > 0
or
(
DURATIONDAYS(sub(str(a[2]),1,10),str(._TODAYSDATE)) == 0
and
timeCompare(t1Hour,t1Minute,t1AMPM,t2Hour,t2Minute,t2AMPM) == 1
)
) then
break
else
retVal = str("on ",sub(str(a[2]),1,10)," at ",t2Hour,":",t2Minute," ",t2AMPM," with",PCPName," at our ",a[4]," location.")
endif
endwhile
if retVal == "" then
retVal = "NO APPOINTMENT SCHEDULED."
endif
return retVal
}}{APPT_NEXT_PCP(PATIENT.PCP)}
Produces this:
You are currently scheduled for a new patient appointment on 05/14/2014 at 08:40 AM with Harry Winston MD at our AMA American Medicine Association location.
It looks at the PCP and pulls the next appointment associated with the PCP. Just thought I would share.
Laurie