PSDORSN ;BIR/JPW-Nurse Order Stats Report ; 8 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,$D(^XUSEC("PSJ RNURSE",DUZ)):1,$D(^XUSEC("PSD NURSE",DUZ)):1,1:0)
I 'OK W $C(7),!!,?9,"** Please contact your Coordinator for access to",!,?12,"print this report.",!!,"PSJ RPHARM, PSJ PHARM TECH, PSJ RNURSE, or PSD NURSE security key required.",! K OK Q
ASKN ;ask naou
K DA,DIC S DIC=58.8,DIC(0)="QEA",DIC("A")="Select NAOU: "
S DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>DT:1,1:0),$P(^(0),""^"",2)=""N"",'$P(^(0),""^"",7)" D ^DIC K DIC G:Y<0 END
S NAOU=+Y,NAOUN=$P(Y,"^",2)
ALL ;asks for all orders
W ! K DA,DIR,DIRUT S DIR(0)="Y",DIR("A")="Do you want to print this report for all drugs",DIR("B")="NO"
S DIR("?",1)="Answer 'YES' to list all pending orders for this NAOU,",DIR("?")="answer 'NO' to list orders for a specific drug or '^' to quit."
D ^DIR K DIR G:$D(DIRUT) END S ALL=+Y
G:ALL DEV
DRUG ;select drugs
W ! K DA,DIC S DIC("W")="W:$P(^PSDRUG(Y,0),""^"",9) "" N/F"" I $P(^PSD(58.8,NAOU,1,Y,0),""^"",14)]"""",$P(^(0),""^"",14)'>DT W $C(7),"" *** INACTIVE ***"""
S DA(1)=+NAOU,DIC(0)="QEAM",DIC="^PSD(58.8,"_NAOU_",1," D ^DIC K DIC G:Y<0 END S PSDR=+Y
DEV ;ask device and queue info
W !!,"You may queue this report to print at a later time.",!!
K %ZIS,IOP,IO("Q"),POP S %ZIS="QM",%ZIS("B")="HOME" 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^PSDORSN",ZTDESC="Status of Pending Narcotic Orders" D SAVE,^%ZTLOAD,HOME^%ZIS K ZTSK G END
U IO
START ;loops thru pending orders and orders cancelled in the past 3 days
K ^TMP("PSDNST",$J)
D NOW^%DTC S (PSDT,X1)=X,X2=-3 D C^%DTC S PSDST=X
I ALL F STAT=.5:0 S STAT=$O(^PSD(58.8,"AC",STAT)) Q:'STAT!(STAT>3) D LOOP
I ALL S STAT=9 D:$D(^PSD(58.8,"AC",STAT)) LOOP G PRINT
F STAT=.5:0 S STAT=$O(^PSD(58.8,"AC",STAT)) Q:'STAT!(STAT>3) D ORD
S STAT=9 D:$D(^PSD(58.8,"AC",STAT,NAOU,PSDR)) ORD
PRINT ;prints the report
S (PG,PSDOUT)=0,Y=PSDT X ^DD("DD") S RPDT=Y
K LN S $P(LN,"-",80)="" D HDR I '$D(^TMP("PSDNST",$J)) W !!,?10,"**** NO PENDING ORDERS TO REPORT ****" G END
S PSDR="" F S PSDR=$O(^TMP("PSDNST",$J,PSDR)) Q:PSDR=""!(PSDOUT) W !!,?2,"=> ",PSDR,! D Q:PSDOUT
.F ORD=0:0 S ORD=$O(^TMP("PSDNST",$J,PSDR,ORD)) Q:'ORD!(PSDOUT) D:$Y+4>IOSL HDR Q:PSDOUT D
..S NODE=^TMP("PSDNST",$J,PSDR,ORD) W !,$P(NODE,"^",4),?11,$P(NODE,"^",3),?33,$J($P(NODE,"^",2),6),?42,$P(NODE,"^")
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,ALL,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,LN,NAOU,NAOUN,NODE,OK,ORD
K PG,POP,PSDOUT,PSDPN,PSDR,PSDRN,PSDST,PSDT,QTY,REQ,RPDT,STAT,STATN,X,X1,X2,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
K ^TMP("PSDNST",$J) D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
Q
LOOP ;starts drug loop for all orders
F PSDR=0:0 S PSDR=$O(^PSD(58.8,"AC",STAT,NAOU,PSDR)) Q:'PSDR D ORD
Q
ORD ;order loop
F ORD=0:0 S ORD=$O(^PSD(58.8,"AC",STAT,NAOU,PSDR,ORD)) Q:'ORD D SET
Q
SET ;sets data for printing
Q:'$D(^PSD(58.8,NAOU,1,PSDR,3,ORD,0)) S NODE=^(0),PSDRN=$S($P($G(^PSDRUG(PSDR,0)),"^")]"":$P(^(0),"^"),1:"DRUG NAME MISSING")
I STAT=9,$P(NODE,"^",2)<PSDST Q
S STATN=$P($G(^PSD(58.82,STAT,0)),"^"),STATN=$E(STATN,1,30),QTY=$P(NODE,"^",6),PSDPN=$P(NODE,"^",16),REQ=$P(NODE,"^",2) I REQ S Y=REQ X ^DD("DD") S REQ=Y
S ^TMP("PSDNST",$J,PSDRN,ORD)=STATN_"^"_QTY_"^"_REQ_"^"_PSDPN
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 !,?25,"Status of Pending Narcotic Orders",?70,"Page: ",PG,!,?35,NAOUN,!,?35,RPDT,!
W !,?2,"=> DRUG",!,?13,"DATE",?33,"QUANTITY",!,"DISP #",?12,"ORDERED",?33,"ORDERED",?48,"ORDER STATUS"
W !,LN,!
Q
SAVE S (ZTSAVE("ALL"),ZTSAVE("NAOU"),ZTSAVE("NAOUN"))="" S:$D(PSDR) ZTSAVE("PSDR")=""
Q
PSDORSN ;BIR/JPW-Nurse Order Stats Report ; 8 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,$DATA(^XUSEC("PSJ RNURSE",DUZ)):1,$DATA(^XUSEC("PSD NURSE",DUZ)):1,1:0)
+4 IF 'OK
WRITE $CHAR(7),!!,?9,"** Please contact your Coordinator for access to",!,?12,"print this report.",!!,"PSJ RPHARM, PSJ PHARM TECH, PSJ RNURSE, or PSD NURSE security key required.",!
KILL OK
QUIT
ASKN ;ask naou
+1 KILL DA,DIC
SET DIC=58.8
SET DIC(0)="QEA"
SET DIC("A")="Select NAOU: "
+2 SET DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>DT:1,1:0),$P(^(0),""^"",2)=""N"",'$P(^(0),""^"",7)"
DO ^DIC
KILL DIC
IF Y<0
GOTO END
+3 SET NAOU=+Y
SET NAOUN=$PIECE(Y,"^",2)
ALL ;asks for all orders
+1 WRITE !
KILL DA,DIR,DIRUT
SET DIR(0)="Y"
SET DIR("A")="Do you want to print this report for all drugs"
SET DIR("B")="NO"
+2 SET DIR("?",1)="Answer 'YES' to list all pending orders for this NAOU,"
SET DIR("?")="answer 'NO' to list orders for a specific drug or '^' to quit."
+3 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO END
SET ALL=+Y
+4 IF ALL
GOTO DEV
DRUG ;select drugs
+1 WRITE !
KILL DA,DIC
SET DIC("W")="W:$P(^PSDRUG(Y,0),""^"",9) "" N/F"" I $P(^PSD(58.8,NAOU,1,Y,0),""^"",14)]"""",$P(^(0),""^"",14)'>DT W $C(7),"" *** INACTIVE ***"""
+2 SET DA(1)=+NAOU
SET DIC(0)="QEAM"
SET DIC="^PSD(58.8,"_NAOU_",1,"
DO ^DIC
KILL DIC
IF Y<0
GOTO END
SET PSDR=+Y
DEV ;ask device and queue info
+1 WRITE !!,"You may queue this report to print at a later time.",!!
+2 KILL %ZIS,IOP,IO("Q"),POP
SET %ZIS="QM"
SET %ZIS("B")="HOME"
DO ^%ZIS
IF POP
WRITE !,"NO DEVICE SELECTED OR REPORT PRINTED!"
GOTO END
+3 IF $DATA(IO("Q"))
KILL IO("Q"),ZTIO,ZTSAVE,ZTDTH,ZTSK
SET ZTRTN="START^PSDORSN"
SET ZTDESC="Status of Pending Narcotic Orders"
DO SAVE
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END
+4 USE IO
START ;loops thru pending orders and orders cancelled in the past 3 days
+1 KILL ^TMP("PSDNST",$JOB)
+2 DO NOW^%DTC
SET (PSDT,X1)=X
SET X2=-3
DO C^%DTC
SET PSDST=X
+3 IF ALL
FOR STAT=.5:0
SET STAT=$ORDER(^PSD(58.8,"AC",STAT))
IF 'STAT!(STAT>3)
QUIT
DO LOOP
+4 IF ALL
SET STAT=9
IF $DATA(^PSD(58.8,"AC",STAT))
DO LOOP
GOTO PRINT
+5 FOR STAT=.5:0
SET STAT=$ORDER(^PSD(58.8,"AC",STAT))
IF 'STAT!(STAT>3)
QUIT
DO ORD
+6 SET STAT=9
IF $DATA(^PSD(58.8,"AC",STAT,NAOU,PSDR))
DO ORD
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)=""
DO HDR
IF '$DATA(^TMP("PSDNST",$JOB))
WRITE !!,?10,"**** NO PENDING ORDERS TO REPORT ****"
GOTO END
+3 SET PSDR=""
FOR
SET PSDR=$ORDER(^TMP("PSDNST",$JOB,PSDR))
IF PSDR=""!(PSDOUT)
QUIT
WRITE !!,?2,"=> ",PSDR,!
Begin DoDot:1
+4 FOR ORD=0:0
SET ORD=$ORDER(^TMP("PSDNST",$JOB,PSDR,ORD))
IF 'ORD!(PSDOUT)
QUIT
IF $Y+4>IOSL
DO HDR
IF PSDOUT
QUIT
Begin DoDot:2
+5 SET NODE=^TMP("PSDNST",$JOB,PSDR,ORD)
WRITE !,$PIECE(NODE,"^",4),?11,$PIECE(NODE,"^",3),?33,$JUSTIFY($PIECE(NODE,"^",2),6),?42,$PIECE(NODE,"^")
End DoDot: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,ALL,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,LN,NAOU,NAOUN,NODE,OK,ORD
+1 KILL PG,POP,PSDOUT,PSDPN,PSDR,PSDRN,PSDST,PSDT,QTY,REQ,RPDT,STAT,STATN,X,X1,X2,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
+2 KILL ^TMP("PSDNST",$JOB)
DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+3 QUIT
LOOP ;starts drug loop for all orders
+1 FOR PSDR=0:0
SET PSDR=$ORDER(^PSD(58.8,"AC",STAT,NAOU,PSDR))
IF 'PSDR
QUIT
DO ORD
+2 QUIT
ORD ;order loop
+1 FOR ORD=0:0
SET ORD=$ORDER(^PSD(58.8,"AC",STAT,NAOU,PSDR,ORD))
IF 'ORD
QUIT
DO SET
+2 QUIT
SET ;sets data for printing
+1 IF '$DATA(^PSD(58.8,NAOU,1,PSDR,3,ORD,0))
QUIT
SET NODE=^(0)
SET PSDRN=$SELECT($PIECE($GET(^PSDRUG(PSDR,0)),"^")]"":$PIECE(^(0),"^"),1:"DRUG NAME MISSING")
+2 IF STAT=9
IF $PIECE(NODE,"^",2)<PSDST
QUIT
+3 SET STATN=$PIECE($GET(^PSD(58.82,STAT,0)),"^")
SET STATN=$EXTRACT(STATN,1,30)
SET QTY=$PIECE(NODE,"^",6)
SET PSDPN=$PIECE(NODE,"^",16)
SET REQ=$PIECE(NODE,"^",2)
IF REQ
SET Y=REQ
XECUTE ^DD("DD")
SET REQ=Y
+4 SET ^TMP("PSDNST",$JOB,PSDRN,ORD)=STATN_"^"_QTY_"^"_REQ_"^"_PSDPN
+5 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 !,?25,"Status of Pending Narcotic Orders",?70,"Page: ",PG,!,?35,NAOUN,!,?35,RPDT,!
+3 WRITE !,?2,"=> DRUG",!,?13,"DATE",?33,"QUANTITY",!,"DISP #",?12,"ORDERED",?33,"ORDERED",?48,"ORDER STATUS"
+4 WRITE !,LN,!
+5 QUIT
SAVE SET (ZTSAVE("ALL"),ZTSAVE("NAOU"),ZTSAVE("NAOUN"))=""
IF $DATA(PSDR)
SET ZTSAVE("PSDR")=""
+1 QUIT