BGPMUF09 ; IHS/MSC/MGH - MI measure NQF0052 ;10-Aug-2011 14:56;DU
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;Code to collect meaningful use report for LOW BACK PAIN
ENTRY ;EP
N START,END,BGPNUM,BGPDEN,BGPNUM,STRING,STRING2
N IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN,RESULT
N CNT,DEN,NUM,ERENC,OUTENC,VENC,ORTHENC,LBPENC
S (BGPDEN,BGPNUM,RESULT)=0
S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
S START=START_".2359"
S (DEN,NUM)=0
;Pts must be >18 and <49
;No need to check further if no age match
Q:BGPAGEE<18!(BGPAGEE>49)
S CNT=0
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, Only Low Back Pain visits for chosen provider
..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
..S LBPENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU BACK PAIN DX")
..Q:'+LBPENC
..;Count this visit if Low Back Pain Dx AND proper encounter code
..S ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
..I +ERENC D VSTSTORE Q
..S OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
..I +OUTENC D VSTSTORE Q
..S VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
..I +VENC D VSTSTORE Q
..S ORTHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENC ORTHO CPT")
..I +ORTHENC D VSTSTORE Q
Q:'$D(VIEN)
;Next check to see if the patient has any Dx within certain timeframes prior to first LBP visit
; **Earliest LBP visit will be the last one in VIEN array (VIEN(CNT))
S DEN=$$DEN(DFN,.VIEN,CNT,BGPBDATE,BGPEDATE)
I +DEN D
.;If the patient has LBP, check to see if they are in the numerator
.S NUM=$$NUM(DFN,.VIEN,CNT,BGPBDATE,BGPEDATE)
.D TOTAL(DFN,DEN,NUM)
Q
VSTSTORE ;Store compliant visit into array
;Count this visit if Low Back Pain Dx AND proper encounter code
S CNT=CNT+1
S VDATE=$P($P($G(^AUPNVSIT(IEN,0)),U,1),".")
S VIEN(CNT)=IEN_U_VDATE_U_$P($P(LBPENC,U,3),".")
Q
TOTAL(DFN,DEN,NUM) ;See where this patient ends up
N PTCNT,DENCT,NUMCT,NOTNUM,TOTALS,DENSTR,DXTIME
S TOTALS=$G(^TMP("BGPMU0052",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0052",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0052",$J,BGPMUTF,"NUM"))
S NOTNUM=+$G(^TMP("BGPMU0052",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S DENSTR=""
S DENCT=DENCT+1 S ^TMP("BGPMU0052",$J,BGPMUTF,"DEN")=DENCT
S DENSTR="LBP:"_$$DATE^BGPMUUTL($P(VIEN(CNT),U,3))
S DENSTR=DENSTR_";EN:"_$$DATE^BGPMUUTL($P(VIEN(CNT),U,2))
I +NUM D
.S NUMCT=NUMCT+1 S ^TMP("BGPMU0052",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0052",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DENSTR_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
I +NUM=0 D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0052",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0052",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DENSTR_U_"NM:"_$P(NUM,U,3)_";"_$P(NUM,U,2)
S ^TMP("BGPMU0052",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0052.1",BGPMUTF)=1_U_+NUM_U_""_U_DENSTR_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
DEN(DFN,VIEN,CNT,BGPBDATE,BGPEDATE) ;Check for conditions that would preclude denominator inclusion
N LBPVDATE,PRIORST,PRIOREND,PRIORDX,PRIORPL
S LBPVDATE=$P($P(VIEN(CNT),U,2),".")
S PRIORST=$$FMADD^XLFDT(LBPVDATE,-180),PRIOREND=$$FMADD^XLFDT(LBPVDATE,-1)
S PRIORDX=$$LASTDX^BGPMUUT2(DFN,PRIORST,PRIOREND,"BGPMU BACK PAIN DX")
Q:+PRIORDX 0
S PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU BACK PAIN DX","C",PRIOREND)
Q:$P(PRIORPL,U,3)>=PRIORST 0
S LBP2YR=$$FMADD^XLFDT(BGPEDATE,-730)
;Check for cancer Dx up to 2 years prior to period end
S PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU CANCER DX")
Q:+PRIORDX 0
S PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU CANCER DX","C",BGPEDATE)
Q:$P(PRIORPL,U,3)>=LBP2YR 0
;Check for trauma Dx up to 2 years prior to period end
S PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU TRAUMA DX")
Q:+PRIORDX 0
S PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU TRAUMA DX","C",BGPEDATE)
Q:$P(PRIORPL,U,3)>=LBP2YR 0
;Check for IV drug abuse Dx up to 2 years prior to period end
S PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU IV DRUG ABUSE DX")
Q:+PRIORDX 0
S PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU IV DRUG ABUSE DX","C",BGPEDATE)
Q:$P(PRIORPL,U,3)>=LBP2YR 0
;Check for neurologic impairment Dx up to 2 years prior to period end
S PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU NEUROLOGIC DISORDER DX")
Q:+PRIORDX 0
S PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU NEUROLOGIC DISORDER DX","C",BGPEDATE)
Q:$P(PRIORPL,U,3)>=LBP2YR 0
Q 1
NUM(DFN,VIEN,CNT,BGPBDATE,BGPEDATE) ;Look for spinal imaging study
N SPINAL,LBPDATE,LBPD28
S LBPDATE=$P(VIEN(CNT),U,3),LBPD28=$$FMADD^XLFDT(LBPDATE,28)
;Look for V RADIOLOGY event for spinal study
S SPINAL=$$RAD^BGPMUUT1(DFN,LBPDATE,LBPD28,"BGPMU SPINAL STUDY CPT",7)
;return TRUE if no spinal study found
I +SPINAL Q 0_U_SPINAL
;Look for ORDER for spinal study
S SPINAL=$$FIND^BGPMUUT7(DFN,"BGPMU SPINAL STUDY CPT",LBPDATE,LBPD28) ;RAD procedure check
I +SPINAL Q 0_U_$P(SPINAL,U,2,3)
Q 1
BGPMUF09 ; IHS/MSC/MGH - MI measure NQF0052 ;10-Aug-2011 14:56;DU
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;Code to collect meaningful use report for LOW BACK PAIN
ENTRY ;EP
+1 NEW START,END,BGPNUM,BGPDEN,BGPNUM,STRING,STRING2
+2 NEW IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN,RESULT
+3 NEW CNT,DEN,NUM,ERENC,OUTENC,VENC,ORTHENC,LBPENC
+4 SET (BGPDEN,BGPNUM,RESULT)=0
+5 SET START=9999999-BGPBDATE
SET END=9999999-BGPEDATE
SET VALUE=0
+6 SET START=START_".2359"
+7 SET (DEN,NUM)=0
+8 ;Pts must be >18 and <49
+9 ;No need to check further if no age match
+10 IF BGPAGEE<18!(BGPAGEE>49)
QUIT
+11 SET CNT=0
+12 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+13 SET IEN=0
FOR
SET IEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,IEN))
IF '+IEN
QUIT
Begin DoDot:2
+14 ;Check provider, Only Low Back Pain visits for chosen provider
+15 IF '$$PRV^BGPMUUT1(IEN,BGPPROV)
QUIT
+16 SET LBPENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU BACK PAIN DX")
+17 IF '+LBPENC
QUIT
+18 ;Count this visit if Low Back Pain Dx AND proper encounter code
+19 SET ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
+20 IF +ERENC
DO VSTSTORE
QUIT
+21 SET OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
+22 IF +OUTENC
DO VSTSTORE
QUIT
+23 SET VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
+24 IF +VENC
DO VSTSTORE
QUIT
+25 SET ORTHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENC ORTHO CPT")
+26 IF +ORTHENC
DO VSTSTORE
QUIT
End DoDot:2
End DoDot:1
+27 IF '$DATA(VIEN)
QUIT
+28 ;Next check to see if the patient has any Dx within certain timeframes prior to first LBP visit
+29 ; **Earliest LBP visit will be the last one in VIEN array (VIEN(CNT))
+30 SET DEN=$$DEN(DFN,.VIEN,CNT,BGPBDATE,BGPEDATE)
+31 IF +DEN
Begin DoDot:1
+32 ;If the patient has LBP, check to see if they are in the numerator
+33 SET NUM=$$NUM(DFN,.VIEN,CNT,BGPBDATE,BGPEDATE)
+34 DO TOTAL(DFN,DEN,NUM)
End DoDot:1
+35 QUIT
VSTSTORE ;Store compliant visit into array
+1 ;Count this visit if Low Back Pain Dx AND proper encounter code
+2 SET CNT=CNT+1
+3 SET VDATE=$PIECE($PIECE($GET(^AUPNVSIT(IEN,0)),U,1),".")
+4 SET VIEN(CNT)=IEN_U_VDATE_U_$PIECE($PIECE(LBPENC,U,3),".")
+5 QUIT
TOTAL(DFN,DEN,NUM) ;See where this patient ends up
+1 NEW PTCNT,DENCT,NUMCT,NOTNUM,TOTALS,DENSTR,DXTIME
+2 SET TOTALS=$GET(^TMP("BGPMU0052",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0052",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0052",$JOB,BGPMUTF,"NUM"))
+5 SET NOTNUM=+$GET(^TMP("BGPMU0052",$JOB,BGPMUTF,"NOT"))
+6 SET PTCNT=TOTALS
+7 SET PTCNT=PTCNT+1
+8 SET DENSTR=""
+9 SET DENCT=DENCT+1
SET ^TMP("BGPMU0052",$JOB,BGPMUTF,"DEN")=DENCT
+10 SET DENSTR="LBP:"_$$DATE^BGPMUUTL($PIECE(VIEN(CNT),U,3))
+11 SET DENSTR=DENSTR_";EN:"_$$DATE^BGPMUUTL($PIECE(VIEN(CNT),U,2))
+12 IF +NUM
Begin DoDot:1
+13 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0052",$JOB,BGPMUTF,"NUM")=NUMCT
+14 IF BGPMUTF="C"
SET ^TMP("BGPMU0052",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DENSTR_U_"M:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+15 IF +NUM=0
Begin DoDot:1
+16 SET NOTNUM=NOTNUM+1
SET ^TMP("BGPMU0052",$JOB,BGPMUTF,"NOT")=NOTNUM
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0052",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DENSTR_U_"NM:"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,2)
End DoDot:1
+18 SET ^TMP("BGPMU0052",$JOB,BGPMUTF,"TOT")=PTCNT
+19 ;Setup iCare array for patient
+20 SET BGPICARE("MU.EP.0052.1",BGPMUTF)=1_U_+NUM_U_""_U_DENSTR_";"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
+21 QUIT
DEN(DFN,VIEN,CNT,BGPBDATE,BGPEDATE) ;Check for conditions that would preclude denominator inclusion
+1 NEW LBPVDATE,PRIORST,PRIOREND,PRIORDX,PRIORPL
+2 SET LBPVDATE=$PIECE($PIECE(VIEN(CNT),U,2),".")
+3 SET PRIORST=$$FMADD^XLFDT(LBPVDATE,-180)
SET PRIOREND=$$FMADD^XLFDT(LBPVDATE,-1)
+4 SET PRIORDX=$$LASTDX^BGPMUUT2(DFN,PRIORST,PRIOREND,"BGPMU BACK PAIN DX")
+5 IF +PRIORDX
QUIT 0
+6 SET PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU BACK PAIN DX","C",PRIOREND)
+7 IF $PIECE(PRIORPL,U,3)>=PRIORST
QUIT 0
+8 SET LBP2YR=$$FMADD^XLFDT(BGPEDATE,-730)
+9 ;Check for cancer Dx up to 2 years prior to period end
+10 SET PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU CANCER DX")
+11 IF +PRIORDX
QUIT 0
+12 SET PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU CANCER DX","C",BGPEDATE)
+13 IF $PIECE(PRIORPL,U,3)>=LBP2YR
QUIT 0
+14 ;Check for trauma Dx up to 2 years prior to period end
+15 SET PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU TRAUMA DX")
+16 IF +PRIORDX
QUIT 0
+17 SET PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU TRAUMA DX","C",BGPEDATE)
+18 IF $PIECE(PRIORPL,U,3)>=LBP2YR
QUIT 0
+19 ;Check for IV drug abuse Dx up to 2 years prior to period end
+20 SET PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU IV DRUG ABUSE DX")
+21 IF +PRIORDX
QUIT 0
+22 SET PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU IV DRUG ABUSE DX","C",BGPEDATE)
+23 IF $PIECE(PRIORPL,U,3)>=LBP2YR
QUIT 0
+24 ;Check for neurologic impairment Dx up to 2 years prior to period end
+25 SET PRIORDX=$$LASTDX^BGPMUUT2(DFN,LBP2YR,BGPEDATE,"BGPMU NEUROLOGIC DISORDER DX")
+26 IF +PRIORDX
QUIT 0
+27 SET PRIORPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU NEUROLOGIC DISORDER DX","C",BGPEDATE)
+28 IF $PIECE(PRIORPL,U,3)>=LBP2YR
QUIT 0
+29 QUIT 1
NUM(DFN,VIEN,CNT,BGPBDATE,BGPEDATE) ;Look for spinal imaging study
+1 NEW SPINAL,LBPDATE,LBPD28
+2 SET LBPDATE=$PIECE(VIEN(CNT),U,3)
SET LBPD28=$$FMADD^XLFDT(LBPDATE,28)
+3 ;Look for V RADIOLOGY event for spinal study
+4 SET SPINAL=$$RAD^BGPMUUT1(DFN,LBPDATE,LBPD28,"BGPMU SPINAL STUDY CPT",7)
+5 ;return TRUE if no spinal study found
+6 IF +SPINAL
QUIT 0_U_SPINAL
+7 ;Look for ORDER for spinal study
+8 ;RAD procedure check
SET SPINAL=$$FIND^BGPMUUT7(DFN,"BGPMU SPINAL STUDY CPT",LBPDATE,LBPD28)
+9 IF +SPINAL
QUIT 0_U_$PIECE(SPINAL,U,2,3)
+10 QUIT 1