Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BGP8D39

BGP8D39.m

Go to the documentation of this file.
BGP8D39 ; IHS/CMI/LAB - measure C ; 11 Jan 2018  12:20 PM
 ;;18.1;IHS CLINICAL REPORTING;;MAY 25, 2018;Build 66
 ;
MEDCOV ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPN13,BGPN14,BGPN15,BGPN16,BGPN17,BGPN18,BGPN19,BGPN20)=0
 S (BGPN21,BGPN22,BGPN23,BGPN24,BGPN25,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9,BGPD10,BGPD11,BGPD12,BGPD13)=0
 NEW BGPBETA,BGPACEI,BGPCCB,BGPBIG,BGPSULF,BGPTHIA,BGPSTATI,BGPANTI,BGPDPP,BGPDMALL,BGPNWARI,BGPBRONC,BGPINFU
 S (BGPBETA,BGPACEI,BGPCCB,BGPBIG,BGPSULF,BGPTHIA,BGPSTATI,BGPANTI,BGPDPP,BGPDMALL,BGPNWARI,BGPBRONC,BGPINFU)=""
 S BGPVALUE=""
 I 'BGPACTUP S BGPSTOP=1 Q
 I 'BGPACTCL S BGPSTOP=1 Q
 I BGPAGEB>17 S BGPBETA=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA BETA BLOCKER MEDS","BGP PQA BETA BLOCKER NDC","BB") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPBETA,U,1) D
 .S BGPD1=1
 .S %=$P(BGPBETA,U,2) I %>79 S BGPN1=1
 .S BGPN2=$P(BGPBETA,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPBETA,U,4)
 I BGPAGEB>17 S BGPACEI=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA RASA MEDS","BGP PQA RASA NDC","RASA")
 I $P(BGPACEI,U,1) D
 .S BGPD2=1
 .S %=$P(BGPACEI,U,2) I %>79 S BGPN3=1
 .S BGPN4=$P(BGPACEI,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPACEI,U,4)
 I BGPAGEB>17 S BGPCCB=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA CCB MEDS","BGP PQA CCB NDC","CCB") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPCCB,U,1) D
 .S BGPD3=1
 .S %=$P(BGPCCB,U,2) I %>79 S BGPN5=1
 .S BGPN6=$P(BGPCCB,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPCCB,U,4)
 I BGPAGEB>17 S BGPBIG=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA BIGUANIDE MEDS","BGP PQA BIGUANIDE NDC","BIG") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPBIG,U,1) D
 .S BGPD4=1
 .S %=$P(BGPBIG,U,2) I %>79 S BGPN7=1
 .S BGPN8=$P(BGPBIG,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPBIG,U,4)
 I BGPAGEB>17 S BGPSULF=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA SULFONYLUREA MEDS","BGP PQA SULFONYLUREA NDC","SULF") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPSULF,U,1) D
 .S BGPD5=1
 .S %=$P(BGPSULF,U,2) I %>79 S BGPN9=1
 .S BGPN10=$P(BGPSULF,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPSULF,U,4)
 I BGPAGEB>17 S BGPTHIA=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA THIAZOLIDINEDIONE MEDS","BGP PQA THIAZOLIDINEDIONE NDC","THIAZ") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPTHIA,U,1) D
 .S BGPD6=1
 .S %=$P(BGPTHIA,U,2) I %>79 S BGPN11=1
 .S BGPN12=$P(BGPTHIA,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPTHIA,U,4)
 I BGPAGEB>17 S BGPDPP=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA DPP IV MEDS","BGP PQA DPP IV NDC","DPP") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPDPP,U,1) D
 .S BGPD9=1
 .S %=$P(BGPDPP,U,2) I %>79 S BGPN16=1
 .S BGPN17=$P(BGPDPP,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPDPP,U,4)
 I BGPAGEB>17 S BGPDMALL=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA DIABETES ALL CLASS","BGP PQA DIABETES ALL CLASS NDC","DMALL") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPDMALL,U,1) D
 .S BGPD10=1
 .S %=$P(BGPDMALL,U,2) I %>79 S BGPN18=1
 .S BGPN19=$P(BGPDMALL,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPDMALL,U,4)
 I BGPAGEB>17 S BGPSTATI=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA STATIN MEDS","BGP PQA STATIN NDC","STATIN") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPSTATI,U,1) D
 .S BGPD7=1
 .S %=$P(BGPSTATI,U,2) I %>79 S BGPN13=1
 .S BGPN14=$P(BGPSTATI,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPSTATI,U,4)
 I BGPAGEB>17 S BGPNWARI=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA NON-WARF ANTICOAG MEDS","BGP PQA NON-WARF ANTICOAG NDC","ANTICOAG") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPNWARI,U,1) D
 .S BGPD11=1
 .S %=$P(BGPNWARI,U,2) I %>79 S BGPN20=1
 .S BGPN21=$P(BGPNWARI,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPNWARI,U,4)
 I BGPAGEB>17 S BGPANTI=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA ANTIRETROVIRAL MEDS","BGP PQA ANTIRETROVIRAL NDC","ANTIRET") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPANTI,U,1) D
 .S BGPD8=1
 .S %=$P(BGPANTI,U,2) I %>89 S BGPN15=1
 .;S BGPN14=$P(BGPSTATI,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPANTI,U,4)
 ;V18 P1 - ADDED COPD/BRONCHO  BGPN22, BGPN23, BGPD12
 I $$COPD^BGP8D22(DFN,BGPBDATE,BGPEDATE)!($$EMP^BGP8D213(DFN,BGPBDATE,BGPEDATE)) S BGPBRONC=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA LA INHALED BRONCHO MED","BGP PQA LA INHALED BRONCHO NDC","BRONCHO")
 I $P(BGPBRONC,U,1) D
 .S BGPD12=1
 .S %=$P(BGPBRONC,U,2) I %>79 S BGPN22=1
 .S BGPN23=$P(BGPBRONC,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPBRONC,U,4)
 ;V18 P1 BGPN24, BGPN25, BGPD13
 I BGPAGEB>17 S BGPINFU=$$COVERAGE(DFN,BGPBDATE,BGPEDATE,"BGP PQA NON-INFUSED MS MEDS","BGP PQA NON-INFUSED MS NDC","MS") ; return 1 if meets denominator^%coverage^# gap days^# prescriptions
 I $P(BGPINFU,U,1) D
 .S BGPD13=1
 .S %=$P(BGPINFU,U,2) I %>79 S BGPN24=1
 .S BGPN25=$P(BGPINFU,U,3)
 .S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"")_$P(BGPINFU,U,4)
 S BGPVALUE="AC"_"|||"_BGPVALUE
 K A,B,C,D,E,F,G,H,I,J,K,M,N,O,P,Q,R,S,T,V,W,X,Y,Z,BDATE,EDATE,BGPDN,BGPN,BGPG,BGPC,BGPDMALL,BGPSTATI,BGPANTI
 K ^TMP($J,"A"),BGPMEDS1
 Q
 ;
COVERAGE(P,BDATE,EDATE,MTAX,NTAX,TYPE) ;
 K ^TMP($J,"A")
 NEW A,B,E,Z,X,D,V,Y,G,M,T,T1,BGPMEDS1,C,BGPISD,BGPMP,DAYS,LEND,SD,DC,N,S,PER,GAP,Q
 S A="" I TYPE="RASA"!(TYPE="DMALL")!(TYPE="BIG")!(TYPE="SULF")!(TYPE="THIAZ")!(TYPE="DPP") S A=1
 I A,$$ESRD^BGP8D211(P,$P(^DPT(P,0),U,3),BGPEDATE) Q ""
 I TYPE="RASA",$$HASARB(P,BDATE,EDATE) Q ""
 I TYPE="BRONCHO",$$HASNEB(P,BDATE,EDATE) Q ""
 I TYPE="MS",$$HASINFU(P,BDATE,EDATE) Q ""
 I TYPE="ANTICOAG" I $$HADWARF^BGP8D36(P,BDATE,EDATE) Q ""  ;HAD WARFARIN IN TIME PERIOD
 K BGPMEDS1
 D GETMEDS^BGP8UTL2(P,BDATE,EDATE,MTAX,NTAX,,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q ""  ; no meds
 S BGPISD=""
 S (A,C)=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  D
 .S M=$P(BGPMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
 .I $P(^AUPNVMED(M,0),U,8)=$P(BGPMEDS1(A),U,1) K BGPMEDS1(A) Q  ;d/c'ed on same day as visit so no days suppply
 .I '$P(^AUPNVMED(M,0),U,7) K BGPMEDS1(A) Q  ;no days supply
 .;GET PRESCRIPTION #
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q  ; no POS
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q  ;no POS
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q  ;NO EHR OUTSIDE
 .I BGPISD="" S BGPISD=$P(BGPMEDS1(A),U,1)  ;first date
 .S C=C+1
 I C<2 Q ""  ;does not have 2 scripts
 I BGPISD>$$FMADD^XLFDT(EDATE,-90) Q ""  ;INDEX START DATE AFTER EDATE-90
 I TYPE="ANTICOAG" S G=0 D NONW180 I G Q ""
 S BGPMP=$$FMDIFF^XLFDT(EDATE,BGPISD)
 ;COVERAGE
 S DAYS=0,LEND="",GAP=""
 S X=0 F  S X=$O(BGPMEDS1(X)) Q:X'=+X  D
 .S M=+$P(BGPMEDS1(X),U,4)
 .;GET PRESCRIPTION #
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q  ; no POS
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q  ;no POS
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q  ;NO EHR OUTSIDE
 .S V=$P(BGPMEDS1(X),U,5)
 .S SD=$$VD^APCLV(V)  ;start date of med
 .I LEND="" S LEND=SD
 .I LEND,LEND>SD S SD=LEND
 .S G=$$FMDIFF^XLFDT(SD,LEND) I G>30,GAP="" S GAP=G
 .S M=+$P(BGPMEDS1(X),U,4)
 .S DC=$P(^AUPNVMED(M,0),U,8)  ;date discontinued
 .S N=$P(^AUPNVMED(M,0),U,7)  ;days supply
 .I $$FMADD^XLFDT(SD,N)>EDATE S N=$$FMDIFF^XLFDT(EDATE,SD)
 .S S=0 I DC]"",SD]"" S S=$$FMDIFF^XLFDT(DC,SD)
 .I S>0,S<N S N=S
 .;N IS DAYS SUPPLY
 .S LEND=$$FMADD^XLFDT(SD,(N+1))  ;new end date
 .S DAYS=DAYS+N
 I DAYS<61,TYPE="ANTICOAG" Q ""
 I DAYS<56,TYPE="MS" Q ""
 I LEND]"" S G=$$FMDIFF^XLFDT(EDATE,LEND) I G>30,GAP="" S GAP=G
 S PER=$J(((DAYS/BGPMP)*100),3,0)
 S PER=$$STRIP^XLFSTR(PER," ")
 S C=1_U_PER_U_$S(GAP:1,1:"")_U_TYPE_": IXRD: "_$$DATE^BGP8UTL(BGPISD)_" ["_BGPMP_"] Days="_DAYS
 I TYPE'="ANTIRET" S %=$S(PER>79:">80",1:"<80") S C=C_" "_%
 I TYPE="ANTIRET" S %=$S(PER>89:">90",1:"<90") S C=C_" "_%
 I TYPE'="ANTIRET" S C=C_$S(GAP:", GAP="_GAP,1:"")
 ;CALULATE %COVERAGE AND GAP DAYS
 Q C
HASARB(P,BDATE,EDATE) ;
 NEW BGPMEDS1,C,A,M
 K BGPMEDS1
 D GETMEDS^BGP8UTL2(P,BDATE,EDATE,"BGP PQA ARB NEPRILYSIN MEDS","BGP PQA ARB NEPRILYSIN NDC",,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q ""  ; NO MEDS
 S (A,C)=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  D
 .S M=$P(BGPMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .;GET PRESCRIPTION #
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q  ; no POS
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q  ;no POS
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
 .I $P(^AUPNVMED(M,0),U,8)=$P(BGPMEDS1(A),U,1) K BGPMEDS1(A) Q
 .I '$P(^AUPNVMED(M,0),U,7) K BGPMEDS1(A) Q
 .S C=C+1
 .Q
 Q C
HASINFU(P,BDATE,EDATE) ;
 NEW BGPMEDS1,C,A,M,T
 K BGPMEDS1
 D GETMEDS^BGP8UTL2(P,BDATE,EDATE,"BGP PQA INFUSED MS MEDS","BGP PQA INFUSED MS NDC",,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q ""  ; NO MEDS
 S (A,C,T)=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  D
 .S M=$P(BGPMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .;GET PRESCRIPTION #
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q  ; no POS
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q  ;no POS
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q  ;NO EHR OUTSIDE
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
 .I $P(^AUPNVMED(M,0),U,8)=$P(BGPMEDS1(A),U,1) K BGPMEDS1(A) Q  ;d/c'ed on same day as visit so no days suppply
 .I '$P(^AUPNVMED(M,0),U,7) K BGPMEDS1(A) Q  ;no days supply
 .S T=T+$P(^AUPNVMED(M,0),U,7)  ;days supply
 .S C=C+1
 .Q
 ;I C>1,T>55 Q 1
 I C Q 1
 Q 0
HASNEB(P,BDATE,EDATE) ;
 NEW BGPMEDS1,C,A,M
 K BGPMEDS1
 D GETMEDS^BGP8UTL2(P,BDATE,EDATE,"BGP PQA NEBULIZED BRONCHO MEDS","BGP PQA NEBULIZED BRONCHO NDC",,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q ""  ; NO MEDS
 S (A,C)=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  D
 .S M=$P(BGPMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .;GET PRESCRIPTION #
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q  ; no POS
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q  ;no POS
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q  ;NO EHR OUTSIDE
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
 .I $P(^AUPNVMED(M,0),U,8)=$P(BGPMEDS1(A),U,1) K BGPMEDS1(A) Q  ;d/c'ed on same day as visit so no days suppply
 .I '$P(^AUPNVMED(M,0),U,7) K BGPMEDS1(A) Q  ;no days supply
 .S C=C+1
 .Q
 Q C
NONW180 ;
 ;is the index start greater that 180 from last fill date?  if so set g=1
 NEW A,B,C,D
 S A=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  S B=A
 S D=$P(BGPMEDS1(B),U,1)  ;LAST FILL
 I $$FMDIFF^XLFDT(D,BGPISD)<180 S G=1
 Q
COB ;EP
 S (BGPD1,BGPN1)=0
 S BGPVALUE=""
 I 'BGPACTCL S BGPSTOP=1 Q  ;NOT AC
 I BGPAGEB<18 S BGPSTOP=1 Q  ;NOT 18+
 I $$HOSPICE^BGP8D74(DFN,BGPBDATE,BGPEDATE) S BGPSTOP=1 Q  ;HAS HOSPICE INDICATOR
 I $$LASTDX^BGP8UTL1(DFN,"BGP PQA CANCER DXS",BGPBDATE,BGPEDATE) S BGPSTOP=1 Q  ;HAS CANCER DX
 D GETOP
 S (X,C,S)=0 F  S X=$O(BGPOPI(X)) Q:X'=+X  S C=C+1,S=S+$P(BGPOPI(X),U,8)
 I C<2 S BGPSTOP=1 Q  ;did not have 2 scripts on 2 different days
 I S<15 S BGPSTOP=1 Q  ;must have at least days supply of 15
 S BGPD1=1
 ;GET BENZOS
 D GETBENZO
 ;get # of days that have both opi and benzo
 K ^TMP($J,"A")
 S (C,X)=0 F  S X=$O(BGPBENZO(X)) Q:X'=+X  S C=C+1
 I C<2 S T=0 G S
 I '$D(BGPBENZO) S T=0 G S  ;not benzos
 S X=0 F  S X=$O(BGPOPI(X)) Q:X'=+X  S D=$P(BGPOPI(X),U,1),S=$P(BGPOPI(X),U,8),E=$$FMADD^XLFDT(D,S) S ^TMP($J,"A","OPI",D)=BGPOPI(X) F Y=1:1 S G=$$FMADD^XLFDT(D,Y) Q:G>E  S ^TMP($J,"A","OPI",G)=BGPOPI(X)
 S X=0 F  S X=$O(BGPBENZO(X)) Q:X'=+X  S D=$P(BGPBENZO(X),U,1),S=$P(BGPBENZO(X),U,8),E=$$FMADD^XLFDT(D,S) S ^TMP($J,"A","BENZO",D)=BGPBENZO(X) F Y=1:1 S G=$$FMADD^XLFDT(D,Y) Q:G>E  S ^TMP($J,"A","BENZO",G)=BGPBENZO(X)
 S T=0,X=0
 K BGPUDO,BGPBENO
 F  S X=$O(^TMP($J,"A","OPI",X)) Q:X'=+X  I $D(^TMP($J,"A","BENZO",X)) D
 .S T=T+1,BGPUDO($P(^TMP($J,"A","OPI",X),U,1))=$P(^TMP($J,"A","OPI",X),U,2)_U_$P(^TMP($J,"A","OPI",X),U,8),BGPBENO($P(^TMP($J,"A","BENZO",X),U,1))=$P(^TMP($J,"A","BENZO",X),U,2)_U_$P(^TMP($J,"A","BENZO",X),U,8)
 S (C,X)=0 F  S X=$O(BGPUDO(X)) Q:X'=+X  S C=C+1
 I C<2 S X=0 F  S X=$O(BGPOPI(X)) Q:X'=+X!(C>1)  I '$D(BGPUDO(X)) S BGPUDO(X)=$P(BGPOPI(X),U,2),C=C+1
 I T>30 S BGPN1=1
 S X="" S Y=0 F  S Y=$O(BGPUDO(Y)) Q:Y'=+Y  S:X]"" X=X_"; " S X=X_$$DATE^BGP8UTL(Y)_" "_$P(BGPOPI(Y),U,2)_" ["_$P(BGPOPI(Y),U,8)_"]"
S S (BGPVALUE,BGPVALUD)="AC "_X_"|||"
 ;SET NUMERATOR
 S X="" D
 .I BGPN1 D
 ..S Y=0,X="" F  S Y=$O(BGPBENO(Y)) Q:Y'=+Y  S:X]"" X=X_"; " S X=X_$$DATE^BGP8UTL(Y)_" "_$P(BGPBENZO(Y),U,2)_" ["_$P(BGPBENZO(Y),U,8)_"]"
 ..S X=X_" (OVERLAP: "_T_")"
 S BGPVALUE=BGPVALUE_X
 S BGPVALUD=BGPVALUD_X
 K BGPUDO,BGPBENO,BGPOPI,BGPBENZO
 Q
 ;
GETOP ;GET OPIOD MEDS
 K BGPMEDS1
 D GETMEDS^BGP8UTL2(DFN,BGPBDATE,BGPEDATE,"BGP PQA OPIOID MEDS","BGP PQA OPIOID NDC",,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q
 K BGPOPI
 S (A,C)=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  D
 .S M=$P(BGPMEDS1(A),U,4)
 .Q:'$D(^AUPNVMED(M,0))
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
 .I $P(^AUPNVMED(M,0),U,8)=$P(BGPMEDS1(A),U,1) K BGPMEDS1(A) Q
 .S S=$P(^AUPNVMED(M,0),U,7) I 'S K BGPMEDS1(A) Q
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q
 .S D=$P(BGPMEDS1(A),U,1)
 .I $D(BGPOPI(D)),S>$P(BGPOPI(D),U,8) S BGPOPI(D)=BGPMEDS1(A),$P(BGPOPI(D),U,8)=S Q
 .S BGPOPI(D)=BGPMEDS1(A),$P(BGPOPI(D),U,8)=S
 .Q
 K BGPMEDS1
 Q
GETBENZO ;GET OPIOD MEDS
 K BGPMEDS1
 D GETMEDS^BGP8UTL2(DFN,BGPBDATE,BGPEDATE,"BGP PQA BENZODIAZ OP MEDS","BGP PQA BENZODIAZ OP NDC",,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q  ; no meds
 K BGPBENZO
 S (A,C)=0 F  S A=$O(BGPMEDS1(A)) Q:A'=+A  D
 .S M=$P(BGPMEDS1(A),U,4)  ;IEN OF V MED
 .Q:'$D(^AUPNVMED(M,0))
 .I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
 .I $P(^AUPNVMED(M,0),U,8)=$P(BGPMEDS1(A),U,1) K BGPMEDS1(A) Q
 .S S=$P(^AUPNVMED(M,0),U,7) I 'S K BGPMEDS1(A) Q
 .;GET PRESCRIPTION #
 .S Q=$S($D(^PSRX("APCC",M)):$O(^(M,0)),1:0)
 .I Q,$E($P($G(^PSRX(Q,0)),U,1))="X" Q
 .I $E($$VAL^XBDIQ1(9000010.14,M,1102))="X" Q
 .I $$VAL^XBDIQ1(9000010.14,M,1108)]"" Q
 .S D=$P(BGPMEDS1(A),U,1)
 .I $D(BGPBENZO(D)),S>$P(BGPBENZO(D),U,8) S BGPBENZO(D)=BGPMEDS1(A),$P(BGPBENZO(D),U,8)=S Q
 .S BGPBENZO(D)=BGPMEDS1(A),$P(BGPBENZO(D),U,8)=S
 .Q
 K BGPMEDS1
 Q