I am having trouble with the following code. It does not pull just the past 3 days. I cannot figure out what I am doing wrong. Please help!!!
Labs and Tests received in the past 3 days:
{labs = GET_FLOWSHEET_VALUES('Enterprise\Printing\Chart_Summary\Current-Labs')
if labs <> "" then
lablist = getfield(labs, "\n", "")
sz = size(lablist)
list = ""
for i = 1, i <= sz, i = i + 1 do
dt = ""
tody = str(._todaysdate)
lab = lablist[i]
if size(lab) > 0 then
dtbegin = match( lab,"/") -2
dt = sub(lab, dtbegin, 10)
dur = durationdays(dt, tody)
if dur < 4 then
list = list + lab + "\n\r"
else
list = list
endif
else
list = list
endif
endfor
if list <> "" then list else "No lab results." endif
else
"No lab results."
endif}
Is this wrapped up as a function with a RETURN? Have you run a MEL trace?
What I posted is all there is. How would I do a trace?
This probably needs to be a function. You need to have your code read:
{fn fnLast3DaysLabs(){labs = GET_FLOWSHEET_VALUES('Enterprise\Printing\Chart_Summary\Current-Labs')
if labs <> "" then
lablist = getfield(labs, "\n", "")
etc. etc.
then after your last endif line you need a line that reads:
return list
and you need one more } at the end to offset the one before the fn
Also, where you have "No lab results." you need to set the variable list to that value too so when you return the value of list it would have that text in it if appropriate.
Then in your letter or whatever you follow all that code with the line:
{fnLast3DaysLabs()} to run the function.
The easiest way to run a trace is CTRL-ALT-M but if you have never looked at one before, they are tough to read. You can also turn it on by using Options, Tracing and that will show you were it is being saved.
Hope that helps. Others feel free to chime in if I've messed it up somewhere!
Thank you Thank you Thank you. Its working but not totally. It doesnt seem to be picking up on the 3 day rule!
Without looking that a trace I'm not sure why the date matching is failing but you could try this - change
dur = durationdays(dt, tody)
to
dur = durationdays(str(dt), tody)
Might be that dt isn't being seen as a string. But it could be something in
dtbegin = match( lab,"/") -2
dt = sub(lab, dtbegin, 10)
It looks like the date field is getting non date info in it. For example: If the results are "142 MEQ/L" It gets "14EQL" in it instead of the date. So , if there is anything else entered besides a number the function, as written, will not work. Can this be editted to account for that occurence?
You might need to pull the current year from your tody variable and set a backslash + the current year as a variable and then use it to match "/2013" in the obs term line and backtrack to the beginning of the date from there.
Hello,
I have entered the following:
{fn fnLast3DaysLabs(){labs = GET_FLOWSHEET_VALUES(
"Enterprise\Printing\Chart_Summary\Current-Labs")
if labs <>
"" then
lablist = getfield(labs,
"\n", "")
sz = size(lablist)
list =
""
for i = 1, i <= sz, i = i + 1 do
dt =
""
tody = str(._todaysdate)
lab = lablist[i]
if size(lab) > 0 then
dtbegin = match( lab,
"/") -2
dt = sub(lab, dtbegin, 10)
dur = durationdays(dt, tody)
if dur < 4 then
list = list + lab +
"\n\r"
else
list = list
endif
else
list = list
endif
endfor
if list <>
"" then list else "No lab results." endif
else
"No lab results."
endif
return list}{fnLast3DaysLabs()}
and I don't receive any results. Do you see anything I need to change or add?
Thank you!!
This:
if list <>"" then list else "No lab results." endif
else
"No lab results."
Needs to be:
if list <>"" then list else list = "No lab results." endif
else
list = "No lab results."
But that will only help when there is actually nothing to report. I don't have time to try it out here to see what is going on but if you post or send a MEL trace I can take a look at it. David-Shower at OUHSC dot EDU
Here is my mel trace.
>{/*START OF FORM TRANSLATION BODY*/\par }
execute>end
results>NULL
execute>Attach Symbols Begin
execute>Attach Symbols End
execute>Attach Symbols Begin
execute>Attach Symbols End
>{/*VARIABLES FOR MEL BUILT-IN SYMBOLS USED IN FORM*/\par }
execute>end
results>NULL
>{\par /*FUNCTION DEFINITIONS*/\par\par }
execute>end
results>NULL
>{/*START OF FORM TRANSLATION BODY*/\par }
execute>end
results>NULL
>{/*VARIABLES FOR MEL BUILT-IN SYMBOLS USED IN FORM*/\par }
execute>end
results>NULL
>{\par /*FUNCTION DEFINITIONS*/\par\par }
execute>end
results>NULL
>{/*START OF FORM TRANSLATION BODY*/\par }
execute>end
results>NULL
>{/*VARIABLES FOR MEL BUILT-IN SYMBOLS USED IN FORM*/\par }
execute>end
results>NULL
>{/*START OF FORM TRANSLATION BODY*/\par }
execute>end
results>NULL
execute>Attach Symbols Begin
{!fn fnLast3DaysLabs(){labs = GET_FLOWSHEET_VALUES( "Enterprise\Printing\Chart_Summary\Current-Labs") if labs <> "" then lablist = getfield(labs, "\n", "") sz = size(lablist) list = "" for i = 1, i <= sz, i = i + 1 do dt = "" tody = str(._todaysdate) lab = lablist [ i
COMPILER ERROR NEARBY: Expect RIGHT SQUARE BRACKET. Instead had EOF after IDENTIFIER
execute>Attach Symbols End
execute>Attach Symbols Begin
execute>Attach Symbols End
Thank you!
yOU NEED ANOTHER } BEFORE YOU CALL THE FUNCTION, AFTER RETURN LIST}}
I am still getting:
{!fn fnLast14DaysLabs(){labs = GET_FLOWSHEET_VALUES("Enterprise\Printing\Chart_Summary\Current-Labs") if labs <> "" then lablist = getfield(labs,"\n", "") sz = size(lablist) list ="" for i = 1, i <= sz, i = i + 1 do dt ="" tody = str(._todaysdate) lab = lablist[i
COMPILER ERROR NEARBY: Expect RIGHT SQUARE BRACKET. Instead had EOF after IDENTIFIER
execute>Attach Symbols End
execute>Attach Symbols Begin
execute>Attach Symbols End
{fn fnLast3DaysLabs(){labs = GET_FLOWSHEET_VALUES(
"Enterprise\Printing\Chart_Summary\Current-Labs")
if labs <>
"" then
lablist = getfield(labs,
"\n", "")
sz = size(lablist)
list =
""
for i = 1, i <= sz, i = i + 1 do
dt =
""
tody = str(._todaysdate)
lab = lablist[i]
if size(lab) > 0 then
dtbegin = match( lab,
"/") -2
dt = sub(lab, dtbegin, 10)
dur = durationdays(dt, tody)
if dur < 4 then
list = list + lab +
"\n\r"
else
list = list
endif
else
list = list
endif
endfor
if list <>
"" then list else "No lab results." endif
else
list = "No lab results."
endif
return list}}{fnLast3DaysLabs()}
Try this. It worked for me. Let me know.
I copied the text you entered above, placed it in a data display and I get the a box with a flashing cursor. I do not even get "No lab results."