I wrote a function to calculate the APRI Index of a patient in a VFE form, and I'd like the result of that function to be assigned to an obs term.
Here is my function below. I placed it in the function view in VFE. I can verify that the calculation does indeed work great, but the obs term APRIINDEX is not being added with the value.
Any clue what I'm doing wrong?
/* Calculate APRI */
{fn APRI()
{
local aprindex
aprindex = val(OBSANY("SGOT (AST)"))/40/val(replacestr(OBSANY("PLATELETS")," X10(3)/UL","")) * 100
OBSNOW("APRIINDEX", aprindex)
return aprindex
}}
Give this a try, the commented out quotes will help debug which variable is causing an issue when you uncomment them.
!fn APRI()
{
local aprindex = 0
local obs1 = val(OBSANY(“SGOT (AST)”))
/*userok("OBS1: "+obs1)*/
local obs2 = val(OBSANY(“PLATELETS”))
/*userok("OBS2: "+obs2)*/
aprindex = (((obs1 / 40)/obs2)*100)
/*userok("Aprindex: "+aprindex)*/
return aprindex
}
{!
local tmp = APRI()
if tmp (insert not equal here) "" then
OBSNOW(“APRIINDEX”, tmp)
endif
}
Note: For safety final product should implement error checking for division by zero cases
IIRC, you'll need to convert the result to a string in order for your Obsnow call to work.
Yes, what Chris said:
OBSNOW(“APRIINDEX”, str(aprindex))