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

BGPMUA01.m

Go to the documentation of this file.
BGPMUA01 ; IHS/MSC/MGH - MI measure NQF0421 ;22-Mar-2011 09:57;DU
 ;;12.1;IHS CLINICAL REPORTING;;MAY 17, 2012;Build 66
 ;Code to collect meaningful use report adult weight and followup 0421
ENTRY ;EP
 N START,END,BGPDEN1,BGPDEN1A,BGPDEN2,BGPDEN2A,BGPNUM1,BGPNUM1A,BGPNUM2,BGPNUM2A
 N IEN,INV,VISIT,WTIEN,DATA,VDATE,BGPSIX,FIRST,NORMAL,VIEN
 N BGPN1,BGPN3,DEN,EXC
 S (BGPDEN1,BGPDEN1A,BGPDEN2,BGPDEN2A,BGPNUM1,BGPNUM1A,BGPNUM2,BGPNUM2A)=0
 S START=9999999-BGPBDATE,END=9999999-BGPEDATE
 ;Pts must be 18 and older
 ;No need to check further on children
 Q:BGPAGEE<19
 S DEN="",VIEN=0,EXC=0,VIEN=0
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)!(+VIEN)  D
 .S IEN=0 F  S IEN=$O(^AUPNVSIT("AA",DFN,FIRST,IEN)) Q:'+IEN!(+VIEN)  D
 ..;Check provider, Only visits for chosen provider
 ..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
 ..;Quit if the visit does not have a valid E&M code
 ..Q:'$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU BMI ENCOUNTER EM")
 ..S DATA=$G(^AUPNVSIT(IEN,0))
 ..S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1),VIEN=IEN
 ..S DEN="EN:"_$$DATE^BGPMUUTL(VDATE)
 I +VIEN D
 .S NUM=$$NUM(DFN,BGPBDATE,BGPEDATE)
 .;If not in numerator, see if they are an exception
 .I +NUM=0 S EXC=$$EXCLUDE(DFN,BGPBDATE,BGPEDATE,BGPAGEE)
 .D TOTAL(DFN,DEN,NUM,EXC)
 Q
EXCLUDE(DFN,BGPBDATE,BGPEDATE,BGPAGEE) ;Find exclusions
 ;Set a new begin date of 6 most prior to the visit to find exclusons and wt
 N X1,X2,EXC,X,STRING,TERMINAL,PREG,REF
 S STRING=""
 S X1=BGPBDATE,X2=-180 D C^%DTC S BGPSIX=X
 ;Quit if the patient has a terminal diagnosis in last 6mos
 S EXC=0
 S TERMINAL=$$LASTDX^BGPMUUT2(DFN,BGPSIX,BGPEDATE,"BGPMU TERMINAL")
 I +TERMINAL=1 S EXC=1_U_"Excluded"
 ;See if the patient has a pregnancy diagnosis
 S PREG=0
 I BGPSEX="F"&(BGPAGEE<55) S PREG=$$LASTDX^BGPMUUT2(DFN,BGPSIX,BGPEDATE,"BGPMU PREGNANCY")
 I +PREG=1 S EXC=1_U_"Excluded"
 ;Quit if patient refused ht or wt in time frame
 ;10/26/11 - no longer limiting to look back 6 months, ONLY in report period - per Dr. Advani
 S REF=$$REF(DFN,BGPBDATE,BGPEDATE)
 I +REF=1 S EXC=1_U_"Excluded"
 Q EXC
NUM(DFN,BGPBDATE,BGPEDATE) ;see it pt in numerator
 N BGPBN,BGPBMI,BGPN3,NORMAL,FOLLOW,BMI,STRING
 S BMI=0
 S BGPBMI=$$BMI(DFN,BGPBDATE,BGPEDATE,BGPAGEE),BGPN1=$S(BGPBMI]"":1,1:0)
 S BGPBN=$$ROUND($P(BGPBMI,U,1),2)
 ;See if the BMI is abnormal
 I +BGPBMI=0 S BMI=0,STRING="NM:"
 I +BGPBMI>0 D
 .S BGPN3=$$OW(DFN,BGPBN,BGPAGEE)
 .I BGPN3=0 S BMI=1,STRING="M:"_BGPBN_" "_$P(BGPBMI,U,2)
 .I BGPN3=1 D
 ..S NORMAL=0
 ..S FOLLOW=$$FOLLOWUP(DFN,BGPBDATE,BGPEDATE)
 ..I +FOLLOW=0 S BMI=0,STRING="NM:"_BGPBN_" "_$P(BGPBMI,U,2)
 ..I +FOLLOW>0 S BMI=1,STRING="M:"_BGPBN_" "_$P(BGPBMI,U,2)_";"_$P(FOLLOW,U,2)_U_$P(FOLLOW,U,3)
 Q BMI_U_STRING
TOTAL(DFN,DEN,NUM,EXC) ;See where this patient ends up
 N PTCNT,EXCCT1,EXCCT2,DEN1CT,NUM1CT,DEN2CT,NUM2CT,NOT1CT,NOT2CT,TOTALS,PT1,PT2
 S TOTALS=$G(^TMP("BGPMU0421",$J,BGPMUTF,"TOT"))
 S EXCCT1=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"EXC",1))
 S DEN1CT=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"DEN",1))
 S NUM1CT=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"NUM",1))
 S NOT1CT=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"NOT",1))
 S DEN2CT=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"DEN",2))
 S NUM2CT=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"NUM",2))
 S NOT2CT=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"NOT",2))
 S EXCCT2=+$G(^TMP("BGPMU0421",$J,BGPMUTF,"EXC",2))
 S PTCNT=$P(TOTALS,U,1),PT1=$P(TOTALS,U,2),PT2=$P(TOTALS,U,3)
 S PTCNT=PTCNT+1
 I BGPAGEE>64 D
 .S PT1=PT1+1
 .S DEN1CT=DEN1CT+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"DEN",1)=DEN1CT
 .I +NUM D
 ..S NUM1CT=NUM1CT+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"NUM",1)=NUM1CT
 ..I BGPMUTF="C" S ^TMP("BGPMU0421",$J,"PAT",BGPMUTF,1,"NUM",PT1)=DFN_U_DEN_U_NUM
 .I +EXC D
 ..S EXCCT1=EXCCT1+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"EXC",1)=EXCCT1
 ..I BGPMUTF="C" S ^TMP("BGPMU0421",$J,"PAT",BGPMUTF,1,"EXC",PT1)=DFN_U_DEN_U_EXC
 .I +NUM=0&(+EXC=0) D
 ..S NOT1CT=NOT1CT+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"NOT",1)=NOT1CT
 ..I BGPMUTF="C" S ^TMP("BGPMU0421",$J,"PAT",BGPMUTF,1,"NOT",PT1)=DFN_U_DEN_U_NUM
 I BGPAGEE<65 D
 .S PT2=PT2+1
 .S DEN2CT=DEN2CT+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"DEN",2)=DEN2CT
 .I +NUM D
 ..S NUM2CT=NUM2CT+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"NUM",2)=NUM2CT
 ..I BGPMUTF="C" S ^TMP("BGPMU0421",$J,"PAT",BGPMUTF,2,"NUM",PT2)=DFN_U_DEN_U_NUM
 .I +EXC D
 ..S EXCCT2=EXCCT2+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"EXC",2)=EXCCT2
 ..I BGPMUTF="C" S ^TMP("BGPMU0421",$J,"PAT",BGPMUTF,2,"EXC",PT2)=DFN_U_DEN_U_EXC
 .I +NUM=0&(+EXC=0) D
 ..S NOT2CT=NOT2CT+1 S ^TMP("BGPMU0421",$J,BGPMUTF,"NOT",2)=NOT2CT
 ..I BGPMUTF="C" S ^TMP("BGPMU0421",$J,"PAT",BGPMUTF,2,"NOT",PT2)=DFN_U_DEN_U_NUM
 S ^TMP("BGPMU0421",$J,BGPMUTF,"TOT")=PTCNT_U_PT1_U_PT2
 ;Setup iCare array for patient
 I BGPAGEE>64 S BGPICARE("MU.EP.0421.1",BGPMUTF)='EXC_U_+NUM_U_+EXC_U_$P(DEN,U,2)_";"_$P(NUM,U,2)_U_$P(EXC,U,2)
 E  S BGPICARE("MU.EP.0421.3",BGPMUTF)='EXC_U_+NUM_U_+EXC_U_$P(DEN,U,2)_";"_$P(NUM,U,2)_U_$P(EXC,U,2)
 Q
OW(PAT,BMI,AGE) ;EP overweight or underweight
 N RET
 S RET=0
 I $G(BMI)="" Q 0
 I AGE>64 D
 .I BMI>30!(BMI<22) S RET=1
 E  D
 .I BMI>25!(BMI<18.5) S RET=1
 Q RET
HT(DFN,BGPWDATE) ;EP
 I 'P Q ""
 KILL %,BGPDOB,BGPARRY,BGPHT,E,X1,X2,X,BGPMUAGE,BGPHPTR,BGPMDT,BGPHIEN,BGPHDT
 S BGPHT=0
 Q:'+BGPWDATE BGPHT
 S BGPHPTR=$O(^AUTTMSR("B","HT",0))
 S BGPHDT=9999999-(BGPWDATE+1),BGPHT=0
 S BGPHDT=$O(^AUPNVMSR("AA",DFN,BGPHPTR,BGPHDT))
 Q:'+BGPHDT 0
 S BGPHIEN="" S BGPHIEN=$O(^AUPNVMSR("AA",DFN,BGPHPTR,BGPHDT,BGPHIEN)) Q:'+BGPHIEN  D
 .S BGPHT=$P($G(^AUPNVMSR(BGPHIEN,0)),U,4)
 Q:'+BGPHT 0
 S BGPDOB=$P(^DPT(DFN,0),U,3)
 S X1=9999999-BGPHDT,X2=BGPDOB D ^%DTC S BGPMDT=X
 S X2=BGPDOB,X1=BGPEDATE D ^%DTC S BGPMUAGE=X
 Q:(BGPMDT<6571)&(BGPMUAGE>6571) 0
 Q BGPHT
WT(P,BDATE,EDATE) ;EP
 I 'P Q ""
 KILL %,E,BGPLW,X,BGPLN,BGPL,BGPLD,BGPLZ,BGPLX,BGPDT
 S (BGPLW,BGPDT)=""
 K BGPL S BGPLW="" S BGPLX=P_"^LAST 24 MEAS WT;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(BGPLX,"BGPL(")
 S BGPLN=0 F  S BGPLN=$O(BGPL(BGPLN)) Q:'+BGPLN!(+BGPLW)  D
 .S BGPLZ=$P(BGPL(BGPLN),U,5)
 .S BGPLW=$P(BGPL(BGPLN),U,2),BGPDT=$P(BGPL(BGPLN),U,1)
 Q BGPLW_U_BGPDT
 ;
BMI(P,BDATE,EDATE,AGE) ;EP
 N BGPBMIH,HDATE,SDATE,WDATE,E2DATE
 KILL %,W,H,B,D,%DT
 S BGPBMIH=0,WDATE=""
 I AGE>18,AGE<51 D
 .S SDATE=$$FMADD^XLFDT(BDATE,-180),SDATE=$$FMTE^XLFDT(SDATE),E2DATE=$$FMTE^XLFDT(EDATE)
 .S W=$$WT(P,SDATE,E2DATE)
 .I +W D
 ..S WDATE=$P(W,U,2)
 ..S H=$$HT(P,WDATE)
 ..I +H D
 ...S W=+W
 ...S W=W*.45359,H=(H*.0254),H=(H*H),BGPBMIH=(W/H)
 I AGE>50 D
 .S SDATE=$$FMADD^XLFDT(EDATE,-180),SDATE=$$FMTE^XLFDT(SDATE),E2DATE=$$FMTE^XLFDT(EDATE)
 .S W=$$WT(P,SDATE,E2DATE)
 .I +W D
 ..S WDATE=$P(W,U,2)
 ..S H=$$HT(P,WDATE)
 ..I +H D
 ...S W=+W
 ...S W=W*.45359,H=(H*.0254),H=(H*H),BGPBMIH=(W/H)
 I WDATE'="" S WDATE=$$DATE^BGPMUUTL(WDATE)
 Q BGPBMIH_U_WDATE
REF(PAT,BDATE,EDATE) ;EP - get ht/wt refusal in time frame, same date for 18 and under
 N R S R=0
 I $G(BDATE)="" S BDATE=$P(^DPT(PAT,0),U,3)  ;if no date then set to DOB
 S X=$$REFUSAL^BGP0UTL1(PAT,9999999.07,$O(^AUTTMSR("B","HT",0)),BDATE,EDATE) I X S R=1_U_"HT"_U_$P(X,U,2)
 S Y=$$REFUSAL^BGP0UTL1(PAT,9999999.07,$O(^AUTTMSR("B","WT",0)),BDATE,EDATE) I Y S R=1_U_"WT"_U_$P(X,U,2)
 I X="",Y="" Q 0
 Q R
FOLLOWUP(DFN,BDATE,EDATE) ;Find out of followup was done
 N CODE,DX,ED,CON,NEWDT,RET
 S RET=0
 S NEWDT=$$FMADD^XLFDT(BDATE,-180)
 ;Check for CPTs for followup
 S CODE=$$CPT^BGPMUUT1(DFN,NEWDT,EDATE,"BGPMU BMI FOLLOWUP CPTS")
 I +CODE S RET=+CODE_U_$P(CODE,U,2)_" "_$$DATE^BGPMUUTL($P(CODE,U,3))
 ;Check for ICD for followup
 S DX=$$LASTDX^BGPMUUT2(DFN,NEWDT,EDATE,"BGPMU BMI FOLLOWUP ICD")
 I +DX S RET=+DX_U_$P(DX,U,2)_" "_$$DATE^BGPMUUTL($P(DX,U,3))
 ;Check for patient ed codes
 ;S NEWDT=$$FMADD^XLFDT(EDATE,-365)
 ;S ED=$$PED(DFN,NEWDT,EDATE)
 ;I +ED Q ED
 ;Check for consult
 ;S CONSULT=$$CONSULT(DFN,NEWDT,EDATE)
 ;I +CONSULT Q CONSULT
 ;Did not find any followup
 Q RET
CONSULT(DFN,BDATE,EDATE) ;Check for nutrition consult in the last year
 N DATA,PRM,ENT,CONSULT,BEGIN,END,CTYPE,CNAME,I,TYPE,%DT
 S CONSULT=0
 S BEGIN=BDATE+1
 S BEGIN=9999999-BDATE,END=9999999-EDATE
 S PRM="BGPMU DIETARY CONSULT",ENT="DIV^SYS"
 D GETLST^XPAR(.DATA,ENT,PRM,"I")
 I $D(DATA) D
 .S I=0 F  S I=$O(DATA(I)) Q:'+I!(CONSULT'=0)  D
 ..S TYPE=$G(DATA(I))
 ..S %DT="" F  S %DT=$O(^GMR(123,"AD",DFN,%DT)) Q:%DT=""!(CONSULT'=0)  Q:DT>BEGIN!(END<%DT)  D
 ...S IEN="" F  S IEN=$O(^GMR(123,"AD",DFN,%DT,IEN)) Q:IEN=""  D
 ....I $P($G(^GMR(123,IEN,0)),U,5)=TYPE D
 .....S CTYPE=$P($G(^GMR(123,IEN,0)),U,5),CNAME=$P($G(^GMR(123.5,CTYPE,0)),U,1)
 .....S CONSULT=1_U_CNAME
 Q CONSULT
PED(P,BDATE,EDATE) ;EP
 K BGPG
 N Y,X,D,T
 S Y="BGPGMU("
 S X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I '$D(BGPGMU) Q 0
 S (X,D)=0,%=0,T="" F  S X=$O(BGPGMU(X)) Q:X'=+X!(%'=0)  D
 .S T=$P(^AUPNVPED(+$P(BGPGMU(X),U,4),0),U)
 .Q:'T
 .Q:'$D(^AUTTEDT(T,0))
 .S T=$P(^AUTTEDT(T,0),U,2)
 .I $P(T,"-")="OBS" S %=1_U_T_U_$P(BGPGMU(X),U) Q
 .I $P(T,"-",2)="OBS" S %=1_U_T_U_$P(BGPGMU(X),U) Q
 .I $P(T,"-")="278.0" S %=1_U_T_U_$P(BGPGMU(X),U) Q
 .I $P(T,"-")="278.00" S %=1_U_T_U_$P(BGPGMU(X),U) Q
 .I $P(T,"-")="278.01" S %=1_U_T_U_$P(BGPGMU(X),U) Q
 .I $P(T,"-")="783.22" S %=1_U_T_U_$P(BGPGMU(X),U) Q
 K BGPGMU
 Q %
ROUND(VAL,SD) ;EP
 Q:VAL'=+VAL!($G(SD)=0) VAL
 Q +$J(VAL,0,$S($D(SD):SD,VAL<1:2,VAL<10:2,1:2))