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

BGPMUA07.m

Go to the documentation of this file.
BGPMUA07 ; IHS/MSC/MGH - MI measure NQF0056 & NQF0061 ;25-Jul-2011 08:35;DU
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;Code to collect meaningful use report for diabetic foot exam
ENTRY1 ;EP Entry point for NQA0056 Diabetic food exam
 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
 ;Pts must be >18 and <75
 ;No need to check further if no age match
 S DIABDX=0
 S (DIAB,EXC,NUM)=0
 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 VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
 ..I +VENC 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^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 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
 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("BGPMU0056",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0056",$J,BGPMUTF,"DEN"))
 S NUMCT=+$G(^TMP("BGPMU0056",$J,BGPMUTF,"NUM"))
 S EXCCT=+$G(^TMP("BGPMU0056",$J,BGPMUTF,"EXC"))
 S NOTNUM=+$G(^TMP("BGPMU0056",$J,BGPMUTF,"NOT"))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S (DEN,DXTIME)=""
 S DENCT=DENCT+1 S ^TMP("BGPMU0056",$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("BGPMU0056",$J,BGPMUTF,"NUM")=NUMCT
 .I BGPMUTF="C" S ^TMP("BGPMU0056",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)_";"_$P(NUM,U,4)_";"_$P(NUM,U,5)
 I +EXC D
 .S EXCCT=EXCCT+1 S ^TMP("BGPMU0056",$J,BGPMUTF,"EXC")=EXCCT
 .I BGPMUTF="C" S ^TMP("BGPMU0056",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
 I NUM=0&(EXC=0) D
 .S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0056",$J,BGPMUTF,"NOT")=NOTNUM
 .I BGPMUTF="C" S ^TMP("BGPMU0056",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
 S ^TMP("BGPMU0056",$J,BGPMUTF,"TOT")=PTCNT
 ;Setup iCare array for patient
 S BGPICARE("MU.EP.0056.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 diabetic foot exam
 N FOUND,YR1,EXM
 S FOUND=0
 ;Search for CPT code during the reporting period
 S EXM=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU DIAB FOOT EXAM CPT")
 I +EXM S FOUND=1_U_$P(EXM,U,2)_U_$P(EXM,U,3)
 Q FOUND
ENTRY2 ;EP  Entry point for NQA0061 Most recent BP<140/90
 N START,END,BGPNUM,BGPDEN,BGPNUM,AENC,BENC,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)=""
 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 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 visit
 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'=2&(+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,DXTIME,DEN
 S TOTALS=$G(^TMP("BGPMU0061",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0061",$J,BGPMUTF,"DEN"))
 S NUMCT=+$G(^TMP("BGPMU0061",$J,BGPMUTF,"NUM"))
 S EXCCT=+$G(^TMP("BGPMU0061",$J,BGPMUTF,"EXC"))
 S NOTNUM=+$G(^TMP("BGPMU0061",$J,BGPMUTF,"NOT"))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S (DEN,DXTIME)=""
 S DENCT=DENCT+1 S ^TMP("BGPMU0061",$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=2 D
 .S NUMCT=NUMCT+1 S ^TMP("BGPMU0061",$J,BGPMUTF,"NUM")=NUMCT
 .I BGPMUTF="C" S ^TMP("BGPMU0061",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)_";"_$P(NUM,U,4)_";"_$P(NUM,U,5)
 I +EXC D
 .S EXCCT=EXCCT+1 S ^TMP("BGPMU0061",$J,BGPMUTF,"EXC")=EXCCT
 .I BGPMUTF="C" S ^TMP("BGPMU0061",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"EXCLUDE"
 I +NUM'=2&(EXC=0) D
 .S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0061",$J,BGPMUTF,"NOT")=NOTNUM
 .I BGPMUTF="C" S ^TMP("BGPMU0061",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
 S ^TMP("BGPMU0061",$J,BGPMUTF,"TOT")=PTCNT
 ;Setup iCare array for patient
 S BGPICARE("MU.EP.0061.1",BGPMUTF)=1_U_(+NUM=2)_U_+EXC_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
 Q
NUM2(DFN,BGPBDATE,BGPEDATE) ; Find the latest BP
 ;check blood pressure reading of most recent outpatient encounter
 N LDIA,LSYS,BGPBP,BP,SYS,DIA,BGPI,BGPNUM,BGPCNT,RESULT,VSIEN
 S (LDIA,LSYS)=""
 ;Find is pt has a BP on the chosen visits
 N IEN,MSR,MTYP,BP,BPCNT,SAVE,ARRAY,VST,VCNT,INV,DTE,EIE
 S BP=0,BPCNT=0,VCNT=0
 S MTYP="" S MTYP=$O(^AUTTMSR("B","BP",MTYP))
 Q:MTYP="" 0
 Q:'$D(VIEN) 0
 S VSIEN=$P($G(VIEN(1)),U,1)
 S IEN=VSIEN,SAVE=0
 S MSR="" F  S MSR=$O(^AUPNVMSR("AD",VSIEN,MSR)) Q:MSR=""  D
 .S EIE=$$GET1^DIQ(9000010.01,MSR,2,"I")
 .Q:EIE=1
 .I $P($G(^AUPNVMSR(MSR,0)),U,1)=MTYP D
 ..S BPCNT=BPCNT+1
 ..S INV=9999999-$P($G(^AUPNVMSR(MSR,12)),U,1)
 ..S ARRAY(INV)=IEN_U_$P($G(^AUPNVMSR(MSR,0)),U,4)_U_$$DATE^BGPMUUTL($P($G(^AUPNVMSR(MSR,12)),U,1))
 I BPCNT=1 D
 .S DTE="" S DTE=$O(ARRAY(DTE))
 .S RESULT=$P($G(ARRAY(DTE)),U,2)
 .S SYS=$P(RESULT,"/",1),DIAS=$P(RESULT,"/",2)
 .I SYS>139!(DIAS>89) S BP=1_U_RESULT_U_$P($G(ARRAY(DTE)),U,3)
 .E  S BP=2_U_RESULT_U_$P($G(ARRAY(DTE)),U,3)
 ;More than one BP on the visit
 I BPCNT>1 D
 .N DONE,SYSARRAY,DIAARRAY
 .S DONE=0
 .S DTE="" F  S DTE=$O(ARRAY(DTE)) Q:DTE=""!(+DONE)  D
 ..S RESULT=$P($G(ARRAY(DTE)),U,2)
 ..S SYS=$P(RESULT,"/",1),DIAS=$P(RESULT,"/",2)
 ..I SYS<140&(DIAS<90) D  Q
 ...;If any BP is <140/90 we are done
 ...S DONE=1
 ...S BP=2_U_RESULT_U_$P($G(ARRAY(DTE)),U,3)
 ..;If Sys <140 save it
 ..I SYS<140 D  Q
 ...S SYSARRAY(SYS)=RESULT_U_$P($G(ARRAY(DTE)),U,3)
 ..;If Dias <90 save it
 ..I DIAS<90 D  Q
 ...S DIAARRAY(DIAS)=RESULT_U_$P($G(ARRAY(DTE)),U,3)
 .;when done looping, see if there are any saved items
 .I $D(SYSARRAY)&$D(DIAARRAY) D
 ..S RES1=$O(SYSARRAY(""))
 ..S RES2=$O(DIAARRAY(""))
 ..S BP=2_U_$G(SYSARRAY(RES1))_U_$G(DIAARRAY(RES2))
 Q BP