BGP5D731 ; IHS/CMI/LAB - measure AHR.A ;
;;15.1;IHS CLINICAL REPORTING;;MAY 06, 2015;Build 143
;
;
IPAMT ;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<35 S BGPSTOP=1 Q
I 'BGPACTCL S BGPSTOP=1 Q ;must be active clinical
S BGPAMI=$$AMI(DFN,$$FMADD^XLFDT(BGPBDATE,-182),$$FMADD^XLFDT(BGPBDATE,182))
I '$P(BGPAMI,U) S BGPSTOP=1 Q ;no ami
S BGPD1=1
I $P(^DPT(DFN,0),U,2)="M" S BGPD2=1
I $P(^DPT(DFN,0),U,2)="F" S BGPD3=1
S BGPADDAT=$S($P(BGPAMI,U,4)]"":$P(BGPAMI,U,4),1:$P(BGPAMI,U,2)) ;discharge date
K BGPBETA
S BGPBETA("RX")=$$BETA^BGP5D721(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134)
I BGPBETA("RX") S BGPN2=1 ;pt has 135 days of beta blocker
;I 'BGPN2 S BGPBETA("REF")=$$BETAREF^BGP5D721(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPBETA("REF") S BGPN3=1
I 'BGPN2 S BGPBETA("CONTRA")=$$BETACONT^BGP5D721(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPBETA("CONTRA") S BGPN4=1 ;beta Contraindication
I 'BGPN2 S BGPBETA("ADR")=$$BETAALG1^BGP5D72(DFN,$$FMADD^XLFDT(BGPADDAT,180)) I BGPBETA("ADR") S BGPN4=1
I (BGPN2+BGPN4) S BGPN1=1
K BGPASA
S BGPASA("RX")=$$ASA^BGP5D721(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134) ;get 1_U_# days
I BGPASA("RX") S BGPN6=1 ;pt has 135 days of beta blocker
;I 'BGPN6 S BGPASA("REF")=$$ASAREF^BGP5D721(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPASA("REF") S BGPN7=1
I 'BGPN6 S BGPASA("CONTRA")=$$ASACONTR(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180),$$DOB^AUPNPAT(DFN),BGPEDATE) I BGPASA("CONTRA") S BGPN8=1 ;beta Contraindication
I 'BGPN6 S BGPASA("ADR")=$$ASAALLEG^BGP5D721(DFN,$$FMADD^XLFDT(BGPADDAT,180)) I BGPASA("ADR") S BGPN8=1
I (BGPN6+BGPN8) S BGPN5=1
K BGPACE
S BGPACE("RX")=$$ACERX^BGP5D722(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134) ;get 1_U_# days
I BGPACE("RX") S BGPN10=1 ;pt has 135 days of ACE
;I 'BGPN10 S BGPACE("REF")=$$ACEREF^BGP5D722(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPACE("REF") S BGPN11=1
I 'BGPN10 S BGPACE("CONTRA")=$$ACECONT^BGP5D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180),BGPBDATE) I BGPACE("CONTRA") S BGPN12=1 ;beta Contraindication
I 'BGPN10 S BGPACE("ADR")=$$ACEALG^BGP5D722(DFN,BGPBDATE,$$FMADD^XLFDT(BGPADDAT,180)) I BGPACE("ADR") S BGPN12=1
I (BGPN10+BGPN12) S BGPN9=1
K BGPSTAT
S BGPSTAT("RX")=$$STATRX^BGP5D722(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134) ;get 1_U_# days
I BGPSTAT("RX") S BGPN14=1 ;pt has 135 days of STAT
;I 'BGPN14 S BGPSTAT("REF")=$$STATREF^BGP5D722(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPSTAT("REF") S BGPN15=1
I 'BGPN14 S BGPSTAT("CONTRA")=$$STATCON^BGP5D722(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180)) I BGPSTAT("CONTRA") S BGPN16=1 ;beta Contraindication
I 'BGPN14 S BGPSTAT("ADR")=$$STATALG^BGP5D722(DFN,$$DOB^AUPNPAT(DFN),$$FMADD^XLFDT(BGPADDAT,180),BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180)) I BGPSTAT("ADR") S BGPN16=1
I (BGPN14+BGPN16) S BGPN13=1
I BGPN1,BGPN5,BGPN9,BGPN13 S BGPN17=1
S BGPVALUE="AC|||"
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 ;old stuff below
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)]"" S BGPVALUE=BGPVALUE_$P(BGPBETA(X),U,2)_" DAYS"
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)]"" S BGPVALUE=BGPVALUE_$P(BGPASA(X),U,2)
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)]"" S BGPVALUE=BGPVALUE_$P(BGPACE(X),U,2)
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)]"" S BGPVALUE=BGPVALUE_$P(BGPSTAT(X),U,2)
K BGPIHD,BGPBETA,BGPMEDS1,BGPASA,BGPACE,BGPSTAT
K ^TMP($J)
Q
AMI(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
S T=$O(^ATXAX("B","BGP AMI DXS PAMT",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^BGP5D72(H) ;ama
..Q:$$TRANS^BGP5D72(H) ;transferred
..Q:$$EXPIRED^BGP5D72(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)) D
..S %=$P(^AUPNVPOV(Y,0),U) Q:'$$ICD^BGP5UTL2(%,T,9)
..I $P(^AUPNVPOV(Y,0),U,6)]"",$P(^AUPNVPOV(Y,0),U,6)'="F" Q ;modifier
..S N=$$VAL^XBDIQ1(9000010.07,Y,.04)
..S N=$$UP^XLFSTR(N)
..I $E(N,1,8)="CONSIDER" Q
..I $E(N,1,8)="DOUBTFUL" Q
..I $E(N,1,5)="MAYBE" Q
..I $E(N,1,8)="POSSIBLE" Q
..I $E(N,1,7)="PERHAPS" Q
..I $E(N,1,8)="RULE OUT" Q
..I $E(N,1,3)="R/O" Q
..I $E(N,1,8)="PROBABLE" Q
..I $E(N,1,8)="RESOLVED" Q
..I $E(N,1,7)="SUSPECT" Q
..I $E(N,1,10)="SUSPICIOUS" Q
..I $E(N,1,11)="STATUS POST" Q
..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
ASACONTR(P,BGPADM,BGPDD,BDATE,EDATE) ;does patient have an aspirin allergy
K BGPMEDS1
S K=0,R="",BGPG=""
D GETMEDS^BGP5UTL2(P,$$FMADD^XLFDT(BGPADM,-90),BGPDD,,,,,.BGPMEDS1)
I '$D(BGPMEDS1) G HEM
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))
.S G=0
.S D=$P(^AUPNVMED(Y,0),U)
.I T,$D(^ATXAX(T,21,"B",D)) S G=1 G WAR71
.S N=$P($G(^PSDRUG(D,0)),U,1)
.I N["WARFARIN" S G=1 G WAR71
.I $$VAPI^BGP5D81(D,$O(^ATXAX("B","BGP CMS WARFARIN VAPI",0))) S G=1 G WAR71
.Q:'G
WAR71 .;
.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
.I J]"" Q:J<BGPADM ;discontinued before admission
.S E=$P($P(^AUPNVSIT(V,0),U),".")
.I E'<BGPADM,E'>BGPDD S BGPG=1_U_$$DATE^BGP5UTL(E)_U_$P(^PSDRUG(D,0),U)
.S S=$P(^AUPNVMED(Y,0),U,7)
.S Z=$$FMDIFF^XLFDT(BGPADM,$P($P(^AUPNVSIT(V,0),U),"."))
.I S>Z S BGPG=1_U_$$DATE^BGP5UTL($P($P(^AUPNVSIT(V,0),U),"."))_U_" Contra "_$P(^PSDRUG(D,0),U)
.Q
I BGPG Q BGPG
HEM ;now check for dx 459
K BGPG S BGPG=$$LASTDX^BGP5UTL1(P,"BGP HEMORRHAGE DXS",$$DOB^AUPNPAT(P),EDATE)
I BGPG Q 1_U_"asa Contra "_$P(BGPG,U,2)_" "_$$DATE^BGP5UTL($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 Y>EDATE Q ;documented EDATE OF 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_$$DATE^BGP5UTL($P(^AUPNPREF(N,0),U,3))_" Contra NMI "_$$VAL^XBDIQ1(9000022,N,.04) ;_" "_" "_$$VAL^XBDIQ1(9000022,X,1101)
..Q
.Q
I BGPG Q BGPG
;now check for CPT code G8008
S X=$$CPTI^BGP5DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
I X Q 1_U_$$DATE^BGP5UTL($P(X,U,2))_U_" Contra CPT G8008"
S X=$$TRANI^BGP5DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
I X Q 1_U_$$DATE^BGP5UTL($P(X,U,2))_U_" Contra CPT/TRAN G8008"
Q ""
BGP5D731 ; IHS/CMI/LAB - measure AHR.A ;
+1 ;;15.1;IHS CLINICAL REPORTING;;MAY 06, 2015;Build 143
+2 ;
+3 ;
IPAMT ;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<35
SET BGPSTOP=1
QUIT
+4 ;must be active clinical
IF 'BGPACTCL
SET BGPSTOP=1
QUIT
+5 SET BGPAMI=$$AMI(DFN,$$FMADD^XLFDT(BGPBDATE,-182),$$FMADD^XLFDT(BGPBDATE,182))
+6 ;no ami
IF '$PIECE(BGPAMI,U)
SET BGPSTOP=1
QUIT
+7 SET BGPD1=1
+8 IF $PIECE(^DPT(DFN,0),U,2)="M"
SET BGPD2=1
+9 IF $PIECE(^DPT(DFN,0),U,2)="F"
SET BGPD3=1
+10 ;discharge date
SET BGPADDAT=$SELECT($PIECE(BGPAMI,U,4)]"":$PIECE(BGPAMI,U,4),1:$PIECE(BGPAMI,U,2))
+11 KILL BGPBETA
+12 SET BGPBETA("RX")=$$BETA^BGP5D721(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134)
+13 ;pt has 135 days of beta blocker
IF BGPBETA("RX")
SET BGPN2=1
+14 ;I 'BGPN2 S BGPBETA("REF")=$$BETAREF^BGP5D721(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPBETA("REF") S BGPN3=1
+15 ;beta Contraindication
IF 'BGPN2
SET BGPBETA("CONTRA")=$$BETACONT^BGP5D721(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,$PIECE(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180))
IF BGPBETA("CONTRA")
SET BGPN4=1
+16 IF 'BGPN2
SET BGPBETA("ADR")=$$BETAALG1^BGP5D72(DFN,$$FMADD^XLFDT(BGPADDAT,180))
IF BGPBETA("ADR")
SET BGPN4=1
+17 IF (BGPN2+BGPN4)
SET BGPN1=1
+18 KILL BGPASA
+19 ;get 1_U_# days
SET BGPASA("RX")=$$ASA^BGP5D721(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134)
+20 ;pt has 135 days of beta blocker
IF BGPASA("RX")
SET BGPN6=1
+21 ;I 'BGPN6 S BGPASA("REF")=$$ASAREF^BGP5D721(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPASA("REF") S BGPN7=1
+22 ;beta Contraindication
IF 'BGPN6
SET BGPASA("CONTRA")=$$ASACONTR(DFN,$PIECE(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180),$$DOB^AUPNPAT(DFN),BGPEDATE)
IF BGPASA("CONTRA")
SET BGPN8=1
+23 IF 'BGPN6
SET BGPASA("ADR")=$$ASAALLEG^BGP5D721(DFN,$$FMADD^XLFDT(BGPADDAT,180))
IF BGPASA("ADR")
SET BGPN8=1
+24 IF (BGPN6+BGPN8)
SET BGPN5=1
+25 KILL BGPACE
+26 ;get 1_U_# days
SET BGPACE("RX")=$$ACERX^BGP5D722(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134)
+27 ;pt has 135 days of ACE
IF BGPACE("RX")
SET BGPN10=1
+28 ;I 'BGPN10 S BGPACE("REF")=$$ACEREF^BGP5D722(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPACE("REF") S BGPN11=1
+29 ;beta Contraindication
IF 'BGPN10
SET BGPACE("CONTRA")=$$ACECONT^BGP5D722(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE,$PIECE(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180),BGPBDATE)
IF BGPACE("CONTRA")
SET BGPN12=1
+30 IF 'BGPN10
SET BGPACE("ADR")=$$ACEALG^BGP5D722(DFN,BGPBDATE,$$FMADD^XLFDT(BGPADDAT,180))
IF BGPACE("ADR")
SET BGPN12=1
+31 IF (BGPN10+BGPN12)
SET BGPN9=1
+32 KILL BGPSTAT
+33 ;get 1_U_# days
SET BGPSTAT("RX")=$$STATRX^BGP5D722(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),134)
+34 ;pt has 135 days of STAT
IF BGPSTAT("RX")
SET BGPN14=1
+35 ;I 'BGPN14 S BGPSTAT("REF")=$$STATREF^BGP5D722(DFN,$P(BGPAMI,U,2),$$FMADD^XLFDT(BGPADDAT,180)) I BGPSTAT("REF") S BGPN15=1
+36 ;beta Contraindication
IF 'BGPN14
SET BGPSTAT("CONTRA")=$$STATCON^BGP5D722(DFN,BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180),BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180))
IF BGPSTAT("CONTRA")
SET BGPN16=1
+37 IF 'BGPN14
SET BGPSTAT("ADR")=$$STATALG^BGP5D722(DFN,$$DOB^AUPNPAT(DFN),$$FMADD^XLFDT(BGPADDAT,180),BGPADDAT,$$FMADD^XLFDT(BGPADDAT,180))
IF BGPSTAT("ADR")
SET BGPN16=1
+38 IF (BGPN14+BGPN16)
SET BGPN13=1
+39 IF BGPN1
IF BGPN5
IF BGPN9
IF BGPN13
SET BGPN17=1
+40 SET BGPVALUE="AC|||"
+41 SET BGPVALUE=BGPVALUE_$SELECT(BGPN17:"ALL MEDS:",1:"")
+42 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
+43 SET BGPVALUE=BGPVALUE_$PIECE(BGPBETA(X),U,2)_$SELECT($PIECE(BGPBETA(X),U,3)]"":" "_$PIECE(BGPBETA(X),U,3),1:"")
End DoDot:1
+44 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
+45 SET BGPVALUE=BGPVALUE_$PIECE(BGPASA(X),U,2)_$SELECT($PIECE(BGPASA(X),U,3)]"":" "_$PIECE(BGPASA(X),U,3),1:"")
End DoDot:1
+46 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
+47 SET BGPVALUE=BGPVALUE_$PIECE(BGPACE(X),U,2)_$SELECT($PIECE(BGPACE(X),U,3)]"":" "_$PIECE(BGPACE(X),U,3),1:"")
End DoDot:1
+48 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
+49 SET BGPVALUE=BGPVALUE_$PIECE(BGPSTAT(X),U,2)_$SELECT($PIECE(BGPSTAT(X),U,3)]"":" "_$PIECE(BGPSTAT(X),U,3),1:"")
End DoDot:1
+50 KILL ^TMP($JOB)
+51 ;old stuff below
QUIT
+52 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)]""
SET BGPVALUE=BGPVALUE_$PIECE(BGPBETA(X),U,2)_" DAYS"
+53 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)]""
SET BGPVALUE=BGPVALUE_$PIECE(BGPASA(X),U,2)
+54 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)]""
SET BGPVALUE=BGPVALUE_$PIECE(BGPACE(X),U,2)
+55 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)]""
SET BGPVALUE=BGPVALUE_$PIECE(BGPSTAT(X),U,2)
+56 KILL BGPIHD,BGPBETA,BGPMEDS1,BGPASA,BGPACE,BGPSTAT
+57 KILL ^TMP($JOB)
+58 QUIT
AMI(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 IF '$DATA(^TMP($JOB,"A",1))
QUIT 0
+5 SET T=$ORDER(^ATXAX("B","BGP AMI DXS PAMT",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^BGP5D72(H)
QUIT
+16 ;transferred
IF $$TRANS^BGP5D72(H)
QUIT
+17 ;died
IF $$EXPIRED^BGP5D72(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))
Begin DoDot:2
+20 SET %=$PIECE(^AUPNVPOV(Y,0),U)
IF '$$ICD^BGP5UTL2(%,T,9)
QUIT
+21 ;modifier
IF $PIECE(^AUPNVPOV(Y,0),U,6)]""
IF $PIECE(^AUPNVPOV(Y,0),U,6)'="F"
QUIT
+22 SET N=$$VAL^XBDIQ1(9000010.07,Y,.04)
+23 SET N=$$UP^XLFSTR(N)
+24 IF $EXTRACT(N,1,8)="CONSIDER"
QUIT
+25 IF $EXTRACT(N,1,8)="DOUBTFUL"
QUIT
+26 IF $EXTRACT(N,1,5)="MAYBE"
QUIT
+27 IF $EXTRACT(N,1,8)="POSSIBLE"
QUIT
+28 IF $EXTRACT(N,1,7)="PERHAPS"
QUIT
+29 IF $EXTRACT(N,1,8)="RULE OUT"
QUIT
+30 IF $EXTRACT(N,1,3)="R/O"
QUIT
+31 IF $EXTRACT(N,1,8)="PROBABLE"
QUIT
+32 IF $EXTRACT(N,1,8)="RESOLVED"
QUIT
+33 IF $EXTRACT(N,1,7)="SUSPECT"
QUIT
+34 IF $EXTRACT(N,1,10)="SUSPICIOUS"
QUIT
+35 IF $EXTRACT(N,1,11)="STATUS POST"
QUIT
+36 SET D=1
End DoDot:2
+37 ;got one visit
IF D
SET G=G+1
SET G($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))=V
End DoDot:1
+38 IF 'G
QUIT G
+39 SET D=$ORDER(G(0))
SET V=G(D)
SET H=$ORDER(^AUPNVINP("AD",V,0))
+40 QUIT 1_U_$ORDER(G(0))_U_V_U_$SELECT(H:$PIECE($PIECE(^AUPNVINP(H,0),U),"."),1:"")_U_H
ASACONTR(P,BGPADM,BGPDD,BDATE,EDATE) ;does patient have an aspirin allergy
+1 KILL BGPMEDS1
+2 SET K=0
SET R=""
SET BGPG=""
+3 DO GETMEDS^BGP5UTL2(P,$$FMADD^XLFDT(BGPADM,-90),BGPDD,,,,,.BGPMEDS1)
+4 IF '$DATA(BGPMEDS1)
GOTO HEM
+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 SET G=0
+9 SET D=$PIECE(^AUPNVMED(Y,0),U)
+10 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO WAR71
+11 SET N=$PIECE($GET(^PSDRUG(D,0)),U,1)
+12 IF N["WARFARIN"
SET G=1
GOTO WAR71
+13 IF $$VAPI^BGP5D81(D,$ORDER(^ATXAX("B","BGP CMS WARFARIN VAPI",0)))
SET G=1
GOTO WAR71
+14 IF 'G
QUIT
WAR71 ;
+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 ;discontinued before admission
IF J]""
IF J<BGPADM
QUIT
+7 SET E=$PIECE($PIECE(^AUPNVSIT(V,0),U),".")
+8 IF E'<BGPADM
IF E'>BGPDD
SET BGPG=1_U_$$DATE^BGP5UTL(E)_U_$PIECE(^PSDRUG(D,0),U)
+9 SET S=$PIECE(^AUPNVMED(Y,0),U,7)
+10 SET Z=$$FMDIFF^XLFDT(BGPADM,$PIECE($PIECE(^AUPNVSIT(V,0),U),"."))
+11 IF S>Z
SET BGPG=1_U_$$DATE^BGP5UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_U_" Contra "_$PIECE(^PSDRUG(D,0),U)
+12 QUIT
End DoDot:1
+13 IF BGPG
QUIT BGPG
HEM ;now check for dx 459
+1 KILL BGPG
SET BGPG=$$LASTDX^BGP5UTL1(P,"BGP HEMORRHAGE DXS",$$DOB^AUPNPAT(P),EDATE)
+2 IF BGPG
QUIT 1_U_"asa Contra "_$PIECE(BGPG,U,2)_" "_$$DATE^BGP5UTL($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 ;documented EDATE OF REPORT PERIOD
IF Y>EDATE
QUIT
+11 SET N=0
FOR
SET N=$ORDER(^AUPNPREF("AA",P,50,X,D,N))
IF N'=+N
QUIT
Begin DoDot:3
+12 IF $PIECE($GET(^AUPNPREF(N,0)),U,7)'="N"
QUIT
+13 ;_" "_" "_$$VAL^XBDIQ1(9000022,X,1101)
SET BGPG=1_U_$$DATE^BGP5UTL($PIECE(^AUPNPREF(N,0),U,3))_" Contra NMI "_$$VAL^XBDIQ1(9000022,N,.04)
End DoDot:3
+14 QUIT
End DoDot:2
+15 QUIT
End DoDot:1
+16 IF BGPG
QUIT BGPG
+17 ;now check for CPT code G8008
+18 SET X=$$CPTI^BGP5DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
+19 IF X
QUIT 1_U_$$DATE^BGP5UTL($PIECE(X,U,2))_U_" Contra CPT G8008"
+20 SET X=$$TRANI^BGP5DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("G8008"))
+21 IF X
QUIT 1_U_$$DATE^BGP5UTL($PIECE(X,U,2))_U_" Contra CPT/TRAN G8008"
+22 QUIT ""