PSDBALI ;BIR/JPW-Display/Print Drug Inv Sheet & Balance ; 29 Aug 94
;;3.0; CONTROLLED SUBSTANCES ;;13 Feb 97
I '$D(PSDSITE) D ^PSDSET Q:'$D(PSDSITE)
ASKD ;ask disp location
S PSDS=$P(PSDSITE,U,3),PSDSN=$P(PSDSITE,U,4)
G:$P(PSDSITE,U,5) CHKD
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: "
S DIC("B")=PSDSN
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
CHKD I '$O(^PSD(58.8,PSDS,1,0)) W !!,"There are no CS stocked drugs for your dispensing vault.",!! G END
SORT ;asks sort
W ! K DA,DIR,DIRUT S DIR(0)="YO",DIR("A")="Do you wish to sort by Inventory Type",DIR("B")="NO"
S DIR("?")="Answer YES to sort drugs by Inventory Type, NO or <RET> to sort by drug."
D ^DIR K DIR G:$D(DIRUT) END S ASKN=Y
W !!,?5,"You may select a single drug, several drugs,",!,?5,"or enter ^ALL to select all drugs.",!!
DRUG ;ask drug
W ! K DA,DIC
F S DIC("W")="W:$P(^PSDRUG(Y,0),""^"",9) "" N/F"" I $P(^PSD(58.8,PSDS,1,Y,0),""^"",14)]"""",$P(^(0),""^"",14)'>DT W $C(7),"" *** INACTIVE ***""",DA(1)=+PSDS,DIC(0)="QEAM",DIC="^PSD(58.8,"_PSDS_",1," D ^DIC K DIC Q:Y<0 D
.S PSDR(+Y)=""
I '$D(PSDR)&(X'="^ALL") G END
I X="^ALL" S ALL=1
DEV ;sel device
S Y=$P($G(^PSD(58.8,+PSDS,2)),"^",9),C=$P(^DD(58.8,24,0),"^",2) D Y^DIQ S PSDEV=Y
W ! 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^PSDBALI",ZTDESC="CS PHARM Print Inv Sheet " D SAVE,^%ZTLOAD,HOME^%ZIS K ZTSK G END
U IO
START ;entry for compile
K ^TMP("PSDBALI",$J)
I $D(ALL) F PSD=0:0 S PSD=$O(^PSD(58.8,+PSDS,1,PSD)) Q:'PSD I $D(^PSD(58.8,+PSDS,1,PSD,0)) S PSDR(+PSD)=""
F PSD=0:0 S PSD=$O(PSDR(PSD)) Q:'PSD I $D(^PSD(58.8,+PSDS,1,PSD,0)) S NODE=^(0) D
.S PSDOK="" I +$P(NODE,"^",14),+$P(NODE,"^",14)'>DT Q:'+$P(NODE,"^",4) S PSDOK="*"
.S BAL=+$P(NODE,"^",4),DRUGN=$S($P($G(^PSDRUG(+PSD,0)),"^")]"":$P(^(0),"^"),1:"ZZ/"_PSD_" NAME MISSING"),SLVL=+$P(NODE,"^",3),EXP=$S(+$P(NODE,"^",12):+$P(NODE,"^",12),1:"")
.I EXP S Y=EXP X ^DD("DD") S EXP=Y
.I ASKN D LOOP Q
.S ^TMP("PSDBALI",$J,DRUGN,PSD)=BAL_"^"_PSDOK_"^"_SLVL_"^"_EXP
PRINT ;prints data
S (PG,PSDOUT)=0 D NOW^%DTC S Y=+$E(%,1,12) X ^DD("DD") S RPDT=Y
K LN S $P(LN,"-",80)="" D HDR
I '$D(^TMP("PSDBALI",$J)) W !!,?15,"**** NO STOCK BALANCE DATA AVAILABLE ****",!! G DONE
I ASKN D PRINT^PSDBALI1 G DONE
S PSDR="" F S PSDR=$O(^TMP("PSDBALI",$J,PSDR)) Q:PSDR=""!(PSDOUT) F PSD=0:0 S PSD=$O(^TMP("PSDBALI",$J,PSDR,PSD)) Q:'PSD D Q:PSDOUT
.I $Y+6>IOSL W !,?10,"Inspector's Signature: ______________________________",! D HDR Q:PSDOUT
.S NODE=^TMP("PSDBALI",$J,PSDR,PSD),BAL=+NODE,PSDOK=$P(NODE,"^",2),SLVL=$P(NODE,"^",3),EXP=$P(NODE,"^",4)
.W !,PSDOK,?2,PSDR,?50,$J(BAL,6),?66,"___________",! W:SLVL ?5,"Stock Level: ",SLVL W:EXP]"" ?30,"Exp. Date: ",EXP W ! S LNUM=$Y
PRT ;
I LNUM<IOSL-5 F JJ=LNUM:1:IOSL-5 W !
W:'PSDOUT ?10,"Inspector's Signature: ______________________________",!
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,ASKN,BAL,C,DA,DIC,DRUGN,DTOUT,DUOUT,EXP,JJ,LN,LNUM,NODE,PG,POP,PSD,PSDEV,PSDOK,PSDOUT,PSDR,PSDRN,PSDS,PSDSN,RPDT,SLVL,TYP,TYPN,X,Y
K ^TMP("PSDBALI",$J),ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
Q
SAVE S (ZTSAVE("PSDS"),ZTSAVE("PSDSN"),ZTSAVE("PSDSITE"),ZTSAVE("ASKN"))=""
S:$D(ALL) ZTSAVE("ALL")="" S:$D(PSDR) ZTSAVE("PSDR(")=""
Q
HDR ;header
I $E(IOST,1,2)="C-",PG 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 !,?12,"Inventory Sheet for ",PSDSN,?72,"Page: ",PG,!,?20,RPDT,!!
W ?5,"DRUG",?46,"CURRENT BALANCE",?68,"ON-HAND",!,LN,!!
Q
LOOP ;sets inv type
I '$O(^PSD(58.8,+PSDS,1,+PSD,2,0)) S TYPN="ZZ** NO INVENTORY TYPE DATA **" D LOOP1
F TYP=0:0 S TYP=$O(^PSD(58.8,+PSDS,1,+PSD,2,TYP)) Q:'TYP S TYPN=$S($P($G(^PSI(58.16,+TYP,0)),"^")]"":$P(^(0),"^"),1:"TYPE NAME MISSING") D LOOP1
Q
LOOP1 S ^TMP("PSDBALI",$J,TYPN,DRUGN,PSD)=BAL_"^"_PSDOK_"^"_SLVL_"^"_EXP
Q
PSDBALI ;BIR/JPW-Display/Print Drug Inv Sheet & Balance ; 29 Aug 94
+1 ;;3.0; CONTROLLED SUBSTANCES ;;13 Feb 97
+2 IF '$DATA(PSDSITE)
DO ^PSDSET
IF '$DATA(PSDSITE)
QUIT
ASKD ;ask disp location
+1 SET PSDS=$PIECE(PSDSITE,U,3)
SET PSDSN=$PIECE(PSDSITE,U,4)
+2 IF $PIECE(PSDSITE,U,5)
GOTO CHKD
+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: "
+5 SET DIC("B")=PSDSN
+6 DO ^DIC
KILL DIC
IF Y<0
GOTO END
+7 SET PSDS=+Y
SET PSDSN=$PIECE(Y,"^",2)
SET $PIECE(PSDSITE,U,3)=+Y
SET $PIECE(PSDSITE,U,4)=PSDSN
CHKD IF '$ORDER(^PSD(58.8,PSDS,1,0))
WRITE !!,"There are no CS stocked drugs for your dispensing vault.",!!
GOTO END
SORT ;asks sort
+1 WRITE !
KILL DA,DIR,DIRUT
SET DIR(0)="YO"
SET DIR("A")="Do you wish to sort by Inventory Type"
SET DIR("B")="NO"
+2 SET DIR("?")="Answer YES to sort drugs by Inventory Type, NO or <RET> to sort by drug."
+3 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO END
SET ASKN=Y
+4 WRITE !!,?5,"You may select a single drug, several drugs,",!,?5,"or enter ^ALL to select all drugs.",!!
DRUG ;ask drug
+1 WRITE !
KILL DA,DIC
+2 FOR
SET DIC("W")="W:$P(^PSDRUG(Y,0),""^"",9) "" N/F"" I $P(^PSD(58.8,PSDS,1,Y,0),""^"",14)]"""",$P(^(0),""^"",14)'>DT W $C(7),"" *** INACTIVE ***"""
SET DA(1)=+PSDS
SET DIC(0)="QEAM"
SET DIC="^PSD(58.8,"_PSDS_",1,"
DO ^DIC
KILL DIC
IF Y<0
QUIT
Begin DoDot:1
+3 SET PSDR(+Y)=""
End DoDot:1
+4 IF '$DATA(PSDR)&(X'="^ALL")
GOTO END
+5 IF X="^ALL"
SET ALL=1
DEV ;sel device
+1 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
+2 WRITE !
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
+3 IF $DATA(IO("Q"))
KILL IO("Q"),ZTIO,ZTSAVE,ZTDTH,ZTSK
SET ZTRTN="START^PSDBALI"
SET ZTDESC="CS PHARM Print Inv Sheet "
DO SAVE
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END
+4 USE IO
START ;entry for compile
+1 KILL ^TMP("PSDBALI",$JOB)
+2 IF $DATA(ALL)
FOR PSD=0:0
SET PSD=$ORDER(^PSD(58.8,+PSDS,1,PSD))
IF 'PSD
QUIT
IF $DATA(^PSD(58.8,+PSDS,1,PSD,0))
SET PSDR(+PSD)=""
+3 FOR PSD=0:0
SET PSD=$ORDER(PSDR(PSD))
IF 'PSD
QUIT
IF $DATA(^PSD(58.8,+PSDS,1,PSD,0))
SET NODE=^(0)
Begin DoDot:1
+4 SET PSDOK=""
IF +$PIECE(NODE,"^",14)
IF +$PIECE(NODE,"^",14)'>DT
IF '+$PIECE(NODE,"^",4)
QUIT
SET PSDOK="*"
+5 SET BAL=+$PIECE(NODE,"^",4)
SET DRUGN=$SELECT($PIECE($GET(^PSDRUG(+PSD,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ/"_PSD_" NAME MISSING")
SET SLVL=+$PIECE(NODE,"^",3)
SET EXP=$SELECT(+$PIECE(NODE,"^",12):+$PIECE(NODE,"^",12),1:"")
+6 IF EXP
SET Y=EXP
XECUTE ^DD("DD")
SET EXP=Y
+7 IF ASKN
DO LOOP
QUIT
+8 SET ^TMP("PSDBALI",$JOB,DRUGN,PSD)=BAL_"^"_PSDOK_"^"_SLVL_"^"_EXP
End DoDot:1
PRINT ;prints data
+1 SET (PG,PSDOUT)=0
DO NOW^%DTC
SET Y=+$EXTRACT(%,1,12)
XECUTE ^DD("DD")
SET RPDT=Y
+2 KILL LN
SET $PIECE(LN,"-",80)=""
DO HDR
+3 IF '$DATA(^TMP("PSDBALI",$JOB))
WRITE !!,?15,"**** NO STOCK BALANCE DATA AVAILABLE ****",!!
GOTO DONE
+4 IF ASKN
DO PRINT^PSDBALI1
GOTO DONE
+5 SET PSDR=""
FOR
SET PSDR=$ORDER(^TMP("PSDBALI",$JOB,PSDR))
IF PSDR=""!(PSDOUT)
QUIT
FOR PSD=0:0
SET PSD=$ORDER(^TMP("PSDBALI",$JOB,PSDR,PSD))
IF 'PSD
QUIT
Begin DoDot:1
+6 IF $Y+6>IOSL
WRITE !,?10,"Inspector's Signature: ______________________________",!
DO HDR
IF PSDOUT
QUIT
+7 SET NODE=^TMP("PSDBALI",$JOB,PSDR,PSD)
SET BAL=+NODE
SET PSDOK=$PIECE(NODE,"^",2)
SET SLVL=$PIECE(NODE,"^",3)
SET EXP=$PIECE(NODE,"^",4)
+8 WRITE !,PSDOK,?2,PSDR,?50,$JUSTIFY(BAL,6),?66,"___________",!
IF SLVL
WRITE ?5,"Stock Level: ",SLVL
IF EXP]""
WRITE ?30,"Exp. Date: ",EXP
WRITE !
SET LNUM=$Y
End DoDot:1
IF PSDOUT
QUIT
PRT ;
+1 IF LNUM<IOSL-5
FOR JJ=LNUM:1:IOSL-5
WRITE !
+2 IF 'PSDOUT
WRITE ?10,"Inspector's Signature: ______________________________",!
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 ;
+1 KILL %,%H,%I,%ZIS,ALL,ASKN,BAL,C,DA,DIC,DRUGN,DTOUT,DUOUT,EXP,JJ,LN,LNUM,NODE,PG,POP,PSD,PSDEV,PSDOK,PSDOUT,PSDR,PSDRN,PSDS,PSDSN,RPDT,SLVL,TYP,TYPN,X,Y
+2 KILL ^TMP("PSDBALI",$JOB),ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
+3 DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+4 QUIT
SAVE SET (ZTSAVE("PSDS"),ZTSAVE("PSDSN"),ZTSAVE("PSDSITE"),ZTSAVE("ASKN"))=""
+1 IF $DATA(ALL)
SET ZTSAVE("ALL")=""
IF $DATA(PSDR)
SET ZTSAVE("PSDR(")=""
+2 QUIT
HDR ;header
+1 IF $EXTRACT(IOST,1,2)="C-"
IF PG
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 !,?12,"Inventory Sheet for ",PSDSN,?72,"Page: ",PG,!,?20,RPDT,!!
+3 WRITE ?5,"DRUG",?46,"CURRENT BALANCE",?68,"ON-HAND",!,LN,!!
+4 QUIT
LOOP ;sets inv type
+1 IF '$ORDER(^PSD(58.8,+PSDS,1,+PSD,2,0))
SET TYPN="ZZ** NO INVENTORY TYPE DATA **"
DO LOOP1
+2 FOR TYP=0:0
SET TYP=$ORDER(^PSD(58.8,+PSDS,1,+PSD,2,TYP))
IF 'TYP
QUIT
SET TYPN=$SELECT($PIECE($GET(^PSI(58.16,+TYP,0)),"^")]"":$PIECE(^(0),"^"),1:"TYPE NAME MISSING")
DO LOOP1
+3 QUIT
LOOP1 SET ^TMP("PSDBALI",$JOB,TYPN,DRUGN,PSD)=BAL_"^"_PSDOK_"^"_SLVL_"^"_EXP
+1 QUIT