BGPMUG03 ; IHS/MSC/MMT - MI measure NQF0001 ;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 Asthma Assessment
ENTRY ;EP
N START,END,BGPNUM,BGPDEN,STRING,STRING2
N IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN,RESULT
N CNT,NUM,ASTHENC,ASTHMA,ASTDT,ASTDX,ASTPL,LASTVDT
S (BGPDEN,BGPNUM,NUM,RESULT)=0
S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
S START=START_".2359"
;Pts must be between 5 and 40 years
;No need to check further if no age match
Q:BGPAGEE<5!(BGPAGEE>40)
;First check for Asthma Dx since this will eliminate many pts
S ASTHMA=$$ASTHMA(DFN,BGPEDATE)
Q:'ASTHMA
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 ASTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ASTHMA ENCOUNT EM")
..I +ASTENC D VSTSTORE Q
Q:CNT<2
;check to see if they are in the numerator
S NUM=$$NUM(DFN,$P(VIEN(CNT),U,2),$P(VIEN(1),U,2),ASTHMA)
D TOTAL(DFN,ASTHMA,NUM)
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
TOTAL(DFN,ASTHMA,NUM) ;See where this patient ends up
N PTCNT,DENCT,NUMCT,NOTNUM,TOTALS,DEN,DXTIME
S TOTALS=$G(^TMP("BGPMU0001",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0001",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0001",$J,BGPMUTF,"NUM"))
S NOTNUM=+$G(^TMP("BGPMU0001",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S DENCT=DENCT+1 S ^TMP("BGPMU0001",$J,BGPMUTF,"DEN")=DENCT
S DEN="AST:"_$$DATE^BGPMUUTL($P(ASTHMA,U,3))
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("BGPMU0001",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0001",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)
I +NUM=0 D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0001",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0001",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"
S ^TMP("BGPMU0001",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0001.1",BGPMUTF)=1_U_+NUM_U_""_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
ASTHMA(DFN,EDATE) ;Find if patient had a PROBLEM or POV of Asthma on or before the end date
N ASTHMA
S ASTHMA=0
S ASTPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU ASTHMA DX ICD","C",EDATE)
;check date of problem
I +ASTPL S ASTHMA=1_U_$P(ASTPL,U,2,3) Q ASTHMA
S BGPBIRTH=$$DOB^AUPNPAT(DFN)
S ASTDX=$$LASTDX^BGPMUUT2(DFN,BGPBIRTH,EDATE,"BGPMU ASTHMA DX ICD")
I +ASTDX S ASTHMA=2_U_$P(ASTDX,U,2,3) Q ASTHMA
Q ASTHMA
NUM(DFN,BDATE,EDATE,ASTHMA) ;Look for documentation of Asthma assessment
N FOUND,D,G,S,I,ACONTROL
S FOUND=0
;check for documentation in the ASTHMA package
S D=9999999-EDATE-1,G="",S=9999999-BDATE
S D=$O(^AUPNVAST("AS",DFN,D)) I D]""!(D>S) D
.S I="" F S I=$O(^AUPNVAST("AS",DFN,D,I)) Q:I'=+I!(+FOUND) D
..S ACONTROL=$P(^AUPNVAST(I,0),U,14)
..I ACONTROL'="" S FOUND=1_U_"AC "_$$DATE^BGPMUUTL($P($P($G(^AUPNVSIT($P(^AUPNVAST(I,0),U,3),0)),U,1),"."))
Q:+FOUND FOUND
;check for documentation in the PROBLEM record
I $P(ASTHMA,U)=1 D
.S CLASS=$P($G(^AUPNPROB($P(ASTPL,U,4),0)),U,15)
.I CLASS=1!(CLASS=2)!(CLASS=3)!(CLASS=4) D ; YES, this is ALL of the possible values, CLASS=1 MAY be removed later
.S FOUND=1_U_"CL "_$$DATE^BGPMUUTL($P(ASTHMA,U,3))
Q:+FOUND FOUND
;check for CPT code documented
S ASTCPT=$$CPT^BGPMUUT1(DFN,BDATE,EDATE,"BGPMU ASTHMA EVAL CPT")
S:+ASTCPT FOUND=1_U_$P(ASTCPT,U,2)_" "_$$DATE^BGPMUUTL($P(ASTCPT,U,3))
Q FOUND
BGPMUG03 ; IHS/MSC/MMT - MI measure NQF0001 ;20-Aug-2011 14:56;DU
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
+2 ;Code to collect meaningful use report for Asthma Assessment
ENTRY ;EP
+1 NEW START,END,BGPNUM,BGPDEN,STRING,STRING2
+2 NEW IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN,RESULT
+3 NEW CNT,NUM,ASTHENC,ASTHMA,ASTDT,ASTDX,ASTPL,LASTVDT
+4 SET (BGPDEN,BGPNUM,NUM,RESULT)=0
+5 SET START=9999999-BGPBDATE
SET END=9999999-BGPEDATE
SET VALUE=0
+6 SET START=START_".2359"
+7 ;Pts must be between 5 and 40 years
+8 ;No need to check further if no age match
+9 IF BGPAGEE<5!(BGPAGEE>40)
QUIT
+10 ;First check for Asthma Dx since this will eliminate many pts
+11 SET ASTHMA=$$ASTHMA(DFN,BGPEDATE)
+12 IF 'ASTHMA
QUIT
+13 SET CNT=0
+14 SET FIRST=END-0.1
FOR
SET FIRST=$ORDER(^AUPNVSIT("AA",DFN,FIRST))
IF FIRST=""!($PIECE(FIRST,".",1)>START)
QUIT
Begin DoDot:1
+15 SET IEN=0
FOR
SET IEN=$ORDER(^AUPNVSIT("AA",DFN,FIRST,IEN))
IF '+IEN
QUIT
Begin DoDot:2
+16 ;Check provider, Only visits for chosen provider
+17 IF '$$PRV^BGPMUUT1(IEN,BGPPROV)
QUIT
+18 SET ASTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ASTHMA ENCOUNT EM")
+19 IF +ASTENC
DO VSTSTORE
QUIT
End DoDot:2
End DoDot:1
+20 IF CNT<2
QUIT
+21 ;check to see if they are in the numerator
+22 SET NUM=$$NUM(DFN,$PIECE(VIEN(CNT),U,2),$PIECE(VIEN(1),U,2),ASTHMA)
+23 DO TOTAL(DFN,ASTHMA,NUM)
+24 QUIT
VSTSTORE ;Store compliant visit into array
+1 SET CNT=CNT+1
+2 SET VDATE=$PIECE($GET(^AUPNVSIT(IEN,0)),U,1)
+3 SET VIEN(CNT)=IEN_U_VDATE
+4 SET STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
+5 QUIT
TOTAL(DFN,ASTHMA,NUM) ;See where this patient ends up
+1 NEW PTCNT,DENCT,NUMCT,NOTNUM,TOTALS,DEN,DXTIME
+2 SET TOTALS=$GET(^TMP("BGPMU0001",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0001",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0001",$JOB,BGPMUTF,"NUM"))
+5 SET NOTNUM=+$GET(^TMP("BGPMU0001",$JOB,BGPMUTF,"NOT"))
+6 SET PTCNT=TOTALS
+7 SET PTCNT=PTCNT+1
+8 SET DENCT=DENCT+1
SET ^TMP("BGPMU0001",$JOB,BGPMUTF,"DEN")=DENCT
+9 SET DEN="AST:"_$$DATE^BGPMUUTL($PIECE(ASTHMA,U,3))
+10 IF $DATA(STRING(1))
SET DEN=DEN_";EN:"_STRING(1)
+11 IF $DATA(STRING(2))
SET DEN=DEN_";EN:"_STRING(2)
+12 IF +NUM
Begin DoDot:1
+13 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0001",$JOB,BGPMUTF,"NUM")=NUMCT
+14 IF BGPMUTF="C"
SET ^TMP("BGPMU0001",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$PIECE(NUM,U,2)
End DoDot:1
+15 IF +NUM=0
Begin DoDot:1
+16 SET NOTNUM=NOTNUM+1
SET ^TMP("BGPMU0001",$JOB,BGPMUTF,"NOT")=NOTNUM
+17 IF BGPMUTF="C"
SET ^TMP("BGPMU0001",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"
End DoDot:1
+18 SET ^TMP("BGPMU0001",$JOB,BGPMUTF,"TOT")=PTCNT
+19 ;Setup iCare array for patient
+20 SET BGPICARE("MU.EP.0001.1",BGPMUTF)=1_U_+NUM_U_""_U_DEN_";"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
+21 QUIT
ASTHMA(DFN,EDATE) ;Find if patient had a PROBLEM or POV of Asthma on or before the end date
+1 NEW ASTHMA
+2 SET ASTHMA=0
+3 SET ASTPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU ASTHMA DX ICD","C",EDATE)
+4 ;check date of problem
+5 IF +ASTPL
SET ASTHMA=1_U_$PIECE(ASTPL,U,2,3)
QUIT ASTHMA
+6 SET BGPBIRTH=$$DOB^AUPNPAT(DFN)
+7 SET ASTDX=$$LASTDX^BGPMUUT2(DFN,BGPBIRTH,EDATE,"BGPMU ASTHMA DX ICD")
+8 IF +ASTDX
SET ASTHMA=2_U_$PIECE(ASTDX,U,2,3)
QUIT ASTHMA
+9 QUIT ASTHMA
NUM(DFN,BDATE,EDATE,ASTHMA) ;Look for documentation of Asthma assessment
+1 NEW FOUND,D,G,S,I,ACONTROL
+2 SET FOUND=0
+3 ;check for documentation in the ASTHMA package
+4 SET D=9999999-EDATE-1
SET G=""
SET S=9999999-BDATE
+5 SET D=$ORDER(^AUPNVAST("AS",DFN,D))
IF D]""!(D>S)
Begin DoDot:1
+6 SET I=""
FOR
SET I=$ORDER(^AUPNVAST("AS",DFN,D,I))
IF I'=+I!(+FOUND)
QUIT
Begin DoDot:2
+7 SET ACONTROL=$PIECE(^AUPNVAST(I,0),U,14)
+8 IF ACONTROL'=""
SET FOUND=1_U_"AC "_$$DATE^BGPMUUTL($PIECE($PIECE($GET(^AUPNVSIT($PIECE(^AUPNVAST(I,0),U,3),0)),U,1),"."))
End DoDot:2
End DoDot:1
+9 IF +FOUND
QUIT FOUND
+10 ;check for documentation in the PROBLEM record
+11 IF $PIECE(ASTHMA,U)=1
Begin DoDot:1
+12 SET CLASS=$PIECE($GET(^AUPNPROB($PIECE(ASTPL,U,4),0)),U,15)
+13 ; YES, this is ALL of the possible values, CLASS=1 MAY be removed later
IF CLASS=1!(CLASS=2)!(CLASS=3)!(CLASS=4)
Begin DoDot:2
End DoDot:2
+14 SET FOUND=1_U_"CL "_$$DATE^BGPMUUTL($PIECE(ASTHMA,U,3))
End DoDot:1
+15 IF +FOUND
QUIT FOUND
+16 ;check for CPT code documented
+17 SET ASTCPT=$$CPT^BGPMUUT1(DFN,BDATE,EDATE,"BGPMU ASTHMA EVAL CPT")
+18 IF +ASTCPT
SET FOUND=1_U_$PIECE(ASTCPT,U,2)_" "_$$DATE^BGPMUUTL($PIECE(ASTCPT,U,3))
+19 QUIT FOUND