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

BGPMUF05.m

Go to the documentation of this file.
BGPMUF05 ; IHS/MSC/MGH - MI measure NQF0075 ;02-Aug-2011 14:56;DU
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;Code to collect meaningful use report for IVD Lipid/LDL
ENTRY ;EP
 N START,END,BGPNUM,BGPDEN,BGPNUM,STRING,OUTCT,NFCT,INCT
 N IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN,RESULT,IVDSTRT,IVDEND
 N CNT,IVD,NUM,OUTENC,NFENC,VENC,IVDDX
 S (BGPDEN,BGPNUM,RESULT)=0
 S IVDSTRT=$$FMADD^XLFDT(BGPEDATE,-730),IVDEND=$$FMADD^XLFDT(BGPEDATE,-426)
 S STRING="",IVDDX=0
 S (IVD,NUM1,NUM2)=0
 ;Pts must be >18
 ;No need to check further if no age match
 Q:BGPAGEE<18
 S CNT=0
 ;First check for IVD DX as an outpatient since this is more common 
 S START=9999999-IVDSTRT,END=9999999-BGPEDATE,VALUE=0
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)!(+IVD)  D
 .S IEN=0 F  S IEN=$O(^AUPNVSIT("AA",DFN,FIRST,IEN)) Q:'+IEN!(+IVD)  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 NFENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
 ..I +NFENC D VSTSTORE Q
 ..S VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
 ..I +VENC D VSTSTORE Q
 ;skip to numerator checking if IVD Dx found
 I +IVD G NUMCHKS
 ;check for other procedures or diagnoses
 S CNT=0
 S START=9999999-IVDSTRT,END=9999999-IVDEND,VALUE=0
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)!(+IVD)  D
 .S IEN=0 F  S IEN=$O(^AUPNVSIT("AA",DFN,FIRST,IEN)) Q:'+IEN!(+IVD)  D
 ..;Check provider, Only visits for chosen provider
 ..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
 ..S NFENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
 ..I +NFENC D
 ...S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
 ...S CNT=CNT+1
 ...S VIEN(CNT)=IEN_U_VDATE_U_$$DATE^BGPMUUTL(VDATE)
 ...S STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
 ...S IVD=$$INPTDEN(DFN,IEN,IVDSTRT,IVDEND)
NUMCHKS ;If the patient had IVD, check to see if they are in the numerator
 Q:'IVD
 S NUM1=$$NUM1(DFN,BGPBDATE,BGPEDATE)
 ; if patient not in NUM1 then they don't have requisite tests and therefore cannot be in NUM2
 I +NUM1 S NUM2=$$NUM2(DFN,BGPBDATE,BGPEDATE)
 D TOTAL1(DFN,IVD,NUM1,NUM2)
 Q
VSTSTORE ;Store compliant visit into array
 S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
 S CNT=CNT+1
 S VIEN(CNT)=IEN_U_VDATE_U_$$DATE^BGPMUUTL(VDATE)
 S STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
 S IVD=$$OUTPTDEN(DFN,IEN)
 Q
TOTAL1(DFN,IVD,NUM1,NUM2) ;See where this patient ends up
 N PTCNT,DENCT,NUM1CT,NUM2CT,NOTNUM1,NOTNUM2,TOTALS,DXTIME,DEN
 S TOTALS=$G(^TMP("BGPMU0075",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0075",$J,BGPMUTF,"DEN"))
 S NUM1CT=+$G(^TMP("BGPMU0075",$J,BGPMUTF,"NUM",1))
 S NOTNUM1=+$G(^TMP("BGPMU0075",$J,BGPMUTF,"NOT",1))
 S NUM2CT=+$G(^TMP("BGPMU0075",$J,BGPMUTF,"NUM",2))
 S NOTNUM2=+$G(^TMP("BGPMU0075",$J,BGPMUTF,"NOT",2))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S (DEN,DXTIME)=""
 S DENCT=DENCT+1 S ^TMP("BGPMU0075",$J,BGPMUTF,"DEN")=DENCT
 I $P(IVD,U,3)'="" S DXTIME=$$DATE^BGPMUUTL($P(IVD,U,3))
 S DEN=$P(IVD,U,2)_DXTIME_";EN:"_STRING(1)
 I +NUM1 D
 .S NUM1CT=NUM1CT+1 S ^TMP("BGPMU0075",$J,BGPMUTF,"NUM",1)=NUM1CT
 .I BGPMUTF="C" S ^TMP("BGPMU0075",$J,"PAT",BGPMUTF,"NUM",1,PTCNT)=DFN_U_DEN_U_$P(NUM1,U,2)_U_$P(NUM1,U,3)
 I +NUM1=0 D
 .S NOTNUM1=NOTNUM1+1 S ^TMP("BGPMU0075",$J,BGPMUTF,"NOT",1)=NOTNUM1
 .I BGPMUTF="C" S ^TMP("BGPMU0075",$J,"PAT",BGPMUTF,"NOT",1,PTCNT)=DFN_U_DEN
 I +NUM2=1!(+NUM2=3) D
 .S NUM2CT=NUM2CT+1 S ^TMP("BGPMU0075",$J,BGPMUTF,"NUM",2)=NUM2CT
 .I BGPMUTF="C" S ^TMP("BGPMU0075",$J,"PAT",BGPMUTF,"NUM",2,PTCNT)=DFN_U_DEN_U_$P(NUM2,U,2)_U_$P(NUM2,U,3)
 I +NUM2=0!(+NUM2=2) D
 .S NOTNUM2=NOTNUM2+1 S ^TMP("BGPMU0075",$J,BGPMUTF,"NOT",2)=NOTNUM2
 .I BGPMUTF="C" S ^TMP("BGPMU0075",$J,"PAT",BGPMUTF,"NOT",2,PTCNT)=DFN_U_DEN_U_$P(NUM2,U,2)_U_$P(NUM2,U,3)
 S ^TMP("BGPMU0075",$J,BGPMUTF,"TOT")=PTCNT
 ;Setup iCare array for patient
 S BGPICARE("MU.EP.0075.1",BGPMUTF)=1_U_+NUM1_U_""_U_DEN_";"_$P(NUM1,U,2)_";"_$P(NUM1,U,3)
 S BGPICARE("MU.EP.0075.2",BGPMUTF)=1_U_((+NUM2=1)!(+NUM2=3))_U_""_U_DEN_";"_$P(NUM2,U,2)_";"_$P(NUM2,U,3)
 Q
OUTPTDEN(DFN,VIEN) ; Get the denominator
 N RESULT,IVDA,IVDB,IVDDX,DOB
 S RESULT=0
 ;Check for IVD Dx
 S DOB=$$GET1^DIQ(2,DFN,.03,"I")
 S IVDA=$$VSTPOV^BGPMUUT3(DFN,VIEN,"BGPMU IVD DX")
 ; PROBLEM check not in ORT - S IVDB=$$PLTAX^BGPMUUT1(DFN,"BGPMU IVD DX","A",END)
 I +IVDA S IVDDX=IVDA
 ;I +IVDB S IVDDX=IVDB
 ;I +IVDA!(+IVDB) S RESULT=1_U_"IVD:"_$P(IVDDX,U,2)_U_$P(IVDDX,U,3) Q RESULT
 I +IVDA S RESULT=1_U_"IVD:"_U_$P(IVDDX,U,3) Q RESULT
 Q RESULT
INPTDEN(DFN,VIEN,START,END) ;Evaluate Inpatient visit denominator criteria
 N RESULT,PTCA,PTCAP,AMI,CABG,CABGP
 S RESULT=0
 ;Check for PTCA Codes (14 to 24 months hence)
 S PTCA=$$CPT^BGPMUUT1(DFN,IVDSTRT,IVDEND,"BGPMU PTCA CPT")
 ;I +PTCA S RESULT=1_U_"PTCA:"_$P(PTCA,U,2)_U_$P(PTCA,U,3) Q RESULT
 I +PTCA S RESULT=1_U_"PTCA:"_U_$P(PTCA,U,3) Q RESULT
 S PTCAP=$$LASTPRC^BGPMUUT2(DFN,IVDSTRT,IVDEND,"BGPMU PTCA PROCEDURE")
 I +PTCAP S RESULT=1_U_"PTCA:"_U_$P(PTCAP,U,3) Q RESULT
 ;Check for AMI Dx (during visit)
 S AMI=$$VSTPOV^BGPMUUT3(DFN,VIEN,"BGPMU ACUTE MI DX")
 I +AMI S RESULT=1_U_"AMI:"_U_$P(AMI,U,3) Q RESULT
 ;Check for CABG procedure (during visit)
 S CABG=$$VSTCPT^BGPMUUT1(DFN,VIEN,"BGPMU CABG CPT")
 I +CABG S RESULT=1_U_"CABG:"_U_$P(CABG,U,3) Q RESULT
 S CABGP=$$VSTICD0^BGPMUUT3(DFN,VIEN,"BGPMU CABG PROCEDURE")
 I +CABGP S RESULT=1_U_"CABG:"_U_$P(CABGP,U,3) Q RESULT
 Q RESULT
NUM1(DFN,BGPBDATE,BGPEDATE) ;check for LDL Performed
 N FOUND,BGPLDL,BGPHDL,BGPCHOL,BGPTRIG,DATA
 N LDLVAL,HDLVAL,CHOLVAL,TRIGVAL,VAL
 S FOUND=0
 S BGPLDL=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU IVD LDL LOINC")
 I +BGPLDL D
 .S LDLVAL=$P($G(^AUPNVLAB($P(BGPLDL,U,2),0)),U,4)
 .S FOUND=1_U_$P(BGPLDL,U)_U_"LDL "_LDLVAL
 Q:+FOUND FOUND
 ;check for LDL via CPT codes in LAB
 D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT LDL",BGPBDATE,BGPEDATE)
 S VAL="" S VAL=$O(DATA(VAL))
 I +VAL D
 .S LDLVAL=$G(DATA(VAL))
 .S FOUND=1_U_(9999999-VAL)_U_"LDL "_LDLVAL
 Q:+FOUND FOUND
 ;NOW CHECK FOR THE TRIAD OF TESTS INDIVIDUALLY via LOINC and CPT
 S BGPHDL=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU HDL LOINC")
 I +BGPHDL D
 .S HDLVAL=$P($G(^AUPNVLAB($P(BGPHDL,U,2),0)),U,4)
 E  D
 .;check for HDL via CPT codes in LAB
 .D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT HDL",BGPBDATE,BGPEDATE)
 .S VAL="" S VAL=$O(DATA(VAL))
 .I +VAL D
 ..S HDLVAL=$G(DATA(VAL))
 ..S BGPHDL=(9999999-VAL)
 S BGPCHOL=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU CHOLESTEROL LOINC")
 I +BGPCHOL D
 .S CHOLVAL=$P($G(^AUPNVLAB($P(BGPCHOL,U,2),0)),U,4)
 E  D
 .;check for CHOLESTEROL via CPT codes in LAB
 .D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT CHOLESTEROL",BGPBDATE,BGPEDATE)
 .S VAL="" S VAL=$O(DATA(VAL))
 .I +VAL D
 ..S CHOLVAL=$G(DATA(VAL))
 ..S BGPCHOL=(9999999-VAL)
 S BGPTRIG=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU TRIGLYCERIDES LOINC")
 I +BGPTRIG D
 .S TRIGVAL=$P($G(^AUPNVLAB($P(BGPTRIG,U,2),0)),U,4)
 E  D
 .;check for TRIGLYCERIDES via CPT codes in LAB
 .D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT TRIGLYCERIDES",BGPBDATE,BGPEDATE)
 .S VAL="" S VAL=$O(DATA(VAL))
 .I +VAL D
 ..S TRIGVAL=$G(DATA(VAL))
 ..S BGPTRIG=(9999999-VAL)
 I +BGPHDL&(+BGPCHOL)&(+BGPTRIG) D
 .S FOUND=2_U_$P(BGPHDL,U)_";"_$P(BGPCHOL,U)_";"_$P(BGPTRIG,U)_U_"HDL "_HDLVAL_";"_"CHL "_CHOLVAL_";"_"TRI "_TRIGVAL
 Q FOUND
NUM2(DFN,BGPBDATE,BGPEDATE) ;check for good LAB VALUES
 N FOUND,BGPLDL,BGPHDL,BGPCHOL,BGPTRIG,LIEN,DATA
 N LDLVAL,HDLVAL,CHOLVAL,TRIGVAL,VAL
 S FOUND=0
 S (LDLVAL,HDLVAL,CHOLVAL,TRIGVAL)=0
 S BGPLDL=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU IVD LDL LOINC")
 I +BGPLDL D
 .S LIEN=$P(BGPLDL,U,2)
 .S LDLVAL=$P($G(^AUPNVLAB(LIEN,0)),U,4)
 .I (LDLVAL'="") D
 ..I (LDLVAL<100) D
 ...S FOUND=1_U_$P(BGPLDL,U)_U_"LDL "_LDLVAL
 ..E  S FOUND=0_U_$P(BGPLDL,U)_U_"LDL "_LDLVAL
 Q:+FOUND FOUND
 ;check for LDL via CPT codes in LAB
 D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT LDL",BGPBDATE,BGPEDATE)
 S VAL="" S VAL=$O(DATA(VAL))
 I +VAL D
 .S LDLVAL=$G(DATA(VAL))
 .I (LDLVAL'="") D
 ..I (LDLVAL<100) D
 ...S FOUND=1_U_(9999999-VAL)_U_"LDL "_LDLVAL
 ..E  S FOUND=0_U_(9999999-VAL)_U_"LDL "_LDLVAL
 Q:+FOUND FOUND
 ;NOW CHECK FOR THE TRIAD OF TESTS INDIVIDUALLY via LOINC and CPT
 S BGPHDL=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU HDL LOINC")
 I +BGPHDL D
 .S HDLVAL=$P($G(^AUPNVLAB($P(BGPHDL,U,2),0)),U,4)
 E  D
 .;check for HDL via CPT codes in LAB
 .D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT HDL",BGPBDATE,BGPEDATE)
 .S VAL="" S VAL=$O(DATA(VAL))
 .I +VAL D
 ..S HDLVAL=$G(DATA(VAL))
 ..S BGPHDL=(9999999-VAL)
 S BGPCHOL=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU CHOLESTEROL LOINC")
 I +BGPCHOL D
 .S CHOLVAL=$P($G(^AUPNVLAB($P(BGPCHOL,U,2),0)),U,4)
 E  D
 .;check for CHOLESTEROL via CPT codes in LAB
 .D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT CHOLESTEROL",BGPBDATE,BGPEDATE)
 .S VAL="" S VAL=$O(DATA(VAL))
 .I +VAL D
 ..S CHOLVAL=$G(DATA(VAL))
 ..S BGPCHOL=(9999999-VAL)
 S BGPTRIG=$$LOINC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU TRIGLYCERIDES LOINC")
 I +BGPTRIG D
 .S TRIGVAL=$P($G(^AUPNVLAB($P(BGPTRIG,U,2),0)),U,4)
 E  D
 .;check for TRIGLYCERIDES via CPT codes in LAB
 .D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT TRIGLYCERIDES",BGPBDATE,BGPEDATE)
 .S VAL="" S VAL=$O(DATA(VAL))
 .I +VAL D
 ..S TRIGVAL=$G(DATA(VAL))
 ..S BGPTRIG=(9999999-VAL)
 I +BGPHDL&(+BGPCHOL)&(+BGPTRIG) D
 .I ((TRIGVAL'="")&(TRIGVAL<400))&(((CHOLVAL-HDLVAL-TRIGVAL)/5)<100) D
 ..S FOUND=3_U_$P(BGPHDL,U)_";"_$P(BGPCHOL,U)_";"_$P(BGPTRIG,U)_U_"HDL "_HDLVAL_";"_"CHL "_CHOLVAL_";"_"TRI "_TRIGVAL
 .E  S FOUND=2_U_$P(BGPHDL,U)_";"_$P(BGPCHOL,U)_";"_$P(BGPTRIG,U)_U_"HDL "_HDLVAL_";"_"CHL "_CHOLVAL_";"_"TRI "_TRIGVAL
 Q FOUND