Edit: here is what I come up with to kind of manipulate what I needed:
{
global wn = val(OBSNOW("Weight"))
global op = "-"
global wp = val(OBSPREV("Weight"))
global wgs = "Patient has a weight gain of "
global wls = "Patient has a weight loss of "
if wn>wp then wgs + eval(wn + op + wp) else if wn<wp then wls + eval(wp + op + wn) else "" endif endif}{ " pounds in " +durationdays(last_signed_obs_date('weight'),str(._todaysdate))+" days. "}
Also the post below nails it to.
My Original post:
The end goal is to have a quick text that will say:
Patient has gained XX weight.
or
Patient has lost XX weight.
So I know I need to start with the math which I have the following:
{fn CalcWeightDiff(){
local oldweightval = 0
local newweightval = 0
local weightdiff = 0
cond
case OBSPREV("WEIGHT") <> ""
oldweightval = OBSPREV("WEIGHT")
endcond
cond
case OBSNOW("WEIGHT") <> ""
newweightval = OBSNOW("WEIGHT")
endcond
if oldweightval == "" or newweightval == "" then
weightdiff = ""
else
weightdiff = val(oldweightval) - val(newweightval)
endif
if weightdiff <> "" then
return weightdiff
else ""
endif}}
So next step I need to evaluate that which in my head I had:
{fn WeightDiff(){
if LISTSUBSET(CalcWeightDiff(),"string","-", "contains", "any") <> "" then
"Patient gained " + CalcWeightDiff() + " pounds."
else if LISTSUBSET(CalcWeightDiff(),"string","-", "contains", "any") = "" then
"Patient lost " + CalcWeightDiff() + " pounds."
endif endif
}}
Which did not work and even if it did I would of had a problem with the "-" being in there if weight was gained.
Anyway i was wondering if someone had a better way or insight on on the evaluate the math to create a statement. Thanks in advance.
Hi, I don't know if this is better but I found this on the CHUG years ago, it may be of some help.
{if obsprev('weight')"" then "The patient's weight at the last visit ("+last_signed_obs_date('weight')+") was "+obsprev('weight')+" pounds. " else "" endif}{if obsnow('weight')"" then "Today's weight is "+obsnow('weight')+" pounds. " else "" endif}{if (obsnow('weight')"" and obsprev('weight')"") then "This is a change of " + str(val(obsnow('weight'))-val(obsprev('weight')))+" pounds in " +durationdays(last_signed_obs_date('weight'),str(._todaysdate))+" days. " else "" endif}
Bingo thank you.