BGP2D72 ; IHS/CMI/LAB - measure 31 ;
;;12.1;IHS CLINICAL REPORTING;;MAY 17, 2012;Build 66
;
IHEDBBH ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
S BGPVALUE="" K BGPBETA
I BGPAGEB<36 S BGPSTOP=1 Q
I 'BGPACTUP S BGPSTOP=1 Q
S BGPAMI=$$AMIH(DFN,BGPBDATE,$$FMADD^XLFDT(BGPBDATE,(51*7)))
I '$P(BGPAMI,U) S BGPSTOP=1 Q
I $$READM(DFN,$P(BGPAMI,U,4),$P(BGPAMI,U,2)) S BGPSTOP=1 Q
S BGPV=$P(BGPAMI,U,3)
S BGPBETAC=$$BETACONT(DFN,"",$S($P(BGPAMI,U,4)]"":$P(BGPAMI,U,4),1:$P(BGPAMI,U,2)))
I $P(BGPBETAC,U) S BGPSTOP=1 Q
S BGPBETAL=$$BETAALG1(DFN,$S($P(BGPAMI,U,4)]"":$P(BGPAMI,U,4),1:$P(BGPAMI,U,2)))
I $P(BGPBETAL,U) S BGPSTOP=1 Q
I BGPACTCL S BGPD1=1
I BGPACTUP S BGPD2=1
S BGPBETA=$$BETA7(DFN,$$FMADD^XLFDT($P(BGPAMI,U,2),-60),$$FMADD^XLFDT($P(BGPAMI,U,4),7),$P(BGPAMI,U,4))
I $P(BGPBETA,U)=1 S BGPN1=1
S BGPVALUE=$S(BGPRTYPE=3:"",BGPD2:"UP",1:"")_$S(BGPD1:";AC",1:"")_"|||"_$S($P(BGPBETA,U):$P(BGPBETA,U,2)_" "_$P(BGPBETA,U,3),1:"")
K BGPAMI,BGPBETA,BGPBETAC,BGPBETAL
K ^TMP($J)
Q
IHEDPBH ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
K BGPBETA,BGPAMI,BGPV,BGPBETAC,BGPBETAL,BGPVALUE
I BGPAGEB<18 S BGPSTOP=1 Q
I 'BGPACTUP S BGPSTOP=1 Q
S BGPAMI=$$AMI(DFN,$$FMADD^XLFDT(BGPBDATE,-180),$$FMADD^XLFDT(BGPBDATE,180))
I '$P(BGPAMI,U) S BGPSTOP=1 Q
S BGPBETAC=$$BETACONT(DFN,"",$S($P(BGPAMI,U,4)]"":$P(BGPAMI,U,4),1:$P(BGPAMI,U,2)))
I $P(BGPBETAC,U) S BGPSTOP=1 Q ;beta Contra
S BGPBETAL=$$BETAALG1(DFN,$S($P(BGPAMI,U,4)]"":$P(BGPAMI,U,4),1:$P(BGPAMI,U,2))) ;beta allergy
I $P(BGPBETAL,U) S BGPSTOP=1 Q
I BGPACTCL S BGPD1=1
I BGPACTUP S BGPD2=1
S BGPBETA=$$BETA(DFN,$P(BGPAMI,U,2),$P(BGPAMI,U,4))
I $P(BGPBETA,U)=1 S BGPN1=1
S BGPVALUE=$S(BGPRTYPE=3:"",BGPD2:"UP")_$S(BGPD1:";AC",1:"")_"|||"_$S($P(BGPBETA,U):"YES, beta blocker 135+ "_$P(BGPBETA,U,2),1:"")
K BGPAMI,BGPBETA,BGPBETAC,BGPBETAL
K ^TMP($J)
Q
IHEDCHM ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
I BGPAGEB<18 S BGPSTOP=1 Q
I BGPAGEB>75 S BGPSTOP=1 Q
I 'BGPACTUP S BGPSTOP=1 Q
S BGPAMI=$$AMIO(DFN,BGPBDATE,BGPEDATE) I '$P(BGPAMI,U) S BGPSTOP=1 Q
I BGPACTUP S BGPD2=1
I BGPACTCL S BGPD1=1
I BGPRTYPE=3,'BGPD1 S BGPSTOP=1 Q
S BGPLDL=$$LDL^BGP2D2(DFN,BGPBDATE,BGPEDATE,$S(BGPRTYPE=3:1,1:""))
I $P(BGPLDL,U)=1 S BGPN1=1
I $P(BGPLDL,U,3)]"",BGPRTYPE'=3 D
.S V=$P(BGPLDL,U,3)
.I V["CPT" S:V["3048F" BGPN2=1 Q
.S V=+V
.I 'V Q
.I V]"",+V'>100 S BGPN2=1
.I +V>100,+V<131 S BGPN3=1
.I +V>130 S BGPN4=1
I $P(BGPLDL,U,3)]"",BGPRTYPE=3 D
.S V=$P(BGPLDL,U,3)
.I V["CPT" S:V["3048F" BGPN2=1 Q
.S V=+V
.I 'V Q
.I V]"",+V<100 S BGPN2=1
S BGPXPWV=$P(BGPLDL,U,3)
S V=$S(BGPRTYPE=3:"",1:"UP")_$S(BGPD1:",AC",1:"")_"|||"
I $P(BGPLDL,U) S V=V_$$DATE^BGP2UTL($P(BGPLDL,U,2))_" LDL: "_$P(BGPLDL,U,3)
S BGPVALUE=V
K V,BGPAMI,BGPLDL,D
K ^TMP($J)
Q
CHOL(P,BDATE,EDATE) ;
K BGPG
S (Q,R,S,M,N,O,B,D,E,L,G)=""
S R=$O(^ATXLAB("B","DM AUDIT CHOLESTEROL TAX",0))
S N=$O(^ATXAX("B","BGP TOTAL CHOLESTEROL LOINC",0))
S B=9999999-BDATE,E=9999999-EDATE S D=E-1 F S D=$O(^AUPNVLAB("AE",P,D)) Q:D'=+D!(D>B)!(G]"") D
.S L=0 F S L=$O(^AUPNVLAB("AE",P,D,L)) Q:L'=+L!(G]"") D
..S X=0 F S X=$O(^AUPNVLAB("AE",P,D,L,X)) Q:X'=+X!(G]"") D
...Q:'$D(^AUPNVLAB(X,0))
...I R,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(R,21,"B",$P(^AUPNVLAB(X,0),U))) S G=(9999999-D)_"^CHOL"_"^"_$P(^AUPNVLAB(X,0),U,4) Q
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...I $$LOINC(J,N) S G=(9999999-D)_"^CHOL LOINC"_"^"_$P(^AUPNVLAB(X,0),U,4) Q
...Q
I G]"" Q G
S E=+$$CODEN^ICPTCOD(82465),%=$$CPTI^BGP2DU(P,BDATE,EDATE,E) I %]"" Q $P(%,U,2)_"^CPT 82465"
S E=+$$CODEN^ICPTCOD(82465),%=$$TRANI^BGP2DU(P,BDATE,EDATE,E) I %]"" Q $P(%,U,2)_"^TRAN 82465"
Q ""
LOINC(A,B) ;
NEW %
S %=$P($G(^LAB(95.3,A,9999999)),U,2)
I %]"",$D(^ATXAX(B,21,"B",%)) Q 1
S %=$P($G(^LAB(95.3,A,0)),U)_"-"_$P($G(^LAB(95.3,A,0)),U,15)
I $D(^ATXAX(B,21,"B",%)) Q 1
Q ""
AMIO(P,BDATE,EDATE) ;
NEW BGPG
K BGPG
S Y="BGPG("
S X=P_"^LAST DX [BGP AMI DXS (HEDIS);DURING "_$$FMADD^XLFDT(BDATE,-365)_"-"_$$FMADD^XLFDT(BDATE,-61) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) Q 1_U_"AMI DX"
;
S BGPG=$$LASTPRC^BGP2UTL1(P,"BGP CABG PROCS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
I $P(BGPG,U) Q 1_U_"CABG PROC"
;
S BGPG=$$CPT^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$O(^ATXAX("B","BGP CABG CPTS",0)),6)
I $P(BGPG,U) Q 1_U_"CABG CPT"
S BGPG=$$TRAN^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$O(^ATXAX("B","BGP CABG CPTS",0)),6)
I $P(BGPG,U) Q 1_U_"CABG TRAN"
S BGPG=$$LASTDX^BGP2UTL1(P,"BGP CABG DXS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
I $P(BGPG,U) Q 1_U_"CABG POV "_$P(BGPG,U,2)
;
S BGPG=$$LASTPRC^BGP2UTL1(P,"BGP PCI CM PROCS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
I $P(BGPG,U) Q 1_U_"PCI PROC"
;
S BGPG=$$CPT^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$O(^ATXAX("B","BGP PCI CM CPTS",0)),6)
I $P(BGPG,U) Q 1_U_"PCI CPT"
S BGPG=$$TRAN^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$O(^ATXAX("B","BGP PCI CM CPTS",0)),6)
I $P(BGPG,U) Q 1_U_"PCI TRAN"
S BGPG=$$LASTDX^BGP2UTL1(P,"BGP PCI DXS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
I $P(BGPG,U) Q 1_U_"PCI POV "_$P(BGPG,U,2)
;
S BGPG(1)=$$LASTDX^BGP2UTL1(P,"BGP IVD DXS",BDATE,EDATE)
S BGPG(2)=$$LASTDX^BGP2UTL1(P,"BGP IVD DXS",$$FMADD^XLFDT(BDATE,-365),BDATE)
I $P(BGPG(1),U),$P(BGPG(2),U) Q 1_U_"IVD DXS"
Q ""
AMI(P,BDATE,EDATE) ;
;
K ^TMP($J,"A"),G
S A="^TMP($J,""A"",",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
I '$D(^TMP($J,"A",1)) Q 0
S T=$O(^ATXAX("B","BGP AMI DXS (HEDIS)",0))
S (BGPX,G,M,D,E)=0 F S BGPX=$O(^TMP($J,"A",BGPX)) Q:BGPX'=+BGPX S V=$P(^TMP($J,"A",BGPX),U,5) D
.Q:'$D(^AUPNVSIT(V,0))
.Q:'$P(^AUPNVSIT(V,0),U,9)
.Q:$P(^AUPNVSIT(V,0),U,11)
.Q:"AOSH"'[$P(^AUPNVSIT(V,0),U,7)
.S H=0
.I $P(^AUPNVSIT(V,0),U,7)="H" S H=$O(^AUPNVINP("AD",V,0)) D Q:'B
..S B=0
..I 'H Q
..Q:$$AMA(H) ;ama
..Q:$$TRANS(H) ;transferred
..Q:$$EXPIRED(H) ;died
..S B=1
.S (D,Y)=0 F S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y!(D) I $D(^AUPNVPOV(Y,0)) S %=$P(^AUPNVPOV(Y,0),U) I $$ICD^ATXCHK(%,T,9) S D=1
.I D S G=G+1,G($P($P(^AUPNVSIT(V,0),U),"."))=V ;got one visit
I 'G Q G
S D=$O(G(0)),V=G(D),H=$O(^AUPNVINP("AD",V,0))
Q 1_U_$O(G(0))_U_V_U_$S(H:$P($P(^AUPNVINP(H,0),U),"."),1:"")_U_H
;
AMIH(P,BDATE,EDATE) ;
;look for any H with AMI discharge dx
K ^TMP($J,"A"),G
S A="^TMP($J,""A"",",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
I '$D(^TMP($J,"A",1)) Q 0 ;no HOSP
S T=$O(^ATXAX("B","BGP AMI IND 30",0))
S (BGPX,G,M,D,E)=0 F S BGPX=$O(^TMP($J,"A",BGPX)) Q:BGPX'=+BGPX S V=$P(^TMP($J,"A",BGPX),U,5) D
.Q:'$D(^AUPNVSIT(V,0))
.Q:'$P(^AUPNVSIT(V,0),U,9)
.Q:$P(^AUPNVSIT(V,0),U,11)
.Q:$P(^AUPNVSIT(V,0),U,7)'="H"
.S H=0
.S H=$O(^AUPNVINP("AD",V,0)) D Q:'B
..S B=0
..I 'H Q
..Q:$P($P(^AUPNVINP(H,0),U),".")>EDATE
..Q:$$AMA(H)
..Q:$$TRANS(H)
..Q:$$EXPIRED(H)
..S B=1
.S (D,Y)=0 F S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y!(D) I $D(^AUPNVPOV(Y,0)) S %=$P(^AUPNVPOV(Y,0),U) I $$ICD^ATXCHK(%,T,9) S D=1
.I D S G=G+1,G($P($P(^AUPNVSIT(V,0),U),"."))=V ;got one visit
I 'G Q G
S D=$O(G(0)),V=G(D),H=$O(^AUPNVINP("AD",V,0))
Q 1_U_$O(G(0))_U_V_U_$S(H:$P($P(^AUPNVINP(H,0),U),"."),1:"")_U_H
READM(P,D,PV) ;EP
S ED=$$FMADD^XLFDT(D,7),G=0
S X=0,V=0 F S X=$O(^AUPNVSIT("AAH",P,X)) Q:X'=+X D
.S V=0 F S V=$O(^AUPNVSIT("AAH",P,X,V)) Q:V'=+V D
..Q:PV=V
..S E=$P($P($G(^AUPNVSIT(V,0)),U),".")
..Q:E<D
..Q:E>ED
..S G=1
Q G
BETACONT(P,BDATE,EDATE) ;EP BETA BLOCKER CONTRA
I $G(BDATE)="" S BDATE=$$DOB^AUPNPAT(P)
K BGPG,BGPD
S Y="BGPG("
S X=P_"^ALL DX [BGP ASTHMA DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
S (X,G)=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPD($P(BGPG(X),U))=""
S (X,G)=0 F S X=$O(BGPD(X)) Q:X'=+X S G=G+1
I G>1 Q 1_U_"2 POV asthma Contra" ;has 2 POV of asthma so Contra
S BGPG=$$LASTDX^BGP2UTL1(P,"BGP HYPOTENSION DXS",$$DOB^AUPNPAT(P),EDATE)
I $P(BGPG,U)=1 Q 1_U_"hypotension POV Contra" ;has hypotension
S BGPG=$$LASTDX^BGP2UTL1(P,"BGP CMS 2/3 HEART BLOCK DXS",$$DOB^AUPNPAT(P),EDATE)
I $P(BGPG,U)=1 Q 1_U_"heart blk Contra" ;has heart block
K BGPG,BGPD
S Y="BGPG("
S X=P_"^ALL DX [BGP COPD DXS BB CONT;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
S (X,G)=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPD($P(BGPG(X),U))=""
S (X,G)=0 F S X=$O(BGPD(X)) Q:X'=+X S G=G+1
I G>1 Q 1_U_"copd POV Contra"
Q 0
AMA(H) ;EP
S X=$P(^AUPNVINP(H,0),U,6)
I X="" Q 0
S X=$P($G(^DG(405.1,X,"IHS")),U,1)
I X=3 Q 1
Q 0
EXPIRED(H) ;EP
S X=$P(^AUPNVINP(H,0),U,6)
I X="" Q 0
S X=$P($G(^DG(405.1,X,"IHS")),U,1)
I X=4!(X=5)!(X=6)!(X=7) Q 1
Q 0
DSCH(H) ;
Q $P($P(^AUPNVINP(H,0),U),".")
TRANS(H) ;EP
S X=$P(^AUPNVINP(H,0),U,6)
I X="" Q 0
S X=$P($G(^DG(405.1,X,"IHS")),U,1)
I X=2 Q 1
Q 0
BETA(P,BGPADMD,BGPDD) ;EP
;get all beta
I BGPADMD="" Q ""
K ^TMP($J,"MEDS")
S BGPC1=0 K BGPZ
I $G(BGPDD)="" S BGPDD=BGPADMD
S (G,N,Y,X,T,T1,T2,M,K,S,C,K,R)=""
S Y="^TMP($J,""MEDS"",",X=P_"^ALL MED;DURING "_$$FMTE^XLFDT(BGPADMD)_"-"_$$FMTE^XLFDT($$FMADD^XLFDT(BGPDD,180)) S E=$$START1^APCLDF(X,Y)
S T=$O(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
S T1=$O(^ATXAX("B","BGP HEDIS BETA BLOCKER NDC",0))
S X=0 F S X=$O(^TMP($J,"MEDS",X)) Q:X'=+X S Y=+$P(^TMP($J,"MEDS",X),U,4) D
.Q:'$D(^AUPNVMED(Y,0))
.Q:$$UP^XLFSTR($P($G(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
.S G=0
.S D=$P(^AUPNVMED(Y,0),U)
.I T,$D(^ATXAX(T,21,"B",D)) S G=1 G BETA1
.S C=$P($G(^PSDRUG(D,0)),U,2)
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1
.Q:'G
BETA1 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'V
.Q:'$D(^AUPNVSIT(V,0))
.I J]"" S S=$$FMDIFF^XLFDT(J,$P($P(^AUPNVSIT(V,0),U),"."))
.I J="" S S=$P(^AUPNVMED(Y,0),U,7)
.S K=S+K
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP2UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>134 Q 1_U_" total days beta blocker: "_K
BETAADM ;now add in any before admission
K ^TMP($J,"MEDS")
S Y="^TMP($J,""MEDS"",",X=P_"^LAST 30 MED;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT($$FMADD^XLFDT(BGPADMD,-1)) S E=$$START1^APCLDF(X,Y)
S X=0 F S X=$O(^TMP($J,"MEDS",X)) Q:X'=+X S Y=+$P(^TMP($J,"MEDS",X),U,4) D
.Q:'$D(^AUPNVMED(Y,0))
.Q:$$UP^XLFSTR($P($G(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
.S G=0
.S D=$P(^AUPNVMED(Y,0),U)
.I T,$D(^ATXAX(T,21,"B",D)) S G=1 G BETA2
.S C=$P($G(^PSDRUG(D,0)),U,2)
.I C]"",T2,$D(^ATXAX(T2,21,"B",C)) S G=1 G BETA2
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1
.Q:'G
BETA2 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'V
.Q:'$D(^AUPNVSIT(V,0))
.;S IS DAYS SUPPLY, J IS DATE DISCONTINUED
.Q:J]"" ;don't use if discont
.S D=$$FMDIFF^XLFDT(BGPDD,$P($P(^AUPNVSIT(V,0),U),"."))
.S S=$P(^AUPNVMED(Y,0),U,7)
.S S=S-D ;subtract the number of days used
.S:S<0 S=0
.S K=S+K ;TOTAL DAYS SUPPLY
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP2UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>134 Q 1_U_" total days beta blocker: "_K
Q 0_U_R_" total days beta blocker: "_K
BETA7(P,BDATE,EDATE,BGPDD) ;
;see if there ACTIVE PRESCRIPTION
K ^TMP($J,"MEDS")
S BGPG=0
S Y="^TMP($J,""MEDS"",",X=P_"^ALL MED;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
S T=$O(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
S T1=$O(^ATXAX("B","BGP HEDIS BETA BLOCKER NDC",0))
S X=0 F S X=$O(^TMP($J,"MEDS",X)) Q:X'=+X!(BGPG) S Y=+$P(^TMP($J,"MEDS",X),U,4) D
.Q:'$D(^AUPNVMED(Y,0))
.Q:$$UP^XLFSTR($P($G(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
.S G=0
.S D=$P(^AUPNVMED(Y,0),U)
.I T,$D(^ATXAX(T,21,"B",D)) S G=1 G BETA8
.S C=$P($G(^PSDRUG(D,0)),U,2)
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1
.Q:'G
BETA8 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'V
.Q:'$D(^AUPNVSIT(V,0))
.I J]"" Q:J<EDATE ;discontinued W/IN 7 days
.S S=$P(^AUPNVMED(Y,0),U,7)
.S Z=$$FMDIFF^XLFDT(EDATE,$P($P(^AUPNVSIT(V,0),U),"."))
.I S>Z S BGPG=1_U_$$DATE^BGP2UTL($P($P(^AUPNVSIT(V,0),U),"."))_U_$P(^PSDRUG(D,0),U)
.Q
Q BGPG
BETAALG1(P,BGPD) ;EP - Beta Blocker allergy
S BGPC=0
BETAPOV ;
K BGPG,BGPY S Y="BGPG(",X=P_"^ALL DX [BGP ASA ALLERGY 995.0-995.3;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(BGPD) S E=$$START1^APCLDF(X,Y)
S X=0 F S X=$O(BGPG(X)) Q:X'=+X S Y=+$P(BGPG(X),U,4) D
.S N=$$VAL^XBDIQ1(9000010.07,Y,.04) S N=$$UP^XLFSTR(N)
.I N["BETA BLOCK"!(N["BBLOCK")!(N["B BLOCK") S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP2UTL($P(BGPG(X),U))_" ADR POV "_$P(BGPG(X),U,2)_"" Q
.S T=$O(^ATXAX("B","BGP ADV EFF CARD RHYTH",0))
.S Z=$P(^AUPNVPOV(Y,0),U,9) I Z]"",$$ICD^ATXCHK(Z,T,9) S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP1UTL($P(BGPG(X),U))_" ADR POV ["_$P(BGPG(X),U,2)_" + "_$P($$ICDDX^ICDCODE(Z),U,2)_"]" Q
.S Z=$P(^AUPNVPOV(Y,0),U,18) I Z]"",$$ICD^ATXCHK(Z,T,9) S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP1UTL($P(BGPG(X),U))_" ADR POV ["_$P(BGPG(X),U,2)_" + "_$P($$ICDDX^ICDCODE(Z),U,2)_"]" Q
.S Z=$P(^AUPNVPOV(Y,0),U,19) I Z]"",$$ICD^ATXCHK(Z,T,9) S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP1UTL($P(BGPG(X),U))_" ADR POV ["_$P(BGPG(X),U,2)_" + "_$P($$ICDDX^ICDCODE(Z),U,2)_"]" Q
.Q
I BGPC>0 Q 1_U_BGPY(BGPC)
K BGPG S BGPC=0 S Y="BGPG(",X=P_"^ALL DX [BGP HX DRUG ALLERGY NEC;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(DFN))_"-"_$$FMTE^XLFDT(BGPD) S E=$$START1^APCLDF(X,Y)
S X=0 F S X=$O(BGPG(X)) Q:X'=+X S Y=+$P(BGPG(X),U,4) D
.S N=$$VAL^XBDIQ1(9000010.07,Y,.04),N=$$UP^XLFSTR(N)
.I N["BETA BLOCK"!(N["BBLOCK")!(N["B BLOCK") S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP2UTL($P(BGPG(X),U))_" ADR POV "_$P(BGPG(X),U,2)_" "
I BGPC>0 Q 1_U_BGPY(BGPC)
;check problem list
S BGPC=0
S T="",T=$O(^ATXAX("B","BGP ASA ALLERGY 995.0-995.3",0))
S X=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X D
.S I=$P($G(^AUPNPROB(X,0)),U),Y=$P($$ICDDX^ICDCODE(I),U,2)
.S N=$$VAL^XBDIQ1(9000011,X,.05),N=$$UP^XLFSTR(N)
.Q:$P(^AUPNPROB(X,0),U,8)>BGPD
.I $$ICD^ATXCHK(I,$O(^ATXAX("B","BGP HX DRUG ALLERGY NEC",0)),9)!($$ICD^ATXCHK(I,T,9)),N["BETA BLOCK"!(N["BBLOCK")!(N["B BLOCK") S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP2UTL($P(^AUPNPROB(X,0),U,8))_" ADR Problem List "_Y_" "
.Q
I BGPC>0 Q 1_U_BGPY(BGPC)
;allergy tracking
S BGPC=0
S X=0 F S X=$O(^GMR(120.8,"B",P,X)) Q:X'=+X D
.Q:$P($P($G(^GMR(120.8,X,0)),U,4),".")>BGPD ;entered after end date
.S N=$P($G(^GMR(120.8,X,0)),U,2),N=$$UP^XLFSTR(N)
.I N["BETA BLOCK" S BGPC=BGPC+1,BGPY(BGPC)=$$DATE^BGP2UTL($P(^GMR(120.8,X,0),U,4))_" ADR ALLERGY TRACKING "_N
I BGPC>0 Q 1_U_BGPY(BGPC)
Q 0
BGP2D72 ; IHS/CMI/LAB - measure 31 ;
+1 ;;12.1;IHS CLINICAL REPORTING;;MAY 17, 2012;Build 66
+2 ;
IHEDBBH ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+2 SET BGPVALUE=""
KILL BGPBETA
+3 IF BGPAGEB<36
SET BGPSTOP=1
QUIT
+4 IF 'BGPACTUP
SET BGPSTOP=1
QUIT
+5 SET BGPAMI=$$AMIH(DFN,BGPBDATE,$$FMADD^XLFDT(BGPBDATE,(51*7)))
+6 IF '$PIECE(BGPAMI,U)
SET BGPSTOP=1
QUIT
+7 IF $$READM(DFN,$PIECE(BGPAMI,U,4),$PIECE(BGPAMI,U,2))
SET BGPSTOP=1
QUIT
+8 SET BGPV=$PIECE(BGPAMI,U,3)
+9 SET BGPBETAC=$$BETACONT(DFN,"",$SELECT($PIECE(BGPAMI,U,4)]"":$PIECE(BGPAMI,U,4),1:$PIECE(BGPAMI,U,2)))
+10 IF $PIECE(BGPBETAC,U)
SET BGPSTOP=1
QUIT
+11 SET BGPBETAL=$$BETAALG1(DFN,$SELECT($PIECE(BGPAMI,U,4)]"":$PIECE(BGPAMI,U,4),1:$PIECE(BGPAMI,U,2)))
+12 IF $PIECE(BGPBETAL,U)
SET BGPSTOP=1
QUIT
+13 IF BGPACTCL
SET BGPD1=1
+14 IF BGPACTUP
SET BGPD2=1
+15 SET BGPBETA=$$BETA7(DFN,$$FMADD^XLFDT($PIECE(BGPAMI,U,2),-60),$$FMADD^XLFDT($PIECE(BGPAMI,U,4),7),$PIECE(BGPAMI,U,4))
+16 IF $PIECE(BGPBETA,U)=1
SET BGPN1=1
+17 SET BGPVALUE=$SELECT(BGPRTYPE=3:"",BGPD2:"UP",1:"")_$SELECT(BGPD1:";AC",1:"")_"|||"_$SELECT($PIECE(BGPBETA,U):$PIECE(BGPBETA,U,2)_" "_$PIECE(BGPBETA,U,3),1:"")
+18 KILL BGPAMI,BGPBETA,BGPBETAC,BGPBETAL
+19 KILL ^TMP($JOB)
+20 QUIT
IHEDPBH ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+2 KILL BGPBETA,BGPAMI,BGPV,BGPBETAC,BGPBETAL,BGPVALUE
+3 IF BGPAGEB<18
SET BGPSTOP=1
QUIT
+4 IF 'BGPACTUP
SET BGPSTOP=1
QUIT
+5 SET BGPAMI=$$AMI(DFN,$$FMADD^XLFDT(BGPBDATE,-180),$$FMADD^XLFDT(BGPBDATE,180))
+6 IF '$PIECE(BGPAMI,U)
SET BGPSTOP=1
QUIT
+7 SET BGPBETAC=$$BETACONT(DFN,"",$SELECT($PIECE(BGPAMI,U,4)]"":$PIECE(BGPAMI,U,4),1:$PIECE(BGPAMI,U,2)))
+8 ;beta Contra
IF $PIECE(BGPBETAC,U)
SET BGPSTOP=1
QUIT
+9 ;beta allergy
SET BGPBETAL=$$BETAALG1(DFN,$SELECT($PIECE(BGPAMI,U,4)]"":$PIECE(BGPAMI,U,4),1:$PIECE(BGPAMI,U,2)))
+10 IF $PIECE(BGPBETAL,U)
SET BGPSTOP=1
QUIT
+11 IF BGPACTCL
SET BGPD1=1
+12 IF BGPACTUP
SET BGPD2=1
+13 SET BGPBETA=$$BETA(DFN,$PIECE(BGPAMI,U,2),$PIECE(BGPAMI,U,4))
+14 IF $PIECE(BGPBETA,U)=1
SET BGPN1=1
+15 SET BGPVALUE=$SELECT(BGPRTYPE=3:"",BGPD2:"UP")_$SELECT(BGPD1:";AC",1:"")_"|||"_$SELECT($PIECE(BGPBETA,U):"YES, beta blocker 135+ "_$PIECE(BGPBETA,U,2),1:"")
+16 KILL BGPAMI,BGPBETA,BGPBETAC,BGPBETAL
+17 KILL ^TMP($JOB)
+18 QUIT
IHEDCHM ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+2 IF BGPAGEB<18
SET BGPSTOP=1
QUIT
+3 IF BGPAGEB>75
SET BGPSTOP=1
QUIT
+4 IF 'BGPACTUP
SET BGPSTOP=1
QUIT
+5 SET BGPAMI=$$AMIO(DFN,BGPBDATE,BGPEDATE)
IF '$PIECE(BGPAMI,U)
SET BGPSTOP=1
QUIT
+6 IF BGPACTUP
SET BGPD2=1
+7 IF BGPACTCL
SET BGPD1=1
+8 IF BGPRTYPE=3
IF 'BGPD1
SET BGPSTOP=1
QUIT
+9 SET BGPLDL=$$LDL^BGP2D2(DFN,BGPBDATE,BGPEDATE,$SELECT(BGPRTYPE=3:1,1:""))
+10 IF $PIECE(BGPLDL,U)=1
SET BGPN1=1
+11 IF $PIECE(BGPLDL,U,3)]""
IF BGPRTYPE'=3
Begin DoDot:1
+12 SET V=$PIECE(BGPLDL,U,3)
+13 IF V["CPT"
IF V["3048F"
SET BGPN2=1
QUIT
+14 SET V=+V
+15 IF 'V
QUIT
+16 IF V]""
IF +V'>100
SET BGPN2=1
+17 IF +V>100
IF +V<131
SET BGPN3=1
+18 IF +V>130
SET BGPN4=1
End DoDot:1
+19 IF $PIECE(BGPLDL,U,3)]""
IF BGPRTYPE=3
Begin DoDot:1
+20 SET V=$PIECE(BGPLDL,U,3)
+21 IF V["CPT"
IF V["3048F"
SET BGPN2=1
QUIT
+22 SET V=+V
+23 IF 'V
QUIT
+24 IF V]""
IF +V<100
SET BGPN2=1
End DoDot:1
+25 SET BGPXPWV=$PIECE(BGPLDL,U,3)
+26 SET V=$SELECT(BGPRTYPE=3:"",1:"UP")_$SELECT(BGPD1:",AC",1:"")_"|||"
+27 IF $PIECE(BGPLDL,U)
SET V=V_$$DATE^BGP2UTL($PIECE(BGPLDL,U,2))_" LDL: "_$PIECE(BGPLDL,U,3)
+28 SET BGPVALUE=V
+29 KILL V,BGPAMI,BGPLDL,D
+30 KILL ^TMP($JOB)
+31 QUIT
CHOL(P,BDATE,EDATE) ;
+1 KILL BGPG
+2 SET (Q,R,S,M,N,O,B,D,E,L,G)=""
+3 SET R=$ORDER(^ATXLAB("B","DM AUDIT CHOLESTEROL TAX",0))
+4 SET N=$ORDER(^ATXAX("B","BGP TOTAL CHOLESTEROL LOINC",0))
+5 SET B=9999999-BDATE
SET E=9999999-EDATE
SET D=E-1
FOR
SET D=$ORDER(^AUPNVLAB("AE",P,D))
IF D'=+D!(D>B)!(G]"")
QUIT
Begin DoDot:1
+6 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L!(G]"")
QUIT
Begin DoDot:2
+7 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X!(G]"")
QUIT
Begin DoDot:3
+8 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+9 IF R
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(R,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET G=(9999999-D)_"^CHOL"_"^"_$PIECE(^AUPNVLAB(X,0),U,4)
QUIT
+10 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+11 IF $$LOINC(J,N)
SET G=(9999999-D)_"^CHOL LOINC"_"^"_$PIECE(^AUPNVLAB(X,0),U,4)
QUIT
+12 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+13 IF G]""
QUIT G
+14 SET E=+$$CODEN^ICPTCOD(82465)
SET %=$$CPTI^BGP2DU(P,BDATE,EDATE,E)
IF %]""
QUIT $PIECE(%,U,2)_"^CPT 82465"
+15 SET E=+$$CODEN^ICPTCOD(82465)
SET %=$$TRANI^BGP2DU(P,BDATE,EDATE,E)
IF %]""
QUIT $PIECE(%,U,2)_"^TRAN 82465"
+16 QUIT ""
LOINC(A,B) ;
+1 NEW %
+2 SET %=$PIECE($GET(^LAB(95.3,A,9999999)),U,2)
+3 IF %]""
IF $DATA(^ATXAX(B,21,"B",%))
QUIT 1
+4 SET %=$PIECE($GET(^LAB(95.3,A,0)),U)_"-"_$PIECE($GET(^LAB(95.3,A,0)),U,15)
+5 IF $DATA(^ATXAX(B,21,"B",%))
QUIT 1
+6 QUIT ""
AMIO(P,BDATE,EDATE) ;
+1 NEW BGPG
+2 KILL BGPG
+3 SET Y="BGPG("
+4 SET X=P_"^LAST DX [BGP AMI DXS (HEDIS);DURING "_$$FMADD^XLFDT(BDATE,-365)_"-"_$$FMADD^XLFDT(BDATE,-61)
SET E=$$START1^APCLDF(X,Y)
+5 IF $DATA(BGPG(1))
QUIT 1_U_"AMI DX"
+6 ;
+7 SET BGPG=$$LASTPRC^BGP2UTL1(P,"BGP CABG PROCS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
+8 IF $PIECE(BGPG,U)
QUIT 1_U_"CABG PROC"
+9 ;
+10 SET BGPG=$$CPT^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$ORDER(^ATXAX("B","BGP CABG CPTS",0)),6)
+11 IF $PIECE(BGPG,U)
QUIT 1_U_"CABG CPT"
+12 SET BGPG=$$TRAN^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$ORDER(^ATXAX("B","BGP CABG CPTS",0)),6)
+13 IF $PIECE(BGPG,U)
QUIT 1_U_"CABG TRAN"
+14 SET BGPG=$$LASTDX^BGP2UTL1(P,"BGP CABG DXS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
+15 IF $PIECE(BGPG,U)
QUIT 1_U_"CABG POV "_$PIECE(BGPG,U,2)
+16 ;
+17 SET BGPG=$$LASTPRC^BGP2UTL1(P,"BGP PCI CM PROCS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
+18 IF $PIECE(BGPG,U)
QUIT 1_U_"PCI PROC"
+19 ;
+20 SET BGPG=$$CPT^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$ORDER(^ATXAX("B","BGP PCI CM CPTS",0)),6)
+21 IF $PIECE(BGPG,U)
QUIT 1_U_"PCI CPT"
+22 SET BGPG=$$TRAN^BGP2DU(P,$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61),$ORDER(^ATXAX("B","BGP PCI CM CPTS",0)),6)
+23 IF $PIECE(BGPG,U)
QUIT 1_U_"PCI TRAN"
+24 SET BGPG=$$LASTDX^BGP2UTL1(P,"BGP PCI DXS",$$FMADD^XLFDT(BDATE,-365),$$FMADD^XLFDT(BDATE,-61))
+25 IF $PIECE(BGPG,U)
QUIT 1_U_"PCI POV "_$PIECE(BGPG,U,2)
+26 ;
+27 SET BGPG(1)=$$LASTDX^BGP2UTL1(P,"BGP IVD DXS",BDATE,EDATE)
+28 SET BGPG(2)=$$LASTDX^BGP2UTL1(P,"BGP IVD DXS",$$FMADD^XLFDT(BDATE,-365),BDATE)
+29 IF $PIECE(BGPG(1),U)
IF $PIECE(BGPG(2),U)
QUIT 1_U_"IVD DXS"
+30 QUIT ""
AMI(P,BDATE,EDATE) ;
+1 ;
+2 KILL ^TMP($JOB,"A"),G
+3 SET A="^TMP($J,""A"","
SET B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(B,A)
+4 IF '$DATA(^TMP($JOB,"A",1))
QUIT 0
+5 SET T=$ORDER(^ATXAX("B","BGP AMI DXS (HEDIS)",0))
+6 SET (BGPX,G,M,D,E)=0
FOR
SET BGPX=$ORDER(^TMP($JOB,"A",BGPX))
IF BGPX'=+BGPX
QUIT
SET V=$PIECE(^TMP($JOB,"A",BGPX),U,5)
Begin DoDot:1
+7 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+8 IF '$PIECE(^AUPNVSIT(V,0),U,9)
QUIT
+9 IF $PIECE(^AUPNVSIT(V,0),U,11)
QUIT
+10 IF "AOSH"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
+11 SET H=0
+12 IF $PIECE(^AUPNVSIT(V,0),U,7)="H"
SET H=$ORDER(^AUPNVINP("AD",V,0))
Begin DoDot:2
+13 SET B=0
+14 IF 'H
QUIT
+15 ;ama
IF $$AMA(H)
QUIT
+16 ;transferred
IF $$TRANS(H)
QUIT
+17 ;died
IF $$EXPIRED(H)
QUIT
+18 SET B=1
End DoDot:2
IF 'B
QUIT
+19 SET (D,Y)=0
FOR
SET Y=$ORDER(^AUPNVPOV("AD",V,Y))
IF Y'=+Y!(D)
QUIT
IF $DATA(^AUPNVPOV(Y,0))
SET %=$PIECE(^AUPNVPOV(Y,0),U)
IF $$ICD^ATXCHK(%,T,9)
SET D=1
+20 ;got one visit
IF D
SET G=G+1
SET G($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))=V
End DoDot:1
+21 IF 'G
QUIT G
+22 SET D=$ORDER(G(0))
SET V=G(D)
SET H=$ORDER(^AUPNVINP("AD",V,0))
+23 QUIT 1_U_$ORDER(G(0))_U_V_U_$SELECT(H:$PIECE($PIECE(^AUPNVINP(H,0),U),"."),1:"")_U_H
+24 ;
AMIH(P,BDATE,EDATE) ;
+1 ;look for any H with AMI discharge dx
+2 KILL ^TMP($JOB,"A"),G
+3 SET A="^TMP($J,""A"","
SET B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(B,A)
+4 ;no HOSP
IF '$DATA(^TMP($JOB,"A",1))
QUIT 0
+5 SET T=$ORDER(^ATXAX("B","BGP AMI IND 30",0))
+6 SET (BGPX,G,M,D,E)=0
FOR
SET BGPX=$ORDER(^TMP($JOB,"A",BGPX))
IF BGPX'=+BGPX
QUIT
SET V=$PIECE(^TMP($JOB,"A",BGPX),U,5)
Begin DoDot:1
+7 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+8 IF '$PIECE(^AUPNVSIT(V,0),U,9)
QUIT
+9 IF $PIECE(^AUPNVSIT(V,0),U,11)
QUIT
+10 IF $PIECE(^AUPNVSIT(V,0),U,7)'="H"
QUIT
+11 SET H=0
+12 SET H=$ORDER(^AUPNVINP("AD",V,0))
Begin DoDot:2
+13 SET B=0
+14 IF 'H
QUIT
+15 IF $PIECE($PIECE(^AUPNVINP(H,0),U),".")>EDATE
QUIT
+16 IF $$AMA(H)
QUIT
+17 IF $$TRANS(H)
QUIT
+18 IF $$EXPIRED(H)
QUIT
+19 SET B=1
End DoDot:2
IF 'B
QUIT
+20 SET (D,Y)=0
FOR
SET Y=$ORDER(^AUPNVPOV("AD",V,Y))
IF Y'=+Y!(D)
QUIT
IF $DATA(^AUPNVPOV(Y,0))
SET %=$PIECE(^AUPNVPOV(Y,0),U)
IF $$ICD^ATXCHK(%,T,9)
SET D=1
+21 ;got one visit
IF D
SET G=G+1
SET G($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))=V
End DoDot:1
+22 IF 'G
QUIT G
+23 SET D=$ORDER(G(0))
SET V=G(D)
SET H=$ORDER(^AUPNVINP("AD",V,0))
+24 QUIT 1_U_$ORDER(G(0))_U_V_U_$SELECT(H:$PIECE($PIECE(^AUPNVINP(H,0),U),"."),1:"")_U_H
READM(P,D,PV) ;EP
+1 SET ED=$$FMADD^XLFDT(D,7)
SET G=0
+2 SET X=0
SET V=0
FOR
SET X=$ORDER(^AUPNVSIT("AAH",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+3 SET V=0
FOR
SET V=$ORDER(^AUPNVSIT("AAH",P,X,V))
IF V'=+V
QUIT
Begin DoDot:2
+4 IF PV=V
QUIT
+5 SET E=$PIECE($PIECE($GET(^AUPNVSIT(V,0)),U),".")
+6 IF E<D
QUIT
+7 IF E>ED
QUIT
+8 SET G=1
End DoDot:2
End DoDot:1
+9 QUIT G
BETACONT(P,BDATE,EDATE) ;EP BETA BLOCKER CONTRA
+1 IF $GET(BDATE)=""
SET BDATE=$$DOB^AUPNPAT(P)
+2 KILL BGPG,BGPD
+3 SET Y="BGPG("
+4 SET X=P_"^ALL DX [BGP ASTHMA DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+5 SET (X,G)=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET BGPD($PIECE(BGPG(X),U))=""
+6 SET (X,G)=0
FOR
SET X=$ORDER(BGPD(X))
IF X'=+X
QUIT
SET G=G+1
+7 ;has 2 POV of asthma so Contra
IF G>1
QUIT 1_U_"2 POV asthma Contra"
+8 SET BGPG=$$LASTDX^BGP2UTL1(P,"BGP HYPOTENSION DXS",$$DOB^AUPNPAT(P),EDATE)
+9 ;has hypotension
IF $PIECE(BGPG,U)=1
QUIT 1_U_"hypotension POV Contra"
+10 SET BGPG=$$LASTDX^BGP2UTL1(P,"BGP CMS 2/3 HEART BLOCK DXS",$$DOB^AUPNPAT(P),EDATE)
+11 ;has heart block
IF $PIECE(BGPG,U)=1
QUIT 1_U_"heart blk Contra"
+12 KILL BGPG,BGPD
+13 SET Y="BGPG("
+14 SET X=P_"^ALL DX [BGP COPD DXS BB CONT;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+15 SET (X,G)=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET BGPD($PIECE(BGPG(X),U))=""
+16 SET (X,G)=0
FOR
SET X=$ORDER(BGPD(X))
IF X'=+X
QUIT
SET G=G+1
+17 IF G>1
QUIT 1_U_"copd POV Contra"
+18 QUIT 0
AMA(H) ;EP
+1 SET X=$PIECE(^AUPNVINP(H,0),U,6)
+2 IF X=""
QUIT 0
+3 SET X=$PIECE($GET(^DG(405.1,X,"IHS")),U,1)
+4 IF X=3
QUIT 1
+5 QUIT 0
EXPIRED(H) ;EP
+1 SET X=$PIECE(^AUPNVINP(H,0),U,6)
+2 IF X=""
QUIT 0
+3 SET X=$PIECE($GET(^DG(405.1,X,"IHS")),U,1)
+4 IF X=4!(X=5)!(X=6)!(X=7)
QUIT 1
+5 QUIT 0
DSCH(H) ;
+1 QUIT $PIECE($PIECE(^AUPNVINP(H,0),U),".")
TRANS(H) ;EP
+1 SET X=$PIECE(^AUPNVINP(H,0),U,6)
+2 IF X=""
QUIT 0
+3 SET X=$PIECE($GET(^DG(405.1,X,"IHS")),U,1)
+4 IF X=2
QUIT 1
+5 QUIT 0
BETA(P,BGPADMD,BGPDD) ;EP
+1 ;get all beta
+2 IF BGPADMD=""
QUIT ""
+3 KILL ^TMP($JOB,"MEDS")
+4 SET BGPC1=0
KILL BGPZ
+5 IF $GET(BGPDD)=""
SET BGPDD=BGPADMD
+6 SET (G,N,Y,X,T,T1,T2,M,K,S,C,K,R)=""
+7 SET Y="^TMP($J,""MEDS"","
SET X=P_"^ALL MED;DURING "_$$FMTE^XLFDT(BGPADMD)_"-"_$$FMTE^XLFDT($$FMADD^XLFDT(BGPDD,180))
SET E=$$START1^APCLDF(X,Y)
+8 SET T=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
+9 SET T1=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER NDC",0))
+10 SET X=0
FOR
SET X=$ORDER(^TMP($JOB,"MEDS",X))
IF X'=+X
QUIT
SET Y=+$PIECE(^TMP($JOB,"MEDS",X),U,4)
Begin DoDot:1
+11 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+12 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+13 SET G=0
+14 SET D=$PIECE(^AUPNVMED(Y,0),U)
+15 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO BETA1
+16 SET C=$PIECE($GET(^PSDRUG(D,0)),U,2)
+17 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+18 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
+19 IF 'G
QUIT
BETA1 ;
+1 SET J=$PIECE(^AUPNVMED(Y,0),U,8)
+2 SET V=$PIECE(^AUPNVMED(Y,0),U,3)
+3 IF 'V
QUIT
+4 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+5 IF J]""
SET S=$$FMDIFF^XLFDT(J,$PIECE($PIECE(^AUPNVSIT(V,0),U),"."))
+6 IF J=""
SET S=$PIECE(^AUPNVMED(Y,0),U,7)
+7 SET K=S+K
+8 IF R]""
SET R=R_";"
+9 SET R=R_$$DATE^BGP2UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+10 IF K>134
QUIT 1_U_" total days beta blocker: "_K
BETAADM ;now add in any before admission
+1 KILL ^TMP($JOB,"MEDS")
+2 SET Y="^TMP($J,""MEDS"","
SET X=P_"^LAST 30 MED;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT($$FMADD^XLFDT(BGPADMD,-1))
SET E=$$START1^APCLDF(X,Y)
+3 SET X=0
FOR
SET X=$ORDER(^TMP($JOB,"MEDS",X))
IF X'=+X
QUIT
SET Y=+$PIECE(^TMP($JOB,"MEDS",X),U,4)
Begin DoDot:1
+4 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+5 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+6 SET G=0
+7 SET D=$PIECE(^AUPNVMED(Y,0),U)
+8 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO BETA2
+9 SET C=$PIECE($GET(^PSDRUG(D,0)),U,2)
+10 IF C]""
IF T2
IF $DATA(^ATXAX(T2,21,"B",C))
SET G=1
GOTO BETA2
+11 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+12 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
+13 IF 'G
QUIT
BETA2 ;
+1 SET J=$PIECE(^AUPNVMED(Y,0),U,8)
+2 SET V=$PIECE(^AUPNVMED(Y,0),U,3)
+3 IF 'V
QUIT
+4 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+5 ;S IS DAYS SUPPLY, J IS DATE DISCONTINUED
+6 ;don't use if discont
IF J]""
QUIT
+7 SET D=$$FMDIFF^XLFDT(BGPDD,$PIECE($PIECE(^AUPNVSIT(V,0),U),"."))
+8 SET S=$PIECE(^AUPNVMED(Y,0),U,7)
+9 ;subtract the number of days used
SET S=S-D
+10 IF S<0
SET S=0
+11 ;TOTAL DAYS SUPPLY
SET K=S+K
+12 IF R]""
SET R=R_";"
+13 SET R=R_$$DATE^BGP2UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+14 IF K>134
QUIT 1_U_" total days beta blocker: "_K
+15 QUIT 0_U_R_" total days beta blocker: "_K
BETA7(P,BDATE,EDATE,BGPDD) ;
+1 ;see if there ACTIVE PRESCRIPTION
+2 KILL ^TMP($JOB,"MEDS")
+3 SET BGPG=0
+4 SET Y="^TMP($J,""MEDS"","
SET X=P_"^ALL MED;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+5 SET T=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
+6 SET T1=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER NDC",0))
+7 SET X=0
FOR
SET X=$ORDER(^TMP($JOB,"MEDS",X))
IF X'=+X!(BGPG)
QUIT
SET Y=+$PIECE(^TMP($JOB,"MEDS",X),U,4)
Begin DoDot:1
+8 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+9 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+10 SET G=0
+11 SET D=$PIECE(^AUPNVMED(Y,0),U)
+12 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO BETA8
+13 SET C=$PIECE($GET(^PSDRUG(D,0)),U,2)
+14 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+15 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
+16 IF 'G
QUIT
BETA8 ;
+1 SET J=$PIECE(^AUPNVMED(Y,0),U,8)
+2 SET V=$PIECE(^AUPNVMED(Y,0),U,3)
+3 IF 'V
QUIT
+4 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+5 ;discontinued W/IN 7 days
IF J]""
IF J<EDATE
QUIT
+6 SET S=$PIECE(^AUPNVMED(Y,0),U,7)
+7 SET Z=$$FMDIFF^XLFDT(EDATE,$PIECE($PIECE(^AUPNVSIT(V,0),U),"."))
+8 IF S>Z
SET BGPG=1_U_$$DATE^BGP2UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_U_$PIECE(^PSDRUG(D,0),U)
+9 QUIT
End DoDot:1
+10 QUIT BGPG
BETAALG1(P,BGPD) ;EP - Beta Blocker allergy
+1 SET BGPC=0
BETAPOV ;
+1 KILL BGPG,BGPY
SET Y="BGPG("
SET X=P_"^ALL DX [BGP ASA ALLERGY 995.0-995.3;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(BGPD)
SET E=$$START1^APCLDF(X,Y)
+2 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPG(X),U,4)
Begin DoDot:1
+3 SET N=$$VAL^XBDIQ1(9000010.07,Y,.04)
SET N=$$UP^XLFSTR(N)
+4 IF N["BETA BLOCK"!(N["BBLOCK")!(N["B BLOCK")
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP2UTL($PIECE(BGPG(X),U))_" ADR POV "_$PIECE(BGPG(X),U,2)_""
QUIT
+5 SET T=$ORDER(^ATXAX("B","BGP ADV EFF CARD RHYTH",0))
+6 SET Z=$PIECE(^AUPNVPOV(Y,0),U,9)
IF Z]""
IF $$ICD^ATXCHK(Z,T,9)
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ADR POV ["_$PIECE(BGPG(X),U,2)_" + "_$PIECE($$ICDDX^ICDCODE(Z),U,2)_"]"
QUIT
+7 SET Z=$PIECE(^AUPNVPOV(Y,0),U,18)
IF Z]""
IF $$ICD^ATXCHK(Z,T,9)
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ADR POV ["_$PIECE(BGPG(X),U,2)_" + "_$PIECE($$ICDDX^ICDCODE(Z),U,2)_"]"
QUIT
+8 SET Z=$PIECE(^AUPNVPOV(Y,0),U,19)
IF Z]""
IF $$ICD^ATXCHK(Z,T,9)
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ADR POV ["_$PIECE(BGPG(X),U,2)_" + "_$PIECE($$ICDDX^ICDCODE(Z),U,2)_"]"
QUIT
+9 QUIT
End DoDot:1
+10 IF BGPC>0
QUIT 1_U_BGPY(BGPC)
+11 KILL BGPG
SET BGPC=0
SET Y="BGPG("
SET X=P_"^ALL DX [BGP HX DRUG ALLERGY NEC;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(DFN))_"-"_$$FMTE^XLFDT(BGPD)
SET E=$$START1^APCLDF(X,Y)
+12 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPG(X),U,4)
Begin DoDot:1
+13 SET N=$$VAL^XBDIQ1(9000010.07,Y,.04)
SET N=$$UP^XLFSTR(N)
+14 IF N["BETA BLOCK"!(N["BBLOCK")!(N["B BLOCK")
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP2UTL($PIECE(BGPG(X),U))_" ADR POV "_$PIECE(BGPG(X),U,2)_" "
End DoDot:1
+15 IF BGPC>0
QUIT 1_U_BGPY(BGPC)
+16 ;check problem list
+17 SET BGPC=0
+18 SET T=""
SET T=$ORDER(^ATXAX("B","BGP ASA ALLERGY 995.0-995.3",0))
+19 SET X=0
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+20 SET I=$PIECE($GET(^AUPNPROB(X,0)),U)
SET Y=$PIECE($$ICDDX^ICDCODE(I),U,2)
+21 SET N=$$VAL^XBDIQ1(9000011,X,.05)
SET N=$$UP^XLFSTR(N)
+22 IF $PIECE(^AUPNPROB(X,0),U,8)>BGPD
QUIT
+23 IF $$ICD^ATXCHK(I,$ORDER(^ATXAX("B","BGP HX DRUG ALLERGY NEC",0)),9)!($$ICD^ATXCHK(I,T,9))
IF N["BETA BLOCK"!(N["BBLOCK")!(N["B BLOCK")
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP2UTL($PIECE(^AUPNPROB(X,0),U,8))_" ADR Problem List "_Y_" "
+24 QUIT
End DoDot:1
+25 IF BGPC>0
QUIT 1_U_BGPY(BGPC)
+26 ;allergy tracking
+27 SET BGPC=0
+28 SET X=0
FOR
SET X=$ORDER(^GMR(120.8,"B",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+29 ;entered after end date
IF $PIECE($PIECE($GET(^GMR(120.8,X,0)),U,4),".")>BGPD
QUIT
+30 SET N=$PIECE($GET(^GMR(120.8,X,0)),U,2)
SET N=$$UP^XLFSTR(N)
+31 IF N["BETA BLOCK"
SET BGPC=BGPC+1
SET BGPY(BGPC)=$$DATE^BGP2UTL($PIECE(^GMR(120.8,X,0),U,4))_" ADR ALLERGY TRACKING "_N
End DoDot:1
+32 IF BGPC>0
QUIT 1_U_BGPY(BGPC)
+33 QUIT 0