BGPMUGP6 ; IHS/MSC/MMT - Print MU EP measures NQF0004 ;20-Aug-2011 11:27;DU
;;14.1;IHS CLINICAL REPORTING;**1**;MAY 29, 2014;Build 2
;Printed output reports for this measure
ALCDRUG ;EP
D P1
K ^TMP("BGPMU0004",$J)
Q
P1 ;Write individual measure
N X,Y,Z,LIST1,LIST2,LIST3
N DEN1,NUM1,DEN2,NUM2,NUMPCT,PC2,STRING1,STRING2,STRING3,SUMCT
N PRD1,PRD4,PRN1,PRN4,POP
K STRING1,STRING2,STRING3
S SUMCT=0
D NUM04("C",.STRING1)
D NUM04("P",.STRING2)
D NUM04("B",.STRING3)
D SUMMARY1(.STRING1,.STRING2,.STRING3)
D HEADER^BGPMUPH Q:BGPQUIT
D HDRBLK^BGPMUPH
F POP=1:1:3 D
.D P1SUBDEN(POP)
.D P1SUBN1(POP)
.D P1SUBN2(POP)
I $D(BGPLIST(BGPIC)) D P2
Q
P1SUBDEN(POP) ;display lines for denominator
I $Y>(BGPIOSL-6) D HEADER^BGPMUPH,HDRBLK^BGPMUPH Q:BGPQUIT
W !!,"Denominator "_POP_":"
W !!,$P($T(P1TEXT+POP),";;",2),?33,$P(STRING1(POP),U,1),?44,$P(STRING2(POP),U,1),?64,$P(STRING3(POP),U,1)
W !,"drug dependence"
Q
P1SUBN1(POP) ;display numbers for NUM 1
S PRD1=$P(STRING1(POP),U,5)-$P(STRING2(POP),U,5)
S PRD4=$P(STRING1(POP),U,7)-$P(STRING2(POP),U,7)
S PRN1=$P(STRING1(POP),U,5)-$P(STRING3(POP),U,5)
S PRN4=$P(STRING1(POP),U,7)-$P(STRING3(POP),U,7)
I $Y>(BGPIOSL-6) D HEADER^BGPMUPH,HDRBLK^BGPMUPH Q:BGPQUIT
W !!,"Numerator 1"
W !!,"# w/first treatment",?33,$P(STRING1(POP),U,2),?38,$J($P(STRING1(POP),U,5),5,1),?44,$P(STRING2(POP),U,2)
W ?49,$J($P(STRING2(POP),U,5),5,1),?56,$J($FN(PRD1,",+",1),6),?64,$P(STRING3(POP),U,2),?68,$J($P(STRING3(POP),U,5),5,1),?74,$J($FN(PRN1,",+",1),6)
W !,"# w/o first treatment",?33,$P(STRING1(POP),U,6),?38,$J($P(STRING1(POP),U,7),5,1),?44,$P(STRING2(POP),U,6)
W ?49,$J($P(STRING2(POP),U,7),5,1),?56,$J($FN(PRD4,",+",1),6),?64,$P(STRING3(POP),U,6),?68,$J($P(STRING3(POP),U,7),5,1),?74,$J($FN(PRN4,",+",1),6)
Q
P1SUBN2(POP) ;display numbers for NUM 2
S PRD1=$P(STRING1(POP),U,9)-$P(STRING2(POP),U,9)
S PRD4=$P(STRING1(POP),U,11)-$P(STRING2(POP),U,11)
S PRN1=$P(STRING1(POP),U,9)-$P(STRING3(POP),U,9)
S PRN4=$P(STRING1(POP),U,11)-$P(STRING3(POP),U,11)
I $Y>(BGPIOSL-8) D HEADER^BGPMUPH,HDRBLK^BGPMUPH Q:BGPQUIT
W !!,"Numerator 2"
W !!,"# w/2 treatments within",?33,$P(STRING1(POP),U,8),?38,$J($P(STRING1(POP),U,9),5,1),?44,$P(STRING2(POP),U,8)
W ?49,$J($P(STRING2(POP),U,9),5,1),?56,$J($FN(PRD1,",+",1),6),?64,$P(STRING3(POP),U,8),?68,$J($P(STRING3(POP),U,9),5,1),?74,$J($FN(PRN1,",+",1),6)
W !,"30 days"
W !,"# w/o 2 treatments within",?33,$P(STRING1(POP),U,10),?38,$J($P(STRING1(POP),U,11),5,1),?44,$P(STRING2(POP),U,10)
W ?49,$J($P(STRING2(POP),U,11),5,1),?56,$J($FN(PRD4,",+",1),6),?64,$P(STRING3(POP),U,10),?68,$J($P(STRING3(POP),U,11),5,1),?74,$J($FN(PRN4,",+",1),6)
W !,"30 days or no first treatment"
Q
P1TEXT ;Text lines for output
;;Pts 13-17 w/alcohol or
;;Pts 18+ w/alcohol or
;;Pts 13+ w/alcohol or
NUM04(TF,ARRAY) ;Get the numbers for this measure
N STRING,DENTOT,NUM1,NUM2,NOT1,NOT2,NUM1PCT,NOT1PCT,NUM2PCT,NOT2PCT,FINALDEN,I
F I=1:1:3 S ARRAY(I)=$$NUMSUB(I)
Q
NUMSUB(POP) ;pull numbers out of temp global
S DENTOT=+$G(^TMP("BGPMU0004",$J,TF,POP,"DEN"))
S NUM1=+$G(^TMP("BGPMU0004",$J,TF,POP,"NUM",1))
S NOT1=+$G(^TMP("BGPMU0004",$J,TF,POP,"NOT",1))
S NUM2=+$G(^TMP("BGPMU0004",$J,TF,POP,"NUM",2))
S NOT2=+$G(^TMP("BGPMU0004",$J,TF,POP,"NOT",2))
S FINALDEN=DENTOT
I DENTOT=0 S (NUM1PCT,NOT1PCT,NUM2PCT,NOT2PCT)=0
I DENTOT>0&(FINALDEN=0) D
.S (NUM1PCT,NOT1PCT,NUM2PCT,NOT2PCT)=0
I DENTOT>0&(FINALDEN>0) D
.S NUM1PCT=$$ROUND^BGPMUA01((NUM1/FINALDEN),3)*100
.S NOT1PCT=$$ROUND^BGPMUA01((NOT1/FINALDEN),3)*100
.S NUM2PCT=$$ROUND^BGPMUA01((NUM2/FINALDEN),3)*100
.S NOT2PCT=$$ROUND^BGPMUA01((NOT2/FINALDEN),3)*100
; 1 2 3 4 5 6 7 8 9 10 11
S STRING=DENTOT_U_NUM1_U_FINALDEN_U_""_U_NUM1PCT_U_NOT1_U_NOT1PCT_U_NUM2_U_NUM2PCT_U_NOT2_U_NOT2PCT
Q STRING
P2 ;Do the Details
N PT,NODE,NAME,VST,BMI,FOL,X,PTCT,BGPARR,LINE,I,J
D HEADERL^BGPMUPH
S X="Patients 13+ with a new episode of alcohol and other drug (AOD) dependence" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="who initiate treatment through an inpatient AOD admission, outpatient visit," D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="intensive outpatient encounter, or partial hospitalization within 14 days of" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="the diagnosis and who initiated treatment and who had two or more additional" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="services with an AOD diagnosis within 30 days of the initiation visit, if any." D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="Patients who did not meet the numerator criteria are listed first (NM:)" D W^BGPMUPP(X,0,2,BGPPTYPE)
S X="followed by patients who do meet the numerator criteria (M:)." D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="The following are the abbreviations used in the denominator and numerator" D W^BGPMUPP(X,0,2,BGPPTYPE)
S X="columns:" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="ADX=Alcohol or Drug Dependence Diagnosis" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="ADI=Alcohol, Drug Rehab and Detox Intervention" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="DI=Detoxification Intervention" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="EN=Encounter" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="FT=First Treatment" D W^BGPMUPP(X,0,1,BGPPTYPE)
S X="ST=Subsequent Treatment" D W^BGPMUPP(X,0,1,BGPPTYPE)
S LINE="",$P(LINE,"-",81)=""
F I=1,2 D
.I $Y>(BGPIOSL-11) D HEADERL^BGPMUPH Q:BGPQUIT
.W !!,$P($T(LISTNUM+I),";;",2)
.F J=1,2 D
..W !!,$P($T(LISTDEN+J),";;",2)
..W !!,"PATIENT NAME",?23,"HRN",?30,"COMMUNITY",?42,"SEX",?46,"AGE",?50,"DENOMINATOR",?65,"NUMERATOR"
..W !,LINE
..D LISTSUB(J,I)
Q
LISTSUB(POP,NUM) ;write out patient list for given population
S PTCT=0
I BGPLIST="D"!(BGPLIST="A") D
.K BGPARR
.D PTLSORT^BGPMUUTL(.BGPARR,"^TMP(""BGPMU0004"","_$J_",""PAT"",""C"","_POP_",""NOT"","_NUM_")")
.S PT=0 F S PT=$O(BGPARR(PT)) Q:PT="" D
..S PTCT=PTCT+1
..S NODE=$G(BGPARR(PT))
..D DATA(NODE)
I BGPLIST="N"!(BGPLIST="A") D
.K BGPARR
.D PTLSORT^BGPMUUTL(.BGPARR,"^TMP(""BGPMU0004"","_$J_",""PAT"",""C"","_POP_",""NUM"","_NUM_")")
.S PT=0 F S PT=$O(BGPARR(PT)) Q:PT="" D
..S PTCT=PTCT+1
..S NODE=$G(BGPARR(PT))
..D DATA(NODE)
W !!,"Total # of patients on list: "_PTCT
Q
LISTDEN ;Denominator line text
;;Patients 13-17
;;Patients 18+
LISTNUM ;Numerator line text
;;Numerator 1: First Treatment
;;Numerator 2: Two subsequent treatments within 30 days
DATA(NODE) ;GET DATA
N NAME,HRN,DEN,NUM,AGE,DFN,SEX,COMM,NUM1,DEN1,LINE,I,DENLEN,NUMLEN,MAXLEN
S DFN=$P(NODE,U,1)
S NAME=$E($$GET1^DIQ(2,$P(NODE,U,1),.01),1,22)
S HRN=$$HRN^AUPNPAT(DFN,DUZ(2))
S AGE=$$AGE^AUPNPAT(DFN,BGPED)
S DEN=$P(NODE,U,2)
S DEN1=$P(DEN,";",1)
S NUM=$P(NODE,U,3)
S NUM1=$P(NUM,";",1)
S COMM=$E($$GET1^DIQ(9000001,DFN,1118),1,11)
S SEX=$P(^DPT(DFN,0),U,2)
I $Y>(BGPIOSL-2) D
.D HEADERL^BGPMUPH Q:BGPQUIT
.W !,"PATIENT NAME",?23,"HRN",?30,"COMMUNITY",?42,"SEX",?46,"AGE",?50,"DENOMINATOR",?65,"NUMERATOR"
.S LINE="",$P(LINE,"-",81)="" W !,LINE
W !,NAME,?23,HRN,?30,COMM,?43,SEX,?46,AGE,?50,DEN1,?65,NUM1
S DENLEN=$L(DEN,";"),NUMLEN=$L(NUM,";")
S MAXLEN=$S(DENLEN>NUMLEN:DENLEN,1:NUMLEN)
I MAXLEN>1 F I=2:1:MAXLEN W !,?50,$P(DEN,";",I),?67,$P(NUM,";",I)
Q
SUMMARY1(STRING1,STRING2,STRING3) ;Summmary setup
N DESC,LINE
K ^TMP("BGPMU SUMMARY",$J,BGPIC)
S ^TMP("BGPMU SUMMARY",$J,BGPIC)="0004^"
S DESC="13-17 # w/first treatment"
S LINE="MU.EP.0004.1"_U_DESC_U_$P(STRING1(1),U,4)_U_$P(STRING1(1),U,1)_U_$P(STRING1(1),U,2)_U_$P(STRING1(1),U,5)_U_U_U_U_U
S LINE=LINE_$P(STRING2(1),U,4)_U_$P(STRING2(1),U,1)_U_$P(STRING2(1),U,2)_U_$P(STRING2(1),U,5)_U_$P(STRING3(1),U,4)_U_$P(STRING3(1),U,1)_U_$P(STRING3(1),U,2)_U_$P(STRING3(1),U,5)
S ^TMP("BGPMU SUMMARY",$J,BGPIC,1)=LINE
;
S DESC="13-17 # w/2 treatments w/i 30 days"
S LINE="MU.EP.0004.1"_U_DESC_U_$P(STRING1(1),U,4)_U_$P(STRING1(1),U,1)_U_$P(STRING1(1),U,8)_U_$P(STRING1(1),U,9)_U_U_U_U_U
S LINE=LINE_$P(STRING2(1),U,4)_U_$P(STRING2(1),U,1)_U_$P(STRING2(1),U,8)_U_$P(STRING2(1),U,9)_U_$P(STRING3(1),U,4)_U_$P(STRING3(1),U,1)_U_$P(STRING3(1),U,8)_U_$P(STRING3(1),U,9)
S ^TMP("BGPMU SUMMARY",$J,BGPIC,2)=LINE
;
S DESC="18+ # w/first treatment"
S LINE="MU.EP.0004.1"_U_DESC_U_$P(STRING1(2),U,4)_U_$P(STRING1(2),U,1)_U_$P(STRING1(2),U,2)_U_$P(STRING1(2),U,5)_U_U_U_U_U
S LINE=LINE_$P(STRING2(2),U,4)_U_$P(STRING2(2),U,1)_U_$P(STRING2(2),U,2)_U_$P(STRING2(2),U,5)_U_$P(STRING3(2),U,4)_U_$P(STRING3(2),U,1)_U_$P(STRING3(2),U,2)_U_$P(STRING3(2),U,5)
S ^TMP("BGPMU SUMMARY",$J,BGPIC,3)=LINE
;
S DESC="18+ # w/2 treatments w/i 30 days"
S LINE="MU.EP.0004.1"_U_DESC_U_$P(STRING1(2),U,4)_U_$P(STRING1(2),U,1)_U_$P(STRING1(2),U,8)_U_$P(STRING1(2),U,9)_U_U_U_U_U
S LINE=LINE_$P(STRING2(2),U,4)_U_$P(STRING2(2),U,1)_U_$P(STRING2(2),U,8)_U_$P(STRING2(2),U,9)_U_$P(STRING3(2),U,4)_U_$P(STRING3(2),U,1)_U_$P(STRING3(2),U,8)_U_$P(STRING3(2),U,9)
S ^TMP("BGPMU SUMMARY",$J,BGPIC,4)=LINE
;
S DESC="13+ # w/first treatment"
S LINE="MU.EP.0004.1"_U_DESC_U_$P(STRING1(3),U,4)_U_$P(STRING1(3),U,1)_U_$P(STRING1(3),U,2)_U_$P(STRING1(3),U,5)_U_U_U_U_U
S LINE=LINE_$P(STRING2(3),U,4)_U_$P(STRING2(3),U,1)_U_$P(STRING2(3),U,2)_U_$P(STRING2(3),U,5)_U_$P(STRING3(3),U,4)_U_$P(STRING3(3),U,1)_U_$P(STRING3(3),U,2)_U_$P(STRING3(3),U,5)
S ^TMP("BGPMU SUMMARY",$J,BGPIC,5)=LINE
;
S DESC="13+ # w/2 treatments w/i 30 days"
S LINE="MU.EP.0004.1"_U_DESC_U_$P(STRING1(3),U,4)_U_$P(STRING1(3),U,1)_U_$P(STRING1(3),U,8)_U_$P(STRING1(3),U,9)_U_U_U_U_U
S LINE=LINE_$P(STRING2(3),U,4)_U_$P(STRING2(3),U,1)_U_$P(STRING2(3),U,8)_U_$P(STRING2(3),U,9)_U_$P(STRING3(3),U,4)_U_$P(STRING3(3),U,1)_U_$P(STRING3(3),U,8)_U_$P(STRING3(3),U,9)
S ^TMP("BGPMU SUMMARY",$J,BGPIC,6)=LINE
Q
XML04 ;Populate the BGPXML array with data for each population/numerator
; BGPXMLOUT(i)=PQRI number^""^Denominator Count^Numerator Count^Exclusion Count
S BGPXML(1)="NQF0004.1"_U_""_U_+$G(^TMP("BGPMU0004",$J,"C",3,"DEN"))_U_+$G(^TMP("BGPMU0004",$J,"C",3,"NUM",1))
S BGPXML(2)="NQF0004.2"_U_""_U_+$G(^TMP("BGPMU0004",$J,"C",3,"DEN"))_U_+$G(^TMP("BGPMU0004",$J,"C",3,"NUM",2))
K ^TMP("BGPMU0004",$J)
Q
BGPMUGP6 ; IHS/MSC/MMT - Print MU EP measures NQF0004 ;20-Aug-2011 11:27;DU
+1 ;;14.1;IHS CLINICAL REPORTING;**1**;MAY 29, 2014;Build 2
+2 ;Printed output reports for this measure
ALCDRUG ;EP
+1 DO P1
+2 KILL ^TMP("BGPMU0004",$JOB)
+3 QUIT
P1 ;Write individual measure
+1 NEW X,Y,Z,LIST1,LIST2,LIST3
+2 NEW DEN1,NUM1,DEN2,NUM2,NUMPCT,PC2,STRING1,STRING2,STRING3,SUMCT
+3 NEW PRD1,PRD4,PRN1,PRN4,POP
+4 KILL STRING1,STRING2,STRING3
+5 SET SUMCT=0
+6 DO NUM04("C",.STRING1)
+7 DO NUM04("P",.STRING2)
+8 DO NUM04("B",.STRING3)
+9 DO SUMMARY1(.STRING1,.STRING2,.STRING3)
+10 DO HEADER^BGPMUPH
IF BGPQUIT
QUIT
+11 DO HDRBLK^BGPMUPH
+12 FOR POP=1:1:3
Begin DoDot:1
+13 DO P1SUBDEN(POP)
+14 DO P1SUBN1(POP)
+15 DO P1SUBN2(POP)
End DoDot:1
+16 IF $DATA(BGPLIST(BGPIC))
DO P2
+17 QUIT
P1SUBDEN(POP) ;display lines for denominator
+1 IF $Y>(BGPIOSL-6)
DO HEADER^BGPMUPH
DO HDRBLK^BGPMUPH
IF BGPQUIT
QUIT
+2 WRITE !!,"Denominator "_POP_":"
+3 WRITE !!,$PIECE($TEXT(P1TEXT+POP),";;",2),?33,$PIECE(STRING1(POP),U,1),?44,$PIECE(STRING2(POP),U,1),?64,$PIECE(STRING3(POP),U,1)
+4 WRITE !,"drug dependence"
+5 QUIT
P1SUBN1(POP) ;display numbers for NUM 1
+1 SET PRD1=$PIECE(STRING1(POP),U,5)-$PIECE(STRING2(POP),U,5)
+2 SET PRD4=$PIECE(STRING1(POP),U,7)-$PIECE(STRING2(POP),U,7)
+3 SET PRN1=$PIECE(STRING1(POP),U,5)-$PIECE(STRING3(POP),U,5)
+4 SET PRN4=$PIECE(STRING1(POP),U,7)-$PIECE(STRING3(POP),U,7)
+5 IF $Y>(BGPIOSL-6)
DO HEADER^BGPMUPH
DO HDRBLK^BGPMUPH
IF BGPQUIT
QUIT
+6 WRITE !!,"Numerator 1"
+7 WRITE !!,"# w/first treatment",?33,$PIECE(STRING1(POP),U,2),?38,$JUSTIFY($PIECE(STRING1(POP),U,5),5,1),?44,$PIECE(STRING2(POP),U,2)
+8 WRITE ?49,$JUSTIFY($PIECE(STRING2(POP),U,5),5,1),?56,$JUSTIFY($FNUMBER(PRD1,",+",1),6),?64,$PIECE(STRING3(POP),U,2),?68,$JUSTIFY($PIECE(STRING3(POP),U,5),5,1),?74,$JUSTIFY($FNUMBER(PRN1,",+",1),6)
+9 WRITE !,"# w/o first treatment",?33,$PIECE(STRING1(POP),U,6),?38,$JUSTIFY($PIECE(STRING1(POP),U,7),5,1),?44,$PIECE(STRING2(POP),U,6)
+10 WRITE ?49,$JUSTIFY($PIECE(STRING2(POP),U,7),5,1),?56,$JUSTIFY($FNUMBER(PRD4,",+",1),6),?64,$PIECE(STRING3(POP),U,6),?68,$JUSTIFY($PIECE(STRING3(POP),U,7),5,1),?74,$JUSTIFY($FNUMBER(PRN4,",+",1),6)
+11 QUIT
P1SUBN2(POP) ;display numbers for NUM 2
+1 SET PRD1=$PIECE(STRING1(POP),U,9)-$PIECE(STRING2(POP),U,9)
+2 SET PRD4=$PIECE(STRING1(POP),U,11)-$PIECE(STRING2(POP),U,11)
+3 SET PRN1=$PIECE(STRING1(POP),U,9)-$PIECE(STRING3(POP),U,9)
+4 SET PRN4=$PIECE(STRING1(POP),U,11)-$PIECE(STRING3(POP),U,11)
+5 IF $Y>(BGPIOSL-8)
DO HEADER^BGPMUPH
DO HDRBLK^BGPMUPH
IF BGPQUIT
QUIT
+6 WRITE !!,"Numerator 2"
+7 WRITE !!,"# w/2 treatments within",?33,$PIECE(STRING1(POP),U,8),?38,$JUSTIFY($PIECE(STRING1(POP),U,9),5,1),?44,$PIECE(STRING2(POP),U,8)
+8 WRITE ?49,$JUSTIFY($PIECE(STRING2(POP),U,9),5,1),?56,$JUSTIFY($FNUMBER(PRD1,",+",1),6),?64,$PIECE(STRING3(POP),U,8),?68,$JUSTIFY($PIECE(STRING3(POP),U,9),5,1),?74,$JUSTIFY($FNUMBER(PRN1,",+",1),6)
+9 WRITE !,"30 days"
+10 WRITE !,"# w/o 2 treatments within",?33,$PIECE(STRING1(POP),U,10),?38,$JUSTIFY($PIECE(STRING1(POP),U,11),5,1),?44,$PIECE(STRING2(POP),U,10)
+11 WRITE ?49,$JUSTIFY($PIECE(STRING2(POP),U,11),5,1),?56,$JUSTIFY($FNUMBER(PRD4,",+",1),6),?64,$PIECE(STRING3(POP),U,10),?68,$JUSTIFY($PIECE(STRING3(POP),U,11),5,1),?74,$JUSTIFY($FNUMBER(PRN4,",+",1),6)
+12 WRITE !,"30 days or no first treatment"
+13 QUIT
P1TEXT ;Text lines for output
+1 ;;Pts 13-17 w/alcohol or
+2 ;;Pts 18+ w/alcohol or
+3 ;;Pts 13+ w/alcohol or
NUM04(TF,ARRAY) ;Get the numbers for this measure
+1 NEW STRING,DENTOT,NUM1,NUM2,NOT1,NOT2,NUM1PCT,NOT1PCT,NUM2PCT,NOT2PCT,FINALDEN,I
+2 FOR I=1:1:3
SET ARRAY(I)=$$NUMSUB(I)
+3 QUIT
NUMSUB(POP) ;pull numbers out of temp global
+1 SET DENTOT=+$GET(^TMP("BGPMU0004",$JOB,TF,POP,"DEN"))
+2 SET NUM1=+$GET(^TMP("BGPMU0004",$JOB,TF,POP,"NUM",1))
+3 SET NOT1=+$GET(^TMP("BGPMU0004",$JOB,TF,POP,"NOT",1))
+4 SET NUM2=+$GET(^TMP("BGPMU0004",$JOB,TF,POP,"NUM",2))
+5 SET NOT2=+$GET(^TMP("BGPMU0004",$JOB,TF,POP,"NOT",2))
+6 SET FINALDEN=DENTOT
+7 IF DENTOT=0
SET (NUM1PCT,NOT1PCT,NUM2PCT,NOT2PCT)=0
+8 IF DENTOT>0&(FINALDEN=0)
Begin DoDot:1
+9 SET (NUM1PCT,NOT1PCT,NUM2PCT,NOT2PCT)=0
End DoDot:1
+10 IF DENTOT>0&(FINALDEN>0)
Begin DoDot:1
+11 SET NUM1PCT=$$ROUND^BGPMUA01((NUM1/FINALDEN),3)*100
+12 SET NOT1PCT=$$ROUND^BGPMUA01((NOT1/FINALDEN),3)*100
+13 SET NUM2PCT=$$ROUND^BGPMUA01((NUM2/FINALDEN),3)*100
+14 SET NOT2PCT=$$ROUND^BGPMUA01((NOT2/FINALDEN),3)*100
End DoDot:1
+15 ; 1 2 3 4 5 6 7 8 9 10 11
+16 SET STRING=DENTOT_U_NUM1_U_FINALDEN_U_""_U_NUM1PCT_U_NOT1_U_NOT1PCT_U_NUM2_U_NUM2PCT_U_NOT2_U_NOT2PCT
+17 QUIT STRING
P2 ;Do the Details
+1 NEW PT,NODE,NAME,VST,BMI,FOL,X,PTCT,BGPARR,LINE,I,J
+2 DO HEADERL^BGPMUPH
+3 SET X="Patients 13+ with a new episode of alcohol and other drug (AOD) dependence"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+4 SET X="who initiate treatment through an inpatient AOD admission, outpatient visit,"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+5 SET X="intensive outpatient encounter, or partial hospitalization within 14 days of"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+6 SET X="the diagnosis and who initiated treatment and who had two or more additional"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+7 SET X="services with an AOD diagnosis within 30 days of the initiation visit, if any."
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+8 SET X="Patients who did not meet the numerator criteria are listed first (NM:)"
DO W^BGPMUPP(X,0,2,BGPPTYPE)
+9 SET X="followed by patients who do meet the numerator criteria (M:)."
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+10 SET X="The following are the abbreviations used in the denominator and numerator"
DO W^BGPMUPP(X,0,2,BGPPTYPE)
+11 SET X="columns:"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+12 SET X="ADX=Alcohol or Drug Dependence Diagnosis"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+13 SET X="ADI=Alcohol, Drug Rehab and Detox Intervention"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+14 SET X="DI=Detoxification Intervention"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+15 SET X="EN=Encounter"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+16 SET X="FT=First Treatment"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+17 SET X="ST=Subsequent Treatment"
DO W^BGPMUPP(X,0,1,BGPPTYPE)
+18 SET LINE=""
SET $PIECE(LINE,"-",81)=""
+19 FOR I=1,2
Begin DoDot:1
+20 IF $Y>(BGPIOSL-11)
DO HEADERL^BGPMUPH
IF BGPQUIT
QUIT
+21 WRITE !!,$PIECE($TEXT(LISTNUM+I),";;",2)
+22 FOR J=1,2
Begin DoDot:2
+23 WRITE !!,$PIECE($TEXT(LISTDEN+J),";;",2)
+24 WRITE !!,"PATIENT NAME",?23,"HRN",?30,"COMMUNITY",?42,"SEX",?46,"AGE",?50,"DENOMINATOR",?65,"NUMERATOR"
+25 WRITE !,LINE
+26 DO LISTSUB(J,I)
End DoDot:2
End DoDot:1
+27 QUIT
LISTSUB(POP,NUM) ;write out patient list for given population
+1 SET PTCT=0
+2 IF BGPLIST="D"!(BGPLIST="A")
Begin DoDot:1
+3 KILL BGPARR
+4 DO PTLSORT^BGPMUUTL(.BGPARR,"^TMP(""BGPMU0004"","_$JOB_",""PAT"",""C"","_POP_",""NOT"","_NUM_")")
+5 SET PT=0
FOR
SET PT=$ORDER(BGPARR(PT))
IF PT=""
QUIT
Begin DoDot:2
+6 SET PTCT=PTCT+1
+7 SET NODE=$GET(BGPARR(PT))
+8 DO DATA(NODE)
End DoDot:2
End DoDot:1
+9 IF BGPLIST="N"!(BGPLIST="A")
Begin DoDot:1
+10 KILL BGPARR
+11 DO PTLSORT^BGPMUUTL(.BGPARR,"^TMP(""BGPMU0004"","_$JOB_",""PAT"",""C"","_POP_",""NUM"","_NUM_")")
+12 SET PT=0
FOR
SET PT=$ORDER(BGPARR(PT))
IF PT=""
QUIT
Begin DoDot:2
+13 SET PTCT=PTCT+1
+14 SET NODE=$GET(BGPARR(PT))
+15 DO DATA(NODE)
End DoDot:2
End DoDot:1
+16 WRITE !!,"Total # of patients on list: "_PTCT
+17 QUIT
LISTDEN ;Denominator line text
+1 ;;Patients 13-17
+2 ;;Patients 18+
LISTNUM ;Numerator line text
+1 ;;Numerator 1: First Treatment
+2 ;;Numerator 2: Two subsequent treatments within 30 days
DATA(NODE) ;GET DATA
+1 NEW NAME,HRN,DEN,NUM,AGE,DFN,SEX,COMM,NUM1,DEN1,LINE,I,DENLEN,NUMLEN,MAXLEN
+2 SET DFN=$PIECE(NODE,U,1)
+3 SET NAME=$EXTRACT($$GET1^DIQ(2,$PIECE(NODE,U,1),.01),1,22)
+4 SET HRN=$$HRN^AUPNPAT(DFN,DUZ(2))
+5 SET AGE=$$AGE^AUPNPAT(DFN,BGPED)
+6 SET DEN=$PIECE(NODE,U,2)
+7 SET DEN1=$PIECE(DEN,";",1)
+8 SET NUM=$PIECE(NODE,U,3)
+9 SET NUM1=$PIECE(NUM,";",1)
+10 SET COMM=$EXTRACT($$GET1^DIQ(9000001,DFN,1118),1,11)
+11 SET SEX=$PIECE(^DPT(DFN,0),U,2)
+12 IF $Y>(BGPIOSL-2)
Begin DoDot:1
+13 DO HEADERL^BGPMUPH
IF BGPQUIT
QUIT
+14 WRITE !,"PATIENT NAME",?23,"HRN",?30,"COMMUNITY",?42,"SEX",?46,"AGE",?50,"DENOMINATOR",?65,"NUMERATOR"
+15 SET LINE=""
SET $PIECE(LINE,"-",81)=""
WRITE !,LINE
End DoDot:1
+16 WRITE !,NAME,?23,HRN,?30,COMM,?43,SEX,?46,AGE,?50,DEN1,?65,NUM1
+17 SET DENLEN=$LENGTH(DEN,";")
SET NUMLEN=$LENGTH(NUM,";")
+18 SET MAXLEN=$SELECT(DENLEN>NUMLEN:DENLEN,1:NUMLEN)
+19 IF MAXLEN>1
FOR I=2:1:MAXLEN
WRITE !,?50,$PIECE(DEN,";",I),?67,$PIECE(NUM,";",I)
+20 QUIT
SUMMARY1(STRING1,STRING2,STRING3) ;Summmary setup
+1 NEW DESC,LINE
+2 KILL ^TMP("BGPMU SUMMARY",$JOB,BGPIC)
+3 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC)="0004^"
+4 SET DESC="13-17 # w/first treatment"
+5 SET LINE="MU.EP.0004.1"_U_DESC_U_$PIECE(STRING1(1),U,4)_U_$PIECE(STRING1(1),U,1)_U_$PIECE(STRING1(1),U,2)_U_$PIECE(STRING1(1),U,5)_U_U_U_U_U
+6 SET LINE=LINE_$PIECE(STRING2(1),U,4)_U_$PIECE(STRING2(1),U,1)_U_$PIECE(STRING2(1),U,2)_U_$PIECE(STRING2(1),U,5)_U_$PIECE(STRING3(1),U,4)_U_$PIECE(STRING3(1),U,1)_U_$PIECE(STRING3(1),U,2)_U_$PIECE(STRING3(1),U,5)
+7 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC,1)=LINE
+8 ;
+9 SET DESC="13-17 # w/2 treatments w/i 30 days"
+10 SET LINE="MU.EP.0004.1"_U_DESC_U_$PIECE(STRING1(1),U,4)_U_$PIECE(STRING1(1),U,1)_U_$PIECE(STRING1(1),U,8)_U_$PIECE(STRING1(1),U,9)_U_U_U_U_U
+11 SET LINE=LINE_$PIECE(STRING2(1),U,4)_U_$PIECE(STRING2(1),U,1)_U_$PIECE(STRING2(1),U,8)_U_$PIECE(STRING2(1),U,9)_U_$PIECE(STRING3(1),U,4)_U_$PIECE(STRING3(1),U,1)_U_$PIECE(STRING3(1),U,8)_U_$PIECE(STRING3(1),U,9)
+12 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC,2)=LINE
+13 ;
+14 SET DESC="18+ # w/first treatment"
+15 SET LINE="MU.EP.0004.1"_U_DESC_U_$PIECE(STRING1(2),U,4)_U_$PIECE(STRING1(2),U,1)_U_$PIECE(STRING1(2),U,2)_U_$PIECE(STRING1(2),U,5)_U_U_U_U_U
+16 SET LINE=LINE_$PIECE(STRING2(2),U,4)_U_$PIECE(STRING2(2),U,1)_U_$PIECE(STRING2(2),U,2)_U_$PIECE(STRING2(2),U,5)_U_$PIECE(STRING3(2),U,4)_U_$PIECE(STRING3(2),U,1)_U_$PIECE(STRING3(2),U,2)_U_$PIECE(STRING3(2),U,5)
+17 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC,3)=LINE
+18 ;
+19 SET DESC="18+ # w/2 treatments w/i 30 days"
+20 SET LINE="MU.EP.0004.1"_U_DESC_U_$PIECE(STRING1(2),U,4)_U_$PIECE(STRING1(2),U,1)_U_$PIECE(STRING1(2),U,8)_U_$PIECE(STRING1(2),U,9)_U_U_U_U_U
+21 SET LINE=LINE_$PIECE(STRING2(2),U,4)_U_$PIECE(STRING2(2),U,1)_U_$PIECE(STRING2(2),U,8)_U_$PIECE(STRING2(2),U,9)_U_$PIECE(STRING3(2),U,4)_U_$PIECE(STRING3(2),U,1)_U_$PIECE(STRING3(2),U,8)_U_$PIECE(STRING3(2),U,9)
+22 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC,4)=LINE
+23 ;
+24 SET DESC="13+ # w/first treatment"
+25 SET LINE="MU.EP.0004.1"_U_DESC_U_$PIECE(STRING1(3),U,4)_U_$PIECE(STRING1(3),U,1)_U_$PIECE(STRING1(3),U,2)_U_$PIECE(STRING1(3),U,5)_U_U_U_U_U
+26 SET LINE=LINE_$PIECE(STRING2(3),U,4)_U_$PIECE(STRING2(3),U,1)_U_$PIECE(STRING2(3),U,2)_U_$PIECE(STRING2(3),U,5)_U_$PIECE(STRING3(3),U,4)_U_$PIECE(STRING3(3),U,1)_U_$PIECE(STRING3(3),U,2)_U_$PIECE(STRING3(3),U,5)
+27 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC,5)=LINE
+28 ;
+29 SET DESC="13+ # w/2 treatments w/i 30 days"
+30 SET LINE="MU.EP.0004.1"_U_DESC_U_$PIECE(STRING1(3),U,4)_U_$PIECE(STRING1(3),U,1)_U_$PIECE(STRING1(3),U,8)_U_$PIECE(STRING1(3),U,9)_U_U_U_U_U
+31 SET LINE=LINE_$PIECE(STRING2(3),U,4)_U_$PIECE(STRING2(3),U,1)_U_$PIECE(STRING2(3),U,8)_U_$PIECE(STRING2(3),U,9)_U_$PIECE(STRING3(3),U,4)_U_$PIECE(STRING3(3),U,1)_U_$PIECE(STRING3(3),U,8)_U_$PIECE(STRING3(3),U,9)
+32 SET ^TMP("BGPMU SUMMARY",$JOB,BGPIC,6)=LINE
+33 QUIT
XML04 ;Populate the BGPXML array with data for each population/numerator
+1 ; BGPXMLOUT(i)=PQRI number^""^Denominator Count^Numerator Count^Exclusion Count
+2 SET BGPXML(1)="NQF0004.1"_U_""_U_+$GET(^TMP("BGPMU0004",$JOB,"C",3,"DEN"))_U_+$GET(^TMP("BGPMU0004",$JOB,"C",3,"NUM",1))
+3 SET BGPXML(2)="NQF0004.2"_U_""_U_+$GET(^TMP("BGPMU0004",$JOB,"C",3,"DEN"))_U_+$GET(^TMP("BGPMU0004",$JOB,"C",3,"NUM",2))
+4 KILL ^TMP("BGPMU0004",$JOB)
+5 QUIT