BGPMUA08 ; IHS/MSC/MGH - MI measure NQF0059 & NQF0575 ;10-Mar-2011 09:48;DU
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;Code to collect meaningful use reports for hgba1c
ENTRY1 ;EP Entry point for NQA0059 for poor control with HGBA1c >9.0
N START,END,BGPNUM,BGPDEN,BGPNUM,STRING,STRING2,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 into 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("BGPMU0059",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0059",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0059",$J,BGPMUTF,"NUM"))
S EXCCT=+$G(^TMP("BGPMU0059",$J,BGPMUTF,"EXC"))
S NOTNUM=+$G(^TMP("BGPMU0059",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S (DEN,DXTIME)=""
S DENCT=DENCT+1 S ^TMP("BGPMU0059",$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("BGPMU0059",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0059",$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("BGPMU0059",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0059",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
I +NUM=0&(EXC=0) D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0059",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0059",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
S ^TMP("BGPMU0059",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0059.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
NUM1(DFN,BGPBDATE,BGPEDATE) ;Look for evidence of a hgba1c
N FOUND,YR1,YR2,HGBA1C,DATA,VAL,IEN,RESULT,TAX
S FOUND=0,RESULT=""
S TAX="BGPMU LAB CPT HGBA1C"
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>9.0 S FOUND=1_U_RESULT_U_(9999999-VAL)
.E S FOUND=0_U_RESULT_U_(9999999-VAL)
E D
.S TAX="BGPMU LAB LOINC HGBA1C"
.D LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
.S VAL="" S VAL=$O(DATA(VAL))
.I VAL="" S FOUND=$$VLAB(DFN,BGPBDATE,BGPEDATE,TAX)
.E D
..S RESULT=$G(DATA(VAL))
..I RESULT>9.0 S FOUND=1_U_RESULT_U_(9999999-VAL)
..E S FOUND=0_U_RESULT_U_(9999999-VAL)
Q FOUND
VLAB(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>9.0 S LABVAL=1_U_VAL_U_$P(VLAB,U,1)
.E S LABVAL=0_U_VAL_U_$P(VLAB,U,1)
Q LABVAL
ENTRY2 ;EP Entry point for NQA0575 For good control with HgbA1c <8.0
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,ERENC,DIABDX,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=$$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,NUMCT,NOTNUM,TOTALS,DEN,DXTIME
S TOTALS=$G(^TMP("BGPMU0575",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0575",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0575",$J,BGPMUTF,"NUM"))
S EXCCT=+$G(^TMP("BGPMU0575",$J,BGPMUTF,"EXC"))
S NOTNUM=+$G(^TMP("BGPMU0575",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S (DEN,DXTIME)=""
S DENCT=DENCT+1 S ^TMP("BGPMU0575",$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("BGPMU0575",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0575",$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("BGPMU0575",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0575",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
I +NUM=0&(EXC=0) D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0575",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0575",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
S ^TMP("BGPMU0575",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0575.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
NUM2(DFN,BGPBDATE,BGPEDATE) ; Find the latest HGBA1C
N FOUND,YR1,YR2,HGBA1C,DATA,VAL,IEN,RESULT,TAX
S TAX="BGPMU LAB CPT HGBA1C"
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=""!(RESULT=0) Q
.I RESULT<8.0 S FOUND=1_U_RESULT_U_(9999999-VAL)
.E S FOUND=0_U_RESULT_U_(9999999-VAL)
E D
.S TAX="BGPMU LAB LOINC HGBA1C"
.S FOUND=0,RESULT=""
.S HGBA1C=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,TAX)
.D LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
.S VAL="" S VAL=$O(DATA(VAL))
.I VAL="" S FOUND=$$VLAB2(DFN,BGPBDATE,BGPEDATE,TAX)
.E D
..S RESULT=$G(DATA(VAL))
..I RESULT=""!(RESULT=0) Q
..I RESULT<8.0 S FOUND=1_U_RESULT_U_(9999999-VAL)
..E S FOUND=0_U_RESULT_U_(9999999-VAL)
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=""!(VAL=0) S LABVAL=0
.E D
..I VAL<8.0 S LABVAL=1_U_VAL_U_$P(VLAB,U,1)
..I VAL>7.999 S LABVAL=0_U_VAL_U_$P(VLAB,U,1)
Q LABVAL
BGPMUA08 ; IHS/MSC/MGH - MI measure NQF0059 & NQF0575 ;10-Mar-2011 09:48;DU
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;Code to collect meaningful use reports for hgba1c
ENTRY1 ;EP Entry point for NQA0059 for poor control with HGBA1c >9.0
+1 NEW START,END,BGPNUM,BGPDEN,BGPNUM,STRING,STRING2,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 into 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("BGPMU0059",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0059",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0059",$JOB,BGPMUTF,"NUM"))
+5 SET EXCCT=+$GET(^TMP("BGPMU0059",$JOB,BGPMUTF,"EXC"))
+6 SET NOTNUM=+$GET(^TMP("BGPMU0059",$JOB,BGPMUTF,"NOT"))
+7 SET PTCNT=TOTALS
+8 SET PTCNT=PTCNT+1
+9 SET (DEN,DXTIME)=""
+10 SET DENCT=DENCT+1
SET ^TMP("BGPMU0059",$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("BGPMU0059",$JOB,BGPMUTF,"NUM")=NUMCT
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0059",$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("BGPMU0059",$JOB,BGPMUTF,"EXC")=EXCCT
+20 IF BGPMUTF="C"
SET ^TMP("BGPMU0059",$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("BGPMU0059",$JOB,BGPMUTF,"NOT")=NOTNUM
+23 IF BGPMUTF="C"
SET ^TMP("BGPMU0059",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+24 SET ^TMP("BGPMU0059",$JOB,BGPMUTF,"TOT")=PTCNT
+25 ;Setup iCare array for patient
+26 SET BGPICARE("MU.EP.0059.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 evidence of a hgba1c
+1 NEW FOUND,YR1,YR2,HGBA1C,DATA,VAL,IEN,RESULT,TAX
+2 SET FOUND=0
SET RESULT=""
+3 SET TAX="BGPMU LAB CPT HGBA1C"
+4 DO LABCPT^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+5 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+6 IF +VAL
Begin DoDot:1
+7 SET RESULT=$GET(DATA(VAL))
+8 IF RESULT>9.0
SET FOUND=1_U_RESULT_U_(9999999-VAL)
+9 IF '$TEST
SET FOUND=0_U_RESULT_U_(9999999-VAL)
End DoDot:1
+10 IF '$TEST
Begin DoDot:1
+11 SET TAX="BGPMU LAB LOINC HGBA1C"
+12 DO LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+13 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+14 IF VAL=""
SET FOUND=$$VLAB(DFN,BGPBDATE,BGPEDATE,TAX)
+15 IF '$TEST
Begin DoDot:2
+16 SET RESULT=$GET(DATA(VAL))
+17 IF RESULT>9.0
SET FOUND=1_U_RESULT_U_(9999999-VAL)
+18 IF '$TEST
SET FOUND=0_U_RESULT_U_(9999999-VAL)
End DoDot:2
End DoDot:1
+19 QUIT FOUND
VLAB(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>9.0
SET LABVAL=1_U_VAL_U_$PIECE(VLAB,U,1)
+8 IF '$TEST
SET LABVAL=0_U_VAL_U_$PIECE(VLAB,U,1)
End DoDot:1
+9 QUIT LABVAL
ENTRY2 ;EP Entry point for NQA0575 For good control with HgbA1c <8.0
+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,ERENC,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 (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,NUMCT,NOTNUM,TOTALS,DEN,DXTIME
+2 SET TOTALS=$GET(^TMP("BGPMU0575",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0575",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0575",$JOB,BGPMUTF,"NUM"))
+5 SET EXCCT=+$GET(^TMP("BGPMU0575",$JOB,BGPMUTF,"EXC"))
+6 SET NOTNUM=+$GET(^TMP("BGPMU0575",$JOB,BGPMUTF,"NOT"))
+7 SET PTCNT=TOTALS
+8 SET PTCNT=PTCNT+1
+9 SET (DEN,DXTIME)=""
+10 SET DENCT=DENCT+1
SET ^TMP("BGPMU0575",$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("BGPMU0575",$JOB,BGPMUTF,"NUM")=NUMCT
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0575",$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("BGPMU0575",$JOB,BGPMUTF,"EXC")=EXCCT
+20 IF BGPMUTF="C"
SET ^TMP("BGPMU0575",$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("BGPMU0575",$JOB,BGPMUTF,"NOT")=NOTNUM
+23 IF BGPMUTF="C"
SET ^TMP("BGPMU0575",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+24 SET ^TMP("BGPMU0575",$JOB,BGPMUTF,"TOT")=PTCNT
+25 ;Setup iCare array for patient
+26 SET BGPICARE("MU.EP.0575.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
+27 QUIT
NUM2(DFN,BGPBDATE,BGPEDATE) ; Find the latest HGBA1C
+1 NEW FOUND,YR1,YR2,HGBA1C,DATA,VAL,IEN,RESULT,TAX
+2 SET TAX="BGPMU LAB CPT HGBA1C"
+3 DO LABCPT^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+4 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+5 IF +VAL
Begin DoDot:1
+6 SET RESULT=$GET(DATA(VAL))
+7 IF RESULT=""!(RESULT=0)
QUIT
+8 IF RESULT<8.0
SET FOUND=1_U_RESULT_U_(9999999-VAL)
+9 IF '$TEST
SET FOUND=0_U_RESULT_U_(9999999-VAL)
End DoDot:1
+10 IF '$TEST
Begin DoDot:1
+11 SET TAX="BGPMU LAB LOINC HGBA1C"
+12 SET FOUND=0
SET RESULT=""
+13 SET HGBA1C=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,TAX)
+14 DO LAB^BGPMUUT5(.DATA,DFN,TAX,BGPBDATE,BGPEDATE)
+15 SET VAL=""
SET VAL=$ORDER(DATA(VAL))
+16 IF VAL=""
SET FOUND=$$VLAB2(DFN,BGPBDATE,BGPEDATE,TAX)
+17 IF '$TEST
Begin DoDot:2
+18 SET RESULT=$GET(DATA(VAL))
+19 IF RESULT=""!(RESULT=0)
QUIT
+20 IF RESULT<8.0
SET FOUND=1_U_RESULT_U_(9999999-VAL)
+21 IF '$TEST
SET FOUND=0_U_RESULT_U_(9999999-VAL)
End DoDot:2
End DoDot:1
+22 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=""!(VAL=0)
SET LABVAL=0
+8 IF '$TEST
Begin DoDot:2
+9 IF VAL<8.0
SET LABVAL=1_U_VAL_U_$PIECE(VLAB,U,1)
+10 IF VAL>7.999
SET LABVAL=0_U_VAL_U_$PIECE(VLAB,U,1)
End DoDot:2
End DoDot:1
+11 QUIT LABVAL