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

BGPMUF06.m

Go to the documentation of this file.
BGPMUF06 ; IHS/MSC/MGH - MI measure NQF0073 ;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 BP Mgmt
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,NUM)=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 NUM=$$NUM(DFN,BGPBDATE,BGPEDATE)
 D TOTAL1(DFN,IVD,NUM)
 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,NUM) ;See where this patient ends up
 N PTCNT,DENCT,NUM1CT,NOTNUM1,TOTALS,DXTIME,DEN
 S TOTALS=$G(^TMP("BGPMU0073",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0073",$J,BGPMUTF,"DEN"))
 S NUM1CT=+$G(^TMP("BGPMU0073",$J,BGPMUTF,"NUM"))
 S NOTNUM1=+$G(^TMP("BGPMU0073",$J,BGPMUTF,"NOT"))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S (DEN,DXTIME)=""
 S DENCT=DENCT+1 S ^TMP("BGPMU0073",$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 +NUM=2 D
 .S NUM1CT=NUM1CT+1 S ^TMP("BGPMU0073",$J,BGPMUTF,"NUM")=NUM1CT
 .I BGPMUTF="C" S ^TMP("BGPMU0073",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_$P(NUM,U,2,5)
 I +NUM<2 D
 .S NOTNUM1=NOTNUM1+1 S ^TMP("BGPMU0073",$J,BGPMUTF,"NOT")=NOTNUM1
 .I BGPMUTF="C" S ^TMP("BGPMU0073",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_$P(NUM,U,2,5)
 S ^TMP("BGPMU0073",$J,BGPMUTF,"TOT")=PTCNT
 ;Setup iCare array for patient
 S BGPICARE("MU.EP.0073.1",BGPMUTF)=1_U_(+NUM=2)_U_""_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,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
NUM(DFN,BGPBDATE,BGPEDATE) ;check for BP's
 ;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 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)=VSIEN_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