PSDPND ;BIR/BJW-Pharm Dispensing Report ; 18 Jun 98
;;3.0; CONTROLLED SUBSTANCES ;**8,10**;13 Feb 97
;**Y2K compliance**,"P" added to date input string
;mod.for nois:tua-0498-32173,start+19
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 CS reports.",!!,"PSJ RPHARM or PSJ PHARM TECH security key required.",! K OK Q
ASKD ;ask disp loc
S PSDS=$P(PSDSITE,U,3),PSDSN=$P(PSDSITE,U,4)
G:$P(PSDSITE,U,5) DATE
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
DATE ;ask date range
W ! K %DT S %DT="AEPX",%DT("A")="Start with Date: " D ^%DT I Y<0 S PSDOUT=1 G END
S PSDSD=Y D D^DIQ S PSDATE=Y,%DT("A")="End with Date: " D ^%DT I Y<0 S PSDOUT=1 G END
I Y<PSDSD W !!,"The ending date of the range must be later than the starting date." G DATE
S PSDED=Y D D^DIQ S PSDATE=PSDATE_"^"_Y,PSDSD=PSDSD-.0001,PSDED=PSDED+.9999
SUM ;if sum only
K DA,DIR,DIRUT S DIR(0)="Y",DIR("A")="Do you want to print the summary totals only",DIR("B")="NO"
S DIR("?",1)="Answer 'YES' to print only the summary totals for this report,",DIR("?")="answer 'NO' to print the report and the summary totals."
D ^DIR K DIR G:$D(DIRUT) END S SUM=Y
DEV ;dev & queue info
W !!,"This report is designed for a 132 column format.",!,"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^PSDPND",ZTDESC="Pharm Narcotic Disp Report" D SAVE,^%ZTLOAD,HOME^%ZIS K ZTSK G END
U IO
START ;compile data
K ^TMP("PSDND",$J),^TMP("PSDNDT",$J)
F PSD=PSDSD:0 S PSD=$O(^PSD(58.81,"AF",PSD)) Q:'PSD!(PSD>PSDED) F JJ=2,6,7 F PSDA=0:0 S PSDA=$O(^PSD(58.81,"AF",PSD,PSDS,JJ,PSDA)) Q:'PSDA I $D(^PSD(58.81,PSDA,0)) D
.S NODE=^PSD(58.81,PSDA,0),PSDPN=$S($P(NODE,"^",17)]"":$P(NODE,"^",17),1:"UNKNOWN")
.S NAOU=+$P(NODE,"^",18),NAOUN=$S($P($G(^PSD(58.8,NAOU,0)),"^")]"":$P(^(0),"^"),1:"ZZ/"_NAOU) I NAOUN'="UNKNOWN" S NAOUN=$E(NAOUN,1,24)
.S DRUG=+$P(NODE,"^",5),DRUGN=$S($P($G(^PSDRUG(DRUG,0)),"^")]"":$P(^(0),"^"),1:"ZZ/"_DRUG)
.S QTY=$P(NODE,"^",6) I $D(^PSD(58.81,PSDA,4)),+$P(^(4),"^",3) S QTY=$P(^(4),"^",3)
.I JJ=7 S QTY=0 Q:PSDPN="UNKNOWN"
.I $D(^PSD(58.81,PSDA,5)),+^(5) S QTY=0,NAOUN="CANCELLED"
.S:'$D(^TMP("PSDNDT",$J,DRUGN)) ^TMP("PSDNDT",$J,DRUGN)=0
.S ^TMP("PSDNDT",$J,DRUGN)=^TMP("PSDNDT",$J,DRUGN)+QTY Q:SUM
.I 'PSDPN S PSDPN="W/O 2638",PHARM=+$P(NODE,"^",7)
.I $D(^PSD(58.81,PSDA,1)) S PHARM=+$P(^(1),"^")
.S PHARMN=$S($P($G(^VA(200,+PHARM,0)),"^")]"":$P(^(0),"^"),1:"UNKNOWN") I PHARMN'="UNKNOWN" S PHARMN=$P(PHARMN,",")_","_$E($P(PHARMN,",",2))
.S PSDST=$P(NODE,"^",4),PSDDT="" I PSDST S Y=$E(PSDST,1,7) X ^DD("DD") S PSDDT=Y
.I JJ=6,'$D(^PSD(58.81,PSDA,6)) Q
.I JJ=6 S PSRX=+$P(^PSD(58.81,PSDA,6),"^"),PSDPN=$S($P(^(6),"^",5)]"":$P(^(6),"^",5),$P($G(^PSRX(PSRX,0)),"^")]"":$P(^(0),"^"),1:"UNKNOWN") D
..S PSRXP=+$P($G(^PSRX(PSRX,0)),"^",2)
..K C S Y=PSRXP,C=$P(^DD(58.81,73,0),"^",2) D Y^DIQ K C
..S PSDRXIN=PSRX D VER^PSDOPT
..S NAOUN=$S('$O(^PSRX("B",PSDPN,0)):"RX DELETED",$G(PSDSTA)=13:"RX DELETED",PSRXP]"":Y,1:"UNKNOWN"),NAOUN=$E(NAOUN,1,24)
..K PSDSTA,PSDRXIN,PSOVR
.S ^TMP("PSDND",$J,PSDPN,PSDA)=DRUGN_"^"_NAOUN_"^"_QTY_"^"_PSDDT_"^"_PHARMN
PRT D PRINT^PSDPND1
END ;
K %,%DT,%H,%I,%ZIS,C,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DRUG,DRUGN,DUOUT,JJ,LN,NAOU,NAOUN,NODE,NUM,OK
K PG,PHARM,PHARMN,POP,PSD,PSDA,PSDATE,PSDDT,PSDED,PSDEV,PSDOUT,PSDPN,PSRX,PSRXP,PSDS,PSDSD,PSDSN,PSDST,QTY,SUM,X,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
K ^TMP("PSDND",$J),^TMP("PSDNDT",$J) D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
Q
SAVE S (ZTSAVE("SUM"),ZTSAVE("PSDSN"),ZTSAVE("PSDS"),ZTSAVE("PSDSD"),ZTSAVE("PSDED"),ZTSAVE("PSDATE"))=""
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSDPND 4236 printed Nov 22, 2024@16:58:20 Page 2
PSDPND ;BIR/BJW-Pharm Dispensing Report ; 18 Jun 98
+1 ;;3.0; CONTROLLED SUBSTANCES ;**8,10**;13 Feb 97
+2 ;**Y2K compliance**,"P" added to date input string
+3 ;mod.for nois:tua-0498-32173,start+19
+4 IF '$DATA(PSDSITE)
DO ^PSDSET
if '$DATA(PSDSITE)
QUIT
+5 SET OK=$SELECT($DATA(^XUSEC("PSJ RPHARM",DUZ)):1,$DATA(^XUSEC("PSJ PHARM TECH",DUZ)):1,1:0)
+6 IF 'OK
WRITE $CHAR(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to",!,?12,"print CS reports.",!!,"PSJ RPHARM or PSJ PHARM TECH security key required.",!
KILL OK
QUIT
ASKD ;ask disp loc
+1 SET PSDS=$PIECE(PSDSITE,U,3)
SET PSDSN=$PIECE(PSDSITE,U,4)
+2 if $PIECE(PSDSITE,U,5)
GOTO DATE
+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
DATE ;ask date range
+1 WRITE !
KILL %DT
SET %DT="AEPX"
SET %DT("A")="Start with Date: "
DO ^%DT
IF Y<0
SET PSDOUT=1
GOTO END
+2 SET PSDSD=Y
DO D^DIQ
SET PSDATE=Y
SET %DT("A")="End with Date: "
DO ^%DT
IF Y<0
SET PSDOUT=1
GOTO END
+3 IF Y<PSDSD
WRITE !!,"The ending date of the range must be later than the starting date."
GOTO DATE
+4 SET PSDED=Y
DO D^DIQ
SET PSDATE=PSDATE_"^"_Y
SET PSDSD=PSDSD-.0001
SET PSDED=PSDED+.9999
SUM ;if sum only
+1 KILL DA,DIR,DIRUT
SET DIR(0)="Y"
SET DIR("A")="Do you want to print the summary totals only"
SET DIR("B")="NO"
+2 SET DIR("?",1)="Answer 'YES' to print only the summary totals for this report,"
SET DIR("?")="answer 'NO' to print the report and the summary totals."
+3 DO ^DIR
KILL DIR
if $DATA(DIRUT)
GOTO END
SET SUM=Y
DEV ;dev & queue info
+1 WRITE !!,"This report is designed for a 132 column format.",!,"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^PSDPND"
SET ZTDESC="Pharm Narcotic Disp Report"
DO SAVE
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END
+5 USE IO
START ;compile data
+1 KILL ^TMP("PSDND",$JOB),^TMP("PSDNDT",$JOB)
+2 FOR PSD=PSDSD:0
SET PSD=$ORDER(^PSD(58.81,"AF",PSD))
if 'PSD!(PSD>PSDED)
QUIT
FOR JJ=2,6,7
FOR PSDA=0:0
SET PSDA=$ORDER(^PSD(58.81,"AF",PSD,PSDS,JJ,PSDA))
if 'PSDA
QUIT
IF $DATA(^PSD(58.81,PSDA,0))
Begin DoDot:1
+3 SET NODE=^PSD(58.81,PSDA,0)
SET PSDPN=$SELECT($PIECE(NODE,"^",17)]"":$PIECE(NODE,"^",17),1:"UNKNOWN")
+4 SET NAOU=+$PIECE(NODE,"^",18)
SET NAOUN=$SELECT($PIECE($GET(^PSD(58.8,NAOU,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ/"_NAOU)
IF NAOUN'="UNKNOWN"
SET NAOUN=$EXTRACT(NAOUN,1,24)
+5 SET DRUG=+$PIECE(NODE,"^",5)
SET DRUGN=$SELECT($PIECE($GET(^PSDRUG(DRUG,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ/"_DRUG)
+6 SET QTY=$PIECE(NODE,"^",6)
IF $DATA(^PSD(58.81,PSDA,4))
IF +$PIECE(^(4),"^",3)
SET QTY=$PIECE(^(4),"^",3)
+7 IF JJ=7
SET QTY=0
if PSDPN="UNKNOWN"
QUIT
+8 IF $DATA(^PSD(58.81,PSDA,5))
IF +^(5)
SET QTY=0
SET NAOUN="CANCELLED"
+9 if '$DATA(^TMP("PSDNDT",$JOB,DRUGN))
SET ^TMP("PSDNDT",$JOB,DRUGN)=0
+10 SET ^TMP("PSDNDT",$JOB,DRUGN)=^TMP("PSDNDT",$JOB,DRUGN)+QTY
if SUM
QUIT
+11 IF 'PSDPN
SET PSDPN="W/O 2638"
SET PHARM=+$PIECE(NODE,"^",7)
+12 IF $DATA(^PSD(58.81,PSDA,1))
SET PHARM=+$PIECE(^(1),"^")
+13 SET PHARMN=$SELECT($PIECE($GET(^VA(200,+PHARM,0)),"^")]"":$PIECE(^(0),"^"),1:"UNKNOWN")
IF PHARMN'="UNKNOWN"
SET PHARMN=$PIECE(PHARMN,",")_","_$EXTRACT($PIECE(PHARMN,",",2))
+14 SET PSDST=$PIECE(NODE,"^",4)
SET PSDDT=""
IF PSDST
SET Y=$EXTRACT(PSDST,1,7)
XECUTE ^DD("DD")
SET PSDDT=Y
+15 IF JJ=6
IF '$DATA(^PSD(58.81,PSDA,6))
QUIT
+16 IF JJ=6
SET PSRX=+$PIECE(^PSD(58.81,PSDA,6),"^")
SET PSDPN=$SELECT($PIECE(^(6),"^",5)]"":$PIECE(^(6),"^",5),$PIECE($GET(^PSRX(PSRX,0)),"^")]"":$PIECE(^(0),"^"),1:"UNKNOWN")
Begin DoDot:2
+17 SET PSRXP=+$PIECE($GET(^PSRX(PSRX,0)),"^",2)
+18 KILL C
SET Y=PSRXP
SET C=$PIECE(^DD(58.81,73,0),"^",2)
DO Y^DIQ
KILL C
+19 SET PSDRXIN=PSRX
DO VER^PSDOPT
+20 SET NAOUN=$SELECT('$ORDER(^PSRX("B",PSDPN,0)):"RX DELETED",$GET(PSDSTA)=13:"RX DELETED",PSRXP]"":Y,1:"UNKNOWN")
SET NAOUN=$EXTRACT(NAOUN,1,24)
+21 KILL PSDSTA,PSDRXIN,PSOVR
End DoDot:2
+22 SET ^TMP("PSDND",$JOB,PSDPN,PSDA)=DRUGN_"^"_NAOUN_"^"_QTY_"^"_PSDDT_"^"_PHARMN
End DoDot:1
PRT DO PRINT^PSDPND1
END ;
+1 KILL %,%DT,%H,%I,%ZIS,C,DA,DIC,DIR,DIROUT,DIRUT,DTOUT,DRUG,DRUGN,DUOUT,JJ,LN,NAOU,NAOUN,NODE,NUM,OK
+2 KILL PG,PHARM,PHARMN,POP,PSD,PSDA,PSDATE,PSDDT,PSDED,PSDEV,PSDOUT,PSDPN,PSRX,PSRXP,PSDS,PSDSD,PSDSN,PSDST,QTY,SUM,X,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
+3 KILL ^TMP("PSDND",$JOB),^TMP("PSDNDT",$JOB)
DO ^%ZISC
if $DATA(ZTQUEUED)
SET ZTREQ="@"
+4 QUIT
SAVE SET (ZTSAVE("SUM"),ZTSAVE("PSDSN"),ZTSAVE("PSDS"),ZTSAVE("PSDSD"),ZTSAVE("PSDED"),ZTSAVE("PSDATE"))=""
+1 QUIT