AMHRE2 ; IHS/CMI/LAB - PLACEMENT TO RESIDENTIAL ;
;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
;
I '$D(IOF) D HOME^%ZIS
W @(IOF),!!
W "********** RESIDENTIAL TREATMENT AFTERCARE REPORT **********",!!
W "This report will produce a list of patients who have residential treatment ",!,"placement in a date range you specify.",!
GETDATES ;
BD ;get beginning date
W !,"Please enter the date range during which the patient had a placement.",!
W ! S DIR(0)="D^:DT:EP",DIR("A")="Enter beginning Date" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
I $D(DIRUT) G XIT
S AMHBD=Y
ED ;get ending date
W ! S DIR(0)="D^"_AMHBD_":DT:EP",DIR("A")="Enter ending Date" S Y=AMHBD D DD^%DT D ^DIR K DIR S:$D(DUOUT) DIRUT=1
I $D(DIRUT) G BD
S AMHED=Y
S X1=AMHBD,X2=-1 D C^%DTC S AMHSD=X S Y=AMHBD D DD^%DT S AMHBDD=Y S Y=AMHED D DD^%DT S AMHEDD=Y
;
ZIS ;
S DIR(0)="S^P:PRINT Output;B:BROWSE Output on Screen",DIR("A")="Do you wish to ",DIR("B")="P" K DA D ^DIR K DIR
I $D(DIRUT) G XIT
I $G(Y)="B" D BROWSE,XIT Q
S XBRC="PROC^AMHRE2",XBRP="PRINT^AMHRE2",XBNS="AMH",XBRX="XIT^AMHRE2"
D ^XBDBQUE
XIT ;
D EN^XBVK("AMH")
D KILL^AUPNPAT
Q
;
BROWSE ;
S XBRP="VIEWR^XBLM(""PRINT^AMHRE2"")"
S XBNS="AMH",XBRC="PROC^AMHRE2",XBRX="XIT^AMHRE2",XBIOP=0 D ^XBDBQUE
Q
PROC ;EP - entry point for processing
S AMHJOB=$J,AMHBTH=$H,AMHTOT=0,DFN=0,AMHBT=$H
K AMHTOTP,AMHTOTF
D XTMP^AMHUTIL("AMHRE2","BH - PLACEMENT REPORT")
S X1=AMHBD,X2=-1 D C^%DTC S AMHSD=X
S AMHODAT=AMHSD_".9999" F S AMHODAT=$O(^AMHREC("B",AMHODAT)) Q:AMHODAT=""!((AMHODAT\1)>AMHED) D PROC1
S AMHET=$H
Q
PROC1 ;
S (AMHR,AMHRCNT)=0 F S AMHR=$O(^AMHREC("B",AMHODAT,AMHR)) Q:AMHR'=+AMHR I $D(^AMHREC(AMHR,0)),$P(^AMHREC(AMHR,0),U,8)]"" D SET
Q
SET ;
I $P(^AMHREC(AMHR,0),U,17)'=3 Q
S S1=$S($P(^AMHREC(AMHR,0),U,18)]"":$P(^AMHREC(AMHR,0),U,18),1:"UNKNOWN")
S ^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",S1,$$VAL^XBDIQ1(9002011,AMHR,.08),AMHR)="",AMHTOT=AMHTOT+1
Q
PRINT ;
S Y=AMHBD D DD^%DT S AMHBDD=Y S Y=AMHED D DD^%DT S AMHEDD=Y
S AMH80D="-------------------------------------------------------------------------------"
S AMHPG=0 D HEAD
I '$D(^XTMP("AMHRE2",AMHJOB,AMHBTH)) W !!,"NO PATIENTS TO REPORT" G DONE
S AMHR="" K AMHQ
S AMHF="" F S AMHF=$O(^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",AMHF)) Q:AMHF=""!($D(AMHQ)) D
.S AMHNAME="" F S AMHNAME=$O(^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",AMHF,AMHNAME)) Q:AMHNAME=""!($D(AMHQ)) D
..S AMHR=0 F S AMHR=$O(^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",AMHF,AMHNAME,AMHR)) Q:AMHR'=+AMHR!($D(AMHQ)) D PRINT1
DONE ;
K ^XTMP("AMHRE2",AMHJOB,AMHBTH),AMHJOB,AMHBTH
Q
PRINT1 ;
I $Y>(IOSL-4) D HEAD Q:$D(AMHQ)
S DFN=$P(^AMHREC(AMHR,0),U,8)
W !,$E($P(^DPT(DFN,0),U),1,20),?22,$$HRN^AUPNPAT(DFN,DUZ(2)),?29,$E($$VAL^XBDIQ1(9002011.55,DFN,.02),1,15),?45,$E(AMHF,1,15),?62,$$D($P(^AMHREC(AMHR,0),U)),?72,$$D($$LVD^AMHDPEE(DFN,"ID"))
Q
D(D) ;
I $G(D)="" Q ""
Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_$E(D,2,3)
CTR(X,Y) ;EP - Center X in a field Y wide.
Q $J("",$S($D(Y):Y,1:IOM)-$L(X)\2)_X
;----------
HEAD I 'AMHPG G HEAD1
I $E(IOST)="C",IO=IO(0) W ! S DIR(0)="EO" D ^DIR K DIR I Y=0!(Y="^")!($D(DTOUT)) S AMHQ="" Q
HEAD1 ;
W:$D(IOF) @IOF S AMHPG=AMHPG+1
W !?13,"********** CONFIDENTIAL PATIENT INFORMATION **********"
W !,$P(^VA(200,DUZ,0),U,2),?72,"Page ",AMHPG,!
W ?(80-$L($P(^DIC(4,DUZ(2),0),U))/2),$P(^DIC(4,DUZ(2),0),U),!
W $$CTR("RESIDENTIAL PLACEMENTS"),!
W ?15,"PLACEMENT DATES: ",AMHBDD," TO ",AMHEDD,!
PIH W !,"PATIENT NAME",?22,"HRN",?29,"DESG PROV",?45,"REFERRED TO",?62,"DATE PL",?71,"LAST SEEN",!,AMH80D
Q
AMHRE2 ; IHS/CMI/LAB - PLACEMENT TO RESIDENTIAL ;
+1 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
+2 ;
+3 IF '$DATA(IOF)
DO HOME^%ZIS
+4 WRITE @(IOF),!!
+5 WRITE "********** RESIDENTIAL TREATMENT AFTERCARE REPORT **********",!!
+6 WRITE "This report will produce a list of patients who have residential treatment ",!,"placement in a date range you specify.",!
GETDATES ;
BD ;get beginning date
+1 WRITE !,"Please enter the date range during which the patient had a placement.",!
+2 WRITE !
SET DIR(0)="D^:DT:EP"
SET DIR("A")="Enter beginning Date"
DO ^DIR
KILL DIR
IF $DATA(DUOUT)
SET DIRUT=1
+3 IF $DATA(DIRUT)
GOTO XIT
+4 SET AMHBD=Y
ED ;get ending date
+1 WRITE !
SET DIR(0)="D^"_AMHBD_":DT:EP"
SET DIR("A")="Enter ending Date"
SET Y=AMHBD
DO DD^%DT
DO ^DIR
KILL DIR
IF $DATA(DUOUT)
SET DIRUT=1
+2 IF $DATA(DIRUT)
GOTO BD
+3 SET AMHED=Y
+4 SET X1=AMHBD
SET X2=-1
DO C^%DTC
SET AMHSD=X
SET Y=AMHBD
DO DD^%DT
SET AMHBDD=Y
SET Y=AMHED
DO DD^%DT
SET AMHEDD=Y
+5 ;
ZIS ;
+1 SET DIR(0)="S^P:PRINT Output;B:BROWSE Output on Screen"
SET DIR("A")="Do you wish to "
SET DIR("B")="P"
KILL DA
DO ^DIR
KILL DIR
+2 IF $DATA(DIRUT)
GOTO XIT
+3 IF $GET(Y)="B"
DO BROWSE
DO XIT
QUIT
+4 SET XBRC="PROC^AMHRE2"
SET XBRP="PRINT^AMHRE2"
SET XBNS="AMH"
SET XBRX="XIT^AMHRE2"
+5 DO ^XBDBQUE
XIT ;
+1 DO EN^XBVK("AMH")
+2 DO KILL^AUPNPAT
+3 QUIT
+4 ;
BROWSE ;
+1 SET XBRP="VIEWR^XBLM(""PRINT^AMHRE2"")"
+2 SET XBNS="AMH"
SET XBRC="PROC^AMHRE2"
SET XBRX="XIT^AMHRE2"
SET XBIOP=0
DO ^XBDBQUE
+3 QUIT
PROC ;EP - entry point for processing
+1 SET AMHJOB=$JOB
SET AMHBTH=$HOROLOG
SET AMHTOT=0
SET DFN=0
SET AMHBT=$HOROLOG
+2 KILL AMHTOTP,AMHTOTF
+3 DO XTMP^AMHUTIL("AMHRE2","BH - PLACEMENT REPORT")
+4 SET X1=AMHBD
SET X2=-1
DO C^%DTC
SET AMHSD=X
+5 SET AMHODAT=AMHSD_".9999"
FOR
SET AMHODAT=$ORDER(^AMHREC("B",AMHODAT))
IF AMHODAT=""!((AMHODAT\1)>AMHED)
QUIT
DO PROC1
+6 SET AMHET=$HOROLOG
+7 QUIT
PROC1 ;
+1 SET (AMHR,AMHRCNT)=0
FOR
SET AMHR=$ORDER(^AMHREC("B",AMHODAT,AMHR))
IF AMHR'=+AMHR
QUIT
IF $DATA(^AMHREC(AMHR,0))
IF $PIECE(^AMHREC(AMHR,0),U,8)]""
DO SET
+2 QUIT
SET ;
+1 IF $PIECE(^AMHREC(AMHR,0),U,17)'=3
QUIT
+2 SET S1=$SELECT($PIECE(^AMHREC(AMHR,0),U,18)]"":$PIECE(^AMHREC(AMHR,0),U,18),1:"UNKNOWN")
+3 SET ^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",S1,$$VAL^XBDIQ1(9002011,AMHR,.08),AMHR)=""
SET AMHTOT=AMHTOT+1
+4 QUIT
PRINT ;
+1 SET Y=AMHBD
DO DD^%DT
SET AMHBDD=Y
SET Y=AMHED
DO DD^%DT
SET AMHEDD=Y
+2 SET AMH80D="-------------------------------------------------------------------------------"
+3 SET AMHPG=0
DO HEAD
+4 IF '$DATA(^XTMP("AMHRE2",AMHJOB,AMHBTH))
WRITE !!,"NO PATIENTS TO REPORT"
GOTO DONE
+5 SET AMHR=""
KILL AMHQ
+6 SET AMHF=""
FOR
SET AMHF=$ORDER(^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",AMHF))
IF AMHF=""!($DATA(AMHQ))
QUIT
Begin DoDot:1
+7 SET AMHNAME=""
FOR
SET AMHNAME=$ORDER(^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",AMHF,AMHNAME))
IF AMHNAME=""!($DATA(AMHQ))
QUIT
Begin DoDot:2
+8 SET AMHR=0
FOR
SET AMHR=$ORDER(^XTMP("AMHRE2",AMHJOB,AMHBTH,"PLACEMENTS",AMHF,AMHNAME,AMHR))
IF AMHR'=+AMHR!($DATA(AMHQ))
QUIT
DO PRINT1
End DoDot:2
End DoDot:1
DONE ;
+1 KILL ^XTMP("AMHRE2",AMHJOB,AMHBTH),AMHJOB,AMHBTH
+2 QUIT
PRINT1 ;
+1 IF $Y>(IOSL-4)
DO HEAD
IF $DATA(AMHQ)
QUIT
+2 SET DFN=$PIECE(^AMHREC(AMHR,0),U,8)
+3 WRITE !,$EXTRACT($PIECE(^DPT(DFN,0),U),1,20),?22,$$HRN^AUPNPAT(DFN,DUZ(2)),?29,$EXTRACT($$VAL^XBDIQ1(9002011.55,DFN,.02),1,15),?45,$EXTRACT(AMHF,1,15),?62,$$D($PIECE(^AMHREC(AMHR,0),U)),?72,$$D($$LVD^AMHDPEE(DFN,"ID"))
+4 QUIT
D(D) ;
+1 IF $GET(D)=""
QUIT ""
+2 QUIT $EXTRACT(D,4,5)_"/"_$EXTRACT(D,6,7)_"/"_$EXTRACT(D,2,3)
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 ;----------
HEAD IF 'AMHPG
GOTO HEAD1
+1 IF $EXTRACT(IOST)="C"
IF IO=IO(0)
WRITE !
SET DIR(0)="EO"
DO ^DIR
KILL DIR
IF Y=0!(Y="^")!($DATA(DTOUT))
SET AMHQ=""
QUIT
HEAD1 ;
+1 IF $DATA(IOF)
WRITE @IOF
SET AMHPG=AMHPG+1
+2 WRITE !?13,"********** CONFIDENTIAL PATIENT INFORMATION **********"
+3 WRITE !,$PIECE(^VA(200,DUZ,0),U,2),?72,"Page ",AMHPG,!
+4 WRITE ?(80-$LENGTH($PIECE(^DIC(4,DUZ(2),0),U))/2),$PIECE(^DIC(4,DUZ(2),0),U),!
+5 WRITE $$CTR("RESIDENTIAL PLACEMENTS"),!
+6 WRITE ?15,"PLACEMENT DATES: ",AMHBDD," TO ",AMHEDD,!
PIH WRITE !,"PATIENT NAME",?22,"HRN",?29,"DESG PROV",?45,"REFERRED TO",?62,"DATE PL",?71,"LAST SEEN",!,AMH80D
+1 QUIT