Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BGPMUA06

BGPMUA06.m

Go to the documentation of this file.
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