BGP1D721 ; IHS/CMI/LAB - measure AHR.A ;
;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
;
;
IAHRA ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPN13,BGPN14,BGPN15,BGPN16,BGPN17,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
S BGPVALUE=""
I BGPAGEB<22 S BGPSTOP=1 Q
I 'BGPACTCL S BGPSTOP=1 Q ;must be active clinical
S BGPIHD=$$IHD(DFN,BGPBDATE,BGPEDATE)
I 'BGPIHD S BGPSTOP=1 Q ;no IHD
S BGPD1=1
I BGPDMD2 S BGPD3=1
I 'BGPDMD2 S BGPD2=1
K BGPBETA
S BGPBETA("RX")=$$BETA(DFN,BGPBDATE,BGPEDATE,179) ;get 1_U_# days
I BGPBETA("RX") S BGPN2=1 ;pt has 180 days of beta blocker
I 'BGPN2 S BGPBETA("REF")=$$BETAREF(DFN,BGPBDATE,BGPEDATE) I BGPBETA("REF") S BGPN3=1
I 'BGPN2 S BGPBETA("CONTRA")=$$BETACONT(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE) I BGPBETA("CONTRA") S BGPN4=1 ;beta contraindication
I 'BGPN2 S BGPBETA("ADR")=$$BETAALG1^BGP1D72(DFN,BGPEDATE) I BGPBETA("ADR") S BGPN4=1
I (BGPN2+BGPN4) S BGPN1=1
K BGPASA
S BGPASA("RX")=$$ASA(DFN,BGPBDATE,BGPEDATE,179) ;get 1_U_# days
I BGPASA("RX") S BGPN6=1 ;pt has 180 days of beta blocker
I 'BGPN6 S BGPASA("REF")=$$ASAREF(DFN,BGPBDATE,BGPEDATE) I BGPASA("REF") S BGPN7=1
I 'BGPN6 S BGPASA("CONTRA")=$$ASACONTR(DFN,BGPBDATE,BGPEDATE,179) I BGPASA("CONTRA") S BGPN8=1 ;beta contraindication
I 'BGPN6 S BGPASA("ADR")=$$ASAALLEG(DFN,BGPEDATE) I BGPASA("ADR") S BGPN8=1
I (BGPN6+BGPN8) S BGPN5=1
K BGPACE
S BGPACE("RX")=$$ACERX^BGP1D722(DFN,BGPBDATE,BGPEDATE,179) ;get 1_U_# days
I BGPACE("RX") S BGPN10=1 ;pt has 180 days of ACE
I 'BGPN10 S BGPACE("REF")=$$ACEREF^BGP1D722(DFN,BGPBDATE,BGPEDATE) I BGPACE("REF") S BGPN11=1
I 'BGPN10 S BGPACE("CONTRA")=$$ACECONT^BGP1D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE,BGPBDATE) I BGPACE("CONTRA") S BGPN12=1 ;beta contraindication
I 'BGPN10 S BGPACE("ADR")=$$ACEALG^BGP1D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE) I BGPACE("ADR") S BGPN12=1
I (BGPN10+BGPN12) S BGPN9=1
K BGPSTAT
S BGPSTAT("RX")=$$STATRX^BGP1D722(DFN,BGPBDATE,BGPEDATE,179) ;get 1_U_# days
I BGPSTAT("RX") S BGPN14=1 ;pt has 180 days of STAT
I 'BGPN14 S BGPSTAT("REF")=$$STATREF^BGP1D722(DFN,BGPBDATE,BGPEDATE) I BGPSTAT("REF") S BGPN15=1
I 'BGPN14 S BGPSTAT("CONTRA")=$$STATCON^BGP1D722(DFN,BGPBDATE,BGPEDATE,BGPBDATE,BGPEDATE) I BGPSTAT("CONTRA") S BGPN16=1 ;beta contraindication
I 'BGPN14 S BGPSTAT("ADR")=$$STATALG^BGP1D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE) I BGPSTAT("ADR") S BGPN16=1
I (BGPN14+BGPN16) S BGPN13=1
I BGPN1,BGPN5,BGPN9,BGPN13 S BGPN17=1
S BGPVALUE="IHD"_$S(BGPD3:";AD",1:"")_"|||"
S BGPVALUE=BGPVALUE_$S(BGPN17:"ALL MEDS; ",1:"")
I BGPN2!(BGPN3)!(BGPN4) S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":" ",1:"") S BGPVALUE=BGPVALUE_"BETA: " F X="RX","REF","CONTRA","ADR" I $P($G(BGPBETA(X)),U,1),$P($G(BGPBETA(X)),U,2)]"" D
.S BGPVALUE=BGPVALUE_$P(BGPBETA(X),U,2)_$S($P(BGPBETA(X),U,3)]"":" "_$P(BGPBETA(X),U,3),1:"")
I BGPN6!(BGPN7)!(BGPN8) S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:"") S BGPVALUE=BGPVALUE_"ASA: " F X="RX","REF","CONTRA","ADR" I $P($G(BGPASA(X)),U,1),$P($G(BGPASA(X)),U,2)]"" D
.S BGPVALUE=BGPVALUE_$P(BGPASA(X),U,2)_$S($P(BGPASA(X),U,3)]"":" "_$P(BGPASA(X),U,3),1:"")
I BGPN10!(BGPN11)!(BGPN12) S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:"") S BGPVALUE=BGPVALUE_"ACEI/ARB: " F X="RX","REF","CONTRA","ADR" I $P($G(BGPACE(X)),U,1),$P($G(BGPACE(X)),U,2)]"" D
.S BGPVALUE=BGPVALUE_$P(BGPACE(X),U,2)_$S($P(BGPACE(X),U,3)]"":" "_$P(BGPACE(X),U,3),1:"")
I BGPN14!(BGPN15)!(BGPN16) S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:"") S BGPVALUE=BGPVALUE_"STATIN: " F X="RX","REF","CONTRA","ADR" I $P($G(BGPSTAT(X)),U,1),$P($G(BGPSTAT(X)),U,2)]"" D
.S BGPVALUE=BGPVALUE_$P(BGPSTAT(X),U,2)_$S($P(BGPSTAT(X),U,3)]"":" "_$P(BGPSTAT(X),U,3),1:"")
K ^TMP($J)
Q
IHD(P,BDATE,EDATE) ;EP
;first dx prior to report period
;at least 2 visits during report period
;at least 2 ihd dxs ever
I '$$V2^BGP1D1(P,BDATE,EDATE) Q "" ;not 2 visits during report period
K ^TMP($J)
I '$$FIRSTIHD(P,EDATE) Q "" ;first dx not prior to report period
I '$$V2IHD(P,$$DOB^AUPNPAT(P),EDATE) Q "" ;at least 2 IHD dxs ever
Q 1
FIRSTIHD(P,EDATE) ;EP
I $G(P)="" Q ""
NEW BGPG,Y,X,E
K BGPG
S Y="BGPG("
S X=P_"^FIRST DX [BGP IHD DXS" S E=$$START1^APCLDF(X,Y)
I '$D(BGPG(1)) Q ""
S X=$$FMDIFF^XLFDT(EDATE,$P(BGPG(1),U))
Q $S(X>365:1,1:"")
;
V2IHD(P,BDATE,EDATE) ;EP
I '$G(P) Q ""
I '$D(^AUPNVSIT("AC",P)) Q ""
NEW A,B,E,T,X,G,V,Y,%,G
K ^TMP($J,"A")
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 ""
S T=$O(^ATXAX("B","BGP IHD DXS",0))
I 'T Q ""
S (X,G)=0 F S X=$O(^TMP($J,"A",X)) Q:X'=+X!(G>2) S V=$P(^TMP($J,"A",X),U,5) D
.Q:'$D(^AUPNVSIT(V,0))
.Q:'$P(^AUPNVSIT(V,0),U,9)
.Q:$P(^AUPNVSIT(V,0),U,11)
.Q:"SAHO"'[$P(^AUPNVSIT(V,0),U,7)
.Q:"V"[$P(^AUPNVSIT(V,0),U,3)
.Q:$P(^AUPNVSIT(V,0),U,6)=""
.I $G(BGPMFITI),'$D(^ATXAX(BGPMFITI,21,"B",$P(^AUPNVSIT(V,0),U,6))) Q
.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
.Q:'D
.S G=G+1
.Q
K ^TMP($J,"A")
Q $S(G<2:"",1:1)
;
BETA(P,BDATE,EDATE,BGPNDAYS) ;EP
NEW BGPMEDS1,K,R,T,T1,X,Y,G,D,N,J,V,S
K BGPMEDS1
S K=0,R=""
D GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) Q ""
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(BGPMEDS1(X)) Q:X'=+X S Y=+$P(BGPMEDS1(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 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))
.S S=$$DAYS^BGP1D82(Y,V,EDATE)
.S K=S+K ;TOTAL DAYS SUPPLY
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>BGPNDAYS Q 1_U_R_" "_"("_K_" TOTAL DAYS)"
BETAPRIO ;now add in any before BEG DATE
K BGPMEDS1
D GETMEDS^BGP1UTL2(P,$$FMADD^XLFDT(BDATE,-365),BDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) Q ""
S X=0 F S X=$O(BGPMEDS1(X)) Q:X'=+X S Y=+$P(BGPMEDS1(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 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))
.Q:J]"" ;don't use if discontinued
.S D=$$FMDIFF^XLFDT(BDATE,$P($P(^AUPNVSIT(V,0),U),"."))
.S S=$P(^AUPNVMED(Y,0),U,7)
.S S=S-D
.S:S<0 S=0
.S K=S+K
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>BGPNDAYS Q 1_U_R_" "_"("_K_" TOTAL DAYS)"
Q 0_U_R_" "_"("_K_" TOTAL DAYS)"
;
BETAREF(P,BDATE,EDATE) ;EP
NEW T,X,G,D,Y,N
S T=$O(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
S X=0,G="" F S X=$O(^AUPNPREF("AA",P,50,X)) Q:X'=+X!(G) D
.Q:'$D(^ATXAX(T,21,"B",X)) ;not a Beta Blocker
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D!(G) D
..S Y=9999999-D I Y<BDATE Q
..I Y>EDATE Q ;documented after edate
..S N=0 F S N=$O(^AUPNPREF("AA",P,50,X,D,N)) Q:N'=+N!(G) D
...Q:$P($G(^AUPNPREF(N,0)),U,7)'="R"
...S G=1_U_$$DATE^BGP1UTL(Y)_U_"Refused "_$P(^PSDRUG(X,0),U,1)
..Q
.Q
Q G
BETACONT(P,BDATE,EDATE,NMIBD,NMIED) ;EP - BETA BLOCKER CONTRAINDICATION
G BETACONT^BGP1D724
ASA(P,BDATE,EDATE,BGPNDAYS) ;EP
K BGPMEDS1
S K=0,R=""
D GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) Q ""
S T=$O(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
S T1=$O(^ATXAX("B","BGP ANTI-PLATELET DRUGS",0))
S T2=$O(^ATXAX("B","BGP CMS ANTI-PLATELET CLASS",0))
S X=0 F S X=$O(BGPMEDS1(X)) Q:X'=+X S Y=+$P(BGPMEDS1(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 ASA1
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1 G ASA1
.S C=$P($G(^PSDRUG(D,0)),U,2)
.I C]"",T2,$D(^ATXAX(T2,21,"B",C)) S G=1
.Q:'G
ASA1 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'V
.Q:'$D(^AUPNVSIT(V,0))
.S S=$$DAYS^BGP1D82(Y,V,EDATE)
.S K=S+K
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>BGPNDAYS Q 1_U_R_" "_"("_K_" TOTAL DAYS)"
ASAPRIO ;now add in any before BEG DATE
K BGPMEDS1
D GETMEDS^BGP1UTL2(P,$$FMADD^XLFDT(BDATE,-365),BDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) Q ""
S X=0 F S X=$O(BGPMEDS1(X)) Q:X'=+X S Y=+$P(BGPMEDS1(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 ASA2
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1 G ASA2
.S C=$P($G(^PSDRUG(D,0)),U,2)
.I C]"",T2,$D(^ATXAX(T2,21,"B",C)) S G=1
.Q:'G
ASA2 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'V
.Q:'$D(^AUPNVSIT(V,0))
.Q:J]"" ;don't use if discontinued
.S D=$$FMDIFF^XLFDT(BDATE,$P($P(^AUPNVSIT(V,0),U),"."))
.S S=$P(^AUPNVMED(Y,0),U,7)
.S S=S-D ;subtract the number of days used
.I S<0 S S=0
.S K=S+K ;TOTAL DAYS SUPPLY
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>BGPNDAYS Q 1_U_R_" "_"("_K_" TOTAL DAYS)"
Q 0_U_R_" "_"("_K_" TOTAL DAYS)"
;
ASAREF(P,BDATE,EDATE) ;EP
;did patient have a refusal
S T=$O(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
S X=0,G="" F S X=$O(^AUPNPREF("AA",P,50,X)) Q:X'=+X!(G) D
.Q:'$D(^ATXAX(T,21,"B",X))
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D!(G) D
..S Y=9999999-D I Y<BDATE Q
..I Y>EDATE Q
..S N=0 F S N=$O(^AUPNPREF("AA",P,50,X,D,N)) Q:N'=+N!(G) D
...Q:$P($G(^AUPNPREF(N,0)),U,7)'="R"
...S G=1_U_$$DATE^BGP1UTL(Y)_" Refused "_$P(^PSDRUG(X,0),U,1)
..Q
.Q
I G Q G
S T=$O(^ATXAX("B","BGP ANTI-PLATELET DRUGS",0))
S X=0,G="" F S X=$O(^AUPNPREF("AA",P,50,X)) Q:X'=+X!(G) D
.Q:'$D(^ATXAX(T,21,"B",X))
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D!(G) D
..S Y=9999999-D I Y<BDATE Q
..I Y>EDATE Q
..S N=0 F S N=$O(^AUPNPREF("AA",P,50,X,D,N)) Q:N'=+N!(G) D
...Q:$P($G(^AUPNPREF(N,0)),U,7)'="R"
...S G=1_U_$$DATE^BGP1UTL(Y)_" Refused "_$P(^PSDRUG(X,0),U,1)
..Q
.Q
Q G
ASACONTR(P,BDATE,EDATE,BGPNDAYS) ;does patient have an aspirin allergy
K BGPMEDS1
S K=0,R=""
D GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) G ASAC2
S T=$O(^ATXAX("B","BGP CMS WARFARIN MEDS",0))
S X=0 F S X=$O(BGPMEDS1(X)) Q:X'=+X S Y=+$P(BGPMEDS1(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 WAR1
.S N=$P($G(^PSDRUG(D,0)),U,1)
.I N["WARFARIN" S G=1 G WAR1
.Q:'G
WAR1 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'V
.Q:'$D(^AUPNVSIT(V,0))
.S S=$$DAYS^BGP1D82(Y,V,EDATE)
.S K=S+K
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>BGPNDAYS Q 1_U_" aspirin contra total days WARFARIN: "_K
WARPRIO ;now add in any before BEG DATE
K BGPMEDS1
D GETMEDS^BGP1UTL2(P,$$FMADD^XLFDT(BDATE,-365),BDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) G ASAC2
S X=0 F S X=$O(BGPMEDS1(X)) Q:X'=+X S Y=+$P(BGPMEDS1(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 WAR2
.S N=$P($G(^PSDRUG(D,0)),U,1)
.I N["WARFARIN" S G=1 G WAR2
.Q:'G
WAR2 .;
.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]""
.S D=$$FMDIFF^XLFDT(EDATE,$P($P(^AUPNVSIT(V,0),U),"."))
.S S=$P(^AUPNVMED(Y,0),U,7)
.S S=S-D ;subtract the number of days used
.I S<0 S S=0
.S K=S+K ;TOTAL DAYS SUPPLY
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>BGPNDAYS Q 1_U_"asp contra total days WARFARIN: "_K
ASAC2 ;now check for dx 459
K BGPG S BGPG=$$LASTDXI^BGP1UTL1(P,"459.0",$$DOB^AUPNPAT(P),EDATE)
I BGPG Q 1_U_"asa contra 459.0 "_$$DATE^BGP1UTL($P(BGPG,U,3))
;
;nmi in refusal file for aspirin
S BGPG=""
S T=$O(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
S X=0 F S X=$O(^AUPNPREF("AA",P,50,X)) Q:X'=+X D
.Q:'$D(^ATXAX(T,21,"B",X)) ;not an aspirin
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D D
..I (9999999-D)<BDATE Q ;before report period
..I (9999999-D)>EDATE Q ;documented after report period
..S N=0 F S N=$O(^AUPNPREF("AA",P,50,X,D,N)) Q:N'=+N D
...Q:$P($G(^AUPNPREF(N,0)),U,7)'="N"
...S BGPG=1_U_"asa contra NMI Aspirin: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($P(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
..Q
.Q
I BGPG Q BGPG
S X=$$CPTI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
I X Q 1_U_"asa contra CPT code G8008: "_$$DATE^BGP1UTL($P(X,U,2))
S X=$$TRANI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
I X Q 1_U_"asa contra Tran Code G8008: "_$$DATE^BGP1UTL($P(X,U,2))
Q ""
ASAALLEG(P,EDATE) ;EP
K BGPG
S X=$$ASAALLEG^BGP1CU1(P,$$DOB^AUPNPAT(P),EDATE)
I 'X Q 0
S $P(X,U,2)="ADR "_$P(X,U,2)
Q X
BGP1D721 ; IHS/CMI/LAB - measure AHR.A ;
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
+2 ;
+3 ;
IAHRA ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPN13,BGPN14,BGPN15,BGPN16,BGPN17,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+2 SET BGPVALUE=""
+3 IF BGPAGEB<22
SET BGPSTOP=1
QUIT
+4 ;must be active clinical
IF 'BGPACTCL
SET BGPSTOP=1
QUIT
+5 SET BGPIHD=$$IHD(DFN,BGPBDATE,BGPEDATE)
+6 ;no IHD
IF 'BGPIHD
SET BGPSTOP=1
QUIT
+7 SET BGPD1=1
+8 IF BGPDMD2
SET BGPD3=1
+9 IF 'BGPDMD2
SET BGPD2=1
+10 KILL BGPBETA
+11 ;get 1_U_# days
SET BGPBETA("RX")=$$BETA(DFN,BGPBDATE,BGPEDATE,179)
+12 ;pt has 180 days of beta blocker
IF BGPBETA("RX")
SET BGPN2=1
+13 IF 'BGPN2
SET BGPBETA("REF")=$$BETAREF(DFN,BGPBDATE,BGPEDATE)
IF BGPBETA("REF")
SET BGPN3=1
+14 ;beta contraindication
IF 'BGPN2
SET BGPBETA("CONTRA")=$$BETACONT(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE)
IF BGPBETA("CONTRA")
SET BGPN4=1
+15 IF 'BGPN2
SET BGPBETA("ADR")=$$BETAALG1^BGP1D72(DFN,BGPEDATE)
IF BGPBETA("ADR")
SET BGPN4=1
+16 IF (BGPN2+BGPN4)
SET BGPN1=1
+17 KILL BGPASA
+18 ;get 1_U_# days
SET BGPASA("RX")=$$ASA(DFN,BGPBDATE,BGPEDATE,179)
+19 ;pt has 180 days of beta blocker
IF BGPASA("RX")
SET BGPN6=1
+20 IF 'BGPN6
SET BGPASA("REF")=$$ASAREF(DFN,BGPBDATE,BGPEDATE)
IF BGPASA("REF")
SET BGPN7=1
+21 ;beta contraindication
IF 'BGPN6
SET BGPASA("CONTRA")=$$ASACONTR(DFN,BGPBDATE,BGPEDATE,179)
IF BGPASA("CONTRA")
SET BGPN8=1
+22 IF 'BGPN6
SET BGPASA("ADR")=$$ASAALLEG(DFN,BGPEDATE)
IF BGPASA("ADR")
SET BGPN8=1
+23 IF (BGPN6+BGPN8)
SET BGPN5=1
+24 KILL BGPACE
+25 ;get 1_U_# days
SET BGPACE("RX")=$$ACERX^BGP1D722(DFN,BGPBDATE,BGPEDATE,179)
+26 ;pt has 180 days of ACE
IF BGPACE("RX")
SET BGPN10=1
+27 IF 'BGPN10
SET BGPACE("REF")=$$ACEREF^BGP1D722(DFN,BGPBDATE,BGPEDATE)
IF BGPACE("REF")
SET BGPN11=1
+28 ;beta contraindication
IF 'BGPN10
SET BGPACE("CONTRA")=$$ACECONT^BGP1D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE,BGPBDATE)
IF BGPACE("CONTRA")
SET BGPN12=1
+29 IF 'BGPN10
SET BGPACE("ADR")=$$ACEALG^BGP1D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
IF BGPACE("ADR")
SET BGPN12=1
+30 IF (BGPN10+BGPN12)
SET BGPN9=1
+31 KILL BGPSTAT
+32 ;get 1_U_# days
SET BGPSTAT("RX")=$$STATRX^BGP1D722(DFN,BGPBDATE,BGPEDATE,179)
+33 ;pt has 180 days of STAT
IF BGPSTAT("RX")
SET BGPN14=1
+34 IF 'BGPN14
SET BGPSTAT("REF")=$$STATREF^BGP1D722(DFN,BGPBDATE,BGPEDATE)
IF BGPSTAT("REF")
SET BGPN15=1
+35 ;beta contraindication
IF 'BGPN14
SET BGPSTAT("CONTRA")=$$STATCON^BGP1D722(DFN,BGPBDATE,BGPEDATE,BGPBDATE,BGPEDATE)
IF BGPSTAT("CONTRA")
SET BGPN16=1
+36 IF 'BGPN14
SET BGPSTAT("ADR")=$$STATALG^BGP1D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,BGPBDATE,BGPEDATE)
IF BGPSTAT("ADR")
SET BGPN16=1
+37 IF (BGPN14+BGPN16)
SET BGPN13=1
+38 IF BGPN1
IF BGPN5
IF BGPN9
IF BGPN13
SET BGPN17=1
+39 SET BGPVALUE="IHD"_$SELECT(BGPD3:";AD",1:"")_"|||"
+40 SET BGPVALUE=BGPVALUE_$SELECT(BGPN17:"ALL MEDS; ",1:"")
+41 IF BGPN2!(BGPN3)!(BGPN4)
SET BGPVALUE=BGPVALUE_$SELECT($PIECE(BGPVALUE,"|||",2)]"":" ",1:"")
SET BGPVALUE=BGPVALUE_"BETA: "
FOR X="RX","REF","CONTRA","ADR"
IF $PIECE($GET(BGPBETA(X)),U,1)
IF $PIECE($GET(BGPBETA(X)),U,2)]""
Begin DoDot:1
+42 SET BGPVALUE=BGPVALUE_$PIECE(BGPBETA(X),U,2)_$SELECT($PIECE(BGPBETA(X),U,3)]"":" "_$PIECE(BGPBETA(X),U,3),1:"")
End DoDot:1
+43 IF BGPN6!(BGPN7)!(BGPN8)
SET BGPVALUE=BGPVALUE_$SELECT($PIECE(BGPVALUE,"|||",2)]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"ASA: "
FOR X="RX","REF","CONTRA","ADR"
IF $PIECE($GET(BGPASA(X)),U,1)
IF $PIECE($GET(BGPASA(X)),U,2)]""
Begin DoDot:1
+44 SET BGPVALUE=BGPVALUE_$PIECE(BGPASA(X),U,2)_$SELECT($PIECE(BGPASA(X),U,3)]"":" "_$PIECE(BGPASA(X),U,3),1:"")
End DoDot:1
+45 IF BGPN10!(BGPN11)!(BGPN12)
SET BGPVALUE=BGPVALUE_$SELECT($PIECE(BGPVALUE,"|||",2)]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"ACEI/ARB: "
FOR X="RX","REF","CONTRA","ADR"
IF $PIECE($GET(BGPACE(X)),U,1)
IF $PIECE($GET(BGPACE(X)),U,2)]""
Begin DoDot:1
+46 SET BGPVALUE=BGPVALUE_$PIECE(BGPACE(X),U,2)_$SELECT($PIECE(BGPACE(X),U,3)]"":" "_$PIECE(BGPACE(X),U,3),1:"")
End DoDot:1
+47 IF BGPN14!(BGPN15)!(BGPN16)
SET BGPVALUE=BGPVALUE_$SELECT($PIECE(BGPVALUE,"|||",2)]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"STATIN: "
FOR X="RX","REF","CONTRA","ADR"
IF $PIECE($GET(BGPSTAT(X)),U,1)
IF $PIECE($GET(BGPSTAT(X)),U,2)]""
Begin DoDot:1
+48 SET BGPVALUE=BGPVALUE_$PIECE(BGPSTAT(X),U,2)_$SELECT($PIECE(BGPSTAT(X),U,3)]"":" "_$PIECE(BGPSTAT(X),U,3),1:"")
End DoDot:1
+49 KILL ^TMP($JOB)
+50 QUIT
IHD(P,BDATE,EDATE) ;EP
+1 ;first dx prior to report period
+2 ;at least 2 visits during report period
+3 ;at least 2 ihd dxs ever
+4 ;not 2 visits during report period
IF '$$V2^BGP1D1(P,BDATE,EDATE)
QUIT ""
+5 KILL ^TMP($JOB)
+6 ;first dx not prior to report period
IF '$$FIRSTIHD(P,EDATE)
QUIT ""
+7 ;at least 2 IHD dxs ever
IF '$$V2IHD(P,$$DOB^AUPNPAT(P),EDATE)
QUIT ""
+8 QUIT 1
FIRSTIHD(P,EDATE) ;EP
+1 IF $GET(P)=""
QUIT ""
+2 NEW BGPG,Y,X,E
+3 KILL BGPG
+4 SET Y="BGPG("
+5 SET X=P_"^FIRST DX [BGP IHD DXS"
SET E=$$START1^APCLDF(X,Y)
+6 IF '$DATA(BGPG(1))
QUIT ""
+7 SET X=$$FMDIFF^XLFDT(EDATE,$PIECE(BGPG(1),U))
+8 QUIT $SELECT(X>365:1,1:"")
+9 ;
V2IHD(P,BDATE,EDATE) ;EP
+1 IF '$GET(P)
QUIT ""
+2 IF '$DATA(^AUPNVSIT("AC",P))
QUIT ""
+3 NEW A,B,E,T,X,G,V,Y,%,G
+4 KILL ^TMP($JOB,"A")
+5 SET A="^TMP($J,""A"","
SET B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(B,A)
+6 IF '$DATA(^TMP($JOB,"A",1))
QUIT ""
+7 SET T=$ORDER(^ATXAX("B","BGP IHD DXS",0))
+8 IF 'T
QUIT ""
+9 SET (X,G)=0
FOR
SET X=$ORDER(^TMP($JOB,"A",X))
IF X'=+X!(G>2)
QUIT
SET V=$PIECE(^TMP($JOB,"A",X),U,5)
Begin DoDot:1
+10 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+11 IF '$PIECE(^AUPNVSIT(V,0),U,9)
QUIT
+12 IF $PIECE(^AUPNVSIT(V,0),U,11)
QUIT
+13 IF "SAHO"'[$PIECE(^AUPNVSIT(V,0),U,7)
QUIT
+14 IF "V"[$PIECE(^AUPNVSIT(V,0),U,3)
QUIT
+15 IF $PIECE(^AUPNVSIT(V,0),U,6)=""
QUIT
+16 IF $GET(BGPMFITI)
IF '$DATA(^ATXAX(BGPMFITI,21,"B",$PIECE(^AUPNVSIT(V,0),U,6)))
QUIT
+17 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
+18 IF 'D
QUIT
+19 SET G=G+1
+20 QUIT
End DoDot:1
+21 KILL ^TMP($JOB,"A")
+22 QUIT $SELECT(G<2:"",1:1)
+23 ;
BETA(P,BDATE,EDATE,BGPNDAYS) ;EP
+1 NEW BGPMEDS1,K,R,T,T1,X,Y,G,D,N,J,V,S
+2 KILL BGPMEDS1
+3 SET K=0
SET R=""
+4 DO GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
+5 IF '$DATA(BGPMEDS1)
QUIT ""
+6 SET T=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
+7 SET T1=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER NDC",0))
+8 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+9 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+10 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+11 SET G=0
+12 SET D=$PIECE(^AUPNVMED(Y,0),U)
+13 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO BETA1
+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
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 SET S=$$DAYS^BGP1D82(Y,V,EDATE)
+6 ;TOTAL DAYS SUPPLY
SET K=S+K
+7 IF R]""
SET R=R_";"
+8 SET R=R_$$DATE^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+9 IF K>BGPNDAYS
QUIT 1_U_R_" "_"("_K_" TOTAL DAYS)"
BETAPRIO ;now add in any before BEG DATE
+1 KILL BGPMEDS1
+2 DO GETMEDS^BGP1UTL2(P,$$FMADD^XLFDT(BDATE,-365),BDATE,,,,,.BGPMEDS1)
+3 IF '$DATA(BGPMEDS1)
QUIT ""
+4 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+5 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+6 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+7 SET G=0
+8 SET D=$PIECE(^AUPNVMED(Y,0),U)
+9 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO BETA2
+10 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+11 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
+12 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 ;don't use if discontinued
IF J]""
QUIT
+6 SET D=$$FMDIFF^XLFDT(BDATE,$PIECE($PIECE(^AUPNVSIT(V,0),U),"."))
+7 SET S=$PIECE(^AUPNVMED(Y,0),U,7)
+8 SET S=S-D
+9 IF S<0
SET S=0
+10 SET K=S+K
+11 IF R]""
SET R=R_";"
+12 SET R=R_$$DATE^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+13 IF K>BGPNDAYS
QUIT 1_U_R_" "_"("_K_" TOTAL DAYS)"
+14 QUIT 0_U_R_" "_"("_K_" TOTAL DAYS)"
+15 ;
BETAREF(P,BDATE,EDATE) ;EP
+1 NEW T,X,G,D,Y,N
+2 SET T=$ORDER(^ATXAX("B","BGP HEDIS BETA BLOCKER MEDS",0))
+3 SET X=0
SET G=""
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+4 ;not a Beta Blocker
IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+5 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D!(G)
QUIT
Begin DoDot:2
+6 SET Y=9999999-D
IF Y<BDATE
QUIT
+7 ;documented after edate
IF Y>EDATE
QUIT
+8 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N!(G)
QUIT
Begin DoDot:3
+9 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="R"
QUIT
+10 SET G=1_U_$$DATE^BGP1UTL(Y)_U_"Refused "_$PIECE(^PSDRUG(X,0),U,1)
End DoDot:3
+11 QUIT
End DoDot:2
+12 QUIT
End DoDot:1
+13 QUIT G
BETACONT(P,BDATE,EDATE,NMIBD,NMIED) ;EP - BETA BLOCKER CONTRAINDICATION
+1 GOTO BETACONT^BGP1D724
ASA(P,BDATE,EDATE,BGPNDAYS) ;EP
+1 KILL BGPMEDS1
+2 SET K=0
SET R=""
+3 DO GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
+4 IF '$DATA(BGPMEDS1)
QUIT ""
+5 SET T=$ORDER(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
+6 SET T1=$ORDER(^ATXAX("B","BGP ANTI-PLATELET DRUGS",0))
+7 SET T2=$ORDER(^ATXAX("B","BGP CMS ANTI-PLATELET CLASS",0))
+8 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+9 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+10 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+11 SET G=0
+12 SET D=$PIECE(^AUPNVMED(Y,0),U)
+13 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO ASA1
+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
GOTO ASA1
+16 SET C=$PIECE($GET(^PSDRUG(D,0)),U,2)
+17 IF C]""
IF T2
IF $DATA(^ATXAX(T2,21,"B",C))
SET G=1
+18 IF 'G
QUIT
ASA1 ;
+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 SET S=$$DAYS^BGP1D82(Y,V,EDATE)
+6 SET K=S+K
+7 IF R]""
SET R=R_";"
+8 SET R=R_$$DATE^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+9 IF K>BGPNDAYS
QUIT 1_U_R_" "_"("_K_" TOTAL DAYS)"
ASAPRIO ;now add in any before BEG DATE
+1 KILL BGPMEDS1
+2 DO GETMEDS^BGP1UTL2(P,$$FMADD^XLFDT(BDATE,-365),BDATE,,,,,.BGPMEDS1)
+3 IF '$DATA(BGPMEDS1)
QUIT ""
+4 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+5 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+6 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+7 SET G=0
+8 SET D=$PIECE(^AUPNVMED(Y,0),U)
+9 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO ASA2
+10 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+11 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
GOTO ASA2
+12 SET C=$PIECE($GET(^PSDRUG(D,0)),U,2)
+13 IF C]""
IF T2
IF $DATA(^ATXAX(T2,21,"B",C))
SET G=1
+14 IF 'G
QUIT
ASA2 ;
+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 ;don't use if discontinued
IF J]""
QUIT
+6 SET D=$$FMDIFF^XLFDT(BDATE,$PIECE($PIECE(^AUPNVSIT(V,0),U),"."))
+7 SET S=$PIECE(^AUPNVMED(Y,0),U,7)
+8 ;subtract the number of days used
SET S=S-D
+9 IF S<0
SET S=0
+10 ;TOTAL DAYS SUPPLY
SET K=S+K
+11 IF R]""
SET R=R_";"
+12 SET R=R_$$DATE^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+13 IF K>BGPNDAYS
QUIT 1_U_R_" "_"("_K_" TOTAL DAYS)"
+14 QUIT 0_U_R_" "_"("_K_" TOTAL DAYS)"
+15 ;
ASAREF(P,BDATE,EDATE) ;EP
+1 ;did patient have a refusal
+2 SET T=$ORDER(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
+3 SET X=0
SET G=""
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+4 IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+5 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D!(G)
QUIT
Begin DoDot:2
+6 SET Y=9999999-D
IF Y<BDATE
QUIT
+7 IF Y>EDATE
QUIT
+8 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N!(G)
QUIT
Begin DoDot:3
+9 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="R"
QUIT
+10 SET G=1_U_$$DATE^BGP1UTL(Y)_" Refused "_$PIECE(^PSDRUG(X,0),U,1)
End DoDot:3
+11 QUIT
End DoDot:2
+12 QUIT
End DoDot:1
+13 IF G
QUIT G
+14 SET T=$ORDER(^ATXAX("B","BGP ANTI-PLATELET DRUGS",0))
+15 SET X=0
SET G=""
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+16 IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+17 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D!(G)
QUIT
Begin DoDot:2
+18 SET Y=9999999-D
IF Y<BDATE
QUIT
+19 IF Y>EDATE
QUIT
+20 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N!(G)
QUIT
Begin DoDot:3
+21 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="R"
QUIT
+22 SET G=1_U_$$DATE^BGP1UTL(Y)_" Refused "_$PIECE(^PSDRUG(X,0),U,1)
End DoDot:3
+23 QUIT
End DoDot:2
+24 QUIT
End DoDot:1
+25 QUIT G
ASACONTR(P,BDATE,EDATE,BGPNDAYS) ;does patient have an aspirin allergy
+1 KILL BGPMEDS1
+2 SET K=0
SET R=""
+3 DO GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
+4 IF '$DATA(BGPMEDS1)
GOTO ASAC2
+5 SET T=$ORDER(^ATXAX("B","BGP CMS WARFARIN MEDS",0))
+6 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+7 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+8 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+9 SET G=0
+10 SET D=$PIECE(^AUPNVMED(Y,0),U)
+11 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO WAR1
+12 SET N=$PIECE($GET(^PSDRUG(D,0)),U,1)
+13 IF N["WARFARIN"
SET G=1
GOTO WAR1
+14 IF 'G
QUIT
WAR1 ;
+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 SET S=$$DAYS^BGP1D82(Y,V,EDATE)
+6 SET K=S+K
+7 IF R]""
SET R=R_";"
+8 SET R=R_$$DATE^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+9 IF K>BGPNDAYS
QUIT 1_U_" aspirin contra total days WARFARIN: "_K
WARPRIO ;now add in any before BEG DATE
+1 KILL BGPMEDS1
+2 DO GETMEDS^BGP1UTL2(P,$$FMADD^XLFDT(BDATE,-365),BDATE,,,,,.BGPMEDS1)
+3 IF '$DATA(BGPMEDS1)
GOTO ASAC2
+4 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+5 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+6 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
QUIT
+7 SET G=0
+8 SET D=$PIECE(^AUPNVMED(Y,0),U)
+9 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO WAR2
+10 SET N=$PIECE($GET(^PSDRUG(D,0)),U,1)
+11 IF N["WARFARIN"
SET G=1
GOTO WAR2
+12 IF 'G
QUIT
WAR2 ;
+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 IF J]""
QUIT
+7 SET D=$$FMDIFF^XLFDT(EDATE,$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^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
End DoDot:1
+14 IF K>BGPNDAYS
QUIT 1_U_"asp contra total days WARFARIN: "_K
ASAC2 ;now check for dx 459
+1 KILL BGPG
SET BGPG=$$LASTDXI^BGP1UTL1(P,"459.0",$$DOB^AUPNPAT(P),EDATE)
+2 IF BGPG
QUIT 1_U_"asa contra 459.0 "_$$DATE^BGP1UTL($PIECE(BGPG,U,3))
+3 ;
+4 ;nmi in refusal file for aspirin
+5 SET BGPG=""
+6 SET T=$ORDER(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
+7 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X
QUIT
Begin DoDot:1
+8 ;not an aspirin
IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+9 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D
QUIT
Begin DoDot:2
+10 ;before report period
IF (9999999-D)<BDATE
QUIT
+11 ;documented after report period
IF (9999999-D)>EDATE
QUIT
+12 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N
QUIT
Begin DoDot:3
+13 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="N"
QUIT
+14 SET BGPG=1_U_"asa contra NMI Aspirin: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($PIECE(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
End DoDot:3
+15 QUIT
End DoDot:2
+16 QUIT
End DoDot:1
+17 IF BGPG
QUIT BGPG
+18 SET X=$$CPTI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
+19 IF X
QUIT 1_U_"asa contra CPT code G8008: "_$$DATE^BGP1UTL($PIECE(X,U,2))
+20 SET X=$$TRANI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
+21 IF X
QUIT 1_U_"asa contra Tran Code G8008: "_$$DATE^BGP1UTL($PIECE(X,U,2))
+22 QUIT ""
ASAALLEG(P,EDATE) ;EP
+1 KILL BGPG
+2 SET X=$$ASAALLEG^BGP1CU1(P,$$DOB^AUPNPAT(P),EDATE)
+3 IF 'X
QUIT 0
+4 SET $PIECE(X,U,2)="ADR "_$PIECE(X,U,2)
+5 QUIT X