I am guessing that there is something simple wrong with this as I do not get any errors, but nothing is being returned.
Trying to add MEL quicktext (that might also find its way into a form) to display recent (within the past week) service orders. To be part of a checkout process, and remind the checkout staff of any recent orders - to followup with the patient.
{
global hold = getfield(ORDERS_ALL("delimited", "S"), "|", "")
global temp
global odate
global vzise = size(hold)
global rslt = ""
for i = 1, i <= vsize, i = i + 1 do
temp = getfield(hold[i], "^", "")
odate = temp[4]
days = DURATIONDAYS(str(._TODAYSDATE),odate)
if val(days) > -7
then rslt = rslt + temp[3] + " on " + temp[4] + HRET
else ""
endif
endfor
rslt
}
The problem is the use of ORDERS_ALL(), it basically combines ORDERS_NEW() and ORDERS_PRIOR(), meaning it excludes any prior orders with the status complete. I always seem to have to go to mldefs to pull in useful order information. If you go that route and use a loop, make sure you use some condition to break the loop because it can get really slow with patients that have a long history. You will want to use _MasterOrders in mldefs3.txt.
The ORDERS_ALL does seem to be returning data. I can create a quicktext for that, and get lots of data (which is expected). My trouble is in trying to parse through the data with the nested getfield commands. Or, at least that is what I sense is the problem.
In that case, I don't see anything wrong per se, but when I copied it into notepad, it has the wrong type of quotation marks, then it was not storing vsize, even thought it should have. I adjusted those, placed it in a function and made the variables local, and now it works. You can call it with name and pass the ORDERS_ALL() as a parameter if you want it to fire when changes to orders are made
{fn OrderTest(){
local hold = getfield(ORDERS_ALL("delimited","S"),"|","")
local temp
local rslt = ""
for i = 1, i <= size(hold), i = i + 1 do temp = getfield(hold[i], "^","") days = DURATIONDAYS(str(._TODAYSDATE),temp[4]) if val(days) > -7
then rslt = rslt + temp[3] + " on " + temp[4] + HRET
else ""
endif
endfor
rslt
}
}
It's most likely empty because you can't declare and initialize a variable in a watcher at the same time (don't ask me why). Should be:
global hold
hold = getfield(ORDERS_ALL("delimited", "S"), "|", "")
global vzise
vzise = size(hold)
Sharing my answer/solution. I defined a function, and VFE is calling it.
In this specific function, I am looking for a service order created within the past seven days, and displaying it on the screen. I am only looking for specific service orders - those that begin with the letters "RTC". For us, this signifies a return-to-clinic service request.
Although when this is run, the date of the request will often be the same day as when the function is called, I wanted to make it flexible in case the patient check-out process is not the same day as when the order was done.
I also created additional similar functions to look for recent Referrals and Test (lab) requests.
{!fn RTCOrderTest() {
local RTC
local Cnt
local Row
local OL
local OA
local Osz
local RM
local RD
RTC =""
OL = ORDERS_ALL('DELIMITED','S')
OA = getfield(OL,"|","")
Osz = size(OA)
for Cnt=1, Cnt<=Osz, Cnt=Cnt+1 do
Row = getfield(OA[Cnt],"^","")
RM = match(Row[3],"RTC")
RD = val(DURATIONDAYS(str(._TODAYSDATE),ROW[4]))
If (RM=1) and (RD>-8)
then RTC = RTC + str(Row[1]+" on "+ROW[4] + HRET)
Else ""
Endif
Endfor
If RTC = ""
Then RTC = "None"
Else ""
Endif
Return RTC
}