We currently use a button to fun a function to calculate and then populate a edit field tied to BMI. I know there's a way to do this automatically such as when OBSANY("HIEGHT") <> "" and OBSNOW("WEIGHT") <> "" then OBSNOW("BMI") == the calculation. I'm just stumped right now. I've even tried the example VFE comes with and it throws a massive error. Any help or solution would be great.
Thanks in advance.
Here my function in the whiteboard…
{fn CalcBMI(){
IF (OBSNOW("WEIGHT") == "" OR OBSNOW("HEIGHT") == "") THEN
return ""
ENDIF
return round((OBSNOW("WEIGHT") / 2.2046) / ((OBSNOW("HEIGHT") / 39.3701) ^2),2)
}}
How is it being push to the OBS term BMI
Through your button.
Set the button to CALCULATION with the target item of BMI and {CalcBMI()} listed in the text box below...
Ah that's the way it's set up now. I'm looking for a way to have a data display that will automatically do the calculation once a height and weight are entered. I've gotten it to do the calculation automatically just can't figure how to push it to the OBS.
I used this in the data display MEL expression:
{
if (OBSNOW(
"WEIGHT") == "" or OBSANY("HEIGHT") == "" or OBSANY("HEIGHT") <= 0) then ""
else (OBSNOW(
"WEIGHT") / 2.2) / ((OBSANY("HEIGHT") / 39.4) ^ 2)
endif
}
Now to figure out how to push that to the OBS.
adaniel said:
Ah that's the way it's set up now. I'm looking for a way to have a data display that will automatically do the calculation once a height and weight are entered. I've gotten it to do the calculation automatically just can't figure how to push it to the OBS.
I used this in the data display MEL expression:
{
if (OBSNOW(
"WEIGHT") == "" or OBSANY("HEIGHT") == "" or OBSANY("HEIGHT") <= 0) then ""
else (OBSNOW(
"WEIGHT") / 2.2) / ((OBSANY("HEIGHT") / 39.4) ^ 2)
endif
}
Now to figure out how to push that to the OBS.
Not sure what exact coding would be but I'd assume something like :
...If...then...ELSE obsnow("bmi")=(OBSNOW("WEIGHT") / 2.2) / ((OBSANY("HEIGHT") / 39.4) ^ 2)
Close
obsnow("bmi",(OBSNOW("WEIGHT") / 2.2) / ((OBSANY("HEIGHT") / 39.4) ^ 2))
Tried both here's what I get
{/*VARIABLES FOR MEL BUILT-IN SYMBOLS USED IN FORM*/
<-VOID{global F5825_786_1401381537 = OBSANY("HEIGHT") "" <-VOID200{
/*FUNCTION DEFINITIONS*/
<-VOID{/*START OF FORM TRANSLATION BODY*/
<-VOIDHt: 70
Wt: 200
Using this in the data display:
{
if (OBSNOW("WEIGHT") == "" or OBSANY("HEIGHT") == "" or OBSANY("HEIGHT") <= 0) then ""
else (OBSNOW("bmi",(OBSNOW("WEIGHT") / 2.2) / ((OBSANY("HEIGHT") / 39.4) ^ 2)))
endif
}
If you look above that you get the real error:
{global F3477_70_1401386969 = OBSNOW("WEIGHT") "" <-INVALID OPERATION OR BAD SYMBOL TYPE: OBSNOW{if (F3477_70_1401386969 == "" or F3477_40_1401386969 == "" or F3477_40_1401386969 <= 0) then ""
else (OBSNOW("bmi",(F3477_70_1401386969 / 2.2) / ((F3477_40_1401386969 / 39.4) ^ 2)))
endif <-INVALID OPERATION OR BAD SYMBOL TYPE: OBSNOW
I'm not sure if you CAN have it auto populate. Not to be rude, but is it that hard to press a button?
Ours does, set the BMI field to document connection with BODY_MASS_IN as the variable name and post the code below on the white board.
/*Document variable setting for vitals*/
{DOCUMENT.TEMP_veHEIGHTNOW = DOCUMENT.Height}
{DOCUMENT.TEMP_veHEIGHTPREV = OBSPREV("Height")}
{DOCUMENT.TEMP_veWEIGHTNOW = DOCUMENT.Weight}
{DOCUMENT.BODY_MASS_IN = str(CalcBMIConv(DOCUMENT.TEMP_veHEIGHTNOW,DOCUMENT.TEMP_veHEIGHTPREV,DOCUMENT.TEMP_veWEIGHTNOW))
OBSNOW("BMI",DOCUMENT.BODY_MASS_IN)}
{fn CalcBMIConv(heightnow,heightprev,weightnow) {
local heightval = ""
cond
case heightnow <> ""
heightval = heightnow
case heightprev <> ""
heightval = heightprev
else
heightval = ""
endcond
if weightnow == "" or heightval == "" or val(weightnow) == 0 or val(heightval) == 0 then
return ""
endif
if heightval == 0 then
return str(0)
endif
return str((weightnow / 2.2) / ((heightval / 39.4)^2))
}}
chrishuff1 said:
If you look above that you get the real error:
{global F3477_70_1401386969 = OBSNOW("WEIGHT") "" <-INVALID OPERATION OR BAD SYMBOL TYPE: OBSNOW{if (F3477_70_1401386969 == "" or F3477_40_1401386969 == "" or F3477_40_1401386969 <= 0) then ""
else (OBSNOW("bmi",(F3477_70_1401386969 / 2.2) / ((F3477_40_1401386969 / 39.4) ^ 2)))
endif <-INVALID OPERATION OR BAD SYMBOL TYPE: OBSNOW
I'm not sure if you CAN have it auto populate. Not to be rude, but is it that hard to press a button?
I understand just a request that I'm trying to fulfil
We have obsnow("bmi") in the data display and here is our watcher pane code (which is REALLY close to Michael's - we set HEIGHT and WEIGHT obs terms directly on the form):
{!global gHEIGHT = OBSNOW("Height")} {!global gWEIGHT = OBSNOW("Weight")}
{!global gHEIGHTPREV = OBSPREV("Height")}
{!IF (gHEIGHT<>"" OR gHEIGHTPREV<>"") AND gWEIGHT<>"" THEN DOCUMENT.BODY_MASS_IN = str(CalcBMIConv(gHEIGHT,gHEIGHTPREV,gWEIGHT)) if DOCUMENT.BODY_MASS_IN <> "" THEN OBSNOW("BMI",DOCUMENT.BODY_MASS_IN) ELSE OBSNOW("BMI","") ENDIF ELSE "" ENDIF}
{fn CalcBMIConv(heightnow,heightprev,weightnow) { local heightval = "" cond case heightnow <> "" heightval = heightnow case heightprev <> "" and heightnow = "" heightval = heightprev else heightval = "" endcond if weightnow == "" or heightval == "" then return "" endif if heightval == 0 then return str(0) endif return str((weightnow / 2.2) / ((heightval / 39.4)^2)) }}
Works just like I was thinking it could. Thank you all.