I'm working on a form, and I need to logically figure out when the last time this patient visited a clinic (in our database). I've been working with find() and using the mldefs as a guide, but I haven't had much luck yet. Here is what I am currently trying to use:
find("_CurPatientAppointment", "ApptStart", "OwnerId", PATIENT.PATIENTID)
From my understanding of the find function, this would search the object _CurPatientAppointment for ApptStart associated with OwnerId = PATIENT.PATIENTID; however, I'm having zero luck getting anything to return. I'm tempted to just use office visit CPT Codes in past orders to go by, but I don't want to give up on find().
Something I've noticed is that if I were to query this in the database, I would have multiple results come up if the patient had more than one appt in the past (which would be 99% of the time). Maybe this is somehow affecting the results from showing.
APPT_PRIOR() works in this situation (just forgot about it). I would still like to understand why find() wasn't working for me, there are a few other situations I'm needing to use it in.
We use the code below in usrlib.txt to show last arrived appt, the only problem is that am and pm may not work correctly between noon and 12:59 pm.
//APPT (PRIOR) FUNCTION
fn SMRMC_APPT_PRIOR() {
local a, b,c, loc, atype, book
local result=''
local i = getRowCount('_MELCurPatientAppt')
// Loop thru patients appointments
while i > 0 do
i = i-1
a = getRow('_MELCurPatientAppt',i,'ApptDate', 'ApptTime',
'Appttype','Booklist','ApptStatus')
// Find the last appointment
if val(a[1]) < ._TODAYSDATE and val(a[5]) = 3 then
// Get the type of appointment
atype = find('_MELApptDef', 'ApptType', 'ID', a[3])
// Get the location of care from the first book
b = getfield(a[4],',',' :')
loc = find('_MELBook', 'LocationAbbrevName', 'ID', b[1])
//Get the Book Name
c = getfield(a[4],',',' :')
book = find('_MELBook', 'Name', 'ID',
c[1])
// Build the result
result = a[1] + ',' + appttime(a[2]) + ',' + atype + ',' + loc + "," + book
break
endif
endwhile
result
}
Stacey LaGrange
Software Developer/Analyst
St. Mary's Health System
[email protected]
(207) 777-8410