BGPMUA09 ; IHS/MSC/MGH - MI measure NQF0062 & NQF0064 ;25-Jul-2011 08:19;DU
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;Code to collect meaningful use reports
ENTRY1 ;EP Entry point for NQA0062 for nephropathy
N START,END,BGPNUM,BGPDEN,BGPNUM,STRING,BGPHYPER,BGPHYPL
N IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT
N CNT,DIAB,NUM,EXC,DIAB,OUTENC,OPHENC,NONENC,VENC,DIABDX,ERENC,INENC
S (BGPDEN,BGPNUM,RESULT)=0
S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
S START=START_".2359"
S (STRING,STRING2)="",DIABDX=0
S (DIAB,EXC,NUM)=0
;Pts must be >18 and <75
;No need to check further if no age match
Q:BGPAGEE<18!(BGPAGEE>75)
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 visits for chosen provider
..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
..S OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
..I +OUTENC D VSTSTORE Q
..S OPHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU OPTHAMOLOGY CPTS")
..I +OPHENC D VSTSTORE Q
..S NONENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU NON-ACUTE INPT CPT")
..I +NONENC D VSTSTORE Q
..S INENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
..I +INENC D VSTSTORE Q
..S ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
..I +ERENC D VSTSTORE Q
..S VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
..I +VENC D VSTSTORE Q
;Next check to see if the patient is in the denominator
;Denominator is that the pt had a diabetes medicine
;in the last 2 years or a DX of diabetes in the last 2 years along with
;one inpt visit or 2 or more outpt visits
S DIAB=$$DIAB^BGPMUA06(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX)
I +DIAB D
.;If the patient is diabetetic, check to see if they are in the numerator
.S NUM=$$NUM1(DFN,BGPBDATE,BGPEDATE)
.;If not in the numerator,see if they are an exception
.I +NUM=0&(+DIAB=2) S EXC=$$EXCEPT^BGPMUA06(DFN,BGPBDATE,BGPEDATE,DIABDX)
.D TOTAL1(DFN,DIAB,NUM,EXC)
Q
VSTSTORE ;Store compliant visit in array
S CNT=CNT+1
S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
S VIEN(CNT)=IEN_U_VDATE
S STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
Q
TOTAL1(DFN,DIAB,NUM,EXC) ;See where this patient ends up
N PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DXTIME,DEN
S TOTALS=$G(^TMP("BGPMU0062",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0062",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0062",$J,BGPMUTF,"NUM"))
S EXCCT=+$G(^TMP("BGPMU0062",$J,BGPMUTF,"EXC"))
S NOTNUM=+$G(^TMP("BGPMU0062",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S (DEN,DXTIME)=""
S DENCT=DENCT+1 S ^TMP("BGPMU0062",$J,BGPMUTF,"DEN")=DENCT
I $P(DIAB,U,3)'="" S DXTIME=$$DATE^BGPMUUTL($P(DIAB,U,3))
S DEN=$P(DIAB,U,2)_" "_DXTIME
I $D(STRING(1)) S DEN=DEN_";EN:"_STRING(1)
I $D(STRING(2)) S DEN=DEN_";EN:"_STRING(2)
I +EXC D
.S EXCCT=EXCCT+1 S ^TMP("BGPMU0062",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0062",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
I +NUM D
.S NUMCT=NUMCT+1 S ^TMP("BGPMU0062",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0062",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
I +NUM=0&(EXC=0) D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0062",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0062",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
S ^TMP("BGPMU0062",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0062.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
NUM1(DFN,BGPBDATE,BGPEDATE) ;Look for wide range of items to satisfy this measure
N FOUND,YR1,YR2,HGBA1C,DATA,IEN,RESULT,TAX,NEPHDX,NEPHDX2,NEPCPT,NEPICD0,ACE,ARB
N LABIEN,MICRO,VAL,VAL2,DATA2,RESULT2,SCREEN,NEPHDX
S FOUND=0
;Set date 1yr before end
N X1,X2,X S X1=BGPEDATE,X2=-365 D C^%DTC S YR1=X
;First check for DX of nephropathy
S NEPHDX=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB NEPHROPATHY DX")
I +NEPHDX S FOUND=1_U_$P(NEPHDX,U,2)_U_$P(NEPHDX,U,3) Q FOUND
S NEPHDX2=$$PLTAX^BGPMUUT1(DFN,"BGPMU DIAB NEPHROPATHY DX","A",BGPEDATE)
I +NEPHDX2 S FOUND=1_U_$P(NEPHDX2,U,2)_U_$P(NEPHDX2,U,3) Q FOUND
;Second, check for nephropathy procedures
S NEPCPT=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB NEPH PROC CPT")
I +NEPCPT S FOUND=1_U_$P(NEPCPT,U,2)_U_$P(NEPCPT,U,3) Q FOUND
S NEPICD0=$$LASTPRC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB NEPH PROC ICD0")
I +NEPICD0 S FOUND=1_U_$P(NEPICD0,U,2)_U_$P(NEPICD0,U,3) Q FOUND
;Third check to see if the patient is on an ACE/ARB
S ACE=$$FIND^BGPMUUT8(DFN,"BGPMU ACE INHIBITOR NDC",BGPBDATE,"",BGPEDATE)
I +ACE S FOUND=1_U_"ACE"_U_$P(ACE,U,3) Q FOUND
S ARB=$$FIND^BGPMUUT8(DFN,"BGPMU ARB NDCS",BGPBDATE,"",BGPEDATE)
I +ARB S FOUND=1_U_"ARB"_U_$P(ARB,U,3) Q FOUND
;Fourth check for microalbumin
S MICRO=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB MICRO CPT")
I +MICRO S FOUND=1_U_$P(MICRO,U,2)_U_$P(MICRO,U,3) Q FOUND
S TAX="BGPMU LAB CPT MICRO"
D LABCPT^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
S VAL="" S VAL=$O(DATA(VAL))
I +VAL D
.S RESULT=$G(DATA(VAL))
.I +RESULT>0 S FOUND=1_U_"ACR"_U_(9999999-VAL)
E D
.S TAX="BGPMU LAB LOINC MICROALBUMIN"
.D LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
.S VAL="" S VAL=$O(DATA(VAL))
.I VAL="" S FOUND=$$VLAB^BGPMUA08(DFN,BGPBDATE,BGPEDATE,TAX)
.E D
..S RESULT=$G(DATA(VAL))
..I +RESULT>0 S FOUND=1_U_"ACR"_U_(9999999-VAL)
I +FOUND Q FOUND
;Fifth check for nephropathy screening
S SCREEN=$$CPT^BGPMUUT1(DFN,YR1,BGPEDATE,"BGPMU DIAB NEPH SCREEN CPT")
I +SCREEN S FOUND=1_U_$P(SCREEN,U,2)_U_$P(SCREEN,U,3) Q FOUND
S TAX="BGPMU LAB CPT NEPH"
D LABCPT^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
S VAL="" S VAL=$O(DATA(VAL))
I +VAL D
.S RESULT=$G(DATA(VAL))
.I +RESULT>0 S FOUND=1_U_"NEP"_U_(9999999-VAL)
E D
.S TAX="BGPMU LAB LOINC NEPHROPATHY"
.D LAB^BGPMUUT5(.DATA2,DFN,TAX,BGPBDATE,BGPEDATE)
.S VAL2="" S VAL2=$O(DATA2(VAL2))
.I VAL2="" S FOUND=$$VLAB(DFN,BGPBDATE,BGPEDATE,TAX)
.E D
..S RESULT2=$G(DATA2(VAL2))
..I +RESULT2 S FOUND=1_U_"NEP"_U_(9999999-VAL2)
Q FOUND
VLAB(DFN,BGPBDATE,BGPEDATE,TAX) ;get lab results
N VLAB,LABVAL,LIEN
S LABVAL=0
S VLAB=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,TAX)
I VLAB D
.S LIEN=$P(VLAB,U,2)
.S LABVAL=1_U_$P($G(^AUPNVLAB(LIEN,0)),U,4)_U_$P(VLAB,U,1)
Q LABVAL
ENTRY2 ;EP Entry point for NQA0064 for LDL<100
N START,END,BGPNUM,BGPDEN,BGPNUM,AENC,BENC,STRING,STRING2
N IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT,INENC
N CNT,DIAB,EXC,NUM1,NUM2,DIAB,OUTENC,OPHENC,NONENC,VENC,DIABDX,ERENC
S (BGPDEN,BGPNUM,RESULT)=0
S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
S START=START_".2359"
S (STRING,STRING2)="",DIABDX=0
S (DIAB,EXC,NUM)=0
;Pts must be >18 and <75
;No need to check further if no age match
Q:BGPAGEE<18!(BGPAGEE>75)
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 visits for chosen provider
..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
..S OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
..I +OUTENC D VSTSTORE Q
..S OPHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU OPTHAMOLOGY CPTS")
..I +OPHENC D VSTSTORE Q
..S NONENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU NON-ACUTE INPT CPT")
..I +NONENC D VSTSTORE Q
..S INENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
..I +INENC D VSTSTORE Q
..S ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
..I +ERENC D VSTSTORE Q
..S VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
..I +VENC D VSTSTORE Q
;Next check to see if the patient is in the denominator
;Denominator is that the pt had a diabetes medicine
;in the last 2 years or a DX of diabetes in the last 2 years along with
;one inpt visit or 2 or more outpt visits
S DIAB=$$DIAB^BGPMUA06(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX)
I +DIAB D
.;If the patient is diabetetic, check to see if they are in the numerator
.S NUM=$$NUM2(DFN,BGPBDATE,BGPEDATE)
.;If not in the numerator,see if they are an exception
.I +NUM=0&(+DIAB=2) S EXC=$$EXCEPT^BGPMUA06(DFN,BGPBDATE,BGPEDATE,DIABDX)
.D TOTAL2(DFN,DIAB,NUM,EXC)
Q
TOTAL2(DFN,DIAB,NUM,EXC) ;See where this patient ends up
N PTCNT,EXCCT,DENCT,NUM1CT,NUM2CT,NOTNUM,TOTALS,DXTIME,DEN,NOTNUM1,NOTNUM2
S TOTALS=$G(^TMP("BGPMU0064",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0064",$J,BGPMUTF,"DEN"))
S NUM1CT=+$G(^TMP("BGPMU0064",$J,BGPMUTF,"NUM1"))
S NUM2CT=+$G(^TMP("BGPMU0064",$J,BGPMUTF,"NUM2"))
S EXCCT=+$G(^TMP("BGPMU0064",$J,BGPMUTF,"EXC"))
S NOTNUM1=+$G(^TMP("BGPMU0064",$J,BGPMUTF,"NOT1"))
S NOTNUM2=+$G(^TMP("BGPMU0064",$J,BGPMUTF,"NOT2"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S (DEN,DXTIME)=""
S DENCT=DENCT+1 S ^TMP("BGPMU0064",$J,BGPMUTF,"DEN")=DENCT
I $P(DIAB,U,3)'="" S DXTIME=$$DATE^BGPMUUTL($P(DIAB,U,3))
S DEN=$P(DIAB,U,2)_" "_DXTIME
I $D(STRING(1)) S DEN=DEN_";EN:"_STRING(1)
I $D(STRING(2)) S DEN=DEN_";EN:"_STRING(2)
I +EXC D
.S EXCCT=EXCCT+1 S ^TMP("BGPMU0064",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0064",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
I +NUM D
.S NUM1CT=NUM1CT+1 S ^TMP("BGPMU0064",$J,BGPMUTF,"NUM1")=NUM1CT
.I BGPMUTF="C" S ^TMP("BGPMU0064",$J,"PAT",BGPMUTF,"NUM1",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,3)_";"_$P(NUM,U,4)
I +NUM=0&(EXC=0) D
.S NOTNUM1=NOTNUM1+1 S ^TMP("BGPMU0064",$J,BGPMUTF,"NOT1")=NOTNUM1
.I BGPMUTF="C" S ^TMP("BGPMU0064",$J,"PAT",BGPMUTF,"NOT1",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,3)_";"_$P(NUM,U,4)
I $P(NUM,U,2)=1 D
.S NUM2CT=NUM2CT+1 S ^TMP("BGPMU0064",$J,BGPMUTF,"NUM2")=NUM2CT
.I BGPMUTF="C" S ^TMP("BGPMU0064",$J,"PAT",BGPMUTF,"NUM2",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,3)_";"_$P(NUM,U,4)
I $P(NUM,U,2)=0&(EXC=0) D
.S NOTNUM2=NOTNUM2+1 S ^TMP("BGPMU0064",$J,BGPMUTF,"NOT2")=NOTNUM2
.I BGPMUTF="C" S ^TMP("BGPMU0064",$J,"PAT",BGPMUTF,"NOT2",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,3)_";"_$P(NUM,U,4)
S ^TMP("BGPMU0064",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0064.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$P(NUM,U,3)_";"_$P(NUM,U,4)
S BGPICARE("MU.EP.0064.2",BGPMUTF)=1_U_+$P(NUM,U,2)_U_+EXC_U_DEN_";"_$P(NUM,U,3)_";"_$P(NUM,U,4)
Q
NUM2(DFN,BGPBDATE,BGPEDATE) ; Find the latest LDL
N FOUND,YR1,YR2,LDL,DATA,VAL,IEN,RESULT,TAX,CPT
S FOUND=0_U_0
S RESULT=0
S CPT=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB LDL CPT")
I +CPT S FOUND=1_U_0_$P(CPT,U,2)_U_$P(CPT,U,3)
S TAX="BGPMU DIAB LDL CPT"
D LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
S VAL="" S VAL=$O(DATA(VAL))
I +VAL D
.S RESULT=$G(DATA(VAL))
.I RESULT<100 S FOUND=1_U_1_U_RESULT_U_(9999999-VAL)
.E S FOUND=1_U_0_U_RESULT_U_(9999999-VAL)
E D
.S TAX="BGPMU DIAB LDL LOINC"
.D LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
.S VAL="" S VAL=$O(DATA(VAL))
.I VAL'="" D
..S RESULT=$G(DATA(VAL))
..I RESULT<100 S FOUND=1_U_1_U_RESULT_U_(9999999-VAL)
..E S FOUND=1_U_0_U_RESULT_U_(9999999-VAL)
.I VAL="" D
..S RESULT=$$VLAB2(DFN,BGPBDATE,BGPEDATE,TAX)
..I +RESULT S FOUND=RESULT
Q FOUND
VLAB2(DFN,BGPBDATE,BGPEDATE,TAX) ;Get lab results
N VLAB,LABVAL,LIEN,VAL
S LABVAL=0
S VLAB=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,TAX)
I +VLAB D
.S LIEN=$P(VLAB,U,2)
.S VAL=$P($G(^AUPNVLAB(LIEN,0)),U,4)
.I +VAL D
..I VAL<100.0 S LABVAL=1_U_1_U_VAL_U_$P(VLAB,U,1)
..E S LABVAL=1_U_0_U_VAL_U_$P(VLAB,U,1)
Q LABVAL
BGPMUA09 ; IHS/MSC/MGH - MI measure NQF0062 & NQF0064 ;25-Jul-2011 08:19;DU
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;Code to collect meaningful use reports
ENTRY1 ;EP Entry point for NQA0062 for nephropathy
+1 NEW START,END,BGPNUM,BGPDEN,BGPNUM,STRING,BGPHYPER,BGPHYPL
+2 NEW IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT
+3 NEW CNT,DIAB,NUM,EXC,DIAB,OUTENC,OPHENC,NONENC,VENC,DIABDX,ERENC,INENC
+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 (STRING,STRING2)=""
SET DIABDX=0
+8 SET (DIAB,EXC,NUM)=0
+9 ;Pts must be >18 and <75
+10 ;No need to check further if no age match
+11 IF BGPAGEE<18!(BGPAGEE>75)
QUIT
+12 SET CNT=0
+13 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+14 SET IEN=0
FOR
SET IEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,IEN))
IF '+IEN
QUIT
Begin DoDot:2
+15 ;Check provider, Only visits for chosen provider
+16 IF '$$PRV^BGPMUUT1(IEN,BGPPROV)
QUIT
+17 SET OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
+18 IF +OUTENC
DO VSTSTORE
QUIT
+19 SET OPHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU OPTHAMOLOGY CPTS")
+20 IF +OPHENC
DO VSTSTORE
QUIT
+21 SET NONENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU NON-ACUTE INPT CPT")
+22 IF +NONENC
DO VSTSTORE
QUIT
+23 SET INENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
+24 IF +INENC
DO VSTSTORE
QUIT
+25 SET ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
+26 IF +ERENC
DO VSTSTORE
QUIT
+27 SET VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
+28 IF +VENC
DO VSTSTORE
QUIT
End DoDot:2
End DoDot:1
+29 ;Next check to see if the patient is in the denominator
+30 ;Denominator is that the pt had a diabetes medicine
+31 ;in the last 2 years or a DX of diabetes in the last 2 years along with
+32 ;one inpt visit or 2 or more outpt visits
+33 SET DIAB=$$DIAB^BGPMUA06(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX)
+34 IF +DIAB
Begin DoDot:1
+35 ;If the patient is diabetetic, check to see if they are in the numerator
+36 SET NUM=$$NUM1(DFN,BGPBDATE,BGPEDATE)
+37 ;If not in the numerator,see if they are an exception
+38 IF +NUM=0&(+DIAB=2)
SET EXC=$$EXCEPT^BGPMUA06(DFN,BGPBDATE,BGPEDATE,DIABDX)
+39 DO TOTAL1(DFN,DIAB,NUM,EXC)
End DoDot:1
+40 QUIT
VSTSTORE ;Store compliant visit in array
+1 SET CNT=CNT+1
+2 SET VDATE=$PIECE($GET(^AUPNVSIT(IEN,0)),U,1)
+3 SET VIEN(CNT)=IEN_U_VDATE
+4 SET STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
+5 QUIT
TOTAL1(DFN,DIAB,NUM,EXC) ;See where this patient ends up
+1 NEW PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DXTIME,DEN
+2 SET TOTALS=$GET(^TMP("BGPMU0062",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0062",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0062",$JOB,BGPMUTF,"NUM"))
+5 SET EXCCT=+$GET(^TMP("BGPMU0062",$JOB,BGPMUTF,"EXC"))
+6 SET NOTNUM=+$GET(^TMP("BGPMU0062",$JOB,BGPMUTF,"NOT"))
+7 SET PTCNT=TOTALS
+8 SET PTCNT=PTCNT+1
+9 SET (DEN,DXTIME)=""
+10 SET DENCT=DENCT+1
SET ^TMP("BGPMU0062",$JOB,BGPMUTF,"DEN")=DENCT
+11 IF $PIECE(DIAB,U,3)'=""
SET DXTIME=$$DATE^BGPMUUTL($PIECE(DIAB,U,3))
+12 SET DEN=$PIECE(DIAB,U,2)_" "_DXTIME
+13 IF $DATA(STRING(1))
SET DEN=DEN_";EN:"_STRING(1)
+14 IF $DATA(STRING(2))
SET DEN=DEN_";EN:"_STRING(2)
+15 IF +EXC
Begin DoDot:1
+16 SET EXCCT=EXCCT+1
SET ^TMP("BGPMU0062",$JOB,BGPMUTF,"EXC")=EXCCT
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0062",$JOB,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
End DoDot:1
+18 IF +NUM
Begin DoDot:1
+19 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0062",$JOB,BGPMUTF,"NUM")=NUMCT
+20 IF BGPMUTF="C"
SET ^TMP("BGPMU0062",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+21 IF +NUM=0&(EXC=0)
Begin DoDot:1
+22 SET NOTNUM=NOTNUM+1
SET ^TMP("BGPMU0062",$JOB,BGPMUTF,"NOT")=NOTNUM
+23 IF BGPMUTF="C"
SET ^TMP("BGPMU0062",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+24 SET ^TMP("BGPMU0062",$JOB,BGPMUTF,"TOT")=PTCNT
+25 ;Setup iCare array for patient
+26 SET BGPICARE("MU.EP.0062.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
+27 QUIT
NUM1(DFN,BGPBDATE,BGPEDATE) ;Look for wide range of items to satisfy this measure
+1 NEW FOUND,YR1,YR2,HGBA1C,DATA,IEN,RESULT,TAX,NEPHDX,NEPHDX2,NEPCPT,NEPICD0,ACE,ARB
+2 NEW LABIEN,MICRO,VAL,VAL2,DATA2,RESULT2,SCREEN,NEPHDX
+3 SET FOUND=0
+4 ;Set date 1yr before end
+5 NEW X1,X2,X
SET X1=BGPEDATE
SET X2=-365
DO C^%DTC
SET YR1=X
+6 ;First check for DX of nephropathy
+7 SET NEPHDX=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB NEPHROPATHY DX")
+8 IF +NEPHDX
SET FOUND=1_U_$PIECE(NEPHDX,U,2)_U_$PIECE(NEPHDX,U,3)
QUIT FOUND
+9 SET NEPHDX2=$$PLTAX^BGPMUUT1(DFN,"BGPMU DIAB NEPHROPATHY DX","A",BGPEDATE)
+10 IF +NEPHDX2
SET FOUND=1_U_$PIECE(NEPHDX2,U,2)_U_$PIECE(NEPHDX2,U,3)
QUIT FOUND
+11 ;Second, check for nephropathy procedures
+12 SET NEPCPT=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB NEPH PROC CPT")
+13 IF +NEPCPT
SET FOUND=1_U_$PIECE(NEPCPT,U,2)_U_$PIECE(NEPCPT,U,3)
QUIT FOUND
+14 SET NEPICD0=$$LASTPRC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB NEPH PROC ICD0")
+15 IF +NEPICD0
SET FOUND=1_U_$PIECE(NEPICD0,U,2)_U_$PIECE(NEPICD0,U,3)
QUIT FOUND
+16 ;Third check to see if the patient is on an ACE/ARB
+17 SET ACE=$$FIND^BGPMUUT8(DFN,"BGPMU ACE INHIBITOR NDC",BGPBDATE,"",BGPEDATE)
+18 IF +ACE
SET FOUND=1_U_"ACE"_U_$PIECE(ACE,U,3)
QUIT FOUND
+19 SET ARB=$$FIND^BGPMUUT8(DFN,"BGPMU ARB NDCS",BGPBDATE,"",BGPEDATE)
+20 IF +ARB
SET FOUND=1_U_"ARB"_U_$PIECE(ARB,U,3)
QUIT FOUND
+21 ;Fourth check for microalbumin
+22 SET MICRO=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB MICRO CPT")
+23 IF +MICRO
SET FOUND=1_U_$PIECE(MICRO,U,2)_U_$PIECE(MICRO,U,3)
QUIT FOUND
+24 SET TAX="BGPMU LAB CPT MICRO"
+25 DO LABCPT^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+26 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+27 IF +VAL
Begin DoDot:1
+28 SET RESULT=$GET(DATA(VAL))
+29 IF +RESULT>0
SET FOUND=1_U_"ACR"_U_(9999999-VAL)
End DoDot:1
+30 IF '$TEST
Begin DoDot:1
+31 SET TAX="BGPMU LAB LOINC MICROALBUMIN"
+32 DO LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+33 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+34 IF VAL=""
SET FOUND=$$VLAB^BGPMUA08(DFN,BGPBDATE,BGPEDATE,TAX)
+35 IF '$TEST
Begin DoDot:2
+36 SET RESULT=$GET(DATA(VAL))
+37 IF +RESULT>0
SET FOUND=1_U_"ACR"_U_(9999999-VAL)
End DoDot:2
End DoDot:1
+38 IF +FOUND
QUIT FOUND
+39 ;Fifth check for nephropathy screening
+40 SET SCREEN=$$CPT^BGPMUUT1(DFN,YR1,BGPEDATE,"BGPMU DIAB NEPH SCREEN CPT")
+41 IF +SCREEN
SET FOUND=1_U_$PIECE(SCREEN,U,2)_U_$PIECE(SCREEN,U,3)
QUIT FOUND
+42 SET TAX="BGPMU LAB CPT NEPH"
+43 DO LABCPT^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+44 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+45 IF +VAL
Begin DoDot:1
+46 SET RESULT=$GET(DATA(VAL))
+47 IF +RESULT>0
SET FOUND=1_U_"NEP"_U_(9999999-VAL)
End DoDot:1
+48 IF '$TEST
Begin DoDot:1
+49 SET TAX="BGPMU LAB LOINC NEPHROPATHY"
+50 DO LAB^BGPMUUT5(.DATA2,DFN,TAX,BGPBDATE,BGPEDATE)
+51 SET VAL2=""
SET VAL2=$ORDER(DATA2(VAL2))
+52 IF VAL2=""
SET FOUND=$$VLAB(DFN,BGPBDATE,BGPEDATE,TAX)
+53 IF '$TEST
Begin DoDot:2
+54 SET RESULT2=$GET(DATA2(VAL2))
+55 IF +RESULT2
SET FOUND=1_U_"NEP"_U_(9999999-VAL2)
End DoDot:2
End DoDot:1
+56 QUIT FOUND
VLAB(DFN,BGPBDATE,BGPEDATE,TAX) ;get lab results
+1 NEW VLAB,LABVAL,LIEN
+2 SET LABVAL=0
+3 SET VLAB=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,TAX)
+4 IF VLAB
Begin DoDot:1
+5 SET LIEN=$PIECE(VLAB,U,2)
+6 SET LABVAL=1_U_$PIECE($GET(^AUPNVLAB(LIEN,0)),U,4)_U_$PIECE(VLAB,U,1)
End DoDot:1
+7 QUIT LABVAL
ENTRY2 ;EP Entry point for NQA0064 for LDL<100
+1 NEW START,END,BGPNUM,BGPDEN,BGPNUM,AENC,BENC,STRING,STRING2
+2 NEW IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT,INENC
+3 NEW CNT,DIAB,EXC,NUM1,NUM2,DIAB,OUTENC,OPHENC,NONENC,VENC,DIABDX,ERENC
+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 (STRING,STRING2)=""
SET DIABDX=0
+8 SET (DIAB,EXC,NUM)=0
+9 ;Pts must be >18 and <75
+10 ;No need to check further if no age match
+11 IF BGPAGEE<18!(BGPAGEE>75)
QUIT
+12 SET CNT=0
+13 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+14 SET IEN=0
FOR
SET IEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,IEN))
IF '+IEN
QUIT
Begin DoDot:2
+15 ;Check provider, Only visits for chosen provider
+16 IF '$$PRV^BGPMUUT1(IEN,BGPPROV)
QUIT
+17 SET OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
+18 IF +OUTENC
DO VSTSTORE
QUIT
+19 SET OPHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU OPTHAMOLOGY CPTS")
+20 IF +OPHENC
DO VSTSTORE
QUIT
+21 SET NONENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU NON-ACUTE INPT CPT")
+22 IF +NONENC
DO VSTSTORE
QUIT
+23 SET INENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
+24 IF +INENC
DO VSTSTORE
QUIT
+25 SET ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
+26 IF +ERENC
DO VSTSTORE
QUIT
+27 SET VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
+28 IF +VENC
DO VSTSTORE
QUIT
End DoDot:2
End DoDot:1
+29 ;Next check to see if the patient is in the denominator
+30 ;Denominator is that the pt had a diabetes medicine
+31 ;in the last 2 years or a DX of diabetes in the last 2 years along with
+32 ;one inpt visit or 2 or more outpt visits
+33 SET DIAB=$$DIAB^BGPMUA06(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX)
+34 IF +DIAB
Begin DoDot:1
+35 ;If the patient is diabetetic, check to see if they are in the numerator
+36 SET NUM=$$NUM2(DFN,BGPBDATE,BGPEDATE)
+37 ;If not in the numerator,see if they are an exception
+38 IF +NUM=0&(+DIAB=2)
SET EXC=$$EXCEPT^BGPMUA06(DFN,BGPBDATE,BGPEDATE,DIABDX)
+39 DO TOTAL2(DFN,DIAB,NUM,EXC)
End DoDot:1
+40 QUIT
TOTAL2(DFN,DIAB,NUM,EXC) ;See where this patient ends up
+1 NEW PTCNT,EXCCT,DENCT,NUM1CT,NUM2CT,NOTNUM,TOTALS,DXTIME,DEN,NOTNUM1,NOTNUM2
+2 SET TOTALS=$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"DEN"))
+4 SET NUM1CT=+$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"NUM1"))
+5 SET NUM2CT=+$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"NUM2"))
+6 SET EXCCT=+$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"EXC"))
+7 SET NOTNUM1=+$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"NOT1"))
+8 SET NOTNUM2=+$GET(^TMP("BGPMU0064",$JOB,BGPMUTF,"NOT2"))
+9 SET PTCNT=TOTALS
+10 SET PTCNT=PTCNT+1
+11 SET (DEN,DXTIME)=""
+12 SET DENCT=DENCT+1
SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"DEN")=DENCT
+13 IF $PIECE(DIAB,U,3)'=""
SET DXTIME=$$DATE^BGPMUUTL($PIECE(DIAB,U,3))
+14 SET DEN=$PIECE(DIAB,U,2)_" "_DXTIME
+15 IF $DATA(STRING(1))
SET DEN=DEN_";EN:"_STRING(1)
+16 IF $DATA(STRING(2))
SET DEN=DEN_";EN:"_STRING(2)
+17 IF +EXC
Begin DoDot:1
+18 SET EXCCT=EXCCT+1
SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"EXC")=EXCCT
+19 IF BGPMUTF="C"
SET ^TMP("BGPMU0064",$JOB,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
End DoDot:1
+20 IF +NUM
Begin DoDot:1
+21 SET NUM1CT=NUM1CT+1
SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"NUM1")=NUM1CT
+22 IF BGPMUTF="C"
SET ^TMP("BGPMU0064",$JOB,"PAT",BGPMUTF,"NUM1",PTCNT)=DFN_U_DEN_U_"M:"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,4)
End DoDot:1
+23 IF +NUM=0&(EXC=0)
Begin DoDot:1
+24 SET NOTNUM1=NOTNUM1+1
SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"NOT1")=NOTNUM1
+25 IF BGPMUTF="C"
SET ^TMP("BGPMU0064",$JOB,"PAT",BGPMUTF,"NOT1",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,4)
End DoDot:1
+26 IF $PIECE(NUM,U,2)=1
Begin DoDot:1
+27 SET NUM2CT=NUM2CT+1
SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"NUM2")=NUM2CT
+28 IF BGPMUTF="C"
SET ^TMP("BGPMU0064",$JOB,"PAT",BGPMUTF,"NUM2",PTCNT)=DFN_U_DEN_U_"M:"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,4)
End DoDot:1
+29 IF $PIECE(NUM,U,2)=0&(EXC=0)
Begin DoDot:1
+30 SET NOTNUM2=NOTNUM2+1
SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"NOT2")=NOTNUM2
+31 IF BGPMUTF="C"
SET ^TMP("BGPMU0064",$JOB,"PAT",BGPMUTF,"NOT2",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,4)
End DoDot:1
+32 SET ^TMP("BGPMU0064",$JOB,BGPMUTF,"TOT")=PTCNT
+33 ;Setup iCare array for patient
+34 SET BGPICARE("MU.EP.0064.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,4)
+35 SET BGPICARE("MU.EP.0064.2",BGPMUTF)=1_U_+$PIECE(NUM,U,2)_U_+EXC_U_DEN_";"_$PIECE(NUM,U,3)_";"_$PIECE(NUM,U,4)
+36 QUIT
NUM2(DFN,BGPBDATE,BGPEDATE) ; Find the latest LDL
+1 NEW FOUND,YR1,YR2,LDL,DATA,VAL,IEN,RESULT,TAX,CPT
+2 SET FOUND=0_U_0
+3 SET RESULT=0
+4 SET CPT=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB LDL CPT")
+5 IF +CPT
SET FOUND=1_U_0_$PIECE(CPT,U,2)_U_$PIECE(CPT,U,3)
+6 SET TAX="BGPMU DIAB LDL CPT"
+7 DO LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+8 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+9 IF +VAL
Begin DoDot:1
+10 SET RESULT=$GET(DATA(VAL))
+11 IF RESULT<100
SET FOUND=1_U_1_U_RESULT_U_(9999999-VAL)
+12 IF '$TEST
SET FOUND=1_U_0_U_RESULT_U_(9999999-VAL)
End DoDot:1
+13 IF '$TEST
Begin DoDot:1
+14 SET TAX="BGPMU DIAB LDL LOINC"
+15 DO LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+16 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+17 IF VAL'=""
Begin DoDot:2
+18 SET RESULT=$GET(DATA(VAL))
+19 IF RESULT<100
SET FOUND=1_U_1_U_RESULT_U_(9999999-VAL)
+20 IF '$TEST
SET FOUND=1_U_0_U_RESULT_U_(9999999-VAL)
End DoDot:2
+21 IF VAL=""
Begin DoDot:2
+22 SET RESULT=$$VLAB2(DFN,BGPBDATE,BGPEDATE,TAX)
+23 IF +RESULT
SET FOUND=RESULT
End DoDot:2
End DoDot:1
+24 QUIT FOUND
VLAB2(DFN,BGPBDATE,BGPEDATE,TAX) ;Get lab results
+1 NEW VLAB,LABVAL,LIEN,VAL
+2 SET LABVAL=0
+3 SET VLAB=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,TAX)
+4 IF +VLAB
Begin DoDot:1
+5 SET LIEN=$PIECE(VLAB,U,2)
+6 SET VAL=$PIECE($GET(^AUPNVLAB(LIEN,0)),U,4)
+7 IF +VAL
Begin DoDot:2
+8 IF VAL<100.0
SET LABVAL=1_U_1_U_VAL_U_$PIECE(VLAB,U,1)
+9 IF '$TEST
SET LABVAL=1_U_0_U_VAL_U_$PIECE(VLAB,U,1)
End DoDot:2
End DoDot:1
+10 QUIT LABVAL