BGP6D213 ; IHS/CMI/LAB - measure 6 13 Aug 2015 6:58 AM ;
;;16.1;IHS CLINICAL REPORTING;;MAR 22, 2016;Build 170
;
CVD ;EP - called from report execution
I BGPAGEB<21 S BGPSTOP=1 Q ;ONLY 21+
NEW BGPCVDL
F X=1:1:6 S Y="BGPD"_X S @Y="" ;6 denominators
S (BGPN1,BGPN2,BGPN3)="" ;2 numerators
S BGPCVDL=$$CHDLDL^BGP6D212(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE) ;CHD OR LDL^CHD^LDL
I BGPAGEB>20,BGPAGEB<40,'BGPCVDL S BGPSTOP=1 Q ;21-39 and no cvd/ldl
I BGPAGEB>75,'BGPCVDL S BGPSTOP=1 Q ;>75 and no cvd/ldl
;DENOM 1
I BGPDMD1,BGPAGEB>39,BGPAGEB<76 S BGPD1=1 ;up diabetic ages 40-75
I BGPAGEB>20,BGPCVDL S BGPD1=1 ;or UP 21+ w/CVD or LDL =>190
;DENOM 2 21-39, UP with CVD or LDL >=190
I BGPAGEB>20,BGPAGEB<40,BGPCVDL S BGPD2=1
;DENOM 3 40-75, UP with CVD or LDL =>190
I BGPAGEB>39,BGPAGEB<76,BGPCVDL S BGPD3=1
;DENOM 4 76+ with cvd or ldl >=190
I BGPAGEB>75,BGPCVDL S BGPD4=1
;DENOM 5 UP diabetic 40-75
I BGPDMD1,BGPAGEB>39,BGPAGEB<76 S BGPD5=1
;DENOM 6 up 21+
I BGPD1 S BGPD6=1
;I 'BGPD6 S BGPSTOP=1 Q ;not in at least UP denominator
;now exclude people
S (BGPEXL1,BGPEXL2,BGPEXL3,BGPEXL4,BGPEXL5,BGPEXL6)=""
S BGPEXL1=$$STATALG^BGP6D212(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE) I BGPEXL1 S (BGPN2,BGPN3)=1 G SETL ;excl 1
;ALCOHOL HEP
S BGPEXL1=$$ALCHEP^BGP6D212(DFN,BGPBDATE,BGPEDATE) I BGPEXL1 S BGPN2=1 G SETL
;NMI
S BGPEXL1=$$STATNMI^BGP6D212(DFN,BGPBDATE,BGPEDATE) I BGPEXL1 S BGPN2=1 G SETL
;PREGNANCY
S BGPEXL2=$$PREG^BGP6D7(DFN,BGPBDATE,BGPEDATE,1,1,1) I BGPEXL2 S BGPN2=1 G SETL
;BREASTFEEDING
S BGPEXL2=$$BF^BGP6D21(DFN,BGPBDATE,BGPEDATE) I BGPEXL2 S BGPN2=1 G SETL
;cirrhosis of liver
S BGPEXL6=$$CLIVER(DFN,BGPPBD,BGPEDATE) I BGPEXL6 S BGPN2=1 G SETL
;PALLIATIVE
S BGPEXL3=$$LASTDX^BGP6UTL1(DFN,"BGP PALLIATIVE CARE DXS",BGPBDATE,BGPEDATE) I BGPEXL3 S BGPN2=1,BGPEXL3=1_U_$$DATE^BGP6UTL($P(BGPEXL3,U,3))_" Palliative Care" G SETL ;excl 3
;ESRD
S BGPEXL4=$$ESRD^BGP6D211(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE) I BGPEXL4 S BGPEXL4=1_U_$$DATE^BGP6UTL($P(BGPEXL4,U,3))_" ESRD" S BGPN2=1 G SETL ;excl 4 ESRD
;EXCL 5
NEW BGPSTAT
S BGPSTAT=$$STATIN^BGP6D214(DFN,BGPBDATE,BGPEDATE,0)
S BGPEXL5=$$LASTLDLV^BGP6D212(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE) I BGPEXL5,'$P(BGPCVDL,U,3),'BGPSTAT S BGPN2=1 G SETL ;excl 5
;numerator
S BGPN1=BGPSTAT
SETL ;
I BGPN2 S (BGPD1,BGPD2,BGPD3,BGPD4,BGPD5)="" ;if exclusion don't count in those denoms per Megan
I BGPN2,BGPD1 S BGPD6=1
S BGPVALUD=$S(BGPDMD2:"UP,AD",1:"UP") I BGPDMD1!(BGPCVDL) D
.;S BGPVALUD=BGPVALUD_" ("
.I BGPDMD1,'BGPCVDL S BGPVALUD=BGPVALUD_" (DM)"_"|||" Q
.I BGPDMD1,BGPCVDL S BGPVALUD=BGPVALUD_$S($P(BGPCVDL,U,2):" (DM,CHD)",$P(BGPCVDL,U,3):" (DM,LDL)",1:"")_"|||" Q
.S BGPVALUD=BGPVALUD_$S($P(BGPCVDL,U,2):" (CHD)",$P(BGPCVDL,U,3):" (LDL)",1:"")_"|||"
I BGPN1 S BGPVALUD=BGPVALUD_$P(BGPN1,U,2)
I BGPEXL1 S BGPVALUD=BGPVALUD_"Exclusion: "_$P(BGPEXL1,U,2)
I BGPEXL2 S BGPVALUD=BGPVALUD_"Exclusion: "_$P(BGPEXL2,U,2)_" Pregnant/Breastfeeding"
I BGPEXL3 S BGPVALUD=BGPVALUD_"Exclusion: "_$P(BGPEXL3,U,2)
I BGPEXL4 S BGPVALUD=BGPVALUD_"Exclusion: "_$P(BGPEXL4,U,2)
I BGPEXL6 S BGPVALUD=BGPVALUD_"Exclusion: "_$P(BGPEXL6,U,2)_" Cirrhosis"
I BGPEXL5,BGPN2 S BGPVALUD=BGPVALUD_"Exclusion: "_$P(BGPEXL5,U,2)
K BGPEXL1,BGPEXL2,BGPEXL3,BGPEXL4,BGPEXL5,BGPCVDL
Q
CLIVER(P,BD,ED) ;EP - cirrhosis of liver?
NEW %,X
S X=$$LASTDX^BGP6UTL1(P,"BGP CIRRHOSIS OF LIVER DXS",BD,ED)
I X Q 1_U_$$DATE^BGP6UTL($P(X,U,3))
Q ""
BGP6D213 ; IHS/CMI/LAB - measure 6 13 Aug 2015 6:58 AM ;
+1 ;;16.1;IHS CLINICAL REPORTING;;MAR 22, 2016;Build 170
+2 ;
CVD ;EP - called from report execution
+1 ;ONLY 21+
IF BGPAGEB<21
SET BGPSTOP=1
QUIT
+2 NEW BGPCVDL
+3 ;6 denominators
FOR X=1:1:6
SET Y="BGPD"_X
SET @Y=""
+4 ;2 numerators
SET (BGPN1,BGPN2,BGPN3)=""
+5 ;CHD OR LDL^CHD^LDL
SET BGPCVDL=$$CHDLDL^BGP6D212(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
+6 ;21-39 and no cvd/ldl
IF BGPAGEB>20
IF BGPAGEB<40
IF 'BGPCVDL
SET BGPSTOP=1
QUIT
+7 ;>75 and no cvd/ldl
IF BGPAGEB>75
IF 'BGPCVDL
SET BGPSTOP=1
QUIT
+8 ;DENOM 1
+9 ;up diabetic ages 40-75
IF BGPDMD1
IF BGPAGEB>39
IF BGPAGEB<76
SET BGPD1=1
+10 ;or UP 21+ w/CVD or LDL =>190
IF BGPAGEB>20
IF BGPCVDL
SET BGPD1=1
+11 ;DENOM 2 21-39, UP with CVD or LDL >=190
+12 IF BGPAGEB>20
IF BGPAGEB<40
IF BGPCVDL
SET BGPD2=1
+13 ;DENOM 3 40-75, UP with CVD or LDL =>190
+14 IF BGPAGEB>39
IF BGPAGEB<76
IF BGPCVDL
SET BGPD3=1
+15 ;DENOM 4 76+ with cvd or ldl >=190
+16 IF BGPAGEB>75
IF BGPCVDL
SET BGPD4=1
+17 ;DENOM 5 UP diabetic 40-75
+18 IF BGPDMD1
IF BGPAGEB>39
IF BGPAGEB<76
SET BGPD5=1
+19 ;DENOM 6 up 21+
+20 IF BGPD1
SET BGPD6=1
+21 ;I 'BGPD6 S BGPSTOP=1 Q ;not in at least UP denominator
+22 ;now exclude people
+23 SET (BGPEXL1,BGPEXL2,BGPEXL3,BGPEXL4,BGPEXL5,BGPEXL6)=""
+24 ;excl 1
SET BGPEXL1=$$STATALG^BGP6D212(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE)
IF BGPEXL1
SET (BGPN2,BGPN3)=1
GOTO SETL
+25 ;ALCOHOL HEP
+26 SET BGPEXL1=$$ALCHEP^BGP6D212(DFN,BGPBDATE,BGPEDATE)
IF BGPEXL1
SET BGPN2=1
GOTO SETL
+27 ;NMI
+28 SET BGPEXL1=$$STATNMI^BGP6D212(DFN,BGPBDATE,BGPEDATE)
IF BGPEXL1
SET BGPN2=1
GOTO SETL
+29 ;PREGNANCY
+30 SET BGPEXL2=$$PREG^BGP6D7(DFN,BGPBDATE,BGPEDATE,1,1,1)
IF BGPEXL2
SET BGPN2=1
GOTO SETL
+31 ;BREASTFEEDING
+32 SET BGPEXL2=$$BF^BGP6D21(DFN,BGPBDATE,BGPEDATE)
IF BGPEXL2
SET BGPN2=1
GOTO SETL
+33 ;cirrhosis of liver
+34 SET BGPEXL6=$$CLIVER(DFN,BGPPBD,BGPEDATE)
IF BGPEXL6
SET BGPN2=1
GOTO SETL
+35 ;PALLIATIVE
+36 ;excl 3
SET BGPEXL3=$$LASTDX^BGP6UTL1(DFN,"BGP PALLIATIVE CARE DXS",BGPBDATE,BGPEDATE)
IF BGPEXL3
SET BGPN2=1
SET BGPEXL3=1_U_$$DATE^BGP6UTL($PIECE(BGPEXL3,U,3))_" Palliative Care"
GOTO SETL
+37 ;ESRD
+38 ;excl 4 ESRD
SET BGPEXL4=$$ESRD^BGP6D211(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
IF BGPEXL4
SET BGPEXL4=1_U_$$DATE^BGP6UTL($PIECE(BGPEXL4,U,3))_" ESRD"
SET BGPN2=1
GOTO SETL
+39 ;EXCL 5
+40 NEW BGPSTAT
+41 SET BGPSTAT=$$STATIN^BGP6D214(DFN,BGPBDATE,BGPEDATE,0)
+42 ;excl 5
SET BGPEXL5=$$LASTLDLV^BGP6D212(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
IF BGPEXL5
IF '$PIECE(BGPCVDL,U,3)
IF 'BGPSTAT
SET BGPN2=1
GOTO SETL
+43 ;numerator
+44 SET BGPN1=BGPSTAT
SETL ;
+1 ;if exclusion don't count in those denoms per Megan
IF BGPN2
SET (BGPD1,BGPD2,BGPD3,BGPD4,BGPD5)=""
+2 IF BGPN2
IF BGPD1
SET BGPD6=1
+3 SET BGPVALUD=$SELECT(BGPDMD2:"UP,AD",1:"UP")
IF BGPDMD1!(BGPCVDL)
Begin DoDot:1
+4 ;S BGPVALUD=BGPVALUD_" ("
+5 IF BGPDMD1
IF 'BGPCVDL
SET BGPVALUD=BGPVALUD_" (DM)"_"|||"
QUIT
+6 IF BGPDMD1
IF BGPCVDL
SET BGPVALUD=BGPVALUD_$SELECT($PIECE(BGPCVDL,U,2):" (DM,CHD)",$PIECE(BGPCVDL,U,3):" (DM,LDL)",1:"")_"|||"
QUIT
+7 SET BGPVALUD=BGPVALUD_$SELECT($PIECE(BGPCVDL,U,2):" (CHD)",$PIECE(BGPCVDL,U,3):" (LDL)",1:"")_"|||"
End DoDot:1
+8 IF BGPN1
SET BGPVALUD=BGPVALUD_$PIECE(BGPN1,U,2)
+9 IF BGPEXL1
SET BGPVALUD=BGPVALUD_"Exclusion: "_$PIECE(BGPEXL1,U,2)
+10 IF BGPEXL2
SET BGPVALUD=BGPVALUD_"Exclusion: "_$PIECE(BGPEXL2,U,2)_" Pregnant/Breastfeeding"
+11 IF BGPEXL3
SET BGPVALUD=BGPVALUD_"Exclusion: "_$PIECE(BGPEXL3,U,2)
+12 IF BGPEXL4
SET BGPVALUD=BGPVALUD_"Exclusion: "_$PIECE(BGPEXL4,U,2)
+13 IF BGPEXL6
SET BGPVALUD=BGPVALUD_"Exclusion: "_$PIECE(BGPEXL6,U,2)_" Cirrhosis"
+14 IF BGPEXL5
IF BGPN2
SET BGPVALUD=BGPVALUD_"Exclusion: "_$PIECE(BGPEXL5,U,2)
+15 KILL BGPEXL1,BGPEXL2,BGPEXL3,BGPEXL4,BGPEXL5,BGPCVDL
+16 QUIT
CLIVER(P,BD,ED) ;EP - cirrhosis of liver?
+1 NEW %,X
+2 SET X=$$LASTDX^BGP6UTL1(P,"BGP CIRRHOSIS OF LIVER DXS",BD,ED)
+3 IF X
QUIT 1_U_$$DATE^BGP6UTL($PIECE(X,U,3))
+4 QUIT ""