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

BGP8DPA4.m

Go to the documentation of this file.
BGP8DPA4 ;IHS/CMI/LAB - FORECAST;
 ;;18.1;IHS CLINICAL REPORTING;;MAY 25, 2018;Build 66
 ;
EYE(P,BDATE,EDATE,FORECAST) ;EP
 S BGPLEYE=""
 S FORECAST=$G(FORECAST)
 K BGPG S %=P_"^LAST EXAM DIABETIC EYE EXAM;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,"BGPG(")
 I $D(BGPG(1)) S BGPLEYE="1^"_$P(BGPG(1),U)_"^Diab Eye Ex"
 K ^TMP($J,"A")
 S A="^TMP($J,""A"","
 S %=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,A)
 S X=0,Y=0 F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(Y)  S R=$$CLINIC^APCLV($P(^TMP($J,"A",X),U,5),"C") I R="A2",'$$DNKA^BGP8D21($P(^TMP($J,"A",X),U,5)) S Y=1,D=$P(^TMP($J,"A",X),U)
 I Y,$P(BGPLEYE,U,2)<D S BGPLEYE=3_"^"_D_"^Cl "_R
 S X=0,Y=0 F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(Y)  S R=$$CLINIC^APCLV($P(^TMP($J,"A",X),U,5),"C") I (R=17!(R=18)!(R=64)),'$$DNKA^BGP8D21($P(^TMP($J,"A",X),U,5)) S Y=1,D=$P(^TMP($J,"A",X),U)
 I Y,$P(BGPLEYE,U,2)<D S BGPLEYE=$S(R="A2":3,1:3)_"^"_D_"^Cl "_R
 S (X,Y)=0,D="" F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(Y)  S R=$$PRIMPROV^APCLV($P(^TMP($J,"A",X),U,5),"D") I (R=24!(R=79)!(R="08")),'$$DNKA^BGP8D21($P(^TMP($J,"A",X),U,5)) S Y=1,D=$P(^TMP($J,"A",X),U)
 I Y,$P(BGPLEYE,U,2)<D S BGPLEYE="3^"_D_"^Prv "_R
 ;
 ;K BGPG S %=P_"^LAST DX [BGP EYE EXAM DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,"BGPG(")
 ;I $D(BGPG(1)),$P(BGPLEYE,U,2)<$P(BGPG(1),U) S BGPLEYE="3^"_$P(BGPG(1),U)_"^"_$P(BGPG(1),U,2)_" POV"  -LORI V13
 ;now check cpt taxonomies
 S T=$O(^ATXAX("B","BGP DM RETINAL EXAM CPTS",0))
 I T D  I X]"",$P(BGPLEYE,U,2)<$P(X,U,1) S BGPLEYE=1_U_$P(X,U,1)_U_"CPT: "_$P(X,U,2)
 .S X=$$CPT^BGP8DU(P,BDATE,EDATE,T,5) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,BDATE,EDATE,T,5)
 S T=$O(^ATXAX("B","BGP DM EYE EXAM CPTS",0))
 I T D  I X]"",$P(BGPLEYE,U,2)<$P(X,U,1) S BGPLEYE=3_U_$P(X,U,1)_U_"CPT: "_$P(X,U,2)
 .S X=$$CPT^BGP8DU(P,BDATE,EDATE,T,5) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,BDATE,EDATE,T,5)
 S X=$$LASTPRC^BGP8UTL1(P,"BGP EYE EXAM PROCS",BDATE,EDATE) I X]"",$P(BGPLEYE,U,2)<$P(X,U,3) S BGPLEYE=3_U_$P(X,U,3)_U_"Proc "_$P(X,U,2)
 Q BGPLEYE
EYEREF(P,BDATE,EDATE) ;EP
 S G=$$REFUSAL^BGP8UTL1(P,9999999.15,$O(^AUTTEXAM("B","DIABETIC EYE EXAM",0)),BDATE,EDATE)
 I $P(G,U)=1 Q "2^"_$P(G,U,2)_"^Refused"
 Q ""
STAT ;EP - called from forecast report
 NEW BGPD,BGPSTOP
 S BGPSKIP=""
 S BGPSTOP=""
 D STRC^BGP8D212
 I $G(BGPSTOP) S BGPSKIP=1 Q
 I BGPN2 S BGPSKIP=1 Q  ;has an exclusion
 I 'BGPD7 S BGPSKIP=1 Q  ;not in the denominator
 S BGPD=$$HASSTAT(DFN,BGPBDATE,DT)  ;does the pt have a statin pill on this date?
 I BGPD="" S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)_U_"Last Statin: None on file" D I020X Q
 I $P(BGPD,U,2) S BGPSKIP=1 Q  ;not due has a pill
 S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)
 S $P(BGPISSV,U,2)="Last Statin (in past 5 years): "_$$DATE^BGP8UTL($P(BGPD,U,1))
 S $P(BGPISSV,U,2)="Medication end date: "_$$DATE^BGP8UTL($P(BGPD,U,3)) D I020X Q
I020X ;
 K BGPD,BGPN,BGPN1,BGPREF,BGPNS
 Q
HASSTAT(P,BDATE,EDATE) ;EP
 ;look for last statin v med/cpt
 ;if none Q ""
 ;if found Q date^current?^med end date   current=1 if has a pill left today, 0 if not
 NEW %,E,BGPV,S,R,T,T1,BGPMEDS1,K,C
 S BGPV=""
 S %="",E=+$$CODEN^ICPTCOD("4013F"),%=$$CPTI^BGP8DU(P,BDATE,EDATE,E)
 I % Q $P(%,U,2)_U_1  ;HAS CPT IN REPORT PERIOD SO CURRENT
 ;GET LAST PRESCRIPTION ENTRY
 K BGPMEDS1 S K=0,R=""
 D GETMEDS^BGP8UTL2(P,$$FMADD^XLFDT(BDATE,-(5*365)),EDATE,,,,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q ""
 S T=$O(^ATXAX("B","BGP PQA STATIN MEDS",0))
 S T1=$O(^ATXAX("B","BGP PQA STATIN NDC",0))
 S X="",R="" F  S X=$O(BGPMEDS1(X),-1) Q:X'=+X!(R]"")  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 S=$P(^AUPNVMED(Y,0),U,7)  ;days supply
 .S E=$$FMADD^XLFDT($P(BGPMEDS1(X),U,1),S)
 .S C=""  ;V17.1  FIX
 .I E'<BDATE S C=1
 .S R=$P(BGPMEDS1(X),U,1)_U_C_U_E
 I C Q R
EHROUT ;
 ;any EHR outside meds?
 K BGPMEDS1 S K=0,R=""
 D GETMEDS^BGP8UTL2(P,$$DOB^AUPNPAT(P),EDATE,"BGP PQA STATIN MEDS","BGP PQA STATIN NDC",,,.BGPMEDS1)
 I '$D(BGPMEDS1) Q ""
 S X=0 F  S X=$O(BGPMEDS1(X)) Q:X'=+X!(R]"")  S Y=+$P(BGPMEDS1(X),U,4) D
 .Q:'$D(^AUPNVMED(Y,0))
 .Q:$P($G(^AUPNVMED(Y,11)),U,8)=""  ;NOT AN EHR OUTSIDE MED
 .Q:$$UP^XLFSTR($P($G(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
 .Q:$P(^AUPNVMED(Y,0),U,8)  ;discontinued
 .S V=$P(^AUPNVMED(Y,0),U,3)
 .Q:'V
 .Q:'$D(^AUPNVSIT(V,0))
 .S R=1_U_"Statin: "_$$DATE^BGP8UTL($P($P(^AUPNVSIT(V,0),U),"."))_" "_$$VAL^XBDIQ1(9000010.14,Y,.01)_" (EHR OUTSIDE)"
 Q R
FLU617 ;EP - FLU
 ;get last date and value for patient DFN
 ;date of last^value of last^next date due
 S BGPSKIP=""
 NEW BGPVALUE,BGPD,BGPND
 S BGPAIM=$$AGE^BGP8D36(DFN,2,BGPBDATE)
 I BGPAIM<6 S BGPSKIP=1 Q
 I BGPAGEB>17 S BGPSKIP=1 Q  ;18 and older as of crs v16
 S BGPISSV="",BGPIN=""
 K BGPISSV
 S BGPVALUE=$$FLU^BGP8D3(DFN,BGPBD,BGPED,1)
 I BGPVALUE]"",$P(BGPVALUE,U,3)'=2 S BGPSKIP=1 Q
 S BGPVALUE=$$FLU^BGP8D3(DFN,$$DOB^AUPNPAT(DFN),BGPED,1)
 I BGPVALUE="" S BGPISSV=$$TITLE^BGP8DPA1(BGPGPRAI)_U_"Last IZ: Never|Overdue as of: "_$$DATE^BGP8UTL(BGPBD) Q
 S BGPD=$P(BGPVALUE,U,1)
 S BGPND=$$FMADD^XLFDT(BGPD,365)
 S BGPND=$$DATE^BGP8UTL(BGPND)
 I BGPVALUE["Refus" S BGPIN=1 S BGPISSV=$$TITLE^BGP8DPA1(BGPGPRAI)_U_"Last IZ: patient refused on "_$$DATE^BGP8UTL($P(BGPVALUE,U,1))_"|Overdue as of: "_$$DATE^BGP8UTL(BGPBD) Q
 S BGPISSV=$$TITLE^BGP8DPA1(BGPGPRAI)_U_"Last IZ: "_$$DATE^BGP8UTL(BGPD)_"|Overdue as of: "_BGPND
 Q
SBIRT ;EP - Alcohol Screening
 ;GET LAST POSITIVE ALCOHOL SCREEN
 I BGPAGEB<9 S BGPSKIP=1 Q
 I BGPAGEB>75 S BGPSKIP=1 Q
 S (BGPD,BGPN,BGPN1,BGPREF,BGPNS,BGPV)=""
 NEW BGPALL,BGPABNI,BGPBNID
 K BGPALL
 ;get last positive
 K BGPALL
 D ALSCRN^BGP8D55(DFN,BGPBDATE,BGPEDATE,.BGPALL,1)
 I '$D(BGPALL) S BGPSKIP=1 Q  ; no screens
 NEW X,Y,Z,D,G
 S (D,G)=0 F  S D=$O(BGPALL(D)) Q:D'=+D!(G)  D
 .S Y=0 F  S Y=$O(BGPALL(D,Y)) Q:Y'=+Y!(G)  I $P(BGPALL(D,Y),U,6)["POS" S G=BGPALL(D,Y)
 I 'G S BGPSKIP=1 Q  ;no positive
 ;did patient have bni after this screen?
 K BGPABNI
 S BGPBNID=""
 D BNI^BGP8D24(DFN,$P(G,U,4),$$FMADD^XLFDT($P(G,U,4),7),.BGPABNI)
 I $D(BGPABNI) S BGPSKIP=1 Q  ;HAD A BNI
 S BGPISSV=$$TITLE^BGP8DPA1(BGPGPRAI)_U_"Last Positive Alcohol Screen: "_$$DATE^BGP8UTL($P(G,U,4))_"|BNI/BI Overdue as of "_$$DATE^BGP8UTL($$FMADD^XLFDT($P(G,U,4),7))
 ;
SBIRTX ;
 K BGPD,BGPN,BGPN1,BGPREF,BGPNS
 Q
CVSSTAT ;EP - called from forecast report
 NEW BGPD,BGPSTOP
 S BGPSKIP=""
 S BGPSTOP=""
 D CVD^BGP8D213
 I $G(BGPSTOP) S BGPSKIP=1 Q
 I '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5) S BGPSKIP=1 Q
 I BGPN2 S BGPSKIP=1 Q  ;has an exclusion
 I 'BGPD1 S BGPSKIP=1 Q  ;not in the denominator
 S BGPD=$$HASSTAT(DFN,BGPBDATE,DT)  ;does the pt have a statin pill on this date?
 I BGPD="" S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)_U_"Last Statin: None on file" D CVDSTATX Q
 I $P(BGPD,U,2) S BGPSKIP=1 Q  ;not due has a pill
 S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)
 S $P(BGPISSV,U,2)="Last Statin (in past 5 years): "_$$DATE^BGP8UTL($P(BGPD,U,1))
 S $P(BGPISSV,U,2)="Medication end date: "_$$DATE^BGP8UTL($P(BGPD,U,3)) D CVDSTATX Q
CVDSTATX ;
 K BGPD,BGPN,BGPN1,BGPREF,BGPNS
 Q
IAA18 ;EP
 ;I 'BGPACTUP S BGPSKIP=1 Q
 I BGPAGEB<18 S BGPSKIP=1 Q
 S (BGPD,BGPN,BGPN1,BGPREF,BGPNS)=""
 S BGPN1=$$DEP^BGP8D25(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
 I BGPN1 NEW X S X=$P(BGPN1,U,4) S BGPD=X,BGPV="2 Mood Disorder DXs "
 S BGPN1=$$DEPSCR^BGP8D25(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
 I BGPN1,BGPD<$P(BGPN1,U,4) S BGPD=$P(BGPN1,U,4),BGPV=$P(BGPN1,U,2)
 S BGPN1=$$DEPEDU^BGP8D25(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
 I BGPN1,BGPD<$P(BGPN1,U,4) S BGPD=$P(BGPN1,U,4),BGPV=$P(BGPN1,U,2)
 I BGPD="" S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)_U_"Last Depression Screen: Never|Overdue as of: "_$$DATE^BGP8UTL(BGPBD) D IAAX Q
 S BGPNS=$S(BGPD:$$FMADD^XLFDT(BGPD,365),1:"")
 I BGPNS>BGPED S BGPSKIP=1 D IAAX Q
 S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)_U_"Last Depression Screen: "_$$DATE^BGP8UTL(BGPD)_"|Overdue as of: "_$$DATE^BGP8UTL(BGPNS)
 ;
IAAX ;
 K BGPD,BGPN,BGPN1,BGPREF,BGPNS
 Q
EAPT(P,BDATE,EDATE) ;EP
 ;get all ANTIDEPRESSANTS
 K ^TMP($J,"MEDS")
 NEW BGPZ,M,K,Y,T,T2,X,V,G,D,C
 S K=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 ANTIDEPRESSANT MEDS",0))
 S T2=$O(^ATXAX("B","BGP HEDIS ANTIDEPRESSANT VA CLASS",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))
 .S V=$P(^AUPNVMED(Y,0),U,3)
 .Q:'$D(^AUPNVSIT(V,0))
 .S G=0
 .S D=$P(^AUPNVMED(Y,0),U)
 .I T,$D(^ATXAX(T,21,"B",D)) S G=1 D EAPT1 Q
 .S C=$P($G(^PSDRUG(D,0)),U,2)
 .I C]"",T2,$D(^ATXAX(T2,21,"B",C)) S G=1 D EAPT1 Q
 .Q:'G
 K ^TMP($J,"MEDS")
 Q $O(BGPZ(0))
EAPT1 ;
 S BGPZ($$VD^APCLV(V))=""
 Q
ICRSAMM2 ;EP
 D ICRSAMM^BGP8D51
 I 'BGPD2 S BGPSKIP=1 Q  ;not in up denominator
 I BGPN3 S BGPSKIP=1 Q  ;met numerator
 S L=$$EAPT(DFN,$$FMADD^XLFDT(BGPBDATE,-366),BGPEDATE)
 I L="" S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)_U_"Last RX: Never" D ICRSAM2X Q
 S BGPISSV=$$TITLE^BGP8DPA2(BGPGPRAI)_U_"Last RX: "_$$DATE^BGP8UTL(L)
 ;
ICRSAM2X ;
 K BGPD,BGPN,BGPN1,BGPREF,BGPNS
 Q
ADULTIZ ;EP - ADULT IZ 19+ AGE APPROPRIATE
 F X=1:1:99 S Y="BGPN"_X K @Y
 F X=1:1:99 S Y="BGPD"_X K @Y
 I BGPAGEB<19 S BGPSKIP=1 D ADULTIZQ Q
 NEW BGPVALUE,BGPD,BGPND
 S BGPISSO=1,BGPIN="",BGPIN1=""
 K BGPISSV
 D I13^BGP8D3B
 I $G(BGPSTOP)=1 S BGPSKIP=1 D ADULTIZQ Q
 I BGPD11,BGPN45 S BGPSKIP=1 D ADULTIZQ Q  ;19-59 and up to date
 I BGPD11,'BGPN45 D
 .S BGPVALUE="Immunizations Overdue for: "_$S('BGPN9:" 1 Tdap ever",1:"")
 .I 'BGPN10 S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; 1 Tdap/Td past 10 years"
 I BGPD13,BGPN45 S BGPSKIP=1 D ADULTIZQ Q  ; 60-64 UP TO DATE
 I BGPD13,'BGPN45 D
 .S BGPVALUE="Immunizations Overdue for: "_$S('BGPN9:" 1 Tdap ever",1:"")
 .I 'BGPN10 S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; 1 Tdap/Td past 10 years"
 .I 'BGPN17 S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; 1 Zoster"
 I BGPD3,BGPN45 S BGPSKIP=1 D ADULTIZQ Q  ; 60-64 UP TO DATE
 I BGPD3,'BGPN45 D
 .S BGPVALUE="Immunizations Overdue for: "_$S('BGPN9:" 1 Tdap ever",1:"")
 .I 'BGPN10 S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; 1 Tdap/Td past 10 years"
 .I 'BGPN17 S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; 1 Zoster"
 .I 'BGPN38 S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; 1 up-to-date PPSV23/PCV3"
 I 'BGPN45 S BGPISSV=$$TITLE^BGP8DPA1(BGPGPRAI)_U_BGPVALUE
ADULTIZQ ;
 F X=1:1:99 S Y="BGPN"_X K @Y
 F X=1:1:99 S Y="BGPD"_X K @Y
 K BGPVALUE
 K BGPDTAP,BGPOPV,BGPMMR,BGPD,BGPT,BGPPER,BGPTET,BGPM,BGPMU,BGPME,BGPHIB,BGPHEP,BGPVAR
 Q