BGP1D732 ; IHS/CMI/LAB - measure AHR.A ;
;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
;
;ROUTINE NOT USED
ACEALG(P,BDATE,EDATE) ;EP
K BGPG
D ACEIALG1^BGP1C11(P,EDATE,.BGPG)
S X=$O(BGPG(X))
I 'X Q ""
Q 1_U_"ace/arb alleg: "_BGPG(X)
;
ACECONT(P,BDATE,EDATE) ;EP does patient have an ACEI contraidication
NEW ED,BD,BGPG,BGPC,X,Y,Z,N,E
K BGPG S Y="BGPG(",X=P_"^LAST DX [BGP CMS AORTIC STENOSIS DXS;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) Q 1_U_"ACEI contra POV: "_$$DATE^BGP1UTL($P(BGPG(1),U))_" ["_$P(BGPG(1),U,2)_"] "_$$VAL^XBDIQ1(9000010.07,+$P(BGPG(1),U,4),.04)
;
;nmi in refusal file for ACEI
S BGPG=""
S T=$O(^ATXAX("B","BGP HEDIS ACEI MEDS",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 ACEI
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D D
..S Y=9999999-D I Y<BDATE Q ;documented more than 1 year before discharge
..I Y>EDATE Q ;documented after End date
..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_"NMI ACEI: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($P(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
..Q
.Q
I BGPG Q BGPG
;nmi in refusal file for ACEI
S BGPG=""
S T=$O(^ATXAX("B","BGP HEDIS ARB MEDS",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 ACEI
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D D
..S Y=9999999-D I Y<BDATE Q
..I Y>EDATE Q ;documented after End date
..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_"NMI ARB: "_$$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("G8029"))
I X Q 1_U_"arb contra CPT code G8029: "_$$DATE^BGP1UTL($P(X,U,2))
S X=$$TRANI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8029"))
I X Q 1_U_"arb contra Tran Code G8029: "_$$DATE^BGP1UTL($P(X,U,2))
Q ""
ACERX(P,BDATE,EDATE) ;EP
K BGPMEDS1
S K=0,R=""
D GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) Q ""
S T=$O(^ATXAX("B","BGP HEDIS ACEI MEDS",0))
S T1=$O(^ATXAX("B","BGP HEDIS ACEI NDC",0))
S T2=$O(^ATXAX("B","BGP HEDIS ARB MEDS",0))
S T3=$O(^ATXAX("B","BGP HEDIS ARB 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))
.S G=0
.S D=$P(^AUPNVMED(Y,0),U)
.I T,$D(^ATXAX(T,21,"B",D)) S G=1 G ACE1
.I T2,$D(^ATXAX(T2,21,"B",D)) S G=1 G ACE1
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1
.I N]"",T3,$D(^ATXAX(T3,21,"B",N)) S G=1
.Q:'G
ACE1 .;
.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>179 Q 1_U_" total days ACE/ARB: "_K
ACEPRIO ;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 ACE2
.I T2,$D(^ATXAX(T2,21,"B",D)) S G=1 G ACE2
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1 G ACE2
.I N]"",T3,$D(^ATXAX(T3,21,"B",N)) S G=1
.Q:'G
ACE2 .;
.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 discontinued
.S D=$$FMDIFF^XLFDT(BDATE,$P($P(^AUPNVSIT(V,0),U),".")) ;difference between dsch date and date prescribed
.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^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
I K>179 Q 1_U_" total ACE/ARB: "_K
Q 0_U_R_" total days ACE/ARB: "_K
;
ACEREF(P,BDATE,EDATE) ;
;did patient have a refusal in time period?
S T=$O(^ATXAX("B","BGP HEDIS ACEI 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))
.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 ;documented more than 1 year before edate
..I Y>EDATE Q ;documented after end date
..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)'="N"
...S G=1_U_"ACEI Refusal "_$$DATE^BGP1UTL(Y)
..Q
.Q
I G Q G
S T=$O(^ATXAX("B","BGP HEDIS ARB 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))
.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 ;documented more than 1 year before edate
..I Y>EDATE Q ;documented after end date
..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)'="N"
...S G=1_U_"ARB Refusal "_$$DATE^BGP1UTL(Y)
..Q
.Q
Q G
STATALG(P,BDATE,EDATE) ;EP
S BGPC=""
;get all visits and check for ALT/AST tests on 2 consecutive visits
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(EDATE) 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["STATIN"!(N["STATINS") S BGPC="Alg Statin POV: "_$$DATE^BGP1UTL($P(BGPG(X),U))_" ["_$P(BGPG(X),U,2)_"] "_N
.S Z=$P(^AUPNVPOV(Y,0),U,9) I Z]"",$P($$ICDDX^ICDCODE(Z),U,2)="E942.9" S BGPC=BGPC+1,BGPY(BGPC)=1_U_"POV: "_$$DATE^BGP1UTL($P(BGPG(X),U))_" ["_$P(BGPG(X),U,2)_" + E942.9] "_N Q
.S Z=$P(^AUPNVPOV(Y,0),U,18) I Z]"",$P($$ICDDX^ICDCODE(Z),U,2)="E942.9" S BGPC=BGPC+1,BGPY(BGPC)=1_U_"POV: "_$$DATE^BGP1UTL($P(BGPG(X),U))_" ["_$P(BGPG(X),U,2)_" + E942.9] "_N Q
.S Z=$P(^AUPNVPOV(Y,0),U,19) I Z]"",$P($$ICDDX^ICDCODE(Z),U,2)="E942.9" S BGPC=BGPC+1,BGPY(BGPC)=1_U_"POV: "_$$DATE^BGP1UTL($P(BGPG(X),U))_" ["_$P(BGPG(X),U,2)_" + E942.9] "_N Q
.Q
I BGPC Q BGPC
K BGPG S BGPC=0 S Y="BGPG(",X=P_"^ALL DX V14.8;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(EDATE) 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["STATIN"!(N["STATINS") S BGPC=1_U_"alg statin POV: "_$$DATE^BGP1UTL($P(BGPG(X),U))_" ["_$P(BGPG(X),U,2)_"] "_N
I BGPC Q BGPC
;now check problem list for these codes
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)>EDATE ;added after discharge date
.I Y="V14.8"!($$ICD^ATXCHK(I,T,9)),N["STATIN"!(N["STATINS") S BGPC=1_U_"alg statin PROBLEM LIST: "_$$DATE^BGP1UTL($P(^AUPNPROB(X,0),U,8))_" ["_Y_"] "_N
.Q
I BGPC Q BGPC
;now check 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),".")>EDATE ;entered after discharge date
.S N=$P($G(^GMR(120.8,X,0)),U,2),N=$$UP^XLFSTR(N)
.I N["STATIN" S BGPC=1_U_" alg statin ALLERGY TRACKING: "_$$DATE^BGP1UTL($P(^GMR(120.8,X,0),U,4))_" "_N
I BGPC Q BGPC
Q 0
;
STATCON(P,BDATE,EDATE) ;EP does patient have an STATIN contraidication
NEW ED,BD,BGPG,BGPC,X,Y,Z,N,E
;
;pregnant
S X=$$PREG^BGP1D7(P,BDATE,EDATE,0,1) I X Q 1_U_"contra statin - pregnant"
;nmi in refusal file for STATI
S BGPG=""
S T=$O(^ATXAX("B","BGP HEDIS STATIN MEDS",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 STATI
.S D=0 F S D=$O(^AUPNPREF("AA",P,50,X,D)) Q:D'=+D D
..S Y=9999999-D I Y<BDATE Q ;documented more than 1 year before discharge
..I Y>EDATE Q ;documented after End date
..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_"NMI STATIN: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($P(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
..Q
.Q
I BGPG Q BGPG
;breastfeeding
K BGPG S Y="BGPG(",X=P_"^LAST DX V24.1;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) Q 1_U_"STATIN contra POV: "_$$DATE^BGP1UTL($P(BGPG(1),U))_" ["_$P(BGPG(1),U,2)_"] "_$$VAL^XBDIQ1(9000010.07,+$P(BGPG(1),U,4),.04)
;now check education
K BGPG
S Y="BGPG("
S X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I '$D(BGPG) Q ""
S (X,D)=0,%="",T="" F S X=$O(BGPG(X)) Q:X'=+X!(%]"") D
.S T=$P(^AUPNVPED(+$P(BGPG(X),U,4),0),U)
.Q:'T
.Q:'$D(^AUTTEDT(T,0))
.S T=$P(^AUTTEDT(T,0),U,2)
.I T="BF-BC" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-BP" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-CS" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-EQ" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-FU" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-HC" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-ON" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-M" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-MK" S %=T_U_$P(BGPG(X),U) Q
.I T="BF-N" S %=T_U_$P(BGPG(X),U) Q
.I $P(T,"-")="V24.1" S %=T_U_$P(BGPG(X),U) Q
I %]"" Q 1_U_"Statin contra - "_%
;NOW CHECK ALCOHOL HEPATITIS
K BGPG S Y="BGPG(",X=P_"^LAST DX 571.1;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) Q 1_U_"STATIN contra POV: "_$$DATE^BGP1UTL($P(BGPG(1),U))_" ["_$P(BGPG(1),U,2)_"] "_$$VAL^XBDIQ1(9000010.07,+$P(BGPG(1),U,4),.04)
Q ""
STATRX(P,BDATE,EDATE) ;EP
K BGPMEDS1 S K=0,R=""
D GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) Q ""
S T=$O(^ATXAX("B","BGP HEDIS STATIN MEDS",0))
S T1=$O(^ATXAX("B","BGP HEDIS STATIN 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 STAT1
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1
.Q:'G
STAT1 .;
.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>179 Q 1_U_" total days STATIN: "_K
STATPRIO ;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 STAT2
.S N=$P($G(^PSDRUG(D,2)),U,4)
.I N]"",T1,$D(^ATXAX(T1,21,"B",N)) S G=1 G STAT2
.Q:'G
STAT2 .;
.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 discontinued
.S D=$$FMDIFF^XLFDT(BDATE,$P($P(^AUPNVSIT(V,0),U),".")) ;difference between dsch date and date prescribed
.S S=$P(^AUPNVMED(Y,0),U,7)
.S S=S-D ;subtract the number of days used
.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>179 Q 1_U_" total STATIN: "_K
Q 0_U_R_" total days STATIN: "_K
;
STATREF(P,BDATE,EDATE) ;
;did patient have a refusal in time period?
S T=$O(^ATXAX("B","BGP HEDIS STATIN 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))
.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 ;documented more than 1 year before edate
..I Y>EDATE Q ;documented after end date
..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)'="N"
...S G=1_U_"ACEI Refusal "_$$DATE^BGP1UTL(Y)
..Q
.Q
Q G
BGP1D732 ; IHS/CMI/LAB - measure AHR.A ;
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
+2 ;
+3 ;ROUTINE NOT USED
ACEALG(P,BDATE,EDATE) ;EP
+1 KILL BGPG
+2 DO ACEIALG1^BGP1C11(P,EDATE,.BGPG)
+3 SET X=$ORDER(BGPG(X))
+4 IF 'X
QUIT ""
+5 QUIT 1_U_"ace/arb alleg: "_BGPG(X)
+6 ;
ACECONT(P,BDATE,EDATE) ;EP does patient have an ACEI contraidication
+1 NEW ED,BD,BGPG,BGPC,X,Y,Z,N,E
+2 KILL BGPG
SET Y="BGPG("
SET X=P_"^LAST DX [BGP CMS AORTIC STENOSIS DXS;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+3 IF $DATA(BGPG(1))
QUIT 1_U_"ACEI contra POV: "_$$DATE^BGP1UTL($PIECE(BGPG(1),U))_" ["_$PIECE(BGPG(1),U,2)_"] "_$$VAL^XBDIQ1(9000010.07,+$PIECE(BGPG(1),U,4),.04)
+4 ;
+5 ;nmi in refusal file for ACEI
+6 SET BGPG=""
+7 SET T=$ORDER(^ATXAX("B","BGP HEDIS ACEI MEDS",0))
+8 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X
QUIT
Begin DoDot:1
+9 ;not an ACEI
IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+10 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D
QUIT
Begin DoDot:2
+11 ;documented more than 1 year before discharge
SET Y=9999999-D
IF Y<BDATE
QUIT
+12 ;documented after End date
IF Y>EDATE
QUIT
+13 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N
QUIT
Begin DoDot:3
+14 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="N"
QUIT
+15 SET BGPG=1_U_"NMI ACEI: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($PIECE(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
End DoDot:3
+16 QUIT
End DoDot:2
+17 QUIT
End DoDot:1
+18 IF BGPG
QUIT BGPG
+19 ;nmi in refusal file for ACEI
+20 SET BGPG=""
+21 SET T=$ORDER(^ATXAX("B","BGP HEDIS ARB MEDS",0))
+22 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X
QUIT
Begin DoDot:1
+23 ;not an ACEI
IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+24 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D
QUIT
Begin DoDot:2
+25 SET Y=9999999-D
IF Y<BDATE
QUIT
+26 ;documented after End date
IF Y>EDATE
QUIT
+27 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N
QUIT
Begin DoDot:3
+28 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="N"
QUIT
+29 SET BGPG=1_U_"NMI ARB: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($PIECE(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
End DoDot:3
+30 QUIT
End DoDot:2
+31 QUIT
End DoDot:1
+32 IF BGPG
QUIT BGPG
+33 SET X=$$CPTI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8029"))
+34 IF X
QUIT 1_U_"arb contra CPT code G8029: "_$$DATE^BGP1UTL($PIECE(X,U,2))
+35 SET X=$$TRANI^BGP1DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8029"))
+36 IF X
QUIT 1_U_"arb contra Tran Code G8029: "_$$DATE^BGP1UTL($PIECE(X,U,2))
+37 QUIT ""
ACERX(P,BDATE,EDATE) ;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","BGP HEDIS ACEI MEDS",0))
+6 SET T1=$ORDER(^ATXAX("B","BGP HEDIS ACEI NDC",0))
+7 SET T2=$ORDER(^ATXAX("B","BGP HEDIS ARB MEDS",0))
+8 SET T3=$ORDER(^ATXAX("B","BGP HEDIS ARB NDC",0))
+9 SET X=0
FOR
SET X=$ORDER(BGPMEDS1(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPMEDS1(X),U,4)
Begin DoDot:1
+10 IF '$DATA(^AUPNVMED(Y,0))
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 ACE1
+14 IF T2
IF $DATA(^ATXAX(T2,21,"B",D))
SET G=1
GOTO ACE1
+15 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+16 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
+17 IF N]""
IF T3
IF $DATA(^ATXAX(T3,21,"B",N))
SET G=1
+18 IF 'G
QUIT
ACE1 ;
+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>179
QUIT 1_U_" total days ACE/ARB: "_K
ACEPRIO ;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 ACE2
+10 IF T2
IF $DATA(^ATXAX(T2,21,"B",D))
SET G=1
GOTO ACE2
+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
GOTO ACE2
+13 IF N]""
IF T3
IF $DATA(^ATXAX(T3,21,"B",N))
SET G=1
+14 IF 'G
QUIT
ACE2 ;
+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 discontinued
IF J]""
QUIT
+7 ;difference between dsch date and date prescribed
SET D=$$FMDIFF^XLFDT(BDATE,$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>179
QUIT 1_U_" total ACE/ARB: "_K
+15 QUIT 0_U_R_" total days ACE/ARB: "_K
+16 ;
ACEREF(P,BDATE,EDATE) ;
+1 ;did patient have a refusal in time period?
+2 SET T=$ORDER(^ATXAX("B","BGP HEDIS ACEI 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 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 ;documented more than 1 year before edate
SET Y=9999999-D
IF Y<BDATE
QUIT
+7 ;documented after end date
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 ;Q:$P($G(^AUPNPREF(N,0)),U,7)'="N"
+10 SET G=1_U_"ACEI Refusal "_$$DATE^BGP1UTL(Y)
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 HEDIS ARB MEDS",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 ;documented more than 1 year before edate
SET Y=9999999-D
IF Y<BDATE
QUIT
+19 ;documented after end date
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 ;Q:$P($G(^AUPNPREF(N,0)),U,7)'="N"
+22 SET G=1_U_"ARB Refusal "_$$DATE^BGP1UTL(Y)
End DoDot:3
+23 QUIT
End DoDot:2
+24 QUIT
End DoDot:1
+25 QUIT G
STATALG(P,BDATE,EDATE) ;EP
+1 SET BGPC=""
+2 ;get all visits and check for ALT/AST tests on 2 consecutive visits
+3 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(EDATE)
SET E=$$START1^APCLDF(X,Y)
+4 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPG(X),U,4)
Begin DoDot:1
+5 SET N=$$VAL^XBDIQ1(9000010.07,Y,.04)
SET N=$$UP^XLFSTR(N)
+6 IF N["STATIN"!(N["STATINS")
SET BGPC="Alg Statin POV: "_$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ["_$PIECE(BGPG(X),U,2)_"] "_N
+7 SET Z=$PIECE(^AUPNVPOV(Y,0),U,9)
IF Z]""
IF $PIECE($$ICDDX^ICDCODE(Z),U,2)="E942.9"
SET BGPC=BGPC+1
SET BGPY(BGPC)=1_U_"POV: "_$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ["_$PIECE(BGPG(X),U,2)_" + E942.9] "_N
QUIT
+8 SET Z=$PIECE(^AUPNVPOV(Y,0),U,18)
IF Z]""
IF $PIECE($$ICDDX^ICDCODE(Z),U,2)="E942.9"
SET BGPC=BGPC+1
SET BGPY(BGPC)=1_U_"POV: "_$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ["_$PIECE(BGPG(X),U,2)_" + E942.9] "_N
QUIT
+9 SET Z=$PIECE(^AUPNVPOV(Y,0),U,19)
IF Z]""
IF $PIECE($$ICDDX^ICDCODE(Z),U,2)="E942.9"
SET BGPC=BGPC+1
SET BGPY(BGPC)=1_U_"POV: "_$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ["_$PIECE(BGPG(X),U,2)_" + E942.9] "_N
QUIT
+10 QUIT
End DoDot:1
+11 IF BGPC
QUIT BGPC
+12 KILL BGPG
SET BGPC=0
SET Y="BGPG("
SET X=P_"^ALL DX V14.8;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+13 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET Y=+$PIECE(BGPG(X),U,4)
Begin DoDot:1
+14 SET N=$$VAL^XBDIQ1(9000010.07,Y,.04)
SET N=$$UP^XLFSTR(N)
+15 IF N["STATIN"!(N["STATINS")
SET BGPC=1_U_"alg statin POV: "_$$DATE^BGP1UTL($PIECE(BGPG(X),U))_" ["_$PIECE(BGPG(X),U,2)_"] "_N
End DoDot:1
+16 IF BGPC
QUIT BGPC
+17 ;now check problem list for these codes
+18 SET BGPC=0
+19 SET T=""
SET T=$ORDER(^ATXAX("B","BGP ASA ALLERGY 995.0-995.3",0))
+20 SET X=0
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+21 SET I=$PIECE($GET(^AUPNPROB(X,0)),U)
SET Y=$PIECE($$ICDDX^ICDCODE(I),U,2)
+22 SET N=$$VAL^XBDIQ1(9000011,X,.05)
SET N=$$UP^XLFSTR(N)
+23 ;added after discharge date
IF $PIECE(^AUPNPROB(X,0),U,8)>EDATE
QUIT
+24 IF Y="V14.8"!($$ICD^ATXCHK(I,T,9))
IF N["STATIN"!(N["STATINS")
SET BGPC=1_U_"alg statin PROBLEM LIST: "_$$DATE^BGP1UTL($PIECE(^AUPNPROB(X,0),U,8))_" ["_Y_"] "_N
+25 QUIT
End DoDot:1
+26 IF BGPC
QUIT BGPC
+27 ;now check allergy tracking
+28 SET BGPC=0
+29 SET X=0
FOR
SET X=$ORDER(^GMR(120.8,"B",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+30 ;entered after discharge date
IF $PIECE($PIECE($GET(^GMR(120.8,X,0)),U,4),".")>EDATE
QUIT
+31 SET N=$PIECE($GET(^GMR(120.8,X,0)),U,2)
SET N=$$UP^XLFSTR(N)
+32 IF N["STATIN"
SET BGPC=1_U_" alg statin ALLERGY TRACKING: "_$$DATE^BGP1UTL($PIECE(^GMR(120.8,X,0),U,4))_" "_N
End DoDot:1
+33 IF BGPC
QUIT BGPC
+34 QUIT 0
+35 ;
STATCON(P,BDATE,EDATE) ;EP does patient have an STATIN contraidication
+1 NEW ED,BD,BGPG,BGPC,X,Y,Z,N,E
+2 ;
+3 ;pregnant
+4 SET X=$$PREG^BGP1D7(P,BDATE,EDATE,0,1)
IF X
QUIT 1_U_"contra statin - pregnant"
+5 ;nmi in refusal file for STATI
+6 SET BGPG=""
+7 SET T=$ORDER(^ATXAX("B","BGP HEDIS STATIN MEDS",0))
+8 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,50,X))
IF X'=+X
QUIT
Begin DoDot:1
+9 ;not an STATI
IF '$DATA(^ATXAX(T,21,"B",X))
QUIT
+10 SET D=0
FOR
SET D=$ORDER(^AUPNPREF("AA",P,50,X,D))
IF D'=+D
QUIT
Begin DoDot:2
+11 ;documented more than 1 year before discharge
SET Y=9999999-D
IF Y<BDATE
QUIT
+12 ;documented after End date
IF Y>EDATE
QUIT
+13 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N
QUIT
Begin DoDot:3
+14 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="N"
QUIT
+15 SET BGPG=1_U_"NMI STATIN: "_$$VAL^XBDIQ1(9000022,N,.04)_" "_$$DATE^BGP1UTL($PIECE(^AUPNPREF(N,0),U,3))_" "_$$VAL^XBDIQ1(9000022,X,1101)
End DoDot:3
+16 QUIT
End DoDot:2
+17 QUIT
End DoDot:1
+18 IF BGPG
QUIT BGPG
+19 ;breastfeeding
+20 KILL BGPG
SET Y="BGPG("
SET X=P_"^LAST DX V24.1;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+21 IF $DATA(BGPG(1))
QUIT 1_U_"STATIN contra POV: "_$$DATE^BGP1UTL($PIECE(BGPG(1),U))_" ["_$PIECE(BGPG(1),U,2)_"] "_$$VAL^XBDIQ1(9000010.07,+$PIECE(BGPG(1),U,4),.04)
+22 ;now check education
+23 KILL BGPG
+24 SET Y="BGPG("
+25 SET X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+26 IF '$DATA(BGPG)
QUIT ""
+27 SET (X,D)=0
SET %=""
SET T=""
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X!(%]"")
QUIT
Begin DoDot:1
+28 SET T=$PIECE(^AUPNVPED(+$PIECE(BGPG(X),U,4),0),U)
+29 IF 'T
QUIT
+30 IF '$DATA(^AUTTEDT(T,0))
QUIT
+31 SET T=$PIECE(^AUTTEDT(T,0),U,2)
+32 IF T="BF-BC"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+33 IF T="BF-BP"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+34 IF T="BF-CS"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+35 IF T="BF-EQ"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+36 IF T="BF-FU"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+37 IF T="BF-HC"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+38 IF T="BF-ON"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+39 IF T="BF-M"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+40 IF T="BF-MK"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+41 IF T="BF-N"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
+42 IF $PIECE(T,"-")="V24.1"
SET %=T_U_$PIECE(BGPG(X),U)
QUIT
End DoDot:1
+43 IF %]""
QUIT 1_U_"Statin contra - "_%
+44 ;NOW CHECK ALCOHOL HEPATITIS
+45 KILL BGPG
SET Y="BGPG("
SET X=P_"^LAST DX 571.1;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+46 IF $DATA(BGPG(1))
QUIT 1_U_"STATIN contra POV: "_$$DATE^BGP1UTL($PIECE(BGPG(1),U))_" ["_$PIECE(BGPG(1),U,2)_"] "_$$VAL^XBDIQ1(9000010.07,+$PIECE(BGPG(1),U,4),.04)
+47 QUIT ""
STATRX(P,BDATE,EDATE) ;EP
+1 KILL BGPMEDS1
SET K=0
SET R=""
+2 DO GETMEDS^BGP1UTL2(P,BDATE,EDATE,,,,,.BGPMEDS1)
+3 IF '$DATA(BGPMEDS1)
QUIT ""
+4 SET T=$ORDER(^ATXAX("B","BGP HEDIS STATIN MEDS",0))
+5 SET T1=$ORDER(^ATXAX("B","BGP HEDIS STATIN NDC",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 STAT1
+12 SET N=$PIECE($GET(^PSDRUG(D,2)),U,4)
+13 IF N]""
IF T1
IF $DATA(^ATXAX(T1,21,"B",N))
SET G=1
+14 IF 'G
QUIT
STAT1 ;
+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>179
QUIT 1_U_" total days STATIN: "_K
STATPRIO ;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 STAT2
+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 STAT2
+12 IF 'G
QUIT
STAT2 ;
+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 discontinued
IF J]""
QUIT
+7 ;difference between dsch date and date prescribed
SET D=$$FMDIFF^XLFDT(BDATE,$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 ;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>179
QUIT 1_U_" total STATIN: "_K
+14 QUIT 0_U_R_" total days STATIN: "_K
+15 ;
STATREF(P,BDATE,EDATE) ;
+1 ;did patient have a refusal in time period?
+2 SET T=$ORDER(^ATXAX("B","BGP HEDIS STATIN 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 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 ;documented more than 1 year before edate
SET Y=9999999-D
IF Y<BDATE
QUIT
+7 ;documented after end date
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 ;Q:$P($G(^AUPNPREF(N,0)),U,7)'="N"
+10 SET G=1_U_"ACEI Refusal "_$$DATE^BGP1UTL(Y)
End DoDot:3
+11 QUIT
End DoDot:2
+12 QUIT
End DoDot:1
+13 QUIT G