For those who have been following, I am working on a component to try to build a results letter. One of my my final steps (I hope) is to determine what results are recent. Thus, trying to lookup info on many labs (OBS) and based on the date, set a flag field (as a default) to print the result or not. There is a place where DOCUMENT.LOOKBACK is set by the user to say 10 or 14 (days) to only highlight recent results.
My first attempt was a one line command (it worked) that set the flag (DOCUMENT.DISPLAY_01) based on the rules.
//{if LAST_SIGNED_OBS_VALUE("CHOLESTEROL") = "" then DOCUMENT.DISPLAY_01 = "" else if val(durationdays(str(._TODAYSDATE),LAST_SIGNED_OBS_DATE("CHOLESTEROL"))) > -1 * val(DOCUMENT.LOOKBACK) then DOCUMENT.DISPLAY_01 = "yes" else DOCUMENT.DISPLAY_01 = "" endif endif}
But I want to do as a function to simplify the process.
Thus, the call:
{SetLookback("CHOLESTEROL","DOCUMENT.DISPLAY_01")}
and the defined function on the rightside of the VFE:
{fn SetLookback(FOBS,FDISP) {
if LAST_SIGNED_OBS_VALUE(FOBS) = ""
then FDISP = ""
else if val(durationdays(str(._TODAYSDATE),LAST_SIGNED_OBS_DATE(FOBS))) > -1 * val(DOCUMENT.LOOKBACK)
then FDISP = "yes"
else FDISP = ""
endif
endif}}
Is there something simple I am missing?
TIA.
So here are 2 things that strike me right off the bat that may be causing you issues.
#1. You are passing in a variable to the function ({SetLookback(“CHOLESTEROL”,”DOCUMENT.DISPLAY_01″)}). This will pass the VALUE of DOCMENT.DISPLAY_01. but you cannot update the actual variable. You can pass in the name of the document variable and process it as MEL code using the eval function.
#2. When you use a document variable in a form, it will change the name of the document variable from "DOCUMENT.DISPLAY_01" to a longer, unique name, such as DOCUMENT.DISPLAY_014757y39827365. This prevents multiple forms from stepping on eachothers toes. I have built lots of forms with a DOCUMENT.COMMENTS somewhere in there, and this is how CPS sorts them out.
You can get around this by checking the "Make available to other forms" checkbox in VFE. but I don't have a tested example of fixing problem #1. I may have to play with it a bit and see if I can get a working example with using 'eval'.
Let me know if you have any questions.
Thank you,
Daniel C.
Daniel alluded to the issue. You are using the text "DOCUMENT.DISPLAY_01" instead of passing the value of DOCUMENT.DISPLAY_01.
It looks like you want to return the results of the function to DOCUMENT.DISPLAY_01, so you would modify the function call to:
{DOCUMENT.DISPLAY_01 = SetLookback(“CHOLESTEROL”)}
I believe that will yield the result you are seeking.