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

BGPMUG06.m

Go to the documentation of this file.
BGPMUG06 ; IHS/MSC/MMT - MI measure NQF0004 ;20-Aug-2011 14:56;DU
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;Code to collect meaningful use report for Alcohol and Other Drug Dependence Treatment
ENTRY ;EP 
 N START,END,STRING,STRING2
 N IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN
 N CNT,NUM1,NUM2,DEN
 S (NUM1,NUM2,DEN)=0
 ;Pts must be 13 or older
 ;No need to check further if no age match
 Q:BGPAGEE<13
 S DEN=$$DEN(DFN,BGPBDATE,BGPEDATE)
 Q:'+DEN
 ;check to see if they are in the numerators
 S NUM1=$$NUM1(DFN,DEN)
 S:+NUM1 NUM2=$$NUM2(DFN,NUM1)
 D TOTAL(DFN,DEN,NUM1,NUM2)
 Q
TOTAL(DFN,DEN,NUM1,NUM2) ;See where this patient ends up
 D:BGPAGEE<18 TOTSUB(1)  ;ages 13-17
 D:BGPAGEE>17 TOTSUB(2)  ;ages 18+
 D TOTSUB(3)  ;all ages 13+
 Q
TOTSUB(DENPOP) ;ADD Patient to a population's totals
 N TOTAL,PTCNT,DENCT,NUM1CT,NUM2CT,NOTNUM
 N DENSTR1,DENSTR2,NUMSTR1,NUMSTR2
 S TOTAL=$G(^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"DEN"))
 S NUM1CT=+$G(^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NUM",1))
 S NUM2CT=+$G(^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NUM",2))
 S NOTNUM1=+$G(^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NOT",1))
 S NOTNUM2=+$G(^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NOT",2))
 S PTCNT=TOTAL
 S PTCNT=PTCNT+1
 S DENCT=DENCT+1 S ^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"DEN")=DENCT
 S DENSTR1=$$DENSTR1(DEN)
 S DENSTR2=DENSTR1
 S NUMSTR1=$$NUMSTR1(NUM1)
 S NUMSTR2=$$NUMSTR2(NUM1)
 I +NUM1 D
 .S NUM1CT=NUM1CT+1 S ^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NUM",1)=NUM1CT
 .I BGPMUTF="C" S ^TMP("BGPMU0004",$J,"PAT",BGPMUTF,DENPOP,"NUM",1,PTCNT)=DFN_U_DENSTR1_U_"M:"_NUMSTR1
 I +NUM1=0 D
 .S NOTNUM1=NOTNUM1+1 S ^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NOT",1)=NOTNUM1
 .I BGPMUTF="C" S ^TMP("BGPMU0004",$J,"PAT",BGPMUTF,DENPOP,"NOT",1,PTCNT)=DFN_U_DENSTR1_U_"NM:"_NUMSTR1
 I +NUM2 D
 .S NUM2CT=NUM2CT+1 S ^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NUM",2)=NUM2CT
 .I BGPMUTF="C" S ^TMP("BGPMU0004",$J,"PAT",BGPMUTF,DENPOP,"NUM",2,PTCNT)=DFN_U_DENSTR2_U_"M:"_NUMSTR2
 I +NUM2=0 D
 .S NOTNUM2=NOTNUM2+1 S ^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"NOT",2)=NOTNUM2
 .I BGPMUTF="C" S ^TMP("BGPMU0004",$J,"PAT",BGPMUTF,DENPOP,"NOT",2,PTCNT)=DFN_U_DENSTR2_U_"NM:"_NUMSTR2
 S ^TMP("BGPMU0004",$J,BGPMUTF,DENPOP,"TOT")=PTCNT
 ;Setup iCare array for patient only for the 3rd (all encompassing) population
 S:DENPOP=3 BGPICARE("MU.EP.0004.1",BGPMUTF)=1_U_+NUM1_U_0_U_DENSTR1_U_NUMSTR1
 S:DENPOP=3 BGPICARE("MU.EP.0004.2",BGPMUTF)=1_U_+NUM2_U_0_U_DENSTR2_U_NUMSTR2
 Q
NUM1(DFN,DEN) ;Look for alcohol/drug treatment
 ;return: local VIEN array ptr ^ VISIT file ptr ^ VISIT DATE/TIME
 N FOUND,VPTR,INITDATE,VSTRT
 S FOUND=0,INITDATE=$$FMADD^XLFDT($P($P(DEN,U,2),"."),14)_".2359"
 ;quit early if DEN visit also qualifies as FIRST treatment (7th flag)
 I $P($G(VIEN($P(DEN,U,3))),U,7) S FOUND=$P(DEN,U,3)_U_$P(VIEN($P(DEN,U,3)),U,1,2)_U_U_$P(DEN,U,3) Q FOUND
 S VSTRT=$S($P(DEN,U)=2:CNT,1:($P(DEN,U,3)-1))
 F VPTR=VSTRT:-1:1 D  Q:FOUND'=0
 .;make sure to avoid ED visits(3rd flag) and BH w/o Dx (6th flag)
 .I '$P(VIEN(VPTR),U,3)&'$P(VIEN(VPTR),U,6) S FOUND=$S($P(VIEN(VPTR),U,2)>INITDATE:0,1:VPTR)_U_$P(VIEN(VPTR),U,1,2)_U_VPTR Q
 Q FOUND
NUM2(DFN,NUM1) ;Look for 2nd & 3rd alcohol/drug treatment <= 30 days after first treatment (NUM1)
 ;return just a TRUE if met since not mets will still need to display encounters
 N FOUND,VPTR,V1,FUP2DATE,TCNT,ST
 K ST
 S TCNT=0,FUP2DATE=$$FMADD^XLFDT($P($P(NUM1,U,3),"."),30)_".2359"
 S FOUND=""
 S V1=$P(NUM1,U)-1
 F VPTR=V1:-1:1 D
 .Q:$P(VIEN(VPTR),U,2)>FUP2DATE  ;stop once we've gone past 30 days after FIRST
 .;make sure to avoid ED visits
 .S:'$P(VIEN(VPTR),U,3)&'$P(VIEN(VPTR),U,7) TCNT=TCNT+1
 .I TCNT>1 S FOUND=1 Q
 Q FOUND
DEN(DFN,BDATE,EDATE) ;CHECK IF PT IS IN DENOMINATOR
 N SRCHSTRT,SRCHEND,START,END
 N ALCDX,ALCPROC,EDENC,IPENC,IPAENC,BHENC,BHPENC
 N FIRSTVST,INTVPRC,PREVDX,VPTR
 S SRCHSTRT=$$FMADD^XLFDT(EDATE,-365),SRCHEND=$$FMADD^XLFDT(EDATE,-45)
 S START=9999999-SRCHSTRT,END=9999999-SRCHEND
 S START=START_".2359"
 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)
 ..;Next check for Dx of AOD dependence
 ..S ALCDX=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ALCOHOL DRUG DEP DX")
 ..S ALCPROC=$$VSTICD0^BGPMUUT3(DFN,IEN,"BGPMU ALCOHOL IP DETOX ICD0")
 ..S (EDENC,IPENC,IPAENC,BHENC,BHPENC)=""
 ..;check encounter codes
 ..S EDENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER ED CPT")
 ..I +EDENC&(+ALCDX) D VSTSTORE Q
 ..S IPAENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
 ..I +IPAENC&(+ALCDX!+ALCPROC) D VSTSTORE Q
 ..S IPENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU NON-ACUTE INPT CPT")
 ..I +IPENC&(+ALCDX!+ALCPROC) D VSTSTORE Q
 ..S BHENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENC OUTPT BEHAVIOR HLTH")
 ..I +BHENC D VSTSTORE Q
 ..S BHPENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENC OUTPT BEHAVIOR POS")
 ..I +BHPENC&(+ALCDX) D VSTSTORE Q
 ;if no visits found, check entire search period for Intervention procedure, otherwise BEFORE earliest visit or Intervention
 ;set up earliest episode in either case
 S FIRSTVST=0
 I CNT=0 D
 .S INTVPRC=$$LASTPRC^BGPMUUT2(DFN,SRCHSTRT,SRCHEND,"BGPMU ALCOHOL DETOX INTV ICD0")
 .I +INTVPRC S:($P($G(^AUPNVPRC($P(INTVPRC,U,5),12)),U,4)=BGPPROV) FIRSTVST=2_U_$P(INTVPRC,U,3)_U_$P(INTVPRC,U,5) ;2 ^ Date  ^ V PROC ptr
 E  D
 .F VPTR=CNT:-1:1 I '$P(VIEN(VPTR),U,6) S FIRSTVST=$P(VIEN(VPTR),U,2) Q
 .Q:FIRSTVST=0
 .S INTVPRC=$$LASTPRC^BGPMUUT2(DFN,SRCHSTRT,FIRSTVST,"BGPMU ALCOHOL DETOX INTV ICD0")
 .I +INTVPRC,(($P(INTVPRC,U,3)<FIRSTVST)&($P($G(^AUPNVPRC($P(INTVPRC,U,5),12)),U,4)=BGPPROV)) S FIRSTVST=2_U_$P(INTVPRC,U,3)_U_$P(INTVPRC,U,5)
 .E  S FIRSTVST=1_U_$P(VIEN(VPTR),U,2)_U_VPTR
 I FIRSTVST=0 S DEN=0 Q DEN
 ;now that the first episode is established, check to make sure a previous Dx not present in the 60 days prior
 S PREVDX=$$LASTDX^BGPMUUT2(DFN,$$FMADD^XLFDT($P(FIRSTVST,U,2),-60),$$FMADD^XLFDT($P(FIRSTVST,U,2),-2),"BGPMU ALCOHOL DRUG DEP DX")
 I +PREVDX S DEN=0 Q DEN
 S DEN=FIRSTVST
 K ALCDX,ALCPROC,EDENC,IPENC,IPAENC,BHENC,BHPENC
 Q DEN
VSTSTORE ;Store compliant visit into array
 S CNT=CNT+1
 S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
 ;3rd flag = ED encounters so they can be ignored for both NUM's
 ;6th flag = may count towards subsequent treatments (Num2) but NOT for the denominator or Num 1
 ;7th flag = may count toward Den and Num 1, but NOT Num2
 S VIEN(CNT)=IEN_U_VDATE_U_+EDENC_U_$P(ALCDX,U,3)_U_$P(ALCPROC,U,3)_U_$S(+$G(BHENC):'ALCDX,1:0)_U_$S(+$G(IPAENC)!+$G(IPENC):(+ALCPROC),1:0)
 ;S VIEN(CNT)=IEN_U_VDATE_U_+EDENC_U_$P(ALCDX,U,3)_U_$P(ALCPROC,U,3)_U_$S(+$G(BHENC):'ALCDX,1:0)_U_$S(+$G(IPAENC)!+$G(IPENC):(+ALCPROC&'ALCDX),1:0)
 S STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
 Q
DENSTR1(DEN) ;generate display string for denom criteria 1 - Dx present with IP/ED visit 
 N STRING,DXDT,PRCDT
 S DXDT=$S($P(DEN,U)=1:$P(VIEN($P(DEN,U,3)),U,4),1:"")
 S PRCDT=$S($P(DEN,U)=1:$P(VIEN($P(DEN,U,3)),U,5),1:"")
 I $P(DEN,U)=2 D
 .S STRING="DI:"_$$DATE^BGPMUUTL($P(DEN,U,2))
 E  D
 .S STRING=$S(DXDT'="":"ADX:"_$$DATE^BGPMUUTL(DXDT),PRCDT'="":"ADI:"_$$DATE^BGPMUUTL(PRCDT),1:"")
 .S STRING=STRING_";EN:"_$$DATE^BGPMUUTL($P(VIEN($P(DEN,U,3)),U,2))
 Q STRING
NUMSTR1(NUM1) ;generate display string for NUM 1
 Q $S($P(NUM1,U,3)'="":"FT:"_$$DATE^BGPMUUTL($P(NUM1,U,3)),1:"")
NUMSTR2(NUM1) ;generate display string for NUM 2 
 N STRING,V1,VPTR,COUNT
 S STRING="",COUNT=0
 S STRING=$S($P(NUM1,U,3)'="":"FT:"_$$DATE^BGPMUUTL($P(NUM1,U,3)),1:"")
 S V1=$P(NUM1,U,4)-1
 F VPTR=V1:-1:1 D  Q:COUNT>1
 .S STRING=STRING_$S(STRING'="":";",1:"")_"ST:"_$$DATE^BGPMUUTL($P(VIEN(VPTR),U,2))
 .S COUNT=COUNT+1
 .Q:COUNT>1
 Q STRING