Does anyone have a form or code to share that calculates BMI%tile ONLY....
Thanks!
{DOCUMENT.TEMP_veHEIGHTNOW = OBSNOW("Height")}
{DOCUMENT.TEMP_veHEIGHTPREV = OBSPREV("Height")}
{DOCUMENT.TEMP_veWEIGHTNOW = OBSNOW("Weight")}
{DOCUMENT.BODY_MASS_IN = str(CalcBMIConv(DOCUMENT.TEMP_veHEIGHTNOW,DOCUMENT.TEMP_veHEIGHTPREV,DOCUMENT.TEMP_veWEIGHTNOW))}
{if DOCUMENT.CHECK2 ""
THEN OBSNOW("BMI",DOCUMENT.BODY_MASS_IN)
ELSE OBSNOW("BMI","")
ENDIF}
{
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))
}
Below is the code I use for calculating it on my peds forms. I got it from these forums. You call it by using the first function GetBMIPercentile(bmi), and it doesn't return anything, just sets the obs term BMI%ILE:
fn GetBMIPercentile(bmi)
{
local lmsArr
local index = 0
cond
case PATIENT._AGEINMONTHS = 276: /*Do Nothing*/
else:
if PATIENT._AGEINMONTHS < 60 then
index = 24
endif
lmsArr=GetLms("bmi_age", PATIENT._AGEINMONTHS - index, TRUE, index)
if size(lmsArr) 0 then
OBSNOW("BMI%ILE", STR(GetPercentile(GetZScore(bmi, lmsArr[2], lmsArr[3],lmsArr[4]))))
endif
endcond
}
fn GetLms(fileName, ageInMonths, addAgeToFileName, adjIndex)
{
local fileNameAge = 0
local rawLmsArr
local lmsArr
local index
if addAgeToFileName then
cond
case ageInMonths < 60: fileNameAge = 60
case ageInMonths < 120: fileNameAge = 120
case ageInMonths < 180: fileNameAge = 180
case ageInMonths = 240: fileNameAge = ""
endcond
fileName=fileName + "_" + str(fileNameAge)
endif
lmsArr=GetRawLmsArray( fileName )
// RETURN "" ON ERROR
if size(lmsArr)==0 then
return ""
endif
index=ageInMonths-fileNameAge+1.5
if addAgeToFileName then
index=index+60
endif
index = div(index, 1)
if size(lmsArr) index then
index = index+1
endif
rawHi=get(lmsArr,(index))
rawLo = getfield( rawLo, "|")
rawHi=getfield( rawHi, "|")
ageInMonths = ageInMonths+adjIndex
lmsArr=GetLMSArray(ageInMonths, rawLo, rawHi)
return lmsArr
}
fn GetRawLmsArray(fileName)
{
local path
local file
local text = ""
local lmsArr
path = GetGrowthChartLmsDataPath() + fileName
file = FILEOPEN( path, "r")
if file NULL then
text = FILEREAD(file)
FILECLOSE(file)
else
USEROK( "Unable to open file '" + path + "'" )
endif
if size(text)==0 then
return ""
endif
lmsArr = getfield(text, ",")
return lmsArr
}
fn GetGrowthChartLmsDataPath()
{
local path
local GC_DIR
local backslashes = "\\\\"
local backslash
backslash=get(backslashes, 2)
GC_DIR = backslash + "clinical content" + backslash + "peds_growth_data" + backslash + PATIENT.SEX + backslash
path=DIR_EMR() + GC_DIR
return path
}
fn GetLMSArray(ptAge, lmsArrLow, lmsArrHigh )
{
local ageLow
local ageHigh
local L
local M
local S
local LMSArr
local fractAbove
ageLow=1*lmsArrLow[4]
ageHigh=1*lmsArrHigh[4]
if (ageHigh-ageLow)==0 then
fractAbove=1
else
fractAbove = (ptAge-ageLow)/(ageHigh-ageLow)
endif
L = 1*lmsArrLow[1] + (1*lmsArrHigh[1]-1*lmsArrLow[1])*fractAbove
M = 1*lmsArrLow[2] + (1*lmsArrHigh[2]-1*lmsArrLow[2])*fractAbove
S = 1*lmsArrLow[3] + (1*lmsArrHigh[3]-1*lmsArrLow[3])*fractAbove
LMSArr = array( ptAge, L, M, S )
return LMSArr
}
fn GetPercentile(z)
{
local p10
local p9
local p4
local p3
local p2
local p1
local p
p10 = 1 + (0.33267 * AbsValue(z))
p9 = 1/p10
p4 = (0.4361836 * p9) - (0.1201676 * (p9^2)) + (0.937298 * (p9^3))
p1= 2 * 3.14159265
p3 = (AbsValue(z)^2)
p2 = -1 * p3/2
local pp
pp = 1/(p1^0.5)*(2.71828182845905^p2)*p4
p = 1 - pp
if z > 0 then
p = p*100
else
p= 100 - p*100
endif
p = div((p+0.5),1)
return p
}
fn GetZScore(val, lVal, mVal, sVal)
{
local z
z = val/mVal
if lVal == 0 then
lVal = 0.000000001
endif
z = z^lVal
z = z-1
z = z/(1*lVal*1*sVal)
return z
}
fn AbsValue(val)
{
if val < 0 then
return -1 * val
endif
return val
}