I am looking to list the last 3 appointments a patient has had or preferably last appointment with their PCP. The code I am using lists either just the last appointment or all last appointments by status. We are a multispecialty clinic so listing all last appointments is not helpful. Does someone have a code that they are using to do this?
This is the code that I am currently using in a quick text but I am unsure how to pull by PCP or just last 3 visits.
{global alist = getfield(APPTS_BY_STATUS("completed","FULL"),"\r","")
global asz = size(alist)
global tempa
global rslt=""
for count = 1, count < asz, count = count + 1
do
tempa = getfield(alist[count],",","")
days = DURATIONDAYS(str(._TODAYSDATE),tempa[1])
if days<0 then
rslt = rslt + tempa[1] + " at" + tempa[2] + " Type:" + tempa[3] + " with" + tempa[5]
else "" endif
endfor
rslt
}
I don't have code for this specific purpose, but could you get the values that you need by limiting your output with the values in index 2 (location) or index 3 (visit type) of your tempa array? You could nest an if statement:
if days<0 then
if tempa[2] == "Location where there are PCP Appts" then
rslt = rslt + tempa[1] + ” at” + tempa[2] + ” Type:” + tempa[3] + ” with” + tempa[5]
else
“”
endif
endif
Also to limit to 3 items you could use a while statement instead of a for. You would need to check that your counter is less than 4 and also not outside of the size of your array. Hope this is helpful.
Brad
Thank you for your response. I did try your example but I must be doing something wrong since it just continues to return the same thing as before. I haven't written an endwhile statement before so I am not sure how to do that.
{global alist = getfield(APPTS_BY_STATUS(“completed”,”FULL”),”\r”,””)
global asz = size(alist)
global tempa
global rslt=””
for count = 1, count < asz, count = count + 1
do
tempa = getfield(alist[count],”,”,””)
days = DURATIONDAYS(str(._TODAYSDATE),tempa[1])
if days<0
then if tempa[4] == "Primary Care Clinic" then
rslt = rslt + tempa[1] + ” at” + tempa[2] + ” Type:” + tempa[3] + ” with” + tempa[5]
else “” endif endif
endfor
rslt
}
FYI for anyone interested in this I did finally get it to work. Here is the code:
{global alist = getfield(APPTS_BY_STATUS("completed","FULL"),"\r","")
global asz = size(alist)
global tempa
global rslt=""
for count = 1, count < 4, count = count + 1
do
tempa = getfield(alist[count],",","")
days = DURATIONDAYS(str(._TODAYSDATE),tempa[1])
if days<0 then
rslt = rslt + tempa[1] + " at" + tempa[2] + " Type:" + tempa[3] + " with" + tempa[5]
else "" endif
endfor
rslt
}
What do you do when there are 0 completed statuses?
For the zero completed you might need to change your options. If your clinic doesn't change the status of the visits to completed then maybe try "arrived".
Just a quick word for warning though: The code above returns three visits but it actually returns the first 3 visits not the last 3. I still haven't figured that out. I just didn't notice at first.
Thank you heggea!!