PSOCST10 ;BHAM ISC/SAB - high cost report ; 12/11/96 13:47
;;7.0;OUTPATIENT PHARMACY;**31,56**;DEC 1997
;this routine list rxs that cost over a specified $ amount for a specified date range
;External Ref. ^PSDRUG( is supp. by DBIA# 221
BEG W ! S %DT(0)=-DT,%DT("A")="Beginning Date: ",%DT="APE" D ^%DT G:Y<0!($D(DTOUT)) EXIT S (%DT(0),BEGDATE)=Y
W ! S %DT("A")="Ending Date: " D ^%DT G:Y<0!($D(DTOUT)) EXIT S ENDDATE=Y D:+$E(Y,6,7)=0 DTC
MAX K DIR S DIR("A")="Dollar Limit ",DIR("B")=30,DIR(0)="N^0:9999:2",DIR("?")="Enter a dollar amount between 0-9999 with no more than two decimals or ^ quit"
D ^DIR K DIR G:$D(DIRUT) EXIT S MAX=Y
DEV K %ZIS,IOP,POP,ZTSK S PSOION=ION,%ZIS="QM" D ^%ZIS K %ZIS I POP S IOP=PSOION D ^%ZIS K IOP,PSOION W !,"Please try later!" G EXIT
K PSOION I $D(IO("Q")) D G EXIT
.S ZTDESC="Outpatient High Cost Report",ZTRTN="START^PSOCST10" F G="BEGDATE","ENDDATE","MAX" S:$D(@G) ZTSAVE(G)=""
.K IO("Q") D ^%ZTLOAD W:$D(ZTSK) !,"Report is Queued to print !!" K ZTSK
START U IO S PAGE=1,(CNT,TCOST)=0 D HD
F NDT=BEGDATE:1:ENDDATE F TY="AL","AM" S PSDT=NDT D ST1 Q:$D(DIRUT)
Q:$D(DIRUT) D HD:($Y+4)>IOSL
D:'$D(DIRUT) FT
EXIT W ! D ^%ZISC K XTYPE,DIR,DTOUT,DUOUT,DIROUT,DIRUT,^TMP($J),NDT,TY,BEGDATE,CNT,COST,TCOST,DR0,DRCST,ENDDATE,MAX,PAGE,PGM,POP,PSDT,PSFILL,PSRXN,QTY,RX0,RX1,VAR,X,Y,%DT
S:$D(ZTQUEUED) ZTREQ="@" Q
ST1 F S PSDT=$O(^PSRX(TY,PSDT)) Q:'PSDT!(PSDT>(NDT_".999999")) D ST2 Q:$D(DIRUT)
Q
ST2 S PSRXN=0 F S PSRXN=$O(^PSRX(TY,PSDT,PSRXN)) Q:'PSRXN D ST3 Q:$D(DIRUT)
Q
ST3 S PSFILL=""
F S PSFILL=$O(^PSRX(TY,PSDT,PSRXN,PSFILL)) Q:PSFILL="" D CHK Q:$D(DIRUT)
Q
CHK Q:'$D(^PSRX(PSRXN,0))!(+$P(^PSRX(PSRXN,"STA"),"^")=13) S RX0=^(0) Q:'$D(^PSDRUG(+$P(RX0,"^",6),0)) S DR0=^(0)
I TY="AL" S:PSFILL RX1=$G(^PSRX(PSRXN,1,PSFILL,0)) Q:PSFILL&($G(RX1)="")
I TY="AM" Q:'$P($G(^PSRX(PSRXN,"P",PSFILL,0)),"^",19) S RX1=^(0)
S DRCST=$S('PSFILL&(+$P(RX0,"^",17)):$P(RX0,"^",17),PSFILL&(+$P($G(RX1),"^",11)):$P($G(RX1),"^",11),1:0)
S QTY=$S('PSFILL:+$P(RX0,"^",7),1:+$P(RX1,"^",4))
I 'DRCST S DRCST=$S($P($G(^PSDRUG(+$P(RX0,"^",6),660)),"^",6):+$P(^(660),"^",6),1:0)
S COST=QTY*DRCST Q:COST<MAX
D HD:($Y+4)>IOSL Q:$D(DIRUT)
W !,$S(PSFILL&(TY="AL"):"*",TY="AM":"%",1:" ")_$P(RX0,"^"),?11,$E($P(DR0,"^"),"^",40),?51,$J(QTY,6),?60,$J(DRCST,6,3),?68,$J(COST,12,2) S CNT=CNT+1,TCOST=TCOST+COST
Q
HD I PAGE>1,$E(IOST)="C" S DIR(0)="E",DIR("A")=" Press Return to Continue or ^ to Exit" D ^DIR K DIR
Q:$D(DIRUT) W @IOF,!,"Fills That Cost at Least $"_MAX_" for the Period: " S Y=BEGDATE D DT^DIO2 W " to " S Y=ENDDATE D DT^DIO2 W ?72,"Page "_PAGE,!,"Run Date: " S Y=DT D DT^DIO2 S PAGE=PAGE+1
W !!,"Rx #",?11,"Drug",?54,"QTY",?59,"Un.Cost",?70,"Total Cost"
W ! F I=1:1:80 W "-"
Q
FT W ! F I=1:1:80 W "-"
S TCOST="Total Cost = "_$FN(TCOST,",",2)
W !,"No. of Fills = "_CNT,?50,$J(TCOST,30)
W ! F I=1:1:80 W "-"
W !,"(* indicates a refill, % indicates a partial) "
Q
DTC N DD,MM S DD=31,MM=+$E(Y,4,5) I MM'=12 S MM=MM+1,MM=$S(MM<10:"0",1:"")_MM,X2=Y,X1=$E(Y,1,3)_MM_"00" D ^%DTC S DD=X
S ENDDATE=Y+DD
Q
PSOCST10 ;BHAM ISC/SAB - high cost report ; 12/11/96 13:47
+1 ;;7.0;OUTPATIENT PHARMACY;**31,56**;DEC 1997
+2 ;this routine list rxs that cost over a specified $ amount for a specified date range
+3 ;External Ref. ^PSDRUG( is supp. by DBIA# 221
BEG WRITE !
SET %DT(0)=-DT
SET %DT("A")="Beginning Date: "
SET %DT="APE"
DO ^%DT
IF Y<0!($DATA(DTOUT))
GOTO EXIT
SET (%DT(0),BEGDATE)=Y
+1 WRITE !
SET %DT("A")="Ending Date: "
DO ^%DT
IF Y<0!($DATA(DTOUT))
GOTO EXIT
SET ENDDATE=Y
IF +$EXTRACT(Y,6,7)=0
DO DTC
MAX KILL DIR
SET DIR("A")="Dollar Limit "
SET DIR("B")=30
SET DIR(0)="N^0:9999:2"
SET DIR("?")="Enter a dollar amount between 0-9999 with no more than two decimals or ^ quit"
+1 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO EXIT
SET MAX=Y
DEV KILL %ZIS,IOP,POP,ZTSK
SET PSOION=ION
SET %ZIS="QM"
DO ^%ZIS
KILL %ZIS
IF POP
SET IOP=PSOION
DO ^%ZIS
KILL IOP,PSOION
WRITE !,"Please try later!"
GOTO EXIT
+1 KILL PSOION
IF $DATA(IO("Q"))
Begin DoDot:1
+2 SET ZTDESC="Outpatient High Cost Report"
SET ZTRTN="START^PSOCST10"
FOR G="BEGDATE","ENDDATE","MAX"
IF $DATA(@G)
SET ZTSAVE(G)=""
+3 KILL IO("Q")
DO ^%ZTLOAD
IF $DATA(ZTSK)
WRITE !,"Report is Queued to print !!"
KILL ZTSK
End DoDot:1
GOTO EXIT
START USE IO
SET PAGE=1
SET (CNT,TCOST)=0
DO HD
+1 FOR NDT=BEGDATE:1:ENDDATE
FOR TY="AL","AM"
SET PSDT=NDT
DO ST1
IF $DATA(DIRUT)
QUIT
+2 IF $DATA(DIRUT)
QUIT
IF ($Y+4)>IOSL
DO HD
+3 IF '$DATA(DIRUT)
DO FT
EXIT WRITE !
DO ^%ZISC
KILL XTYPE,DIR,DTOUT,DUOUT,DIROUT,DIRUT,^TMP($JOB),NDT,TY,BEGDATE,CNT,COST,TCOST,DR0,DRCST,ENDDATE,MAX,PAGE,PGM,POP,PSDT,PSFILL,PSRXN,QTY,RX0,RX1,VAR,X,Y,%DT
+1 IF $DATA(ZTQUEUED)
SET ZTREQ="@"
QUIT
ST1 FOR
SET PSDT=$ORDER(^PSRX(TY,PSDT))
IF 'PSDT!(PSDT>(NDT_".999999"))
QUIT
DO ST2
IF $DATA(DIRUT)
QUIT
+1 QUIT
ST2 SET PSRXN=0
FOR
SET PSRXN=$ORDER(^PSRX(TY,PSDT,PSRXN))
IF 'PSRXN
QUIT
DO ST3
IF $DATA(DIRUT)
QUIT
+1 QUIT
ST3 SET PSFILL=""
+1 FOR
SET PSFILL=$ORDER(^PSRX(TY,PSDT,PSRXN,PSFILL))
IF PSFILL=""
QUIT
DO CHK
IF $DATA(DIRUT)
QUIT
+2 QUIT
CHK IF '$DATA(^PSRX(PSRXN,0))!(+$PIECE(^PSRX(PSRXN,"STA"),"^")=13)
QUIT
SET RX0=^(0)
IF '$DATA(^PSDRUG(+$PIECE(RX0,"^",6),0))
QUIT
SET DR0=^(0)
+1 IF TY="AL"
IF PSFILL
SET RX1=$GET(^PSRX(PSRXN,1,PSFILL,0))
IF PSFILL&($GET(RX1)="")
QUIT
+2 IF TY="AM"
IF '$PIECE($GET(^PSRX(PSRXN,"P",PSFILL,0)),"^",19)
QUIT
SET RX1=^(0)
+3 SET DRCST=$SELECT('PSFILL&(+$PIECE(RX0,"^",17)):$PIECE(RX0,"^",17),PSFILL&(+$PIECE($GET(RX1),"^",11)):$PIECE($GET(RX1),"^",11),1:0)
+4 SET QTY=$SELECT('PSFILL:+$PIECE(RX0,"^",7),1:+$PIECE(RX1,"^",4))
+5 IF 'DRCST
SET DRCST=$SELECT($PIECE($GET(^PSDRUG(+$PIECE(RX0,"^",6),660)),"^",6):+$PIECE(^(660),"^",6),1:0)
+6 SET COST=QTY*DRCST
IF COST<MAX
QUIT
+7 IF ($Y+4)>IOSL
DO HD
IF $DATA(DIRUT)
QUIT
+8 WRITE !,$SELECT(PSFILL&(TY="AL"):"*",TY="AM":"%",1:" ")_$PIECE(RX0,"^"),?11,$EXTRACT($PIECE(DR0,"^"),"^",40),?51,$JUSTIFY(QTY,6),?60,$JUSTIFY(DRCST,6,3),?68,$JUSTIFY(COST,12,2)
SET CNT=CNT+1
SET TCOST=TCOST+COST
+9 QUIT
HD IF PAGE>1
IF $EXTRACT(IOST)="C"
SET DIR(0)="E"
SET DIR("A")=" Press Return to Continue or ^ to Exit"
DO ^DIR
KILL DIR
+1 IF $DATA(DIRUT)
QUIT
WRITE @IOF,!,"Fills That Cost at Least $"_MAX_" for the Period: "
SET Y=BEGDATE
DO DT^DIO2
WRITE " to "
SET Y=ENDDATE
DO DT^DIO2
WRITE ?72,"Page "_PAGE,!,"Run Date: "
SET Y=DT
DO DT^DIO2
SET PAGE=PAGE+1
+2 WRITE !!,"Rx #",?11,"Drug",?54,"QTY",?59,"Un.Cost",?70,"Total Cost"
+3 WRITE !
FOR I=1:1:80
WRITE "-"
+4 QUIT
FT WRITE !
FOR I=1:1:80
WRITE "-"
+1 SET TCOST="Total Cost = "_$FNUMBER(TCOST,",",2)
+2 WRITE !,"No. of Fills = "_CNT,?50,$JUSTIFY(TCOST,30)
+3 WRITE !
FOR I=1:1:80
WRITE "-"
+4 WRITE !,"(* indicates a refill, % indicates a partial) "
+5 QUIT
DTC NEW DD,MM
SET DD=31
SET MM=+$EXTRACT(Y,4,5)
IF MM'=12
SET MM=MM+1
SET MM=$SELECT(MM<10:"0",1:"")_MM
SET X2=Y
SET X1=$EXTRACT(Y,1,3)_MM_"00"
DO ^%DTC
SET DD=X
+1 SET ENDDATE=Y+DD
+2 QUIT