BGPMUD09 ; IHS/MSC/SAT - MI measure NQF0105 ;01-Sep-2011 14:56
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;
; BGPMUD01 = tobacco use assessment 0028a
; BGPMUD02 = tobacco use cessation 0028b
; BGPMUD03 = Heart Failure w/ACE Inhibitor or ARB 0081
; BGPMUD04 = Prenatal HIV Screening 0012
; BGPMUD05 = Prenatal Anti-D Immune Globulin 0014
; BGPMUD06 = Control High Blood Pressure 0018
; BGPMUD07 = SMOKING CESSATION MEDICAL ASSIST 0027
; BGPMUD08 = Chlamydia Measure 0033
; BGPMUD09 = Antidepressant Medication Management 0105
; BGPMUD10 = Oncology Colon Cancer Stage III 0385
;
;Code to collect meaningful use report for Antidepressant Med Management 0105
ENTRY ;EP
N START,END,STRING,STRING2
N IEN,INV,RFOUND,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN
N CNT,DIAB,NUM,DIAB,DIABDX,OUTENC,OPHENC,NONENC,VENC,INENC,ERENC
N BGPALL,BGPEXC,BGPH
N BGPDEN,BGPNOT1,BGPNOT2,BGPNUM1,BGPNUM2
N BGPX
; BGPNUM1 = Prescription for AntiDepressant Meds => 84 days
; BGPNUM2 = Prescription for AntiDepressant Meds => 180 days
S (BGPDEN,BGPEXC,BGPNUM1,BGPNUM2,BGPNOT1,BGPNOT2)=""
S BGPX=0
;Pts must be >=18 245 days before the end of the reporting period
S BGPAGEE=$$AGE^AUPNPAT(DFN,$$FMADD^XLFDT(BGPEDATE,-245))
;No need to check further if no age match
Q:BGPAGEE<18
;
;1, 2 & 3) look for encounter with the EP with a 1st diagnosis of major depression and possibly subsequent diagnosis for outpatient
S START=9999999-$$FMADD^XLFDT(BGPBDATE,-245),END=9999999-$$FMADD^XLFDT(BGPEDATE,-245),VALUE=0
S START=START_".2359"
S FIRST=END-0.1 F S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START) D Q:BGPDEN'=""
.S VIEN=0 F S VIEN=$O(^AUPNVSIT("AA",DFN,FIRST,VIEN)) Q:'+VIEN D Q:BGPDEN'=""
..S BGPDT=$P($P($G(^AUPNVSIT(VIEN,0)),U,1),".",1)
..;Check provider, determine if there are visits with E&M codes
..I $$PRV^BGPMUUT1(VIEN,BGPPROV) D
...S BGPX=0
...S BGPX=$$VSTPOV(DFN,VIEN,"BGPMU MAJOR DEPRESSION DX")
...I +BGPX D
....I $$EM1(DFN,VIEN,0) D ; (1)
.....S:$P(BGPX,U,4)=1 BGP1D=$P($P(BGPX,U,3),".",1),BGPDEN="DEP:"_$$DATE^BGPMUUTL(BGP1D)_";"_"EN:"_$$DATE^BGPMUUTL($P(BGPDT,".",1))
....Q:BGPDEN'=""
....I $$EM2(DFN,VIEN) D ; (3)
.....S:$P(BGPX,U,4)=1 BGP1D=$P($P(BGPX,U,3),".",1),BGPDEN="DEP:"_$$DATE^BGPMUUTL(BGP1D)_";"_"EN:"_$$DATE^BGPMUUTL($P(BGPDT,".",1))
....Q:BGPDEN'=""
;
Q:BGPDEN=""
;check PRESCRIPTION for antidepressant meds
S BGPX=$$FIND^BGPMUUT8(DFN,"BGPMU ANTIDEPRESSANT MEDS NDCS",$$FMADD^XLFDT(BGP1D,-30),"",$$FMADD^XLFDT(BGP1D,14))
I '+BGPX S BGPDEN=""
Q:BGPDEN=""
;check for depression or major depression within 120 days before first diagnosis
S BGPX=$$LASTDX^BGPMUUT2(DFN,$$FMADD^XLFDT(BGP1D,-120),$$FMADD^XLFDT(BGP1D,-1),"BGPMU DEPRESSION DX")
I +BGPX S BGPDEN=""
Q:BGPDEN=""
S BGPX=$$LASTDX^BGPMUUT2(DFN,$$FMADD^XLFDT(BGP1D,-120),$$FMADD^XLFDT(BGP1D,-1),"BGPMU MAJOR DEPRESSION DX")
I +BGPX S BGPDEN=""
Q:BGPDEN=""
S BGPX=$$PLTAX(DFN,"BGPMU DEPRESSION DX","C",$$FMADD^XLFDT(BGP1D,-120),BGP1D)
I +BGPX S BGPDEN=""
Q:BGPDEN=""
S BGPX=$$PLTAX(DFN,"BGPMU MAJOR DEPRESSION DX","C",$$FMADD^XLFDT(BGP1D,-120),BGP1D)
I +BGPX S BGPDEN=""
Q:BGPDEN=""
;patient is in the denominator
;
;NUM1
;check PRESCRIPTION for antidepressant meds after 84 days of FIRST diagnosis
S BGPX=0
S BGPX=$$FIND^BGPMUUT8(DFN,"BGPMU ANTIDEPRESSANT MEDS NDCS",$$FMADD^XLFDT(BGP1D,84),"",$S($P($$NOW^XLFDT(),".",1)>BGPEDATE:$$NOW^XLFDT,1:BGPEDATE),"")
I +BGPX S BGPNUM1="M:MED "_$$DATE^BGPMUUTL($P(BGPX,U,3))
S:BGPNUM1="" BGPNOT1="NM:"
;NUM2
;check PRESCRIPTION for antidepressant meds after 180 days of FIRST diagnosis
S BGPX=0
I BGPNUM1'="" D
.S BGPX=$$FIND^BGPMUUT8(DFN,"BGPMU ANTIDEPRESSANT MEDS NDCS",$$FMADD^XLFDT(BGP1D,180),"",$S($P($$NOW^XLFDT(),".",1)>BGPEDATE:$$NOW^XLFDT,1:BGPEDATE),"")
.I +BGPX S BGPNUM2="M:MED "_$$DATE^BGPMUUTL($P(BGPX,U,3))
S:BGPNUM2="" BGPNOT2="NM:"
;
;no exclusions
;
D TOTAL(DFN)
Q
;
TOTAL(DFN) ;See where this patient ends up
N PTCNT,EXCCT,DENCT,NUMCT1,NUMCT2,NOTNUM1,NOTNUM2,TOTALS
S TOTALS=$G(^TMP("BGPMU0105",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0105",$J,BGPMUTF,"DEN",1))
S NUMCT1=+$G(^TMP("BGPMU0105",$J,BGPMUTF,"NUM",1))
S NUMCT2=+$G(^TMP("BGPMU0105",$J,BGPMUTF,"NUM",2))
S NOTNUM1=+$G(^TMP("BGPMU0105",$J,BGPMUTF,"NOT",1))
S NOTNUM2=+$G(^TMP("BGPMU0105",$J,BGPMUTF,"NOT",2))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S DENCT=DENCT+1 S ^TMP("BGPMU0105",$J,BGPMUTF,"DEN",1)=DENCT
;
I BGPNOT1'="" D
.S NOTNUM1=NOTNUM1+1 S ^TMP("BGPMU0105",$J,BGPMUTF,"NOT",1)=NOTNUM1
.I BGPMUTF="C" S ^TMP("BGPMU0105",$J,"PAT",BGPMUTF,"NOT",1,PTCNT)=DFN_U_BGPDEN_U_BGPNOT1
I BGPNOT2'="" D
.S NOTNUM2=NOTNUM2+1 S ^TMP("BGPMU0105",$J,BGPMUTF,"NOT",2)=NOTNUM2
.I BGPMUTF="C" S ^TMP("BGPMU0105",$J,"PAT",BGPMUTF,"NOT",2,PTCNT)=DFN_U_BGPDEN_U_BGPNOT2
;
I BGPNUM1'="" D
.S NUMCT1=NUMCT1+1 S ^TMP("BGPMU0105",$J,BGPMUTF,"NUM",1)=NUMCT1
.I BGPMUTF="C" S ^TMP("BGPMU0105",$J,"PAT",BGPMUTF,"NUM",1,PTCNT)=DFN_U_BGPDEN_U_BGPNUM1
I BGPNUM2'="" D
.S NUMCT2=NUMCT2+1 S ^TMP("BGPMU0105",$J,BGPMUTF,"NUM",2)=NUMCT2
.I BGPMUTF="C" S ^TMP("BGPMU0105",$J,"PAT",BGPMUTF,"NUM",2,PTCNT)=DFN_U_BGPDEN_U_BGPNUM2
S ^TMP("BGPMU0105",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
; BGPICARE(INDICATOR_ID,Timeframe)=Denom Flag
; ^ Num Flag ^ Excl Flag ^ Denom disp ; Num disp ^ Excl disp
S BGPICARE("MU.EP.0105.1",BGPMUTF)=1_U_(BGPNUM1'="")_U_0_U_BGPDEN_";"_$S(BGPNUM1'="":BGPNUM1,1:"")_U_""
Q
;
EM1(DFN,VIEN,FLG) ;check visit for at least 1 E&M code indicating ED, outpatient BH, or outpatient BH requirements POS with a POS modifier
N BGPI,BGPTMP
S BGP2=0
F BGPI=1:1 Q:BGP2'=0 S BGPTMP=$P($T(EM1T+BGPI),";;",2) Q:BGPTMP="" D
.S X=+$$VSTCPT^BGPMUUT1(DFN,VIEN,BGPTMP)
.I +X S BGP2=1
I 'BGP2 D
.S X=+$$VSTCPT^BGPMUUT1(DFN,VIEN,"BGPMU OUTPT BEHAVIOR POS ENC")
.I +X D
..S BGP2=1
..;I $E(FLG,1)=1 S X1=$$VSTMOD(DFN,VIEN,"BGPMU BEHAVIOR HLT MODIFIER") S:+X1 BGP2=1
..;I $E(FLG,1)'=1 S BGP2=1
Q BGP2
EM1T ;
;;BGPMU ENCOUNTER ED CPT
;;BGPMU OUTPT BEHAVIOR HLTH ENC
;
VSTMOD(DFN,VIEN,TAX) ;EP Check to see if the patient had a CPT on a particular visit
N TIEN,X,G,CPTT,CPT,EVDT,MOD1,MOD2
S G=0
I '$G(DFN) Q 0
I $G(TAX)="" Q 0
I $G(VIEN)="" Q 0
S TIEN="" S TIEN=$O(^ATXAX("B",TAX,TIEN)) Q:'TIEN
I '$D(^AUPNVSIT(VIEN,0)) Q 0
I '$D(^AUPNVCPT("AD",VIEN)) Q 0
S X=0 F S X=$O(^AUPNVCPT("AD",VIEN,X)) Q:X'=+X!(G) D Q:+G
.S MOD1=$P(^AUPNVCPT(X,0),U,8)
.I $D(^ATXAX(TIEN,21,"B",MOD1)) S G=1_U_MOD1_U_$P($G(^AUPNVCPT(X,12)),U,1)
.I '+G D
..S MOD2=$P(^AUPNVCPT(X,0),U,9)
..I $D(^ATXAX(TIEN,21,"B",MOD2)) S G=1_U_MOD2_U_$P($G(^AUPNVCPT(X,12)),U,1)
Q G
;
EM2(DFN,VIEN) ;check visit for at least 1 E&M code indicating acute inpatient or non-acute inpatient
N BGPI,BGPTMP
S BGP2=0
F BGPI=1:1 Q:BGP2'=0 S BGPTMP=$P($T(EM2T+BGPI),";;",2) Q:BGPTMP="" D
.S X=+$$VSTCPT^BGPMUUT1(DFN,VIEN,BGPTMP)
.I +X S BGP2=1
Q BGP2
EM2T ;
;;BGPMU NON-ACUTE INPT CPT
;;BGPMU ACUTE INPT ENC
;
VSTPOV(DFN,VIEN,TAX) ;EP Check to see if the patient had an ICD on a particular visit
N TIEN,X,G,ICD,ICDT,EVDT,FR
S FR=0
S G=0
I '$G(DFN) Q 0
I $G(TAX)="" Q 0
I $G(VIEN)="" Q 0
S TIEN="" S TIEN=$O(^ATXAX("B",TAX,TIEN)) I 'TIEN Q 0
I '$D(^AUPNVSIT(VIEN,0)) Q 0
I '$D(^AUPNVPOV("AD",VIEN)) Q 0
S X=0 F S X=$O(^AUPNVPOV("AD",VIEN,X)) Q:X'=+X!(G) D
.I $$ICD^ATXCHK($P(^AUPNVPOV(X,0),U),TIEN,9) S G=X
.Q
I 'G Q 0
I G D
.S ICD=$P($G(^AUPNVPOV(G,0)),U,1),ICDT=$P($G(^ICD9(ICD,0)),U,1)
.S EVDT=$P($G(^AUPNVPOV(G,12)),U,1)
.S FR=$P($G(^AUPNVPOV(G,0)),U,8)
.S G=1_U_ICDT_U_EVDT_U_(FR'=2)
Q $S(G:G,1:0)
;
PLTAX(DFN,TAX,STAT,BDATE,EDATE) ;EP - is DX on problem list 1 or 0
;Input variables
;STAT - A for all problems, C for active problems, I for inactive
;DFN=IEN of the patient
;TAX=Name of the taxonomy
;CDATE=Date to check against
I $G(BDATE)="" S BDATE=0
I $G(EDATE)="" S EDATE=$P($$NOW^XLFDT(),".",1)
I $G(DFN)="" Q 0
I $G(TAX)="" Q 0
I $G(STAT)="" S STAT="A"
N TIEN,PLSTAT S TIEN=$O(^ATXAX("B",TAX,0))
I 'TIEN Q 0
N PROB,ICD,I,SDTE,EDTE,PDTE,EDT
S (PROB,ICD,I)=0
F S PROB=$O(^AUPNPROB("AC",DFN,PROB)) Q:PROB'=+PROB!(+I) D
.I $D(^AUPNPROB(PROB,0)) S ICD=$P($G(^AUPNPROB(PROB,0)),U),PLSTAT=$P($G(^AUPNPROB(PROB,0)),U,12)
.S EDT=$P($G(^AUPNPROB(PROB,0)),U,8)
.S SDTE=$P($G(^AUPNPROB(PROB,0)),U,13)
.I SDTE'="" S EDT=SDTE
.Q:(+BDATE&(EDT>BDATE))!(+EDATE&(EDT<EDATE))
.I $$ICD^ATXCHK(ICD,TIEN,9) D
..S SDTE=$P($G(^AUPNPROB(PROB,0)),U,13)
..S EDTE=$P($G(^AUPNPROB(PROB,0)),U,8)
..I +SDTE S PDTE=SDTE
..E S PDTE=EDTE
..I STAT="A" S Y=$$GET1^DIQ(80,ICD,.01) S I=1_U_Y_U_PDTE_U_PROB
..I (STAT="C")&(PLSTAT="A") S Y=$$GET1^DIQ(80,ICD,.01) S I=1_U_Y_U_PDTE_U_PROB
..I (STAT="I")&(PLSTAT="I") S Y=$$GET1^DIQ(80,ICD,.01) S I=1_U_Y_U_PDTE_U_PROB
Q I
;
TEST ; debug target
S U="^"
S DT=$$DT^XLFDT()
S DFN=876 ; DFN = patient code from VA PATIENT file
S BGPBDATE=3100101 ; BGPBDATE = begin date of report
S BGPEDATE=3101231 ; BGPEDATE = end date of report
S BGPPROV=2 ; BGPPROV = provider code from NEW PERSON file
S BGPMUTF="C" ; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
D ENTRY
Q
BGPMUD09 ; IHS/MSC/SAT - MI measure NQF0105 ;01-Sep-2011 14:56
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;
+3 ; BGPMUD01 = tobacco use assessment 0028a
+4 ; BGPMUD02 = tobacco use cessation 0028b
+5 ; BGPMUD03 = Heart Failure w/ACE Inhibitor or ARB 0081
+6 ; BGPMUD04 = Prenatal HIV Screening 0012
+7 ; BGPMUD05 = Prenatal Anti-D Immune Globulin 0014
+8 ; BGPMUD06 = Control High Blood Pressure 0018
+9 ; BGPMUD07 = SMOKING CESSATION MEDICAL ASSIST 0027
+10 ; BGPMUD08 = Chlamydia Measure 0033
+11 ; BGPMUD09 = Antidepressant Medication Management 0105
+12 ; BGPMUD10 = Oncology Colon Cancer Stage III 0385
+13 ;
+14 ;Code to collect meaningful use report for Antidepressant Med Management 0105
ENTRY ;EP
+1 NEW START,END,STRING,STRING2
+2 NEW IEN,INV,RFOUND,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN
+3 NEW CNT,DIAB,NUM,DIAB,DIABDX,OUTENC,OPHENC,NONENC,VENC,INENC,ERENC
+4 NEW BGPALL,BGPEXC,BGPH
+5 NEW BGPDEN,BGPNOT1,BGPNOT2,BGPNUM1,BGPNUM2
+6 NEW BGPX
+7 ; BGPNUM1 = Prescription for AntiDepressant Meds => 84 days
+8 ; BGPNUM2 = Prescription for AntiDepressant Meds => 180 days
+9 SET (BGPDEN,BGPEXC,BGPNUM1,BGPNUM2,BGPNOT1,BGPNOT2)=""
+10 SET BGPX=0
+11 ;Pts must be >=18 245 days before the end of the reporting period
+12 SET BGPAGEE=$$AGE^AUPNPAT(DFN,$$FMADD^XLFDT(BGPEDATE,-245))
+13 ;No need to check further if no age match
+14 IF BGPAGEE<18
QUIT
+15 ;
+16 ;1, 2 & 3) look for encounter with the EP with a 1st diagnosis of major depression and possibly subsequent diagnosis for outpatient
+17 SET START=9999999-$$FMADD^XLFDT(BGPBDATE,-245)
SET END=9999999-$$FMADD^XLFDT(BGPEDATE,-245)
SET VALUE=0
+18 SET START=START_".2359"
+19 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+20 SET VIEN=0
FOR
SET VIEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,VIEN))
IF '+VIEN
QUIT
Begin DoDot:2
+21 SET BGPDT=$PIECE($PIECE($GET(^AUPNVSIT(VIEN,0)),U,1),".",1)
+22 ;Check provider, determine if there are visits with E&M codes
+23 IF $$PRV^BGPMUUT1(VIEN,BGPPROV)
Begin DoDot:3
+24 SET BGPX=0
+25 SET BGPX=$$VSTPOV(DFN,VIEN,"BGPMU MAJOR DEPRESSION DX")
+26 IF +BGPX
Begin DoDot:4
+27 ; (1)
IF $$EM1(DFN,VIEN,0)
Begin DoDot:5
+28 IF $PIECE(BGPX,U,4)=1
SET BGP1D=$PIECE($PIECE(BGPX,U,3),".",1)
SET BGPDEN="DEP:"_$$DATE^BGPMUUTL(BGP1D)_";"_"EN:"_$$DATE^BGPMUUTL($PIECE(BGPDT,".",1))
End DoDot:5
+29 IF BGPDEN'=""
QUIT
+30 ; (3)
IF $$EM2(DFN,VIEN)
Begin DoDot:5
+31 IF $PIECE(BGPX,U,4)=1
SET BGP1D=$PIECE($PIECE(BGPX,U,3),".",1)
SET BGPDEN="DEP:"_$$DATE^BGPMUUTL(BGP1D)_";"_"EN:"_$$DATE^BGPMUUTL($PIECE(BGPDT,".",1))
End DoDot:5
+32 IF BGPDEN'=""
QUIT
End DoDot:4
End DoDot:3
End DoDot:2
IF BGPDEN'=""
QUIT
End DoDot:1
IF BGPDEN'=""
QUIT
+33 ;
+34 IF BGPDEN=""
QUIT
+35 ;check PRESCRIPTION for antidepressant meds
+36 SET BGPX=$$FIND^BGPMUUT8(DFN,"BGPMU ANTIDEPRESSANT MEDS NDCS",$$FMADD^XLFDT(BGP1D,-30),"",$$FMADD^XLFDT(BGP1D,14))
+37 IF '+BGPX
SET BGPDEN=""
+38 IF BGPDEN=""
QUIT
+39 ;check for depression or major depression within 120 days before first diagnosis
+40 SET BGPX=$$LASTDX^BGPMUUT2(DFN,$$FMADD^XLFDT(BGP1D,-120),$$FMADD^XLFDT(BGP1D,-1),"BGPMU DEPRESSION DX")
+41 IF +BGPX
SET BGPDEN=""
+42 IF BGPDEN=""
QUIT
+43 SET BGPX=$$LASTDX^BGPMUUT2(DFN,$$FMADD^XLFDT(BGP1D,-120),$$FMADD^XLFDT(BGP1D,-1),"BGPMU MAJOR DEPRESSION DX")
+44 IF +BGPX
SET BGPDEN=""
+45 IF BGPDEN=""
QUIT
+46 SET BGPX=$$PLTAX(DFN,"BGPMU DEPRESSION DX","C",$$FMADD^XLFDT(BGP1D,-120),BGP1D)
+47 IF +BGPX
SET BGPDEN=""
+48 IF BGPDEN=""
QUIT
+49 SET BGPX=$$PLTAX(DFN,"BGPMU MAJOR DEPRESSION DX","C",$$FMADD^XLFDT(BGP1D,-120),BGP1D)
+50 IF +BGPX
SET BGPDEN=""
+51 IF BGPDEN=""
QUIT
+52 ;patient is in the denominator
+53 ;
+54 ;NUM1
+55 ;check PRESCRIPTION for antidepressant meds after 84 days of FIRST diagnosis
+56 SET BGPX=0
+57 SET BGPX=$$FIND^BGPMUUT8(DFN,"BGPMU ANTIDEPRESSANT MEDS NDCS",$$FMADD^XLFDT(BGP1D,84),"",$SELECT($PIECE($$NOW^XLFDT(),".",1)>BGPEDATE:$$NOW^XLFDT,1:BGPEDATE),"")
+58 IF +BGPX
SET BGPNUM1="M:MED "_$$DATE^BGPMUUTL($PIECE(BGPX,U,3))
+59 IF BGPNUM1=""
SET BGPNOT1="NM:"
+60 ;NUM2
+61 ;check PRESCRIPTION for antidepressant meds after 180 days of FIRST diagnosis
+62 SET BGPX=0
+63 IF BGPNUM1'=""
Begin DoDot:1
+64 SET BGPX=$$FIND^BGPMUUT8(DFN,"BGPMU ANTIDEPRESSANT MEDS NDCS",$$FMADD^XLFDT(BGP1D,180),"",$SELECT($PIECE($$NOW^XLFDT(),".",1)>BGPEDATE:$$NOW^XLFDT,1:BGPEDATE),"")
+65 IF +BGPX
SET BGPNUM2="M:MED "_$$DATE^BGPMUUTL($PIECE(BGPX,U,3))
End DoDot:1
+66 IF BGPNUM2=""
SET BGPNOT2="NM:"
+67 ;
+68 ;no exclusions
+69 ;
+70 DO TOTAL(DFN)
+71 QUIT
+72 ;
TOTAL(DFN) ;See where this patient ends up
+1 NEW PTCNT,EXCCT,DENCT,NUMCT1,NUMCT2,NOTNUM1,NOTNUM2,TOTALS
+2 SET TOTALS=$GET(^TMP("BGPMU0105",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0105",$JOB,BGPMUTF,"DEN",1))
+4 SET NUMCT1=+$GET(^TMP("BGPMU0105",$JOB,BGPMUTF,"NUM",1))
+5 SET NUMCT2=+$GET(^TMP("BGPMU0105",$JOB,BGPMUTF,"NUM",2))
+6 SET NOTNUM1=+$GET(^TMP("BGPMU0105",$JOB,BGPMUTF,"NOT",1))
+7 SET NOTNUM2=+$GET(^TMP("BGPMU0105",$JOB,BGPMUTF,"NOT",2))
+8 SET PTCNT=TOTALS
+9 SET PTCNT=PTCNT+1
+10 SET DENCT=DENCT+1
SET ^TMP("BGPMU0105",$JOB,BGPMUTF,"DEN",1)=DENCT
+11 ;
+12 IF BGPNOT1'=""
Begin DoDot:1
+13 SET NOTNUM1=NOTNUM1+1
SET ^TMP("BGPMU0105",$JOB,BGPMUTF,"NOT",1)=NOTNUM1
+14 IF BGPMUTF="C"
SET ^TMP("BGPMU0105",$JOB,"PAT",BGPMUTF,"NOT",1,PTCNT)=DFN_U_BGPDEN_U_BGPNOT1
End DoDot:1
+15 IF BGPNOT2'=""
Begin DoDot:1
+16 SET NOTNUM2=NOTNUM2+1
SET ^TMP("BGPMU0105",$JOB,BGPMUTF,"NOT",2)=NOTNUM2
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0105",$JOB,"PAT",BGPMUTF,"NOT",2,PTCNT)=DFN_U_BGPDEN_U_BGPNOT2
End DoDot:1
+18 ;
+19 IF BGPNUM1'=""
Begin DoDot:1
+20 SET NUMCT1=NUMCT1+1
SET ^TMP("BGPMU0105",$JOB,BGPMUTF,"NUM",1)=NUMCT1
+21 IF BGPMUTF="C"
SET ^TMP("BGPMU0105",$JOB,"PAT",BGPMUTF,"NUM",1,PTCNT)=DFN_U_BGPDEN_U_BGPNUM1
End DoDot:1
+22 IF BGPNUM2'=""
Begin DoDot:1
+23 SET NUMCT2=NUMCT2+1
SET ^TMP("BGPMU0105",$JOB,BGPMUTF,"NUM",2)=NUMCT2
+24 IF BGPMUTF="C"
SET ^TMP("BGPMU0105",$JOB,"PAT",BGPMUTF,"NUM",2,PTCNT)=DFN_U_BGPDEN_U_BGPNUM2
End DoDot:1
+25 SET ^TMP("BGPMU0105",$JOB,BGPMUTF,"TOT")=PTCNT
+26 ;Setup iCare array for patient
+27 ; BGPICARE(INDICATOR_ID,Timeframe)=Denom Flag
+28 ; ^ Num Flag ^ Excl Flag ^ Denom disp ; Num disp ^ Excl disp
+29 SET BGPICARE("MU.EP.0105.1",BGPMUTF)=1_U_(BGPNUM1'="")_U_0_U_BGPDEN_";"_$SELECT(BGPNUM1'="":BGPNUM1,1:"")_U_""
+30 QUIT
+31 ;
EM1(DFN,VIEN,FLG) ;check visit for at least 1 E&M code indicating ED, outpatient BH, or outpatient BH requirements POS with a POS modifier
+1 NEW BGPI,BGPTMP
+2 SET BGP2=0
+3 FOR BGPI=1:1
IF BGP2'=0
QUIT
SET BGPTMP=$PIECE($TEXT(EM1T+BGPI),";;",2)
IF BGPTMP=""
QUIT
Begin DoDot:1
+4 SET X=+$$VSTCPT^BGPMUUT1(DFN,VIEN,BGPTMP)
+5 IF +X
SET BGP2=1
End DoDot:1
+6 IF 'BGP2
Begin DoDot:1
+7 SET X=+$$VSTCPT^BGPMUUT1(DFN,VIEN,"BGPMU OUTPT BEHAVIOR POS ENC")
+8 IF +X
Begin DoDot:2
+9 SET BGP2=1
+10 ;I $E(FLG,1)=1 S X1=$$VSTMOD(DFN,VIEN,"BGPMU BEHAVIOR HLT MODIFIER") S:+X1 BGP2=1
+11 ;I $E(FLG,1)'=1 S BGP2=1
End DoDot:2
End DoDot:1
+12 QUIT BGP2
EM1T ;
+1 ;;BGPMU ENCOUNTER ED CPT
+2 ;;BGPMU OUTPT BEHAVIOR HLTH ENC
+3 ;
VSTMOD(DFN,VIEN,TAX) ;EP Check to see if the patient had a CPT on a particular visit
+1 NEW TIEN,X,G,CPTT,CPT,EVDT,MOD1,MOD2
+2 SET G=0
+3 IF '$GET(DFN)
QUIT 0
+4 IF $GET(TAX)=""
QUIT 0
+5 IF $GET(VIEN)=""
QUIT 0
+6 SET TIEN=""
SET TIEN=$ORDER(^ATXAX("B",TAX,TIEN))
IF 'TIEN
QUIT
+7 IF '$DATA(^AUPNVSIT(VIEN,0))
QUIT 0
+8 IF '$DATA(^AUPNVCPT("AD",VIEN))
QUIT 0
+9 SET X=0
FOR
SET X=$ORDER(^AUPNVCPT("AD",VIEN,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+10 SET MOD1=$PIECE(^AUPNVCPT(X,0),U,8)
+11 IF $DATA(^ATXAX(TIEN,21,"B",MOD1))
SET G=1_U_MOD1_U_$PIECE($GET(^AUPNVCPT(X,12)),U,1)
+12 IF '+G
Begin DoDot:2
+13 SET MOD2=$PIECE(^AUPNVCPT(X,0),U,9)
+14 IF $DATA(^ATXAX(TIEN,21,"B",MOD2))
SET G=1_U_MOD2_U_$PIECE($GET(^AUPNVCPT(X,12)),U,1)
End DoDot:2
End DoDot:1
IF +G
QUIT
+15 QUIT G
+16 ;
EM2(DFN,VIEN) ;check visit for at least 1 E&M code indicating acute inpatient or non-acute inpatient
+1 NEW BGPI,BGPTMP
+2 SET BGP2=0
+3 FOR BGPI=1:1
IF BGP2'=0
QUIT
SET BGPTMP=$PIECE($TEXT(EM2T+BGPI),";;",2)
IF BGPTMP=""
QUIT
Begin DoDot:1
+4 SET X=+$$VSTCPT^BGPMUUT1(DFN,VIEN,BGPTMP)
+5 IF +X
SET BGP2=1
End DoDot:1
+6 QUIT BGP2
EM2T ;
+1 ;;BGPMU NON-ACUTE INPT CPT
+2 ;;BGPMU ACUTE INPT ENC
+3 ;
VSTPOV(DFN,VIEN,TAX) ;EP Check to see if the patient had an ICD on a particular visit
+1 NEW TIEN,X,G,ICD,ICDT,EVDT,FR
+2 SET FR=0
+3 SET G=0
+4 IF '$GET(DFN)
QUIT 0
+5 IF $GET(TAX)=""
QUIT 0
+6 IF $GET(VIEN)=""
QUIT 0
+7 SET TIEN=""
SET TIEN=$ORDER(^ATXAX("B",TAX,TIEN))
IF 'TIEN
QUIT 0
+8 IF '$DATA(^AUPNVSIT(VIEN,0))
QUIT 0
+9 IF '$DATA(^AUPNVPOV("AD",VIEN))
QUIT 0
+10 SET X=0
FOR
SET X=$ORDER(^AUPNVPOV("AD",VIEN,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+11 IF $$ICD^ATXCHK($PIECE(^AUPNVPOV(X,0),U),TIEN,9)
SET G=X
+12 QUIT
End DoDot:1
+13 IF 'G
QUIT 0
+14 IF G
Begin DoDot:1
+15 SET ICD=$PIECE($GET(^AUPNVPOV(G,0)),U,1)
SET ICDT=$PIECE($GET(^ICD9(ICD,0)),U,1)
+16 SET EVDT=$PIECE($GET(^AUPNVPOV(G,12)),U,1)
+17 SET FR=$PIECE($GET(^AUPNVPOV(G,0)),U,8)
+18 SET G=1_U_ICDT_U_EVDT_U_(FR'=2)
End DoDot:1
+19 QUIT $SELECT(G:G,1:0)
+20 ;
PLTAX(DFN,TAX,STAT,BDATE,EDATE) ;EP - is DX on problem list 1 or 0
+1 ;Input variables
+2 ;STAT - A for all problems, C for active problems, I for inactive
+3 ;DFN=IEN of the patient
+4 ;TAX=Name of the taxonomy
+5 ;CDATE=Date to check against
+6 IF $GET(BDATE)=""
SET BDATE=0
+7 IF $GET(EDATE)=""
SET EDATE=$PIECE($$NOW^XLFDT(),".",1)
+8 IF $GET(DFN)=""
QUIT 0
+9 IF $GET(TAX)=""
QUIT 0
+10 IF $GET(STAT)=""
SET STAT="A"
+11 NEW TIEN,PLSTAT
SET TIEN=$ORDER(^ATXAX("B",TAX,0))
+12 IF 'TIEN
QUIT 0
+13 NEW PROB,ICD,I,SDTE,EDTE,PDTE,EDT
+14 SET (PROB,ICD,I)=0
+15 FOR
SET PROB=$ORDER(^AUPNPROB("AC",DFN,PROB))
IF PROB'=+PROB!(+I)
QUIT
Begin DoDot:1
+16 IF $DATA(^AUPNPROB(PROB,0))
SET ICD=$PIECE($GET(^AUPNPROB(PROB,0)),U)
SET PLSTAT=$PIECE($GET(^AUPNPROB(PROB,0)),U,12)
+17 SET EDT=$PIECE($GET(^AUPNPROB(PROB,0)),U,8)
+18 SET SDTE=$PIECE($GET(^AUPNPROB(PROB,0)),U,13)
+19 IF SDTE'=""
SET EDT=SDTE
+20 IF (+BDATE&(EDT>BDATE))!(+EDATE&(EDT<EDATE))
QUIT
+21 IF $$ICD^ATXCHK(ICD,TIEN,9)
Begin DoDot:2
+22 SET SDTE=$PIECE($GET(^AUPNPROB(PROB,0)),U,13)
+23 SET EDTE=$PIECE($GET(^AUPNPROB(PROB,0)),U,8)
+24 IF +SDTE
SET PDTE=SDTE
+25 IF '$TEST
SET PDTE=EDTE
+26 IF STAT="A"
SET Y=$$GET1^DIQ(80,ICD,.01)
SET I=1_U_Y_U_PDTE_U_PROB
+27 IF (STAT="C")&(PLSTAT="A")
SET Y=$$GET1^DIQ(80,ICD,.01)
SET I=1_U_Y_U_PDTE_U_PROB
+28 IF (STAT="I")&(PLSTAT="I")
SET Y=$$GET1^DIQ(80,ICD,.01)
SET I=1_U_Y_U_PDTE_U_PROB
End DoDot:2
End DoDot:1
+29 QUIT I
+30 ;
TEST ; debug target
+1 SET U="^"
+2 SET DT=$$DT^XLFDT()
+3 ; DFN = patient code from VA PATIENT file
SET DFN=876
+4 ; BGPBDATE = begin date of report
SET BGPBDATE=3100101
+5 ; BGPEDATE = end date of report
SET BGPEDATE=3101231
+6 ; BGPPROV = provider code from NEW PERSON file
SET BGPPROV=2
+7 ; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
SET BGPMUTF="C"
+8 DO ENTRY
+9 QUIT