Sorry for the delay in responding.
The code below uses a watcher and two functions to hopefully do what you want (If I understand your needs here). The watcher is triggered by changes in either obsterm.
The first function first checks if the functions needs to fire, then if the age is appropriate, then if an order is needed using the second function (the second function checks if the order exists and is less than 10 years old). If any are false, the function exists without any real burden on the system. I
If all are true, then it does what you indicated. Because the order was determined as not existing, it will only add the order one time.
Hopefully this will do what you want or at least give you ideas on what you can do to achieve that goal.
Hope this helps!
{
document.checkLOOP = fnCheckColoStatus(str(LASTOBSDATE("COLONOSCOPY"),LASTOBSDATE("HXPREVCOLON")))
}
{! document.checkLOOP}
{! fn fnCheckColoStatus(strTrigger)
{
local retStr = ""
local strBuf = ""
local strColoDate = ""
local strPrevDate = ""
local nDaysSinceColo
if document.checkLOOP == "done" then return "done" else "" endif
if (patient_age() 75) then return "done" else "" endif
if fnCheckOrderDate("SNOMED-CT 73761001: Procedure, Performed: Colonoscopy") == "exists" then return "done" else "" endif
strColoDate = LASTOBSDATE("COLONOSCOPY")
strPrevDate = LASTOBSDATE("HXPREVCOLON")
nDaysSinceColo = DURATIONDAYS(LASTOBSDATE("COLONOSCOPY"),str(._TODAYSDATE))
if strColoDate "" then
if strPrevDate == "" then
if (nDaysSinceColo > 1825 and nDaysSinceColo < 3650) then
strBuf = MEL_ADD_ORDER("S", "PQRI", "SNOMED-CT 73761001: Procedure, Performed: Colonoscopy", "", "", "", "", "", "", "", strColoDate )
OBSNOW("HXPREVCOLON","done")
document.checkLOOP = "done"
else ""
endif
else ""
endif
else ""
endif
return ""
}
}
{! fn fnCheckOrderDate(strOrdDesc)
{
local retStr = ""
local strTemp = ""
local strBuf = ""
local i
local strList = ""
local strOrdDate = ""
strList = ORDERS_ALL("delimited")
strTemp = getfield(strList,"|","")
for i = 1, i <= size(strTemp), i = i + 1 do
strTemp[i] = getfield(strTemp[i],"^","")
if DURATIONDAYS(strTemp[i][3], str(._TODAYSDATE)) <= 3650 then
if strOrdDesc == strTemp[i][1] then
retStr = "exists"
else ""
endif
else
break
endif
endfor
return retStr
}
}
Posted : December 20, 2019 10:56 am