Hello All,
I need to run something in a text component on load. I am consistently getting an error. Either the 'function definition is not executable' or the error below. I'm scratching me head trying to debug this. Any suggestions would be appreciated.
Thanks!
Brad
Current error message:
IF (<-COMPILER ERROR NEARBY: Expect RIGHT PAREN. Instead had IDENTIFIER after IDENTIFIER
The error is by the function call.
{
fn SNCheck()
{
//rewriting w/o fxn library
firstpass = getfield(ORDERS_ALL("delimited"),"|","")
for i = 1, i<=size(firstpass), i=i+1 do
secondpass = getfield(firstpass[i],"^","")
snc[i] = secondpass[1]
endfor
sifirstpass = getfield(ORDERS_ALL("delimited"),"|","")
for f = 1, f<=size(sifirstpass), f=f+1 do
sisecondpass = getfield(sifirstpass[f],"^","")
snd[f] = sisecondpass[4]
endfor
for snl = 1, snl <= size(snc), snl = snl + 1 do
if (snc[snl] == "SNOMED-CT: 73761001 - Historical Colonoscopy") then //is code present
if (durationdays(str(snd[snl]),str(._todaysdate)) >= 365) then //has it been a year
return "true" //code is present, has been a year
else
return "false" //code is present, has not been a year
endif
else if (snl == size(snc)) then
return "true" //code has never been ordered
else
""
endif
endif
endfor
}
{
IF (SNCheck() == "true") then MEL_ADD_ORDER("S","PQRI","SNOMED-CT: 73761001 - Historical Colonoscopy","","","","","","","") else "" endif
}
""
}
First: You are not declaring the variable names used in the function as local, so be aware that they are global in the system. This means that if another function uses the same names, the two functions may (or will not) overwrite existing index values. Ie. if function 1 has 3 array elements and function 2 has 5, after function 2 is run and if function 1 is referenced again, function 1 will now have 5 elements (the last two are not overwritten by function 1). If this is your intent, then no worries, otherwise use caution, please.
Can you elaborate on the purpose of the last two lines of the code you posted? It looks like open and close double quotes with an orphaned close curly brace. You are also missing the second closing brace on the function itself. I think if you clean that up, it will work.
To clean it up, add the second close curly to the end of the function body. Remove the ending double quotes and the orphaned close curly. Because this is to be used in a text component, you will want to place the open/close double quotes inside of the if-then statement, one space after the 'endif'.
Hope this helps.
I am not positive as to what your issue is but your code is way more complex that it needs to be from what I can tell. Since you are looping through the exact same data 3 times, you can consolidate your loops.
You also don't need to check to see if you are on the last record without a match, you can just return true after your for loop if there was no match.
Try this code (not tested):
fn SNCheck() {
ordersList = getfield(ORDERS_ALL("delimited"),"|","")
for i = 1, i<=size(ordersList), i=i+1 do
ordDetail = getfield(ordersList[i],"^","")
local ordDesc = ordDetail[1]
local ordStartDt = ordDetail[4]
if (ordDesc == "SNOMED-CT: 73761001 – Historical Colonoscopy") then //is code present
if (durationdays(str(ordStartDt),str(._todaysdate)) >= 365) then //has it been a year
return "true" //code is present, has been a year
else
return "false" //code is present, has not been a year
endif
endif
endfor
//If we get here there was no matching order
return "true"
}
EDIT: CHUG really botches the code sometimes so the first couple of times it was pasted it was completely wrong. I think it is fixed now even though it isn't pretty
Thank you for the reply and cleaning up the code for me. I took something that ran better in a function library and modified it because I thought that might be the source of my errors. I took what you provided and changed a couple of other things in the function call and got things to run correctly.
In text components I always start with an open and close bracket and a set of quotes. I have found that suppresses TRUE or FALSE from writing to the note where you don't want it to. For example
{
//other functions and variable declarations go here
""
}
I ended up taking rwilliams code suggestion and also cleaning up the function call and things are working correctly now. Thank you for your help.
For those interested what I am trying to accomplish here is adding an order for a snowmed code when a patient is in the office and has last had a colonoscopy between 5-10 years ago. We also only want to do this one time per year. At Centricity Live we were told that this needed to be done to address an issue in CQR. GE provided some code but we felt we needed to modify it because it would send an order every visit. If others want to see this is what is working for me now in a text component on form visit load (sorry for the formatting):
{
fn SNCheck() {
ordersList = getfield(ORDERS_ALL("delimited"),"|","")
for i = 1, i<=size(ordersList), i=i+1 do
ordDetail = getfield(ordersList[i],"^","")
local ordDesc = ordDetail[1]
local ordStartDt = ordDetail[4]
if (match(ordDesc,1,"73761001") > 0) then //is code present
if (durationdays(str(ordStartDt),str(._todaysdate)) >= 365) then //has it been a year
return "true" //code is present, has been a year
else
return "false" //code is present, has not been a year
endif
endif
endfor
//If we get here there was no matching order
return "true"
}
{!IF not(match(ORDERS_NEW("S","comma"), "SCT-73761001")>0)=="TRUE" AND LAST_SIGNED_OBS_DATE("COLONOSCOPY")<>"" AND
durationdays(LAST_SIGNED_OBS_DATE("COLONOSCOPY"),str(._todaysdate))>=1825 AND
durationdays(LAST_SIGNED_OBS_DATE("COLONOSCOPY"),str(._todaysdate))<=3650 AND
SNCheck() == "true"
then MEL_ADD_ORDER("S","PQRI","SNOMED-CT: 73761001 - Historical Colonoscopy","","","","","","","") else "" endif
}
""
}
You should be able to change your first line of your function call to:
if (match(ORDERS_NEW("S","comma"), "SCT-73761001")=0) AND LAST_SIGNED_OBS_DATE("COLONOSCOPY")"" AND
You do not need to compare it to "True" because the fact that it is true/false will tell the if statement what it needs. Also, rather than negating the statement, it is much cleaner and easier to read if you remove the NOT and change your comparison to =0
Agreed. I thought about changing it further but want to try and keep as much of what I could of what GE wanted us to use to address the issue. This is what was originally given to us:
{!IF not(match(ORDERS_NEW("S","comma"),"SCT-73761001")>0 =="TRUE" and (durationdays(lastobsdate("COLONOSCOPY"),str(._todaysdate))<=3285 and lastobsdate("COLONOSCOPY")<>"") then MEL_ADD_ORDER("S","PQRI",Historical Colonoscopy","","","","","","","") else "" endif)