BGPMUH03 ; IHS/MSC/MMT - MI measure NQF0435-STK-2 ;02-Mar-2011 16:17;DU
;;11.0;IHS CLINICAL REPORTING;**4**;JAN 06, 2011;Build 84
;ED meaningful use hospital measures
ENTRY ;PEP Stroke Measure 2 - Stroke antithrombotic therapy
N START,END,BGPIEN,DFN,BGPVST,BGPISDX,BGPHSDX,BGPAGEE,BGPIPROB,BGPHPROB,STROKE,FIB,EXC,NUM,BGPDIS
N BGPFIBDX,BGPFIBPB,BGPFIBCP,BGPFIBPR
N BGPADM,BGPDT,BGPDSTR,BGPNSTR,BGPVCNT
; BGPTDT=visit date; BGPDSTR='not in numerator' string; BGPNSTR='in numerater' string
S (BGPDT,BGPDSTR,BGPNSTR)=""
S BGPVCNT=0
;Start by finding all admissions during the reporting period
S START=BGPBDATE
S END=BGPEDATE_".2359"
F S START=$O(^DGPM("B",START)) Q:START=""!(START>END) D
.S BGPIEN="" F S BGPIEN=$O(^DGPM("B",START,BGPIEN)) Q:BGPIEN="" D
..Q:$P($G(^DGPM(BGPIEN,0)),U,2)'=1 ;Only include admissions
..S DFN=$P($G(^DGPM(BGPIEN,0)),U,3)
..Q:DFN=""
..S BGPACTUP=$$ACTUPAP^BGPMUEHD(DFN,BGPBDATE,BGPEDATE,BGPBEN)
..I 'BGPACTUP,'$G(BGPXPXPX),'$G(BGPIISO) Q
..S BGPVST=$P($G(^DGPM(BGPIEN,0)),U,27) ;Get the visit
..Q:BGPVST=""
..S BGPADM=$P($$GET1^DIQ(9000010,BGPVST_",",.01,"I"),".",1) ;get admin date
..S BGPAGEE=$$AGE^AUPNPAT(DFN,BGPADM)
..S BGPDIS=$P($G(^DGPM(BGPIEN,0)),U,17) ;Don't use if pt is still an inpt
..Q:BGPDIS=""
..S BGPVCNT=BGPVCNT+1
..;Check for a diagnosis of stroke
..S STROKE=0,EXC=0,NUM=0
..S BGPISDX=$$VSTPOVA^BGPMUUT3(DFN,BGPVST,"BGPMU ISCHEMIC STROKE DX")
..;S BGPIPROB=$$PLTAX^BGPMUUT1(DFN,"BGPMU ISCHEMIC STROKE DX","A")
..;Pt must have both a POV of stoke and it must be an active problem
..;I +BGPISDX&(+BGPIPROB) S STROKE=1
..I +BGPISDX S STROKE=1
..Q:'STROKE
..S BGPDSTR=BGPDT
..;Next check for denominator exclusions
..S EXC=$$EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS)
..;If no exclusions, set up denominator string and see if they had the drug ordered
..I 'EXC D
...S BGPNSTR=""
...S BGPDT=$P($P($G(^AUPNVSIT(BGPVST,0)),U,1),".",1)
...;see if they had the drug ordered
...S NUM=$$NUMER(DFN,BGPDIS)
...I NUM'=0 S BGPNSTR=BGPDT_":"_$P(NUM,U,3)
..;Now add it all up
..D TOTAL(DFN)
Q
TOTAL(DFN) ;add up the totals
N PTCNT,EXCCT,DENCT,NUMCT,TOTALS,DATE,NOTCT
S TOTALS=$G(^TMP("BGPMU0435",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0435",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0435",$J,BGPMUTF,"NUM"))
S EXCCT=+$G(^TMP("BGPMU0435",$J,BGPMUTF,"EXC"))
S NOTCT=+$G(^TMP("BGPMU0435",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S DATE=$$DATE^BGPMUUTL($P($G(^DGPM(BGPIEN,0)),U,1))
S DENCT=DENCT+1
S ^TMP("BGPMU0435",$J,BGPMUTF,"DEN")=DENCT
I EXC="" D
.I +NUM D
..S NUMCT=NUMCT+1 S ^TMP("BGPMU0435",$J,BGPMUTF,"NUM")=NUMCT
..S ^TMP("BGPMU0435",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DATE_U_$P(NUM,U,3)_U_$P(NUM,U,2)
.I +NUM=0 D
..S NOTCT=NOTCT+1 S ^TMP("BGPMU0435",$J,BGPMUTF,"NOT")=NOTCT
..S ^TMP("BGPMU0435",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DATE_U_$P(NUM,U,3)_U_$P(NUM,U,2)
I EXC'="" D
.S EXCCT=EXCCT+1 S ^TMP("BGPMU0435",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0435",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN ;_U_DATE_U_$P(EXC,U,2)
S ^TMP("BGPMU0435",$J,BGPMUTF,"TOT")=PTCNT
S BGPICARE("MU.STK.0435.1",BGPMUTF,DFN)=1_U_+$G(NUM)_U_+EXC_U_DATE_";"_$P($G(NUM),U,3)_";"_$P(EXC,U,2)
Q
EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS) ;See if there are exclusions
N REASON,BGPLOS,BGPHOS,BGPCLIN,BGPECI,DTYPE1,DTYPE2,BGPREF,NOXTHROM
N BGPDISDT
S REASON=""
I BGPAGEE<18 S REASON="1^AGE"
;Check for LOS
S BGPLOS=$$LOS^BGPMUH08(BGPIEN,BGPDIS)
I BGPLOS>120 S REASON="1^LOS"
;Check for discharge reasons
;S DTYPE1=$P($G(^DGPM(BGPDIS,0)),U,4)
S DTYPE2=$P($G(^DGPM(BGPDIS,"IHS")),U,7)
;I DTYPE1'=12 S REASON="1^"_DTYPE1 Q REASON
I (DTYPE2="2")!(DTYPE2="3")!(DTYPE2="4")!(DTYPE2="5")!(DTYPE2="7")!(DTYPE2="43")!(DTYPE2="50")!(DTYPE2="51") S REASON="1^"_DTYPE2 Q REASON
;Check for expired
S DTYPE2=$P($G(^DGPM(BGPDIS,"IHS")),U,7)
I (DTYPE2="20")!(DTYPE2="40")!(DTYPE2="41")!(DTYPE2="42") S REASON="1^"_DTYPE2 Q REASON
;Check for hospice care
S BGPHOS=$$HOSPICE^BGPMUH08(DFN,BGPVST)
I +BGPHOS S REASON=BGPHOS Q REASON
;Check for clinical trial
S BGPCLIN=$$TRIAL^BGPMUH08(DFN,BGPVST)
I +BGPCLIN S REASON=BGPCLIN Q REASON
;Check for elective carotid intervention procedure
S BGPECI=$$ELECTIVE^BGPMUH08(DFN,BGPVST,BGPIEN)
I +BGPECI S REASON=BGPECI Q REASON
;Check for refusals
S BGPREF=$$REF(DFN,BGPVST,BGPDIS)
I +BGPREF S REASON=BGPREF Q REASON
S BGPDISDT=$P($P($G(^DGPM(BGPDIS,0)),U,1),".",1)
S NOXTHROM=$$CPT^BGPMUUT1(DFN,$$FMADD^XLFDT(BGPDISDT,-180),BGPDISDT,"BGPMU WARFARIN THERAPY CPT") ;(DFN,BDATE,EDATE,TAX)
I +NOXTHROM S REASON=NOXTHROM Q REASON
Q REASON
REF(DFN,BGPVST,BGPDIS) ;Find refusals for this medication
N ENDDT,X1,X2,X,MED,BGPEVT,DISDT
S MED=0
S BGPEVT=$P($G(^AUPNVSIT(BGPVST,0)),U,1)
S DISDT=$P($G(^DGPM(BGPDIS,0)),U,1)
S ENDDT=$$FMADD^XLFDT(DISDT,+1)
S TAX="BGPMU ANTITHROMBOTIC NDCS"
S MED=$$MEDREF^BGPMUUT2(DFN,BGPEVT,ENDDT,TAX)
Q MED
NUMER(DFN,BGPDIS) ;Check to see if pt is in the numerator
N DRUG,TAX,MEDTYPE,DDATE
S MEDTYPE="OP",TAX="BGPMU ANTITHROMBOTIC NDCS"
S DDATE=$P($G(^DGPM(BGPDIS,0)),U,1)
S DDATE=$$FMADD^XLFDT(DDATE,1)
S DRUG=$$FIND^BGPMUUT4(DFN,TAX,DDATE,MEDTYPE) ; DRUG = 1_U_NDC
Q DRUG_U_DDATE
BGPMUH03 ; IHS/MSC/MMT - MI measure NQF0435-STK-2 ;02-Mar-2011 16:17;DU
+1 ;;11.0;IHS CLINICAL REPORTING;**4**;JAN 06, 2011;Build 84
+2 ;ED meaningful use hospital measures
ENTRY ;PEP Stroke Measure 2 - Stroke antithrombotic therapy
+1 NEW START,END,BGPIEN,DFN,BGPVST,BGPISDX,BGPHSDX,BGPAGEE,BGPIPROB,BGPHPROB,STROKE,FIB,EXC,NUM,BGPDIS
+2 NEW BGPFIBDX,BGPFIBPB,BGPFIBCP,BGPFIBPR
+3 NEW BGPADM,BGPDT,BGPDSTR,BGPNSTR,BGPVCNT
+4 ; BGPTDT=visit date; BGPDSTR='not in numerator' string; BGPNSTR='in numerater' string
+5 SET (BGPDT,BGPDSTR,BGPNSTR)=""
+6 SET BGPVCNT=0
+7 ;Start by finding all admissions during the reporting period
+8 SET START=BGPBDATE
+9 SET END=BGPEDATE_".2359"
+10 FOR
SET START=$ORDER(^DGPM("B",START))
IF START=""!(START>END)
QUIT
Begin DoDot:1
+11 SET BGPIEN=""
FOR
SET BGPIEN=$ORDER(^DGPM("B",START,BGPIEN))
IF BGPIEN=""
QUIT
Begin DoDot:2
+12 ;Only include admissions
IF $PIECE($GET(^DGPM(BGPIEN,0)),U,2)'=1
QUIT
+13 SET DFN=$PIECE($GET(^DGPM(BGPIEN,0)),U,3)
+14 IF DFN=""
QUIT
+15 SET BGPACTUP=$$ACTUPAP^BGPMUEHD(DFN,BGPBDATE,BGPEDATE,BGPBEN)
+16 IF 'BGPACTUP
IF '$GET(BGPXPXPX)
IF '$GET(BGPIISO)
QUIT
+17 ;Get the visit
SET BGPVST=$PIECE($GET(^DGPM(BGPIEN,0)),U,27)
+18 IF BGPVST=""
QUIT
+19 ;get admin date
SET BGPADM=$PIECE($$GET1^DIQ(9000010,BGPVST_",",.01,"I"),".",1)
+20 SET BGPAGEE=$$AGE^AUPNPAT(DFN,BGPADM)
+21 ;Don't use if pt is still an inpt
SET BGPDIS=$PIECE($GET(^DGPM(BGPIEN,0)),U,17)
+22 IF BGPDIS=""
QUIT
+23 SET BGPVCNT=BGPVCNT+1
+24 ;Check for a diagnosis of stroke
+25 SET STROKE=0
SET EXC=0
SET NUM=0
+26 SET BGPISDX=$$VSTPOVA^BGPMUUT3(DFN,BGPVST,"BGPMU ISCHEMIC STROKE DX")
+27 ;S BGPIPROB=$$PLTAX^BGPMUUT1(DFN,"BGPMU ISCHEMIC STROKE DX","A")
+28 ;Pt must have both a POV of stoke and it must be an active problem
+29 ;I +BGPISDX&(+BGPIPROB) S STROKE=1
+30 IF +BGPISDX
SET STROKE=1
+31 IF 'STROKE
QUIT
+32 SET BGPDSTR=BGPDT
+33 ;Next check for denominator exclusions
+34 SET EXC=$$EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS)
+35 ;If no exclusions, set up denominator string and see if they had the drug ordered
+36 IF 'EXC
Begin DoDot:3
+37 SET BGPNSTR=""
+38 SET BGPDT=$PIECE($PIECE($GET(^AUPNVSIT(BGPVST,0)),U,1),".",1)
+39 ;see if they had the drug ordered
+40 SET NUM=$$NUMER(DFN,BGPDIS)
+41 IF NUM'=0
SET BGPNSTR=BGPDT_":"_$PIECE(NUM,U,3)
End DoDot:3
+42 ;Now add it all up
+43 DO TOTAL(DFN)
End DoDot:2
End DoDot:1
+44 QUIT
TOTAL(DFN) ;add up the totals
+1 NEW PTCNT,EXCCT,DENCT,NUMCT,TOTALS,DATE,NOTCT
+2 SET TOTALS=$GET(^TMP("BGPMU0435",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0435",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0435",$JOB,BGPMUTF,"NUM"))
+5 SET EXCCT=+$GET(^TMP("BGPMU0435",$JOB,BGPMUTF,"EXC"))
+6 SET NOTCT=+$GET(^TMP("BGPMU0435",$JOB,BGPMUTF,"NOT"))
+7 SET PTCNT=TOTALS
+8 SET PTCNT=PTCNT+1
+9 SET DATE=$$DATE^BGPMUUTL($PIECE($GET(^DGPM(BGPIEN,0)),U,1))
+10 SET DENCT=DENCT+1
+11 SET ^TMP("BGPMU0435",$JOB,BGPMUTF,"DEN")=DENCT
+12 IF EXC=""
Begin DoDot:1
+13 IF +NUM
Begin DoDot:2
+14 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0435",$JOB,BGPMUTF,"NUM")=NUMCT
+15 SET ^TMP("BGPMU0435",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DATE_U_$PIECE(NUM,U,3)_U_$PIECE(NUM,U,2)
End DoDot:2
+16 IF +NUM=0
Begin DoDot:2
+17 SET NOTCT=NOTCT+1
SET ^TMP("BGPMU0435",$JOB,BGPMUTF,"NOT")=NOTCT
+18 SET ^TMP("BGPMU0435",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DATE_U_$PIECE(NUM,U,3)_U_$PIECE(NUM,U,2)
End DoDot:2
End DoDot:1
+19 IF EXC'=""
Begin DoDot:1
+20 SET EXCCT=EXCCT+1
SET ^TMP("BGPMU0435",$JOB,BGPMUTF,"EXC")=EXCCT
+21 ;_U_DATE_U_$P(EXC,U,2)
IF BGPMUTF="C"
SET ^TMP("BGPMU0435",$JOB,"PAT",BGPMUTF,"EXC",PTCNT)=DFN
End DoDot:1
+22 SET ^TMP("BGPMU0435",$JOB,BGPMUTF,"TOT")=PTCNT
+23 SET BGPICARE("MU.STK.0435.1",BGPMUTF,DFN)=1_U_+$GET(NUM)_U_+EXC_U_DATE_";"_$PIECE($GET(NUM),U,3)_";"_$PIECE(EXC,U,2)
+24 QUIT
EXCLUDE(DFN,BGPIEN,BGPVST,BGPDIS) ;See if there are exclusions
+1 NEW REASON,BGPLOS,BGPHOS,BGPCLIN,BGPECI,DTYPE1,DTYPE2,BGPREF,NOXTHROM
+2 NEW BGPDISDT
+3 SET REASON=""
+4 IF BGPAGEE<18
SET REASON="1^AGE"
+5 ;Check for LOS
+6 SET BGPLOS=$$LOS^BGPMUH08(BGPIEN,BGPDIS)
+7 IF BGPLOS>120
SET REASON="1^LOS"
+8 ;Check for discharge reasons
+9 ;S DTYPE1=$P($G(^DGPM(BGPDIS,0)),U,4)
+10 SET DTYPE2=$PIECE($GET(^DGPM(BGPDIS,"IHS")),U,7)
+11 ;I DTYPE1'=12 S REASON="1^"_DTYPE1 Q REASON
+12 IF (DTYPE2="2")!(DTYPE2="3")!(DTYPE2="4")!(DTYPE2="5")!(DTYPE2="7")!(DTYPE2="43")!(DTYPE2="50")!(DTYPE2="51")
SET REASON="1^"_DTYPE2
QUIT REASON
+13 ;Check for expired
+14 SET DTYPE2=$PIECE($GET(^DGPM(BGPDIS,"IHS")),U,7)
+15 IF (DTYPE2="20")!(DTYPE2="40")!(DTYPE2="41")!(DTYPE2="42")
SET REASON="1^"_DTYPE2
QUIT REASON
+16 ;Check for hospice care
+17 SET BGPHOS=$$HOSPICE^BGPMUH08(DFN,BGPVST)
+18 IF +BGPHOS
SET REASON=BGPHOS
QUIT REASON
+19 ;Check for clinical trial
+20 SET BGPCLIN=$$TRIAL^BGPMUH08(DFN,BGPVST)
+21 IF +BGPCLIN
SET REASON=BGPCLIN
QUIT REASON
+22 ;Check for elective carotid intervention procedure
+23 SET BGPECI=$$ELECTIVE^BGPMUH08(DFN,BGPVST,BGPIEN)
+24 IF +BGPECI
SET REASON=BGPECI
QUIT REASON
+25 ;Check for refusals
+26 SET BGPREF=$$REF(DFN,BGPVST,BGPDIS)
+27 IF +BGPREF
SET REASON=BGPREF
QUIT REASON
+28 SET BGPDISDT=$PIECE($PIECE($GET(^DGPM(BGPDIS,0)),U,1),".",1)
+29 ;(DFN,BDATE,EDATE,TAX)
SET NOXTHROM=$$CPT^BGPMUUT1(DFN,$$FMADD^XLFDT(BGPDISDT,-180),BGPDISDT,"BGPMU WARFARIN THERAPY CPT")
+30 IF +NOXTHROM
SET REASON=NOXTHROM
QUIT REASON
+31 QUIT REASON
REF(DFN,BGPVST,BGPDIS) ;Find refusals for this medication
+1 NEW ENDDT,X1,X2,X,MED,BGPEVT,DISDT
+2 SET MED=0
+3 SET BGPEVT=$PIECE($GET(^AUPNVSIT(BGPVST,0)),U,1)
+4 SET DISDT=$PIECE($GET(^DGPM(BGPDIS,0)),U,1)
+5 SET ENDDT=$$FMADD^XLFDT(DISDT,+1)
+6 SET TAX="BGPMU ANTITHROMBOTIC NDCS"
+7 SET MED=$$MEDREF^BGPMUUT2(DFN,BGPEVT,ENDDT,TAX)
+8 QUIT MED
NUMER(DFN,BGPDIS) ;Check to see if pt is in the numerator
+1 NEW DRUG,TAX,MEDTYPE,DDATE
+2 SET MEDTYPE="OP"
SET TAX="BGPMU ANTITHROMBOTIC NDCS"
+3 SET DDATE=$PIECE($GET(^DGPM(BGPDIS,0)),U,1)
+4 SET DDATE=$$FMADD^XLFDT(DDATE,1)
+5 ; DRUG = 1_U_NDC
SET DRUG=$$FIND^BGPMUUT4(DFN,TAX,DDATE,MEDTYPE)
+6 QUIT DRUG_U_DDATE