PSDORST ;BIR/JPW-Pharmacy Vault Order Stats Report ; 29 Aug 94
;;3.0; CONTROLLED SUBSTANCES ;;13 Feb 97
I '$D(PSDSITE) D ^PSDSET Q:'$D(PSDSITE)
S OK=$S($D(^XUSEC("PSJ RPHARM",DUZ)):1,$D(^XUSEC("PSJ PHARM TECH",DUZ)):1,1:0)
I 'OK W $C(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to",!,?12,"print this status report.",!!,"PSJ RPHARM or PSJ PHARM TECH security key required.",! K OK Q
ASKD ;ask dispensing location
S PSDS=$P(PSDSITE,U,3),PSDSN=$P(PSDSITE,U,4)
G:$P(PSDSITE,U,5) DEV
K DIC,DA S DIC=58.8,DIC(0)="QEAZ",DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S($P(^(0),""^"",2)[""M"":1,$P(^(0),""^"",2)[""S"":1,1:0)"
S DIC("A")="Select Primary Dispensing Site: ",DIC("B")=$P(PSDSITE,U,4)
D ^DIC K DIC G:Y<0 END
S PSDS=+Y,PSDSN=$P(Y,"^",2),$P(PSDSITE,U,3)=+Y,$P(PSDSITE,U,4)=PSDSN
DEV ;ask device and queue info
W !!,"You may queue this report to print at a later time.",!!
S Y=$P($G(^PSD(58.8,+PSDS,2)),"^",9),C=$P(^DD(58.8,24,0),"^",2) D Y^DIQ S PSDEV=Y
K %ZIS,IOP,IO("Q"),POP S %ZIS="QM",%ZIS("B")=PSDEV D ^%ZIS I POP W !,"NO DEVICE SELECTED OR REPORT PRINTED!" G END
I $D(IO("Q")) K IO("Q"),ZTIO,ZTSAVE,ZTDTH,ZTSK S ZTRTN="START^PSDORST",ZTDESC="Pharm Status of Pending Narcotic Orders",(ZTSAVE("PSDS"),ZTSAVE("PSDSN"))="" D ^%ZTLOAD,HOME^%ZIS K ZTSK G END
U IO
START ;loops thru pending orders and orders cancelled in the past 3 days
K ^TMP("PSDTST",$J)
D NOW^%DTC S PSDT=X
F STAT=0:0 S STAT=$O(^PSD(58.85,"AC",STAT)) Q:'STAT!(STAT>2) F NAOU=0:0 S NAOU=$O(^PSD(58.85,"AC",STAT,NAOU)) Q:'NAOU D LOOP
PRINT ;prints the report
S (PG,PSDOUT)=0,Y=PSDT X ^DD("DD") S RPDT=Y
K LN S $P(LN,"-",80)="" I '$D(^TMP("PSDTST",$J)) D HDR W !!,?10,"**** NO PENDING ORDERS TO REPORT ****" G END
D HDR
S DRUG="" F S DRUG=$O(^TMP("PSDTST",$J,DRUG)) Q:DRUG=""!(PSDOUT) W !,?2,"=> ",DRUG,!! F ORD=0:0 S ORD=$O(^TMP("PSDTST",$J,DRUG,ORD)) Q:'ORD!(PSDOUT) D Q:PSDOUT
.S NODE=^TMP("PSDTST",$J,DRUG,ORD) I $Y+5>IOSL D HDR Q:PSDOUT W !,?2,"=> ",DRUG,!!
.W $P(NODE,"^",4),?11,$P(NODE,"^",3),?33,$P(NODE,"^",2),?40,$E($P(NODE,"^",5),1,12),?58,$P($P(NODE,"^"),"-"),!,?55,$P($P(NODE,"^"),"-",2),!!
DONE I $E(IOST)'="C" W @IOF
I $E(IOST,1,2)="C-",'PSDOUT W ! K DIR,DIRUT S DIR(0)="EA",DIR("A")="END OF REPORT! Press <RET> to return to the menu" D ^DIR K DIR
END K %,%H,%I,%ZIS,C,DA,DIC,DIR,DIROUT,DIRUT,DRUG,DRUGN,DTOUT,DUOUT,LN,NAOU,NAOUN,NODE,OK,ORD
K PG,PSDA,PSDEV,PSDOUT,PSDPN,PSDS,PSDSN,PSDT,QTY,REQ,RPDT,STAT,STATN,X,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
K ^TMP("PSDTST",$J) D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
Q
LOOP ;starts drug loop for all orders
F DRUG=0:0 S DRUG=$O(^PSD(58.85,"AC",STAT,NAOU,DRUG)) Q:'DRUG F ORD=0:0 S ORD=$O(^PSD(58.85,"AC",STAT,NAOU,DRUG,ORD)) Q:'ORD S PSDA=$O(^PSD(58.85,"AC",STAT,NAOU,DRUG,ORD,0)) I PSDA D SET
Q
SET ;sets data for printing
Q:'$D(^PSD(58.85,PSDA,0)) S NODE=^(0) Q:+$P(NODE,"^",2)'=+PSDS
S DRUGN=$S($P($G(^PSDRUG(DRUG,0)),"^")]"":$P(^(0),"^"),1:"DRUG NAME MISSING")
S NAOUN=$S($P($G(^PSD(58.8,NAOU,0)),"^")]"":$P(^(0),"^"),1:"NAOU NAME MISSING")
S STATN=$P($G(^PSD(58.82,STAT,0)),"^"),STATN=$E(STATN,1,30),QTY=$P(NODE,"^",6),PSDPN=$P(NODE,"^",15),REQ=$P(NODE,"^",18) I REQ S Y=REQ X ^DD("DD") S REQ=Y
S ^TMP("PSDTST",$J,DRUGN,PSDA)=STATN_"^"_QTY_"^"_REQ_"^"_PSDPN_"^"_NAOUN
Q
HDR ;header for log
I $E(IOST,1,2)="C-",PG W ! K DA,DIR S DIR(0)="E" D ^DIR K DIR I 'Y S PSDOUT=1 Q
S PG=PG+1 W:$Y @IOF W !,?20,"Pharmacy Status of Pending Narcotic Orders",?70,"Page: ",PG,!,?35,PSDSN,!,?35,RPDT,!
W !,?2,"=> DRUG",!,?13,"DATE",!,"DISP #",?12,"ORDERED",?32,"QTY",?40,"NAOU",?55,"ORDER STATUS"
W !,LN,!
Q
PSDORST ;BIR/JPW-Pharmacy Vault Order Stats Report ; 29 Aug 94
+1 ;;3.0; CONTROLLED SUBSTANCES ;;13 Feb 97
+2 IF '$DATA(PSDSITE)
DO ^PSDSET
IF '$DATA(PSDSITE)
QUIT
+3 SET OK=$SELECT($DATA(^XUSEC("PSJ RPHARM",DUZ)):1,$DATA(^XUSEC("PSJ PHARM TECH",DUZ)):1,1:0)
+4 IF 'OK
WRITE $CHAR(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to",!,?12,"print this status report.",!!,"PSJ RPHARM or PSJ PHARM TECH security key required.",!
KILL OK
QUIT
ASKD ;ask dispensing location
+1 SET PSDS=$PIECE(PSDSITE,U,3)
SET PSDSN=$PIECE(PSDSITE,U,4)
+2 IF $PIECE(PSDSITE,U,5)
GOTO DEV
+3 KILL DIC,DA
SET DIC=58.8
SET DIC(0)="QEAZ"
SET DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S($P(^(0),""^"",2)[""M"":1,$P(^(0),""^"",2)[""S"":1,1:0)"
+4 SET DIC("A")="Select Primary Dispensing Site: "
SET DIC("B")=$PIECE(PSDSITE,U,4)
+5 DO ^DIC
KILL DIC
IF Y<0
GOTO END
+6 SET PSDS=+Y
SET PSDSN=$PIECE(Y,"^",2)
SET $PIECE(PSDSITE,U,3)=+Y
SET $PIECE(PSDSITE,U,4)=PSDSN
DEV ;ask device and queue info
+1 WRITE !!,"You may queue this report to print at a later time.",!!
+2 SET Y=$PIECE($GET(^PSD(58.8,+PSDS,2)),"^",9)
SET C=$PIECE(^DD(58.8,24,0),"^",2)
DO Y^DIQ
SET PSDEV=Y
+3 KILL %ZIS,IOP,IO("Q"),POP
SET %ZIS="QM"
SET %ZIS("B")=PSDEV
DO ^%ZIS
IF POP
WRITE !,"NO DEVICE SELECTED OR REPORT PRINTED!"
GOTO END
+4 IF $DATA(IO("Q"))
KILL IO("Q"),ZTIO,ZTSAVE,ZTDTH,ZTSK
SET ZTRTN="START^PSDORST"
SET ZTDESC="Pharm Status of Pending Narcotic Orders"
SET (ZTSAVE("PSDS"),ZTSAVE("PSDSN"))=""
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END
+5 USE IO
START ;loops thru pending orders and orders cancelled in the past 3 days
+1 KILL ^TMP("PSDTST",$JOB)
+2 DO NOW^%DTC
SET PSDT=X
+3 FOR STAT=0:0
SET STAT=$ORDER(^PSD(58.85,"AC",STAT))
IF 'STAT!(STAT>2)
QUIT
FOR NAOU=0:0
SET NAOU=$ORDER(^PSD(58.85,"AC",STAT,NAOU))
IF 'NAOU
QUIT
DO LOOP
PRINT ;prints the report
+1 SET (PG,PSDOUT)=0
SET Y=PSDT
XECUTE ^DD("DD")
SET RPDT=Y
+2 KILL LN
SET $PIECE(LN,"-",80)=""
IF '$DATA(^TMP("PSDTST",$JOB))
DO HDR
WRITE !!,?10,"**** NO PENDING ORDERS TO REPORT ****"
GOTO END
+3 DO HDR
+4 SET DRUG=""
FOR
SET DRUG=$ORDER(^TMP("PSDTST",$JOB,DRUG))
IF DRUG=""!(PSDOUT)
QUIT
WRITE !,?2,"=> ",DRUG,!!
FOR ORD=0:0
SET ORD=$ORDER(^TMP("PSDTST",$JOB,DRUG,ORD))
IF 'ORD!(PSDOUT)
QUIT
Begin DoDot:1
+5 SET NODE=^TMP("PSDTST",$JOB,DRUG,ORD)
IF $Y+5>IOSL
DO HDR
IF PSDOUT
QUIT
WRITE !,?2,"=> ",DRUG,!!
+6 WRITE $PIECE(NODE,"^",4),?11,$PIECE(NODE,"^",3),?33,$PIECE(NODE,"^",2),?40,$EXTRACT($PIECE(NODE,"^",5),1,12),?58,$PIECE($PIECE(NODE,"^"),"-"),!,?55,$PIECE($PIECE(NODE,"^"),"-",2),!!
End DoDot:1
IF PSDOUT
QUIT
DONE IF $EXTRACT(IOST)'="C"
WRITE @IOF
+1 IF $EXTRACT(IOST,1,2)="C-"
IF 'PSDOUT
WRITE !
KILL DIR,DIRUT
SET DIR(0)="EA"
SET DIR("A")="END OF REPORT! Press <RET> to return to the menu"
DO ^DIR
KILL DIR
END KILL %,%H,%I,%ZIS,C,DA,DIC,DIR,DIROUT,DIRUT,DRUG,DRUGN,DTOUT,DUOUT,LN,NAOU,NAOUN,NODE,OK,ORD
+1 KILL PG,PSDA,PSDEV,PSDOUT,PSDPN,PSDS,PSDSN,PSDT,QTY,REQ,RPDT,STAT,STATN,X,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
+2 KILL ^TMP("PSDTST",$JOB)
DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+3 QUIT
LOOP ;starts drug loop for all orders
+1 FOR DRUG=0:0
SET DRUG=$ORDER(^PSD(58.85,"AC",STAT,NAOU,DRUG))
IF 'DRUG
QUIT
FOR ORD=0:0
SET ORD=$ORDER(^PSD(58.85,"AC",STAT,NAOU,DRUG,ORD))
IF 'ORD
QUIT
SET PSDA=$ORDER(^PSD(58.85,"AC",STAT,NAOU,DRUG,ORD,0))
IF PSDA
DO SET
+2 QUIT
SET ;sets data for printing
+1 IF '$DATA(^PSD(58.85,PSDA,0))
QUIT
SET NODE=^(0)
IF +$PIECE(NODE,"^",2)'=+PSDS
QUIT
+2 SET DRUGN=$SELECT($PIECE($GET(^PSDRUG(DRUG,0)),"^")]"":$PIECE(^(0),"^"),1:"DRUG NAME MISSING")
+3 SET NAOUN=$SELECT($PIECE($GET(^PSD(58.8,NAOU,0)),"^")]"":$PIECE(^(0),"^"),1:"NAOU NAME MISSING")
+4 SET STATN=$PIECE($GET(^PSD(58.82,STAT,0)),"^")
SET STATN=$EXTRACT(STATN,1,30)
SET QTY=$PIECE(NODE,"^",6)
SET PSDPN=$PIECE(NODE,"^",15)
SET REQ=$PIECE(NODE,"^",18)
IF REQ
SET Y=REQ
XECUTE ^DD("DD")
SET REQ=Y
+5 SET ^TMP("PSDTST",$JOB,DRUGN,PSDA)=STATN_"^"_QTY_"^"_REQ_"^"_PSDPN_"^"_NAOUN
+6 QUIT
HDR ;header for log
+1 IF $EXTRACT(IOST,1,2)="C-"
IF PG
WRITE !
KILL DA,DIR
SET DIR(0)="E"
DO ^DIR
KILL DIR
IF 'Y
SET PSDOUT=1
QUIT
+2 SET PG=PG+1
IF $Y
WRITE @IOF
WRITE !,?20,"Pharmacy Status of Pending Narcotic Orders",?70,"Page: ",PG,!,?35,PSDSN,!,?35,RPDT,!
+3 WRITE !,?2,"=> DRUG",!,?13,"DATE",!,"DISP #",?12,"ORDERED",?32,"QTY",?40,"NAOU",?55,"ORDER STATUS"
+4 WRITE !,LN,!
+5 QUIT