APCLDV1P ; IHS/CMI/LAB - list refusals ;
;;2.0;IHS PCC SUITE;;MAY 14, 2009
;
;
PRINT ;EP - called from xbdbque
D PRINT1
D DONE
Q
PRINT1 ;
S APCLPG=0 K APCLQUIT
K APCLLSTP
I '$D(^XTMP("APCLDV1",APCLJ,APCLH)) D HEADER W !!,"No data to report.",! G DONE
D HEADER
S APCLTOT=$$TOT
W !," Total Number of Patients screened",?40,$J($$COM(APCLTOT,0),8)
D RES
Q:$$END
D GENDER
Q:$$END
D AGE
Q:$$END
D PRVSC
Q:$$END
D PRVV
Q:$$END
D DESPRV
Q:$$END
D CLINIC
Q:$$END
D DATE
Q:$$END
K ^TMP($J)
I APCLLIST D LIST
Q
RES ;
Q:'$D(APCLTALL(1))
;TALLY BY RESULT FIRST
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,3) S:R="" R="NO RESULT RECORDED" S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Result",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.S Y=$L(APCLX),Y=38-Y W !?Y,APCLX,?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
Q
GENDER ;
Q:'$D(APCLTALL(2))
;TALLY BY GENDER OF PATIENT
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,6) S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Gender",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L(APCLX),Y=38-Y W !?Y,APCLX,?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
.Q
Q
AGE ;
Q:'$D(APCLTALL(3))
;TALLY BY age OF PATIENT
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,5) S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Age",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L(APCLX_" yrs"),Y=38-Y W !?Y,APCLX," yrs",?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
Q
PRVSC ;
Q:'$D(APCLTALL(4))
;TALLY BY PRIMARY provider OF service
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,16) S:R="" R="UNKNOWN" S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Provider who screened",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L(APCLX),Y=38-Y W !?Y,APCLX,?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
Q
PRVV ;
Q:'$D(APCLTALL(5))
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,2) S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Primary Provider of Visit",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L(APCLX),Y=38-Y W !?Y,APCLX,?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
Q
DESPRV ;
Q:'$D(APCLTALL(6))
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,17) S:R="" R="UNKNOWN" S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Designated Primary Care Provider",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L(APCLX),Y=38-Y W !?Y,APCLX,?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
Q
CLINIC ;
Q:'$D(APCLTALL(7))
;TALLY BY clinic
K APCLRES S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,9) S:R="" R="UNKNOWN" S APCLRES(R)=$G(APCLRES(R))+1
W !
W !," By Clinic",!
S APCLX="" F S APCLX=$O(APCLRES(APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L(APCLX),Y=38-Y W !?Y,APCLX,?40,$J($$COM($G(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT) K APCLRES(APCLX)
Q
DATE ;
Q:'$D(APCLTALL(8))
;TALLY BY date OF service
K ^TMP($J) S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X D
.S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
.S R=$P(APCLY,U,7) S ^TMP($J,R)=$G(^TMP($J,R))+1
W !
W !," By Date",!
S APCLX="" F S APCLX=$O(^TMP($J,APCLX)) Q:APCLX=""!($D(APCLQUIT)) D
.Q:$$END
.S Y=$L($$FMTE^XLFDT(APCLX)),Y=38-Y W !?Y,$$FMTE^XLFDT(APCLX),?40,$J($$COM($G(^TMP($J,APCLX)),0),8),?55,$$PER(^TMP($J,APCLX),APCLTOT) K ^TMP($J,APCLX)
Q
;
PER(N,D) ;return % of n/d
I 'D Q "0%"
NEW Z
S Z=N/D,Z=Z*100,Z=$J(Z,5,1)
Q $$STRIP^XLFSTR(Z," ")_"%"
COM(X,X2,X3) ;
D COMMA^%DTC
Q $$STRIP^XLFSTR(X," ")
END() ;
I $Y<(IOSL-3) Q 0
D HEADER
I $D(APCLQUIT) Q 1
Q 0
ENDL() ;
I $Y<(IOSL-8) Q 0
D HEADER
I $D(APCLQUIT) Q 1
Q 0
TOT() ;
NEW C,X
S C=0
S X=0 F S X=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X)) Q:X'=+X S C=C+1
Q C
G:'APCLPG HEADER1
K DIR I $E(IOST)="C",IO=IO(0) W ! S DIR(0)="EO" D ^DIR K DIR I Y=0!(Y="^")!($D(DTOUT)) S APCLQUIT="" Q
W:$D(IOF) @IOF S APCLPG=APCLPG+1
W !?3,$P(^VA(200,DUZ,0),U,2),?35,$$FMTE^XLFDT(DT),?70,"Page ",APCLPG,!
W !,$$CTR("*** IPV SCREENING PATIENT TALLY"_$S(APCLLIST:" AND PATIENT LISTING",1:"")_" ***",80),!
S X="Screening Dates: "_$$FMTE^XLFDT(APCLBD)_" to "_$$FMTE^XLFDT(APCLED) W $$CTR(X,80),!
I APCLEXBH S X="This report includes Behavioral Health Clinics" W $$CTR(X,80),!
I 'APCLEXBH S X="This report excludes Behavioral Health Clinics" W $$CTR(X,80),!
D LOCHDR
D COMMHDR
I $G(APCLLSTP) W !?35,"DATE",!,"PATIENT NAME",?22,"HRN",?29,"AGE",?35,"SCREENED",?44,"RESULT",?61,"CLINIC"
W !,$TR($J("",80)," ","-")
I '$G(APCLLSTP) W !?46,"#",?53,"% of patients"
Q
LOCHDR ;EP
I APCLLOCT="A" S X="All Facilities/Locations" W $$CTR(X,80),!
I APCLLOCT="O" S X="Facility/Location: "_$P(^DIC(4,APCLLOCT("ONE"),0),U) W $$CTR(X,80),!
I APCLLOCT="S" S X="All Facilities/Locations within the "_$P(^AUTTSU(APCLLOCT("SU"),0),U)_" service unit" W $$CTR(X,80),!
Q
COMMHDR ;EP
I APCLCOMT="A" S X="All Patient Communities" W $$CTR(X,80),!
I APCLCOMT="O" S X="Community: "_$P(^AUTTCOM(APCLCOMT("ONE"),0),U) W $$CTR(X,80),!
I APCLCOMT="S" S X="All Communities within the "_$P(^ATXAX(APCLCOMT("SU"),0),U)_" taxonomy" W $$CTR(X,80),!
Q
DONE ;
K ^TMP($J)
K ^XTMP("APCLDV1",APCLJ,APCLH)
D EOP
Q
CTR(X,Y) ;EP - Center X in a field Y wide.
Q $J("",$S($D(Y):Y,1:IOM)-$L(X)\2)_X
;----------
EOP ;EP - End of page.
Q:$E(IOST)'="C"
Q:IO'=IO(0)
Q:$D(ZTQUEUED)!'(IOT="TRM")!$D(IO("S"))
NEW DIR
K DIRUT,DFOUT,DLOUT,DTOUT,DUOUT
W !
S DIR("A")="End of Report. Press Enter",DIR(0)="E" D ^DIR
Q
;----------
USR() ;EP - Return name of current user from ^VA(200.
Q $S($G(DUZ):$S($D(^VA(200,DUZ,0)):$P(^(0),U),1:"UNKNOWN"),1:"DUZ UNDEFINED OR 0")
;----------
LOC() ;EP - Return location name from file 4 based on DUZ(2).
Q $S($G(DUZ(2)):$S($D(^DIC(4,DUZ(2),0)):$P(^(0),U),1:"UNKNOWN"),1:"DUZ(2) UNDEFINED OR 0")
;----------
LIST ;EP - called from xbdbque
S APCLPG=0 K APCLQUIT
S APCLLSTP=1
D HEADER
K ^TMP($J)
;resort by sort item
S DFN=0 F S DFN=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",DFN)) Q:DFN'=+DFN S D=$O(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",DFN,""),-1) S APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",DFN,D) D
.D @APCLSORT
.I APCLSORV="" S APCLSORV="--"
.S ^TMP($J,"PTS",APCLSORV,DFN)=APCLY
.Q
S APCLSORV="" F S APCLSORV=$O(^TMP($J,"PTS",APCLSORV)) Q:APCLSORV=""!($D(APCLQUIT)) D
.S DFN=0 F S DFN=$O(^TMP($J,"PTS",APCLSORV,DFN)) Q:DFN'=+DFN!($D(APCLQUIT)) D
..Q:$$ENDL
..S APCLY=^TMP($J,"PTS",APCLSORV,DFN)
..W !!,$E($P(^DPT(DFN,0),U),1,20),?22,$$HRN^AUPNPAT(DFN,DUZ(2)),?29,$P(APCLY,U,5),?33,$P(^DPT(DFN,0),U,2),?35,$$DT($P(APCLY,U,7)),?44,$E($P(APCLY,U,3),1,16),?61,$E($P(APCLY,U,9),1,17)
..I $P(APCLY,U,4)]"" W !?3,"Comment: ",$P(APCLY,U,4)
..I $P(APCLY,U,1)="EX" S APCLV=$P(APCLY,U,15) I $D(^AUPNVPOV("AD",APCLV)) D
...S APCLC=0 W !?3,"DXs: "
...S APCLX=0 F S APCLX=$O(^AUPNVPOV("AD",APCLV,APCLX)) Q:APCLX'=+APCLX!($D(APCLQUIT)) D
....S APCLC=APCLC+1
....W:APCLC'=1 ! W ?8,$$VAL^XBDIQ1(9000010.07,APCLX,.01),?17,$E($$VAL^XBDIQ1(9000010.07,APCLX,.04),1,60)
..I $P(APCLY,U,1)="BH" S APCLV=$P(APCLY,U,15) I $D(^AMHRPRO("AD",APCLV)) D
...S APCLC=0 W !?3,"DXs: "
...S APCLX=0 F S APCLX=$O(^AMHRPRO("AD",APCLV,APCLX)) Q:APCLX'=+APCLX!($D(APCLQUIT)) D
....S APCLC=APCLC+1
....W:APCLC'=1 ! W ?8,$$VAL^XBDIQ1(9002011.01,APCLX,.01),?17,$E($$VAL^XBDIQ1(9002011.01,APCLX,.04),1,60)
..I $P(APCLY,U,1)="REF" S APCLD=$P(APCLY,U,7) D
...K APCLV S A="APCLV(",B=DFN_"^ALL VISITS;DURING "_$$FMTE^XLFDT(APCLD)_"-"_$$FMTE^XLFDT(APCLD),E=$$START1^APCLDF(B,A)
...I $D(APCLV) S APCLV1=0 F S APCLV1=$O(APCLV(APCLV1)) Q:APCLV1'=+APCLV1 S APCLV=$P(APCLV(APCLV1),U,5) D
....S APCLC=0 W !?3,"DXs: "
....S APCLX=0 F S APCLX=$O(^AUPNVPOV("AD",APCLV,APCLX)) Q:APCLX'=+APCLX!($D(APCLQUIT)) D
.....S APCLC=APCLC+1
.....W:APCLC'=1 ! W ?8,$$VAL^XBDIQ1(9000010.07,APCLX,.01),?17,$E($$VAL^XBDIQ1(9000010.07,APCLX,.04),1,60)
..W !?3,"Primary Provider on Visit: ",?31,$P(APCLY,U,2)
..W !?3," Provider who screened: ",?31,$P(APCLY,U,16)
..I 'APCLDP W ! Q
..K APCLZ S X=$$VAL^XBDIQ1(9002011.55,DFN,.02) I X]"" S APCLZ("MENTAL HEALTH")=X
..S X=$$VAL^XBDIQ1(9002011.55,DFN,.03) I X]"" S APCLZ("SOCIAL SERVICES")=X
..S X=$$VAL^XBDIQ1(9002011.55,DFN,.04) I X]"" S APCLZ("CHEMICAL DEPENDENCY")=X
..S X=$$VAL^XBDIQ1(9000001,DFN,.14) I X]"" S APCLZ("DESIGNATED PRIMARY PROVIDER")=X
..S APCLXX=0 F S APCLXX=$O(^BDPRECN("C",DFN,APCLXX)) Q:APCLXX'=+APCLXX D
...S A=$$VAL^XBDIQ1(90360.1,APCLXX,.01) I '$D(APCLZ(A)) S APCLZ(A)=$$VAL^XBDIQ1(90360.1,APCLXX,.03)
..Q:'$D(APCLZ)
..W !?3," Designated Providers: "
..S APCLZ="",APCLC=0 F S APCLZ=$O(APCLZ(APCLZ)) Q:APCLZ=""!($D(APCLQUIT)) D
...Q:$$END
...S APCLC=APCLC+1
...W:APCLC'=1 ! W ?31,$S(APCLZ="DESIGNATED PRIMARY PROVIDER":"PRIMARY CARE",1:APCLZ),": ",APCLZ(APCLZ)
Q
H ;
S APCLSORV=$$HRN^AUPNPAT(DFN,DUZ(2))
Q
N ;
S APCLSORV=$P(^DPT(DFN,0),U)
Q
P ;
S APCLSORV=$P(APCLY,U,2)
Q
R ;
S APCLSORV=$P(APCLY,U,3)
Q
D ;
S APCLSORV=$P(APCLY,U,7)
Q
A S APCLSORV=$P(APCLY,U,5)
Q
G ;
S APCLSORV=$P(APCLY,U,6)
Q
C ;
S APCLSORV=$P(APCLY,U,9)
Q
T ;
S %=$$HRN^AUPNPAT(DFN,DUZ(2))
S %=%+10000000,%=$E(%,7,8)_"-"_+$E(%,2,8)
S APCLSORV=%
Q
DT(D) ;EP
I D="" Q ""
Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_$E(D,2,3)
;
APCLDV1P ; IHS/CMI/LAB - list refusals ;
+1 ;;2.0;IHS PCC SUITE;;MAY 14, 2009
+2 ;
+3 ;
PRINT ;EP - called from xbdbque
+1 DO PRINT1
+2 DO DONE
+3 QUIT
PRINT1 ;
+1 SET APCLPG=0
KILL APCLQUIT
+2 KILL APCLLSTP
+3 IF '$DATA(^XTMP("APCLDV1",APCLJ,APCLH))
DO HEADER
WRITE !!,"No data to report.",!
GOTO DONE
+4 DO HEADER
+5 SET APCLTOT=$$TOT
+6 WRITE !," Total Number of Patients screened",?40,$JUSTIFY($$COM(APCLTOT,0),8)
+7 DO RES
+8 IF $$END
QUIT
+9 DO GENDER
+10 IF $$END
QUIT
+11 DO AGE
+12 IF $$END
QUIT
+13 DO PRVSC
+14 IF $$END
QUIT
+15 DO PRVV
+16 IF $$END
QUIT
+17 DO DESPRV
+18 IF $$END
QUIT
+19 DO CLINIC
+20 IF $$END
QUIT
+21 DO DATE
+22 IF $$END
QUIT
+23 KILL ^TMP($JOB)
+24 IF APCLLIST
DO LIST
+25 QUIT
RES ;
+1 IF '$DATA(APCLTALL(1))
QUIT
+2 ;TALLY BY RESULT FIRST
+3 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+5 SET R=$PIECE(APCLY,U,3)
IF R=""
SET R="NO RESULT RECORDED"
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+6 WRITE !
+7 WRITE !," By Result",!
+8 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+9 SET Y=$LENGTH(APCLX)
SET Y=38-Y
WRITE !?Y,APCLX,?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
End DoDot:1
+10 QUIT
GENDER ;
+1 IF '$DATA(APCLTALL(2))
QUIT
+2 ;TALLY BY GENDER OF PATIENT
+3 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+5 SET R=$PIECE(APCLY,U,6)
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+6 WRITE !
+7 WRITE !," By Gender",!
+8 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+9 IF $$END
QUIT
+10 SET Y=$LENGTH(APCLX)
SET Y=38-Y
WRITE !?Y,APCLX,?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
+11 QUIT
End DoDot:1
+12 QUIT
AGE ;
+1 IF '$DATA(APCLTALL(3))
QUIT
+2 ;TALLY BY age OF PATIENT
+3 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+5 SET R=$PIECE(APCLY,U,5)
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+6 WRITE !
+7 WRITE !," By Age",!
+8 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+9 IF $$END
QUIT
+10 SET Y=$LENGTH(APCLX_" yrs")
SET Y=38-Y
WRITE !?Y,APCLX," yrs",?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
End DoDot:1
+11 QUIT
PRVSC ;
+1 IF '$DATA(APCLTALL(4))
QUIT
+2 ;TALLY BY PRIMARY provider OF service
+3 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+5 SET R=$PIECE(APCLY,U,16)
IF R=""
SET R="UNKNOWN"
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+6 WRITE !
+7 WRITE !," By Provider who screened",!
+8 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+9 IF $$END
QUIT
+10 SET Y=$LENGTH(APCLX)
SET Y=38-Y
WRITE !?Y,APCLX,?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
End DoDot:1
+11 QUIT
PRVV ;
+1 IF '$DATA(APCLTALL(5))
QUIT
+2 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+3 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+4 SET R=$PIECE(APCLY,U,2)
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+5 WRITE !
+6 WRITE !," By Primary Provider of Visit",!
+7 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+8 IF $$END
QUIT
+9 SET Y=$LENGTH(APCLX)
SET Y=38-Y
WRITE !?Y,APCLX,?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
End DoDot:1
+10 QUIT
DESPRV ;
+1 IF '$DATA(APCLTALL(6))
QUIT
+2 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+3 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+4 SET R=$PIECE(APCLY,U,17)
IF R=""
SET R="UNKNOWN"
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+5 WRITE !
+6 WRITE !," By Designated Primary Care Provider",!
+7 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+8 IF $$END
QUIT
+9 SET Y=$LENGTH(APCLX)
SET Y=38-Y
WRITE !?Y,APCLX,?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
End DoDot:1
+10 QUIT
CLINIC ;
+1 IF '$DATA(APCLTALL(7))
QUIT
+2 ;TALLY BY clinic
+3 KILL APCLRES
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+5 SET R=$PIECE(APCLY,U,9)
IF R=""
SET R="UNKNOWN"
SET APCLRES(R)=$GET(APCLRES(R))+1
End DoDot:1
+6 WRITE !
+7 WRITE !," By Clinic",!
+8 SET APCLX=""
FOR
SET APCLX=$ORDER(APCLRES(APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+9 IF $$END
QUIT
+10 SET Y=$LENGTH(APCLX)
SET Y=38-Y
WRITE !?Y,APCLX,?40,$JUSTIFY($$COM($GET(APCLRES(APCLX)),0),8),?55,$$PER(APCLRES(APCLX),APCLTOT)
KILL APCLRES(APCLX)
End DoDot:1
+11 QUIT
DATE ;
+1 IF '$DATA(APCLTALL(8))
QUIT
+2 ;TALLY BY date OF service
+3 KILL ^TMP($JOB)
SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
Begin DoDot:1
+4 SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X,D)
+5 SET R=$PIECE(APCLY,U,7)
SET ^TMP($JOB,R)=$GET(^TMP($JOB,R))+1
End DoDot:1
+6 WRITE !
+7 WRITE !," By Date",!
+8 SET APCLX=""
FOR
SET APCLX=$ORDER(^TMP($JOB,APCLX))
IF APCLX=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+9 IF $$END
QUIT
+10 SET Y=$LENGTH($$FMTE^XLFDT(APCLX))
SET Y=38-Y
WRITE !?Y,$$FMTE^XLFDT(APCLX),?40,$JUSTIFY($$COM($GET(^TMP($JOB,APCLX)),0),8),?55,$$PER(^TMP($JOB,APCLX),APCLTOT)
KILL ^TMP($JOB,APCLX)
End DoDot:1
+11 QUIT
+12 ;
PER(N,D) ;return % of n/d
+1 IF 'D
QUIT "0%"
+2 NEW Z
+3 SET Z=N/D
SET Z=Z*100
SET Z=$JUSTIFY(Z,5,1)
+4 QUIT $$STRIP^XLFSTR(Z," ")_"%"
COM(X,X2,X3) ;
+1 DO COMMA^%DTC
+2 QUIT $$STRIP^XLFSTR(X," ")
END() ;
+1 IF $Y<(IOSL-3)
QUIT 0
+2 DO HEADER
+3 IF $DATA(APCLQUIT)
QUIT 1
+4 QUIT 0
ENDL() ;
+1 IF $Y<(IOSL-8)
QUIT 0
+2 DO HEADER
+3 IF $DATA(APCLQUIT)
QUIT 1
+4 QUIT 0
TOT() ;
+1 NEW C,X
+2 SET C=0
+3 SET X=0
FOR
SET X=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",X))
IF X'=+X
QUIT
SET C=C+1
+4 QUIT C
+1 IF 'APCLPG
GOTO HEADER1
+2 KILL DIR
IF $EXTRACT(IOST)="C"
IF IO=IO(0)
WRITE !
SET DIR(0)="EO"
DO ^DIR
KILL DIR
IF Y=0!(Y="^")!($DATA(DTOUT))
SET APCLQUIT=""
QUIT
+1 IF $DATA(IOF)
WRITE @IOF
SET APCLPG=APCLPG+1
+2 WRITE !?3,$PIECE(^VA(200,DUZ,0),U,2),?35,$$FMTE^XLFDT(DT),?70,"Page ",APCLPG,!
+3 WRITE !,$$CTR("*** IPV SCREENING PATIENT TALLY"_$SELECT(APCLLIST:" AND PATIENT LISTING",1:"")_" ***",80),!
+4 SET X="Screening Dates: "_$$FMTE^XLFDT(APCLBD)_" to "_$$FMTE^XLFDT(APCLED)
WRITE $$CTR(X,80),!
+5 IF APCLEXBH
SET X="This report includes Behavioral Health Clinics"
WRITE $$CTR(X,80),!
+6 IF 'APCLEXBH
SET X="This report excludes Behavioral Health Clinics"
WRITE $$CTR(X,80),!
+7 DO LOCHDR
+8 DO COMMHDR
+9 IF $GET(APCLLSTP)
WRITE !?35,"DATE",!,"PATIENT NAME",?22,"HRN",?29,"AGE",?35,"SCREENED",?44,"RESULT",?61,"CLINIC"
+10 WRITE !,$TRANSLATE($JUSTIFY("",80)," ","-")
+11 IF '$GET(APCLLSTP)
WRITE !?46,"#",?53,"% of patients"
+12 QUIT
LOCHDR ;EP
+1 IF APCLLOCT="A"
SET X="All Facilities/Locations"
WRITE $$CTR(X,80),!
+2 IF APCLLOCT="O"
SET X="Facility/Location: "_$PIECE(^DIC(4,APCLLOCT("ONE"),0),U)
WRITE $$CTR(X,80),!
+3 IF APCLLOCT="S"
SET X="All Facilities/Locations within the "_$PIECE(^AUTTSU(APCLLOCT("SU"),0),U)_" service unit"
WRITE $$CTR(X,80),!
+4 QUIT
COMMHDR ;EP
+1 IF APCLCOMT="A"
SET X="All Patient Communities"
WRITE $$CTR(X,80),!
+2 IF APCLCOMT="O"
SET X="Community: "_$PIECE(^AUTTCOM(APCLCOMT("ONE"),0),U)
WRITE $$CTR(X,80),!
+3 IF APCLCOMT="S"
SET X="All Communities within the "_$PIECE(^ATXAX(APCLCOMT("SU"),0),U)_" taxonomy"
WRITE $$CTR(X,80),!
+4 QUIT
DONE ;
+1 KILL ^TMP($JOB)
+2 KILL ^XTMP("APCLDV1",APCLJ,APCLH)
+3 DO EOP
+4 QUIT
CTR(X,Y) ;EP - Center X in a field Y wide.
+1 QUIT $JUSTIFY("",$SELECT($DATA(Y):Y,1:IOM)-$LENGTH(X)\2)_X
+2 ;----------
EOP ;EP - End of page.
+1 IF $EXTRACT(IOST)'="C"
QUIT
+2 IF IO'=IO(0)
QUIT
+3 IF $DATA(ZTQUEUED)!'(IOT="TRM")!$DATA(IO("S"))
QUIT
+4 NEW DIR
+5 KILL DIRUT,DFOUT,DLOUT,DTOUT,DUOUT
+6 WRITE !
+7 SET DIR("A")="End of Report. Press Enter"
SET DIR(0)="E"
DO ^DIR
+8 QUIT
+9 ;----------
USR() ;EP - Return name of current user from ^VA(200.
+1 QUIT $SELECT($GET(DUZ):$SELECT($DATA(^VA(200,DUZ,0)):$PIECE(^(0),U),1:"UNKNOWN"),1:"DUZ UNDEFINED OR 0")
+2 ;----------
LOC() ;EP - Return location name from file 4 based on DUZ(2).
+1 QUIT $SELECT($GET(DUZ(2)):$SELECT($DATA(^DIC(4,DUZ(2),0)):$PIECE(^(0),U),1:"UNKNOWN"),1:"DUZ(2) UNDEFINED OR 0")
+2 ;----------
LIST ;EP - called from xbdbque
+1 SET APCLPG=0
KILL APCLQUIT
+2 SET APCLLSTP=1
+3 DO HEADER
+4 KILL ^TMP($JOB)
+5 ;resort by sort item
+6 SET DFN=0
FOR
SET DFN=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",DFN))
IF DFN'=+DFN
QUIT
SET D=$ORDER(^XTMP("APCLDV1",APCLJ,APCLH,"PTS",DFN,""),-1)
SET APCLY=^XTMP("APCLDV1",APCLJ,APCLH,"PTS",DFN,D)
Begin DoDot:1
+7 DO @APCLSORT
+8 IF APCLSORV=""
SET APCLSORV="--"
+9 SET ^TMP($JOB,"PTS",APCLSORV,DFN)=APCLY
+10 QUIT
End DoDot:1
+11 SET APCLSORV=""
FOR
SET APCLSORV=$ORDER(^TMP($JOB,"PTS",APCLSORV))
IF APCLSORV=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:1
+12 SET DFN=0
FOR
SET DFN=$ORDER(^TMP($JOB,"PTS",APCLSORV,DFN))
IF DFN'=+DFN!($DATA(APCLQUIT))
QUIT
Begin DoDot:2
+13 IF $$ENDL
QUIT
+14 SET APCLY=^TMP($JOB,"PTS",APCLSORV,DFN)
+15 WRITE !!,$EXTRACT($PIECE(^DPT(DFN,0),U),1,20),?22,$$HRN^AUPNPAT(DFN,DUZ(2)),?29,$PIECE(APCLY,U,5),?33,$PIECE(^DPT(DFN,0),U,2),?35,$$DT($PIECE(APCLY,U,7)),?44,$EXTRACT($PIECE(APCLY,U,3),1,16),?61,$EXTRACT($PIECE(APCLY,U,9),1,17)
+16 IF $PIECE(APCLY,U,4)]""
WRITE !?3,"Comment: ",$PIECE(APCLY,U,4)
+17 IF $PIECE(APCLY,U,1)="EX"
SET APCLV=$PIECE(APCLY,U,15)
IF $DATA(^AUPNVPOV("AD",APCLV))
Begin DoDot:3
+18 SET APCLC=0
WRITE !?3,"DXs: "
+19 SET APCLX=0
FOR
SET APCLX=$ORDER(^AUPNVPOV("AD",APCLV,APCLX))
IF APCLX'=+APCLX!($DATA(APCLQUIT))
QUIT
Begin DoDot:4
+20 SET APCLC=APCLC+1
+21 IF APCLC'=1
WRITE !
WRITE ?8,$$VAL^XBDIQ1(9000010.07,APCLX,.01),?17,$EXTRACT($$VAL^XBDIQ1(9000010.07,APCLX,.04),1,60)
End DoDot:4
End DoDot:3
+22 IF $PIECE(APCLY,U,1)="BH"
SET APCLV=$PIECE(APCLY,U,15)
IF $DATA(^AMHRPRO("AD",APCLV))
Begin DoDot:3
+23 SET APCLC=0
WRITE !?3,"DXs: "
+24 SET APCLX=0
FOR
SET APCLX=$ORDER(^AMHRPRO("AD",APCLV,APCLX))
IF APCLX'=+APCLX!($DATA(APCLQUIT))
QUIT
Begin DoDot:4
+25 SET APCLC=APCLC+1
+26 IF APCLC'=1
WRITE !
WRITE ?8,$$VAL^XBDIQ1(9002011.01,APCLX,.01),?17,$EXTRACT($$VAL^XBDIQ1(9002011.01,APCLX,.04),1,60)
End DoDot:4
End DoDot:3
+27 IF $PIECE(APCLY,U,1)="REF"
SET APCLD=$PIECE(APCLY,U,7)
Begin DoDot:3
+28 KILL APCLV
SET A="APCLV("
SET B=DFN_"^ALL VISITS;DURING "_$$FMTE^XLFDT(APCLD)_"-"_$$FMTE^XLFDT(APCLD)
SET E=$$START1^APCLDF(B,A)
+29 IF $DATA(APCLV)
SET APCLV1=0
FOR
SET APCLV1=$ORDER(APCLV(APCLV1))
IF APCLV1'=+APCLV1
QUIT
SET APCLV=$PIECE(APCLV(APCLV1),U,5)
Begin DoDot:4
+30 SET APCLC=0
WRITE !?3,"DXs: "
+31 SET APCLX=0
FOR
SET APCLX=$ORDER(^AUPNVPOV("AD",APCLV,APCLX))
IF APCLX'=+APCLX!($DATA(APCLQUIT))
QUIT
Begin DoDot:5
+32 SET APCLC=APCLC+1
+33 IF APCLC'=1
WRITE !
WRITE ?8,$$VAL^XBDIQ1(9000010.07,APCLX,.01),?17,$EXTRACT($$VAL^XBDIQ1(9000010.07,APCLX,.04),1,60)
End DoDot:5
End DoDot:4
End DoDot:3
+34 WRITE !?3,"Primary Provider on Visit: ",?31,$PIECE(APCLY,U,2)
+35 WRITE !?3," Provider who screened: ",?31,$PIECE(APCLY,U,16)
+36 IF 'APCLDP
WRITE !
QUIT
+37 KILL APCLZ
SET X=$$VAL^XBDIQ1(9002011.55,DFN,.02)
IF X]""
SET APCLZ("MENTAL HEALTH")=X
+38 SET X=$$VAL^XBDIQ1(9002011.55,DFN,.03)
IF X]""
SET APCLZ("SOCIAL SERVICES")=X
+39 SET X=$$VAL^XBDIQ1(9002011.55,DFN,.04)
IF X]""
SET APCLZ("CHEMICAL DEPENDENCY")=X
+40 SET X=$$VAL^XBDIQ1(9000001,DFN,.14)
IF X]""
SET APCLZ("DESIGNATED PRIMARY PROVIDER")=X
+41 SET APCLXX=0
FOR
SET APCLXX=$ORDER(^BDPRECN("C",DFN,APCLXX))
IF APCLXX'=+APCLXX
QUIT
Begin DoDot:3
+42 SET A=$$VAL^XBDIQ1(90360.1,APCLXX,.01)
IF '$DATA(APCLZ(A))
SET APCLZ(A)=$$VAL^XBDIQ1(90360.1,APCLXX,.03)
End DoDot:3
+43 IF '$DATA(APCLZ)
QUIT
+44 WRITE !?3," Designated Providers: "
+45 SET APCLZ=""
SET APCLC=0
FOR
SET APCLZ=$ORDER(APCLZ(APCLZ))
IF APCLZ=""!($DATA(APCLQUIT))
QUIT
Begin DoDot:3
+46 IF $$END
QUIT
+47 SET APCLC=APCLC+1
+48 IF APCLC'=1
WRITE !
WRITE ?31,$SELECT(APCLZ="DESIGNATED PRIMARY PROVIDER":"PRIMARY CARE",1:APCLZ),": ",APCLZ(APCLZ)
End DoDot:3
End DoDot:2
End DoDot:1
+49 QUIT
H ;
+1 SET APCLSORV=$$HRN^AUPNPAT(DFN,DUZ(2))
+2 QUIT
N ;
+1 SET APCLSORV=$PIECE(^DPT(DFN,0),U)
+2 QUIT
P ;
+1 SET APCLSORV=$PIECE(APCLY,U,2)
+2 QUIT
R ;
+1 SET APCLSORV=$PIECE(APCLY,U,3)
+2 QUIT
D ;
+1 SET APCLSORV=$PIECE(APCLY,U,7)
+2 QUIT
A SET APCLSORV=$PIECE(APCLY,U,5)
+1 QUIT
G ;
+1 SET APCLSORV=$PIECE(APCLY,U,6)
+2 QUIT
C ;
+1 SET APCLSORV=$PIECE(APCLY,U,9)
+2 QUIT
T ;
+1 SET %=$$HRN^AUPNPAT(DFN,DUZ(2))
+2 SET %=%+10000000
SET %=$EXTRACT(%,7,8)_"-"_+$EXTRACT(%,2,8)
+3 SET APCLSORV=%
+4 QUIT
DT(D) ;EP
+1 IF D=""
QUIT ""
+2 QUIT $EXTRACT(D,4,5)_"/"_$EXTRACT(D,6,7)_"/"_$EXTRACT(D,2,3)
+3 ;