Hi there, I am having some troubles with a BMI calculation that seems to be dumping (?) into the data field. Can someone take a look at this code and tell me what might be wrong, I have looked it over and cannot seem to locate the issue.
/*Calculate the BMI*/
{fn BMI_calc(){
local a,c,e,f
a = obsany("Height")
c = obsnow("Weight")
if (a=="" or c=="") then userok("There must be a previous Height and current Weight to calculate the BMI.") return "" else
if a=="" then "" else e = val(str(a)) endif
if c=="" then "" else f = val(str(c)) endif
return (f / 2.2) / ((e / 39.4)^2)
endif
}}
{fn VS_calc_BSA(a,b){
/* "a" is obsany("height"); "b" is obsnow("weight") */
if (a=="" or b=="") then userok("There must be a previous Height and current Weight to calculate the BSA.") return "" else "" endif
local f="",g=""
if a<>"" then f = val(str(a)) else "" endif
if b<>"" then g = val(str(b)) else "" endif
if str(f)=="" or str(g)=="" or f==0 or g==0 then return "" else return str(((g /2.2) ^.425) * ((f*2.54) ^.725) * (71.84/10000)) endif
}}
/*Set Global watchable variables*/
{! global OBS_NOW_LMP=OBSNOW("LAST MP")}{!
global OBS_NOW_HGB=OBSNOW("HGB")}{!
global OBS_NOW_HEIGHT=OBSNOW("HEIGHT")}{!
global OBS_ANY_HEIGHT=OBSANY("HEIGHT")}{!
global OBS_NOW_WEIGHT=OBSNOW("WEIGHT")}{!
global OBS_NOW_TEMPERATURE=OBSNOW("TEMPERATURE")}{!
global OBS_NOW_TEMP_SITE=OBSNOW("Temp site")}{!
global OBS_NOW_PULSE_RATE=OBSNOW("PULSE RATE")}{!
global OBS_NOW_PULSE_RHYTHM=OBSNOW("PULSE RHYTHM")}{!
global OBS_NOW_RESP_RATE=OBSNOW("RESP RATE")}{!
global OBS_NOW_BP_SYSTOLIC_SIT=OBSNOW("BP systolic")}{!
global OBS_NOW_BP_DIASTOLIC_SIT=OBSNOW("BP diastolic")}{!
global OBS_NOW_BMI=OBSNOW("BMI")}{!
global OBS_NOW_BSA=OBSNOW("BSA")}{!
global TRANS_CYCLEDAY}
{!IF OBSANY("LAST MP")<>"" then TRANS_CYCLEDAY=WEEKS_PREG(LASTOBSVALUE("LAST MP")) else "" endif}
{!IF DOCUMENT.VS_ENTERED_B<>"" THEN OBSNOW("VITALS BY",DOCUMENT.VS_ENTERED_B) ELSE "" ENDIF}
I am not very familiar with MEL unfortunately. Can you provide an example of the output? The BMI function looks pretty straightforward to me.
The outcome for some reason looks like this.
Height: 64 (?)
Weight: 150 (?)
And of course we have to remove the (?) in order for the BMI to calculate correctly, thanks for your help!
Are your HEIGHT and WEIGHT obsterms containing any characters ? Like lbs or in ?
If they do, you can use the VAL( ) function to strip out any characters before doing calculation.
.
a = VAL(obsany(“Height”))
c = VAL(obsnow(“Weight”))
.
Also, change your comparisions to look for 0 now instead of blank. For example:
if (a=0 or c=0)
.
Try that, see if it helps.
.
- Beverly
Beverly it looks like the code already does that, albeit in 2 steps. A and C are first set as strings, then E and F are set as the value of A and C respectively. Similar behavior in the second function.
Both functions appear to me to return a value. How you're getting a string isn't apparent here. Can you post the code that calls these functions?