PSDBAN ;BIR/JPW,LTL-Nurse BAL Report ; 8 Aug 94
;;3.0; CONTROLLED SUBSTANCES ;**63**;13 Feb 97;Build 1
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 Pharmacy Coordinator for access to",!,?12,"print this report.",! K OK Q
;G:$G(NAOU)&($G(NAOUN)]"") ALL
ASKN ;ask naou
K DA,DIC
S DIC=58.8,DIC(0)="QEA",DIC("A")="Select NAOU: ",DIC("B")=$G(NAOUN)
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")="YES"
W ! K DA,DIR,DIRUT
S DIR(0)="S^A:All Drugs;S:Single Drug;C:Contingency Report;G:All drugs (including green sheets)"
S DIR("A")="Please select type of report",DIR("B")="All Drugs"
S DIR("?",1)="Answer 'A' to list all balances for this NAOU,",DIR("?")="answer 'S' to show the balance for a specific drug or '^' to quit."
D ^DIR K DIR G:$D(DIRUT) END S ALL=Y
G:ALL="A"!(ALL="G") DEV G:ALL="C" DEV^PSDBAN1
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 W !!,"Balance: ",$P($G(^PSD(58.8,NAOU,1,+Y,0)),U,4)," ",$S($P($G(^PSD(58.8,NAOU,1,+Y,0)),U,8)]"":$P($G(^(0)),U,8),1:$P($G(^PSDRUG(+Y,660)),U,8)),!! Q
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^PSDBAN",ZTDESC="Balance of NAOU drugs" D SAVE,^%ZTLOAD,HOME^%ZIS K ZTSK G END
;U IO
START ;loops thru DRUGS
U 0
W !!,"Give me a second or two to alphabetize.",!
U IO
N PSDRUG,PSDRUGN S PSDRUG=0,PSDRUGN="" K ^TMP("PSDNST",$J)
F S PSDRUG=$O(^PSD(58.8,NAOU,1,PSDRUG)) Q:'PSDRUG D:$P($G(^PSD(58.8,NAOU,1,PSDRUG,0)),U,4)
.S ^TMP("PSDNST",$J,$P($G(^PSDRUG(+PSDRUG,0)),U))=$P($G(^PSD(58.8,NAOU,1,PSDRUG,0)),U,4)_" "_$S($P($G(^(0)),U,8)]"":$P($G(^(0)),U,8),1:$P($G(^PSDRUG(PSDRUG,660)),U,8))
PRINT ;prints the report
S (PG,PSDOUT)=0,RPDT=$$HTE^XLFDT($H)
K LN S $P(LN,"-",80)="" D HDR I '$D(^TMP("PSDNST",$J)) W !!,?10,"**** NO BALANCES TO REPORT ****" G END
S PSDR="" F S PSDR=$O(^TMP("PSDNST",$J,PSDR)) Q:PSDR=""!(PSDOUT) W !,?2,"=> ",PSDR,?62,$G(^TMP("PSDNST",$J,PSDR)),! Q:PSDOUT
G:PSDOUT END
;W:$O(^TMP("PSDNSU",$J,0))]"" !!,"The following drugs have Green Sheets:",!!
;F S PSDR=$O(^TMP("PSDNSU",$J,PSDR)) Q:PSDR=""!(PSDOUT) W ?2,"=> ",PSDR,?62,$G(^TMP("PSDNSU",$J,PSDR)),! Q:PSDOUT
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 D:$G(ALL)="G"&($D(ZTQUEUED)) START^PSDNSCG K %,%H,%I,%ZIS,ALL,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,LN,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,^TMP("PSDNST",$J),^TMP("PSDNSU",$J)
D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
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,"Controlled Substance Balances",?70,"Page: ",PG,!,?35,NAOUN,!,?25,RPDT,!
W !,?2,"=> DRUG",?62,"QUANTITY",!
W !,LN,!
Q
SAVE S (ZTSAVE("ALL"),ZTSAVE("NAOU"),ZTSAVE("NAOUN"))="" S:$D(PSDR) ZTSAVE("PSDR")=""
Q
PSDBAN ;BIR/JPW,LTL-Nurse BAL Report ; 8 Aug 94
+1 ;;3.0; CONTROLLED SUBSTANCES ;**63**;13 Feb 97;Build 1
+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 ;I 'OK W $C(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to",!,?12,"print this report.",! K OK Q
+5 ;G:$G(NAOU)&($G(NAOUN)]"") ALL
ASKN ;ask naou
+1 KILL DA,DIC
+2 SET DIC=58.8
SET DIC(0)="QEA"
SET DIC("A")="Select NAOU: "
SET DIC("B")=$GET(NAOUN)
+3 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
+4 SET NAOU=+Y
SET NAOUN=$PIECE(Y,"^",2)
ALL ;asks for all orders
+1 ;W ! K DA,DIR,DIRUT S DIR(0)="Y",DIR("A")="Do you want to print this report for all drugs",DIR("B")="YES"
+2 WRITE !
KILL DA,DIR,DIRUT
+3 SET DIR(0)="S^A:All Drugs;S:Single Drug;C:Contingency Report;G:All drugs (including green sheets)"
+4 SET DIR("A")="Please select type of report"
SET DIR("B")="All Drugs"
+5 SET DIR("?",1)="Answer 'A' to list all balances for this NAOU,"
SET DIR("?")="answer 'S' to show the balance for a specific drug or '^' to quit."
+6 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO END
SET ALL=Y
+7 IF ALL="A"!(ALL="G")
GOTO DEV
IF ALL="C"
GOTO DEV^PSDBAN1
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
WRITE !!,"Balance: ",$PIECE($GET(^PSD(58.8,NAOU,1,+Y,0)),U,4)," ",$SELECT($PIECE($GET(^PSD(58.8,NAOU,1,+Y,0)),U,8)]"":$PIECE($GET(^(0)),U,8),1:$PIECE($GET(^PSDRUG(+Y,660)),U,8)),!!
QUIT
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^PSDBAN"
SET ZTDESC="Balance of NAOU drugs"
DO SAVE
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END
+4 ;U IO
START ;loops thru DRUGS
+1 USE 0
+2 WRITE !!,"Give me a second or two to alphabetize.",!
+3 USE IO
+4 NEW PSDRUG,PSDRUGN
SET PSDRUG=0
SET PSDRUGN=""
KILL ^TMP("PSDNST",$JOB)
+5 FOR
SET PSDRUG=$ORDER(^PSD(58.8,NAOU,1,PSDRUG))
IF 'PSDRUG
QUIT
IF $PIECE($GET(^PSD(58.8,NAOU,1,PSDRUG,0)),U,4)
Begin DoDot:1
+6 SET ^TMP("PSDNST",$JOB,$PIECE($GET(^PSDRUG(+PSDRUG,0)),U))=$PIECE($GET(^PSD(58.8,NAOU,1,PSDRUG,0)),U,4)_" "_$SELECT($PIECE($GET(^(0)),U,8)]"":$PIECE($GET(^(0)),U,8),1:$PIECE($GET(^PSDRUG(PSDRUG,660)),U,8))
End DoDot:1
PRINT ;prints the report
+1 SET (PG,PSDOUT)=0
SET RPDT=$$HTE^XLFDT($HOROLOG)
+2 KILL LN
SET $PIECE(LN,"-",80)=""
DO HDR
IF '$DATA(^TMP("PSDNST",$JOB))
WRITE !!,?10,"**** NO BALANCES TO REPORT ****"
GOTO END
+3 SET PSDR=""
FOR
SET PSDR=$ORDER(^TMP("PSDNST",$JOB,PSDR))
IF PSDR=""!(PSDOUT)
QUIT
WRITE !,?2,"=> ",PSDR,?62,$GET(^TMP("PSDNST",$JOB,PSDR)),!
IF PSDOUT
QUIT
+4 IF PSDOUT
GOTO END
+5 ;W:$O(^TMP("PSDNSU",$J,0))]"" !!,"The following drugs have Green Sheets:",!!
+6 ;F S PSDR=$O(^TMP("PSDNSU",$J,PSDR)) Q:PSDR=""!(PSDOUT) W ?2,"=> ",PSDR,?62,$G(^TMP("PSDNSU",$J,PSDR)),! Q:PSDOUT
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 IF $GET(ALL)="G"&($DATA(ZTQUEUED))
DO START^PSDNSCG
KILL %,%H,%I,%ZIS,ALL,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DUOUT,LN,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,^TMP("PSDNST",$JOB),^TMP("PSDNSU",$JOB)
+2 DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+3 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,"Controlled Substance Balances",?70,"Page: ",PG,!,?35,NAOUN,!,?25,RPDT,!
+3 WRITE !,?2,"=> DRUG",?62,"QUANTITY",!
+4 WRITE !,LN,!
+5 QUIT
SAVE SET (ZTSAVE("ALL"),ZTSAVE("NAOU"),ZTSAVE("NAOUN"))=""
IF $DATA(PSDR)
SET ZTSAVE("PSDR")=""
+1 QUIT