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

BGPMUA08.m

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