BGPMUA06 ; IHS/MSC/MGH - MI measure NQF0055 ;20-Jul-2011 14:56;DU
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;Code to collect meaningful use report for diabetic eye exam
ENTRY ;EP
N START,END,BGPNUM,BGPDEN,BGPNUM,AENC,BENC,STRING,STRING2,BGPHYPER,BGPHYPL
N IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT,ERENC
N CNT,DIAB,NUM,DIAB,OUTENC,OPHENC,NONENC,VENC,DIABDX,INENC
S (BGPDEN,BGPNUM,RESULT)=0
S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
S START=START_".2359"
S 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 VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
..I +VENC 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
;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(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX)
I +DIAB D
.;If the patient is diabetic, check to see if they are in the numerator
.S NUM=$$NUM(DFN,BGPBDATE,BGPEDATE)
.;If not in the numerator and pt is on diabetes meds but no DX of diabetes see if they are an exception
.I NUM=0&(+DIAB=2) S EXC=$$EXCEPT(DFN,BGPBDATE,BGPEDATE,DIABDX)
.D TOTAL(DFN,DIAB,NUM,EXC)
Q
VSTSTORE ;Store a compliant visit into the array
S CNT=CNT+1
S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
S VIEN(CNT)=IEN_U_VDATE
Q
TOTAL(DFN,DIAB,NUM,EXC) ;See where this patient ends up
N PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DEN,DXTIME
S TOTALS=$G(^TMP("BGPMU0055",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0055",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0055",$J,BGPMUTF,"NUM"))
S EXCCT=+$G(^TMP("BGPMU0055",$J,BGPMUTF,"EXC"))
S NOTNUM=+$G(^TMP("BGPMU0055",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S (DEN,DXTIME)=""
S DENCT=DENCT+1 S ^TMP("BGPMU0055",$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 +NUM D
.S NUMCT=NUMCT+1 S ^TMP("BGPMU0055",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0055",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
I +EXC D
.S EXCCT=EXCCT+1 S ^TMP("BGPMU0055",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0055",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
I +NUM=0&(EXC=0) D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0055",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0055",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
S ^TMP("BGPMU0055",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0055.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
DIAB(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX) ;look for diabetes diagnosis
N FOUND,YR1,YR2,OENC,AENC,NENC,EENC,DX,AMED,BMED,CMED,DMED,EMED,FMED,GMED,HMED,IMED,DIABX
S FOUND=0,DX=0
;Check for the patient having a DX of diabetes in the last 2yrs and having
;a current visit (One or two years)
N X1,X2,X,DXA,DXB
S X1=BGPBDATE,X2=-730 D C^%DTC S YR2=X
S DXA=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU DIABETES DX")
S DXB=$$PLTAX^BGPMUUT1(DFN,"BGPMU DIABETES DX","C",BGPEDATE)
I +DXA S DX=DXA
E I +DXB S DX=DXB
N X1,X2,X S X1=BGPEDATE,X2=-365 D C^%DTC S YR1=X
I (+DX)&($D(VIEN)) D Q FOUND
.S AENC=$$CPT^BGPMUUT1(DFN,YR1,BGPEDATE,"BGPMU ACUTE INPT ENC")
.I +AENC D Q
..S DIABDX=1,FOUND=1_U_"ICD:"_$$DATE^BGPMUUTL($P($P(DX,U,3),".",1))
..S STRING(1)=$$DATE^BGPMUUTL($P($P(VIEN(1),U,2),".",1))
.S EENC=$$CPT^BGPMUUT1(DFN,YR1,BGPEDATE,"BGPMU DIAB ED ENCOUNTER CPT")
.I +EENC D Q
..S DIABDX=1,FOUND=1_U_"ICD:"_$$DATE^BGPMUUTL($P($P(DX,U,3),".",1))
..S STRING(1)=$$DATE^BGPMUUTL($P($P(VIEN(1),U,2),".",1))
.I CNT>1 D Q
..S DIABX=1,FOUND=1_U_"ICD:"_$$DATE^BGPMUUTL($P($P(DX,U,3),".",1))
..S STRING(1)=$$DATE^BGPMUUTL($P($P(VIEN(1),U,2),".",1))
..S STRING(2)=$$DATE^BGPMUUTL($P($P(VIEN(2),U,2),".",1))
;If DX not found, check for meds
;Check for the patient being on a diabetic med in the last 2 years
S AMED=$$FIND^BGPMUUT8(DFN,"BGPMU DIAB MEDS INDICATIVE ALL",YR2,BGPPROV,BGPEDATE)
I +AMED S FOUND=2_U_"MED:"_$$DATE^BGPMUUTL($P($P(AMED,U,3),".",1)) Q FOUND
Q FOUND
NUM(DFN,BGPBDATE,BGPEDATE) ;Look for evidence of a diabetic eye exam
N FOUND,YR1,YR2,EXMCPT,EXMPRC,EXMICD,RETDX,RETDX1
S FOUND=0
;Set date 1yr before end
;If the exam if found in the reporting period, the patient meets the numerator
N X1,X2,X S X1=BGPBDATE,X2=-365 D C^%DTC S YR1=X
S EXMCPT=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIABETIC EYE EXAM CPT")
I +EXMCPT S FOUND=1_U_$P(EXMCPT,U,2)_U_$P(EXMCPT,U,3) Q FOUND
S EXMPRC=$$LASTPRC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB EYE EXAM ICD0")
I +EXMPRC S FOUND=1_U_$P(EXMPRC,U,2)_U_$P(EXMPRC,U,3) Q FOUND
S EXMICD=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIABETIC EYE EXAM ICD9")
I +EXMICD S FOUND=1_U_$P(EXMICD,U,2)_U_$P(EXMICD,U,3) Q FOUND
;If exam not found in reporting period, try again in year before
S EXMCPT=$$CPT^BGPMUUT1(DFN,YR1,BGPBDATE,"BGPMU DIABETIC EYE EXAM CPT")
I +EXMCPT S FOUND=1_U_$P(EXMCPT,U,2)_U_$P(EXMCPT,U,3) G EXAM
S EXMPRC=$$LASTPRC^BGPMUUT2(DFN,YR1,BGPBDATE,"BGPMU DIAB EYE EXAM ICD0")
I +EXMPRC S FOUND=1_U_$P(EXMPRC,U,2)_U_$P(EXMPRC,U,3) G EXAM
S EXMICD=$$LASTDX^BGPMUUT2(DFN,YR1,BGPBDATE,"BGPMU DIABETIC EYE EXAM ICD9")
I +EXMICD S FOUND=1_U_$P(EXMICD,U,2)_U_$P(EXMICD,U,3) G EXAM
EXAM ;If exam found check and see if the patient has diabetic retinopathy in the year before the reporting period
I +EXMCPT!(+EXMPRC)!(EXMICD) D
.S RETDX=$$LASTDX^BGPMUUT2(DFN,YR1,BGPBDATE,"BGPMU DIABETIC RETINOPATHY DX")
.S RETDX1=$$PLTAX^BGPMUUT1(DFN,"BGPMU DIABETIC RETINOPATHY DX","A")
.;If retinopathy then pt does not meet numerator
.I +RETDX S FOUND=0_U_$P(RETDX,U,2)_";"_$P(RETDX,U,3)
.I +RETDX1 S FOUND=0_U_$P(RETDX1,U,2)_";"_$P(RETDX1,U,3)
Q FOUND
EXCEPT(DFN,BGPBDATE,BGPEDATE,DIABDX) ;See if this patient has exceptions
N EFOUND,YR2,DX,PO,PO1,GD,GD1,SD,SD1
S EFOUND=0
N X1,X2,X S X1=BGPEDATE,X2=-721 D C^%DTC S YR2=X
;Polycystic ovaries are an exception if there is also not an DX of diabetes
S PO=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU POLYCYSTIC OVARIES DX")
S PO1=$$PLTAX^BGPMUUT1(DFN,"BGPMU POLYCYSTIC OVARIES DX","A")
I +PO!(+PO1) S EFOUND=1_U_$P(PO,U,2) Q EFOUND
;Gestational diabetes or steroid induced diabetes is an exception if the pt does not have diabetes
S GD=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU GESTATIONAL DIABETES DX")
S GD1=$$PLTAX^BGPMUUT1(DFN,"BGPMU GESTATIONAL DIABETES DX","A")
I +GD!(+GD1) S EFOUND=1_U_$P(GD,U,2) Q EFOUND
S SD=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU STEROID DIABETES DX")
S SD1=$$PLTAX^BGPMUUT1(DFN,"BGPMU STEROID DIABETES DX","A")
I +SD!(+SD1) S EFOUND=1_U_$P(SD,U,2)
Q EFOUND
BGPMUA06 ; IHS/MSC/MGH - MI measure NQF0055 ;20-Jul-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 diabetic eye exam
ENTRY ;EP
+1 NEW START,END,BGPNUM,BGPDEN,BGPNUM,AENC,BENC,STRING,STRING2,BGPHYPER,BGPHYPL
+2 NEW IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT,ERENC
+3 NEW CNT,DIAB,NUM,DIAB,OUTENC,OPHENC,NONENC,VENC,DIABDX,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 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 VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
+24 IF +VENC
DO VSTSTORE
QUIT
+25 SET INENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
+26 IF +INENC
DO VSTSTORE
QUIT
+27 SET ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU DIAB ED ENCOUNTER CPT")
+28 IF +ERENC
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(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX)
+34 IF +DIAB
Begin DoDot:1
+35 ;If the patient is diabetic, check to see if they are in the numerator
+36 SET NUM=$$NUM(DFN,BGPBDATE,BGPEDATE)
+37 ;If not in the numerator and pt is on diabetes meds but no DX of diabetes see if they are an exception
+38 IF NUM=0&(+DIAB=2)
SET EXC=$$EXCEPT(DFN,BGPBDATE,BGPEDATE,DIABDX)
+39 DO TOTAL(DFN,DIAB,NUM,EXC)
End DoDot:1
+40 QUIT
VSTSTORE ;Store a compliant visit into the array
+1 SET CNT=CNT+1
+2 SET VDATE=$PIECE($GET(^AUPNVSIT(IEN,0)),U,1)
+3 SET VIEN(CNT)=IEN_U_VDATE
+4 QUIT
TOTAL(DFN,DIAB,NUM,EXC) ;See where this patient ends up
+1 NEW PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DEN,DXTIME
+2 SET TOTALS=$GET(^TMP("BGPMU0055",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0055",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0055",$JOB,BGPMUTF,"NUM"))
+5 SET EXCCT=+$GET(^TMP("BGPMU0055",$JOB,BGPMUTF,"EXC"))
+6 SET NOTNUM=+$GET(^TMP("BGPMU0055",$JOB,BGPMUTF,"NOT"))
+7 SET PTCNT=TOTALS
+8 SET PTCNT=PTCNT+1
+9 SET (DEN,DXTIME)=""
+10 SET DENCT=DENCT+1
SET ^TMP("BGPMU0055",$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 +NUM
Begin DoDot:1
+16 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0055",$JOB,BGPMUTF,"NUM")=NUMCT
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0055",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+18 IF +EXC
Begin DoDot:1
+19 SET EXCCT=EXCCT+1
SET ^TMP("BGPMU0055",$JOB,BGPMUTF,"EXC")=EXCCT
+20 IF BGPMUTF="C"
SET ^TMP("BGPMU0055",$JOB,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
End DoDot:1
+21 IF +NUM=0&(EXC=0)
Begin DoDot:1
+22 SET NOTNUM=NOTNUM+1
SET ^TMP("BGPMU0055",$JOB,BGPMUTF,"NOT")=NOTNUM
+23 IF BGPMUTF="C"
SET ^TMP("BGPMU0055",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+24 SET ^TMP("BGPMU0055",$JOB,BGPMUTF,"TOT")=PTCNT
+25 ;Setup iCare array for patient
+26 SET BGPICARE("MU.EP.0055.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
+27 QUIT
DIAB(DFN,BGPBDATE,BGPEDATE,CNT,DIABDX) ;look for diabetes diagnosis
+1 NEW FOUND,YR1,YR2,OENC,AENC,NENC,EENC,DX,AMED,BMED,CMED,DMED,EMED,FMED,GMED,HMED,IMED,DIABX
+2 SET FOUND=0
SET DX=0
+3 ;Check for the patient having a DX of diabetes in the last 2yrs and having
+4 ;a current visit (One or two years)
+5 NEW X1,X2,X,DXA,DXB
+6 SET X1=BGPBDATE
SET X2=-730
DO C^%DTC
SET YR2=X
+7 SET DXA=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU DIABETES DX")
+8 SET DXB=$$PLTAX^BGPMUUT1(DFN,"BGPMU DIABETES DX","C",BGPEDATE)
+9 IF +DXA
SET DX=DXA
+10 IF '$TEST
IF +DXB
SET DX=DXB
+11 NEW X1,X2,X
SET X1=BGPEDATE
SET X2=-365
DO C^%DTC
SET YR1=X
+12 IF (+DX)&($DATA(VIEN))
Begin DoDot:1
+13 SET AENC=$$CPT^BGPMUUT1(DFN,YR1,BGPEDATE,"BGPMU ACUTE INPT ENC")
+14 IF +AENC
Begin DoDot:2
+15 SET DIABDX=1
SET FOUND=1_U_"ICD:"_$$DATE^BGPMUUTL($PIECE($PIECE(DX,U,3),".",1))
+16 SET STRING(1)=$$DATE^BGPMUUTL($PIECE($PIECE(VIEN(1),U,2),".",1))
End DoDot:2
QUIT
+17 SET EENC=$$CPT^BGPMUUT1(DFN,YR1,BGPEDATE,"BGPMU DIAB ED ENCOUNTER CPT")
+18 IF +EENC
Begin DoDot:2
+19 SET DIABDX=1
SET FOUND=1_U_"ICD:"_$$DATE^BGPMUUTL($PIECE($PIECE(DX,U,3),".",1))
+20 SET STRING(1)=$$DATE^BGPMUUTL($PIECE($PIECE(VIEN(1),U,2),".",1))
End DoDot:2
QUIT
+21 IF CNT>1
Begin DoDot:2
+22 SET DIABX=1
SET FOUND=1_U_"ICD:"_$$DATE^BGPMUUTL($PIECE($PIECE(DX,U,3),".",1))
+23 SET STRING(1)=$$DATE^BGPMUUTL($PIECE($PIECE(VIEN(1),U,2),".",1))
+24 SET STRING(2)=$$DATE^BGPMUUTL($PIECE($PIECE(VIEN(2),U,2),".",1))
End DoDot:2
QUIT
End DoDot:1
QUIT FOUND
+25 ;If DX not found, check for meds
+26 ;Check for the patient being on a diabetic med in the last 2 years
+27 SET AMED=$$FIND^BGPMUUT8(DFN,"BGPMU DIAB MEDS INDICATIVE ALL",YR2,BGPPROV,BGPEDATE)
+28 IF +AMED
SET FOUND=2_U_"MED:"_$$DATE^BGPMUUTL($PIECE($PIECE(AMED,U,3),".",1))
QUIT FOUND
+29 QUIT FOUND
NUM(DFN,BGPBDATE,BGPEDATE) ;Look for evidence of a diabetic eye exam
+1 NEW FOUND,YR1,YR2,EXMCPT,EXMPRC,EXMICD,RETDX,RETDX1
+2 SET FOUND=0
+3 ;Set date 1yr before end
+4 ;If the exam if found in the reporting period, the patient meets the numerator
+5 NEW X1,X2,X
SET X1=BGPBDATE
SET X2=-365
DO C^%DTC
SET YR1=X
+6 SET EXMCPT=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIABETIC EYE EXAM CPT")
+7 IF +EXMCPT
SET FOUND=1_U_$PIECE(EXMCPT,U,2)_U_$PIECE(EXMCPT,U,3)
QUIT FOUND
+8 SET EXMPRC=$$LASTPRC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB EYE EXAM ICD0")
+9 IF +EXMPRC
SET FOUND=1_U_$PIECE(EXMPRC,U,2)_U_$PIECE(EXMPRC,U,3)
QUIT FOUND
+10 SET EXMICD=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU DIABETIC EYE EXAM ICD9")
+11 IF +EXMICD
SET FOUND=1_U_$PIECE(EXMICD,U,2)_U_$PIECE(EXMICD,U,3)
QUIT FOUND
+12 ;If exam not found in reporting period, try again in year before
+13 SET EXMCPT=$$CPT^BGPMUUT1(DFN,YR1,BGPBDATE,"BGPMU DIABETIC EYE EXAM CPT")
+14 IF +EXMCPT
SET FOUND=1_U_$PIECE(EXMCPT,U,2)_U_$PIECE(EXMCPT,U,3)
GOTO EXAM
+15 SET EXMPRC=$$LASTPRC^BGPMUUT2(DFN,YR1,BGPBDATE,"BGPMU DIAB EYE EXAM ICD0")
+16 IF +EXMPRC
SET FOUND=1_U_$PIECE(EXMPRC,U,2)_U_$PIECE(EXMPRC,U,3)
GOTO EXAM
+17 SET EXMICD=$$LASTDX^BGPMUUT2(DFN,YR1,BGPBDATE,"BGPMU DIABETIC EYE EXAM ICD9")
+18 IF +EXMICD
SET FOUND=1_U_$PIECE(EXMICD,U,2)_U_$PIECE(EXMICD,U,3)
GOTO EXAM
EXAM ;If exam found check and see if the patient has diabetic retinopathy in the year before the reporting period
+1 IF +EXMCPT!(+EXMPRC)!(EXMICD)
Begin DoDot:1
+2 SET RETDX=$$LASTDX^BGPMUUT2(DFN,YR1,BGPBDATE,"BGPMU DIABETIC RETINOPATHY DX")
+3 SET RETDX1=$$PLTAX^BGPMUUT1(DFN,"BGPMU DIABETIC RETINOPATHY DX","A")
+4 ;If retinopathy then pt does not meet numerator
+5 IF +RETDX
SET FOUND=0_U_$PIECE(RETDX,U,2)_";"_$PIECE(RETDX,U,3)
+6 IF +RETDX1
SET FOUND=0_U_$PIECE(RETDX1,U,2)_";"_$PIECE(RETDX1,U,3)
End DoDot:1
+7 QUIT FOUND
EXCEPT(DFN,BGPBDATE,BGPEDATE,DIABDX) ;See if this patient has exceptions
+1 NEW EFOUND,YR2,DX,PO,PO1,GD,GD1,SD,SD1
+2 SET EFOUND=0
+3 NEW X1,X2,X
SET X1=BGPEDATE
SET X2=-721
DO C^%DTC
SET YR2=X
+4 ;Polycystic ovaries are an exception if there is also not an DX of diabetes
+5 SET PO=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU POLYCYSTIC OVARIES DX")
+6 SET PO1=$$PLTAX^BGPMUUT1(DFN,"BGPMU POLYCYSTIC OVARIES DX","A")
+7 IF +PO!(+PO1)
SET EFOUND=1_U_$PIECE(PO,U,2)
QUIT EFOUND
+8 ;Gestational diabetes or steroid induced diabetes is an exception if the pt does not have diabetes
+9 SET GD=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU GESTATIONAL DIABETES DX")
+10 SET GD1=$$PLTAX^BGPMUUT1(DFN,"BGPMU GESTATIONAL DIABETES DX","A")
+11 IF +GD!(+GD1)
SET EFOUND=1_U_$PIECE(GD,U,2)
QUIT EFOUND
+12 SET SD=$$LASTDX^BGPMUUT2(DFN,YR2,BGPEDATE,"BGPMU STEROID DIABETES DX")
+13 SET SD1=$$PLTAX^BGPMUUT1(DFN,"BGPMU STEROID DIABETES DX","A")
+14 IF +SD!(+SD1)
SET EFOUND=1_U_$PIECE(SD,U,2)
+15 QUIT EFOUND