Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BPXRMBMI

BPXRMBMI.m

Go to the documentation of this file.
BPXRMBMI ; SLC/PKR - This is an example of a computed finding. ;26-Sep-2006 13:44;MGH
 ;;1.5;CLINICAL REMINDERS;**1004**;Jun 19, 2000
 ;IHS/CIA/MGH Patch 1004 Routine for Computed findings for BMI
 ;=======================================================================
BMI(DFN,TEST,DATE,VALUE,TEXT) ; EP Computed finding to return the BMI
 N BMI,HT,WT,HTDATE,WTDATE,HTDATA,WTDATA,X,Y,TODAY
 S (TEST,DATE,VALUE,TEXT)=""
 S X="TODAY" D ^%DT S TODAY=Y
 D CALCLATE I TEST=0 S DATE=TODAY,VALUE="" Q
 I (HTDATE'="")&(WTDATE'="") D
 .S DATE=$$MIN^XLFMTH(HTDATE,WTDATE)
 S TEST=1
 I BMI="" S VALUE="?"
 E  S VALUE=BMI
 Q
CALCLATE ;Calculate the BMI
 S HTDATA=$$LASTMSR($G(DFN),"HT") I HTDATA<1 S TEST=0 Q
 S WTDATA=$$LASTMSR($G(DFN),"WT") I WTDATA<1 S TEST=0 Q
 S BMI=""
 S HT=$P(HTDATA,U,1),HTDATE=$P(HTDATA,U,3)
 S WT=$P(WTDATA,U,1),WTDATE=$P(WTDATA,U,3)
 S WT=WT*.45359,HT=HT*.0254,HT=HT*HT,BMI=+$J(WT/HT,0,2)
 Q
LASTMSR(DFN,MSR) ;--Returns most current measurement
 NEW VDT,IEN,X,TIU,LINE,ARR,DATE,STOP,BPX
 S MSR=$O(^AUTTMSR("B",MSR,0)) I MSR="" Q ""
 ;
 S STOP=$O(^AUPNVMSR("AA",DFN,MSR,0))\1   ;stop at most recent date
 I 'STOP Q ""                             ;none to be found
 S VDT=0
 F  S VDT=$O(^AUPNVMSR("AA",DFN,MSR,VDT)) Q:'VDT!(VDT\1'=STOP)  D
 . S IEN=0
 . F  S IEN=$O(^AUPNVMSR("AA",DFN,MSR,VDT,IEN)) Q:'IEN  D
 .. K ARR D ENP^XBDIQ1(9000010.01,IEN,".03;.04;1201","BPX(","I")
 .. ; value ^ visit ien ^ event date internal format
 .. S LINE=$G(BPX(.04))_U_$G(BPX(.03,"I"))_U_$G(BPX(1201,"I"))
 .. S DATE=$S($G(BPX(1201,"I"))]"":BPX(1201,"I"),1:(9999999-$P(VDT,"."))_"."_$P(VDT,".",2))
 .. S ARR(DATE,IEN)=LINE
 I '$D(ARR) Q ""
 S DATE=$O(ARR(""),-1),IEN=$O(ARR(DATE,""),-1),LINE=ARR(DATE,IEN)
 Q $G(LINE)
HIBMI(DFN,TEST,DATE,VALUE,TEXT) ;EP Find BMI < 25
 N BMI,HT,WT,HTDATE,WTDATE,HTDATA,WTDATA,X,Y,TODAY
 S (TEST,DATE,VALUE,TEXT)=""
 S X="TODAY" D ^%DT S TODAY=Y
 D CALCLATE I TEST=0 S DATE=TODAY,VALUE="" Q
 S DATE=$$MIN^XLFMTH(HTDATE,WTDATE)
 I BMI="" S TEST=0,VALUE="?"
 I BMI>25 S TEST=1,VALUE=BMI
 I BMI=25 S TEST=1,VALUE=BMI
 I BMI<25 S TEST=0,VALUE=BMI
 Q
HIPCENT(DFN,TEST,DATE,VALUE,TEXT) ;EP Find the patients wt percentile
 N PERCENT,WTDATE,X,Y,TODAY,PERC
 S X="TODAY" D ^%DT S TODAY=Y
 D PERCENT(DFN) I TEST=0 S DATE=TODAY,VALUE="" Q
 I PERC<85 S TEST=0,VALUE=PERC,DATE=WTDATE
 I PERC>85 S TEST=1,VALUE=PERC,DATE=WTDATE
 Q
PERCENT(DFN) ;Find the wt percentile
 N MOAGE,AGE,SEX,WTDATA,WT
 S SEX=$$GET1^DIQ(2,DFN,.02,"I")
 S AGE=$$GET1^DIQ(2,DFN,.03,"I")
 D AGEMO
 S WTDATA=$$LASTMSR($G(DFN),"WT") I WTDATA<1 S TEST=0 Q
 S WT=$P(WTDATA,U,1),WTDATE=$P(WTDATA,U,3)
 S PERC=$$AUHTWT^APCHS2A2("WT",SEX,MOAGE,WT)
 I $E(PERC,1,1)=">"!($E(PERC,1,1)="<") S PERC=$E(PERC,2,$L(PERC))
 Q
AGEMO ;Get age in months
 N YR,MO
 S X="TODAY" D ^%DT S TODAY=Y
 S YR=$E(TODAY,1,3)-$E(AGE,1,3),MO=$E(TODAY,4,5)-$E(AGE,4,5)
 I MO<0 S MO=MO+12,YR=YR-1
 S MOAGE=12*YR+MO
 Q