BGPMUF04 ; IHS/MSC/MMT - MU measure NQF0043 ;15-Jul-2011 11:44;MMT
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;
ENTRY ;EP
; expects:
; DFN = patient code from VA PATIENT file
; BGPBDATE = begin date of report
; BGPEDATE = end date of report
; BGPPROV = provider code from NEW PERSON file
; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
N BGP1,BGP2,BGPDEN,BGPNUM,BGPDT,END,FIRST,IEN,START,VDATE,VIEN,BGPZ,BGPX
N AENC,BENC,BGPDSTR,BGPNSTR,IMMC
S (BGPDEN,BGPNUM)=0
;Pts must be 65 years and older
Q:BGPAGEE<65
S START=9999999-BGPBDATE,END=9999999-BGPEDATE
;look for 2 visits with E&M codes (outpatient encounters)
; OR 1 visit with E&M codes (preventive medicine encounter)
S (BGP1,BGP2)=0
S (BGPDSTR,BGPNSTR)=""
S FIRST=END-0.1 F S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START) D
.S IEN=0 F S IEN=$O(^AUPNVSIT("AA",DFN,FIRST,IEN)) Q:'+IEN D
..;Check provider, determine if there are visits with E&M codes
..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
..;Check E&M
..S AENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU PNEUMO ENC EM")
..S BENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU PNEUMO ENC ICD")
..Q:(AENC=0)&(BENC=0)
..S DATA=$G(^AUPNVSIT(IEN,0))
..S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1),VIEN=IEN
I +$G(VIEN) D
.S BGPDEN=1
.S BGPDSTR="EN "_$$DATE^BGPMUUTL($G(VDATE))
.;Setup numerator
.;get all immunizations
.S C="33^100^133"
.S CPTS="90669^90670^90732"
.K BGPX D GETIMMS^BGPMUUT2(DFN,BGPEDATE,C,.BGPX,CPTS)
.I $D(BGPX) D
..S IMMC=""
..F S IMMC=$O(BGPX(IMMC)) Q:IMMC="" D
...S IMMD=BGPX(IMMC)
...S IMMV=$P(IMMD,U,2)
...S IMMDATE=$P($G(^AUPNVSIT(IMMV,0)),U,1)
...S BGPNUM=1
...S BGPNSTR=$S($P(IMMD,U,3):$P(IMMD,U,1),1:$P($G(^AUTTIMM($P(IMMD,U,1),0)),U,3))_" "_$$DATE^BGPMUUTL($P(IMMDATE,".",1))
...Q
.D TOTAL(DFN)
K BGP1,BGP2,BGPDEN,BGPNUM,BGPDT,END,FIRST,IEN,START,VDATE,VIEN,BGPZ,BGPX
K AENC,BENC
Q
;
TOTAL(DFN) ;See where this patient ends up
N PTCNT,EXCCT,DENCT,NUMCT,TOTALS
S TOTALS=+$G(^TMP("BGPMU0043",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0043",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0043",$J,BGPMUTF,"NUM"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
Q:'BGPDEN
S DENCT=DENCT+1 S ^TMP("BGPMU0043",$J,BGPMUTF,"DEN")=DENCT
I +BGPNUM D
.S NUMCT=NUMCT+1 S ^TMP("BGPMU0043",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0043",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_BGPDSTR_U_BGPNSTR
I 'BGPNUM&(BGPMUTF="C") S ^TMP("BGPMU0043",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_BGPDSTR_U_BGPNSTR
S ^TMP("BGPMU0043",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0043.1",BGPMUTF)=+BGPDEN_U_+BGPNUM_U_""_U_BGPDSTR_";"_BGPNSTR
K PTCNT,EXCCT,DENCT,NUMCT,TOTALS
Q
;
TEST ; debug target
;S U="^"
;S DT=$$DT^XLFDT()
;S DFN=184 ; DFN = patient code from VA PATIENT file
;S BGPBDATE=3110101 ; BGPBDATE = begin date of report
;S BGPEDATE=3110301 ; 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
BGPMUF04 ; IHS/MSC/MMT - MU measure NQF0043 ;15-Jul-2011 11:44;MMT
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;
ENTRY ;EP
+1 ; expects:
+2 ; DFN = patient code from VA PATIENT file
+3 ; BGPBDATE = begin date of report
+4 ; BGPEDATE = end date of report
+5 ; BGPPROV = provider code from NEW PERSON file
+6 ; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
+7 NEW BGP1,BGP2,BGPDEN,BGPNUM,BGPDT,END,FIRST,IEN,START,VDATE,VIEN,BGPZ,BGPX
+8 NEW AENC,BENC,BGPDSTR,BGPNSTR,IMMC
+9 SET (BGPDEN,BGPNUM)=0
+10 ;Pts must be 65 years and older
+11 IF BGPAGEE<65
QUIT
+12 SET START=9999999-BGPBDATE
SET END=9999999-BGPEDATE
+13 ;look for 2 visits with E&M codes (outpatient encounters)
+14 ; OR 1 visit with E&M codes (preventive medicine encounter)
+15 SET (BGP1,BGP2)=0
+16 SET (BGPDSTR,BGPNSTR)=""
+17 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+18 SET IEN=0
FOR
SET IEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,IEN))
IF '+IEN
QUIT
Begin DoDot:2
+19 ;Check provider, determine if there are visits with E&M codes
+20 IF '$$PRV^BGPMUUT1(IEN,BGPPROV)
QUIT
+21 ;Check E&M
+22 SET AENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU PNEUMO ENC EM")
+23 SET BENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU PNEUMO ENC ICD")
+24 IF (AENC=0)&(BENC=0)
QUIT
+25 SET DATA=$GET(^AUPNVSIT(IEN,0))
+26 SET VDATE=$PIECE($GET(^AUPNVSIT(IEN,0)),U,1)
SET VIEN=IEN
End DoDot:2
End DoDot:1
+27 IF +$GET(VIEN)
Begin DoDot:1
+28 SET BGPDEN=1
+29 SET BGPDSTR="EN "_$$DATE^BGPMUUTL($GET(VDATE))
+30 ;Setup numerator
+31 ;get all immunizations
+32 SET C="33^100^133"
+33 SET CPTS="90669^90670^90732"
+34 KILL BGPX
DO GETIMMS^BGPMUUT2(DFN,BGPEDATE,C,.BGPX,CPTS)
+35 IF $DATA(BGPX)
Begin DoDot:2
+36 SET IMMC=""
+37 FOR
SET IMMC=$ORDER(BGPX(IMMC))
IF IMMC=""
QUIT
Begin DoDot:3
+38 SET IMMD=BGPX(IMMC)
+39 SET IMMV=$PIECE(IMMD,U,2)
+40 SET IMMDATE=$PIECE($GET(^AUPNVSIT(IMMV,0)),U,1)
+41 SET BGPNUM=1
+42 SET BGPNSTR=$SELECT($PIECE(IMMD,U,3):$PIECE(IMMD,U,1),1:$PIECE($GET(^AUTTIMM($PIECE(IMMD,U,1),0)),U,3))_" "_$$DATE^BGPMUUTL($PIECE(IMMDATE,".",1))
+43 QUIT
End DoDot:3
End DoDot:2
+44 DO TOTAL(DFN)
End DoDot:1
+45 KILL BGP1,BGP2,BGPDEN,BGPNUM,BGPDT,END,FIRST,IEN,START,VDATE,VIEN,BGPZ,BGPX
+46 KILL AENC,BENC
+47 QUIT
+48 ;
TOTAL(DFN) ;See where this patient ends up
+1 NEW PTCNT,EXCCT,DENCT,NUMCT,TOTALS
+2 SET TOTALS=+$GET(^TMP("BGPMU0043",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0043",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0043",$JOB,BGPMUTF,"NUM"))
+5 SET PTCNT=TOTALS
+6 SET PTCNT=PTCNT+1
+7 IF 'BGPDEN
QUIT
+8 SET DENCT=DENCT+1
SET ^TMP("BGPMU0043",$JOB,BGPMUTF,"DEN")=DENCT
+9 IF +BGPNUM
Begin DoDot:1
+10 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0043",$JOB,BGPMUTF,"NUM")=NUMCT
+11 IF BGPMUTF="C"
SET ^TMP("BGPMU0043",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_BGPDSTR_U_BGPNSTR
End DoDot:1
+12 IF 'BGPNUM&(BGPMUTF="C")
SET ^TMP("BGPMU0043",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_BGPDSTR_U_BGPNSTR
+13 SET ^TMP("BGPMU0043",$JOB,BGPMUTF,"TOT")=PTCNT
+14 ;Setup iCare array for patient
+15 SET BGPICARE("MU.EP.0043.1",BGPMUTF)=+BGPDEN_U_+BGPNUM_U_""_U_BGPDSTR_";"_BGPNSTR
+16 KILL PTCNT,EXCCT,DENCT,NUMCT,TOTALS
+17 QUIT
+18 ;
TEST ; debug target
+1 ;S U="^"
+2 ;S DT=$$DT^XLFDT()
+3 ;S DFN=184 ; DFN = patient code from VA PATIENT file
+4 ;S BGPBDATE=3110101 ; BGPBDATE = begin date of report
+5 ;S BGPEDATE=3110301 ; BGPEDATE = end date of report
+6 ;S BGPPROV=2 ; BGPPROV = provider code from NEW PERSON file
+7 ;S BGPMUTF="C" ; BGPMUTF = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
+8 ;D ENTRY
+9 QUIT