PSDERCP ;BIR/BJW-CS Resolved Error Log Report ; 6 Feb 98
;;3.0; CONTROLLED SUBSTANCES ;**8**;13 Feb 97
;**Y2K compliance**,"P" added to date input string
I '$D(PSDSITE) D ^PSDSET Q:'$D(PSDSITE)
S OK=$S($D(^XUSEC("PSDMGR",DUZ)):1,$D(^XUSEC("PSD ERROR",DUZ)):2,1:0)
I 'OK W $C(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to",!,?12,"the pending Controlled Substances error log.",!!,"PSDMGR or PSD ERROR security key required.",! K OK Q
S PSDS=$P(PSDSITE,U,3),PSDSN=$P(PSDSITE,U,4) G:$P(PSDSITE,U,5) DATE
ASKD ;ask disp location
W !!,"You may select a Dispensing Site at the prompt.",!
W ! K DIC,DA S DIC=58.8,DIC(0)="QEAZ"
S DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S($P(^(0),""^"",2)[""M"":1,$P(^(0),""^"",2)[""S"":1,1:0)"
S DIC("A")="Select Dispensing Site: ",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
DATE ;ask date range
W ! K %DT S %DT="AEP",%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
DEV ;select device
W !!,"This report is designed for a 80 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^PSDERCP",ZTDESC="CS Resolved Error Log Report" D SAVE,^%ZTLOAD,HOME^%ZIS K ZTSK G END
U IO
START ;start looping
K ^TMP("PSDERCP",$J)
D NOW^%DTC S Y=X X ^DD("DD") S RPDT=Y
K LN S (COMM,CNT,PG,PSDOUT)=0,$P(LN,"-",80)=""
F PSD=PSDSD:0 S PSD=$O(^PSD(58.89,"AE",PSD)) Q:'PSD!(PSD>PSDED) F PSDA=0:0 S PSDA=$O(^PSD(58.89,"AE",PSD,PSDS,PSDA)) Q:'PSDA D
.Q:'$D(^PSD(58.89,+PSDA,0)) S NODE=^PSD(58.89,+PSDA,0)
.S PSDN=+$P(NODE,"^",2) Q:'$D(^PSD(58.81,+PSDN,0)) S NODE1=^PSD(58.81,+PSDN,0),PSDR=+$P(NODE1,"^",5)
.S NODE9=$G(^PSD(58.81,+PSDN,9)),PHARM=$S(+$P(NODE9,"^",2):+$P(NODE9,"^",2),+$P(NODE9,"^",8):+$P(NODE9,"^",8),1:"")
.S PHARM2=+$P(NODE,"^",4)
.S PSDRN=$S($P($G(^PSDRUG(+PSDR,0)),"^")]"":$P($G(^PSDRUG(+PSDR,0)),"^"),1:"#"_+PSDR_" DRUG NAME MISSING")
.S QTY=$P(NODE1,"^",6),PHARMN=$S($P($G(^VA(200,+PHARM,0)),"^")]"":$P(^(0),"^"),1:"UNKNOWN"),PHARMN2=$S($P($G(^VA(200,+PHARM2,0)),"^")]"":$P(^(0),"^"),1:"UNKNOWN")
.S PSDT=$E(PSD,4,5)_"/"_$E(PSD,6,7)_"/"_$E(PSD,2,3),TYP=+$P(NODE1,"^",2),TYP=$P($G(^PSD(58.84,+TYP,0)),"^")
.S COMM=$S($D(^PSD(58.89,PSDA,1,0)):1,1:0)
.S ^TMP("PSDERCP",$J,PSDRN,PSDA)=QTY_"^"_PHARMN_"^"_PHARMN2_"^"_PSDT_"^"_TYP_"^"_COMM,CNT=CNT+1
I CNT=0 D HDR W !!,?10,"*** NO CONTROLLED SUBSTANCES RESOLVED ERRORS/ADJUSTMENTS ***",!! G DONE
PRINT ;prints data
S COMM=0 D HDR Q:PSDOUT
S PSDRN="" F S PSDRN=$O(^TMP("PSDERCP",$J,PSDRN)) Q:PSDRN="" D:$Y+4>IOSL HDR Q:PSDOUT W !,?2,"=> ",PSDRN,! F PSDA=0:0 S PSDA=$O(^TMP("PSDERCP",$J,PSDRN,PSDA)) Q:'PSDA D Q:PSDOUT
.I $Y+4>IOSL D HDR Q:PSDOUT W !,?2,"=> ",PSDRN,!
.S NODE=^TMP("PSDERCP",$J,PSDRN,PSDA) W !,PSDA,?10,$J($P(NODE,"^"),6),?20,$P(NODE,"^",4),?35,$P(NODE,"^",5),!,?5,$P(NODE,"^",2),?45,$P(NODE,"^",3),!
.I $P(NODE,"^",6) W ?5,"Resolution: " S COMM=1 K ^UTILITY($J,"W") F TEXT=0:0 S TEXT=$O(^PSD(58.89,PSDA,1,TEXT)) Q:'TEXT D:$Y+4>IOSL HDR Q:PSDOUT S X=$G(^PSD(58.89,PSDA,1,TEXT,0)),DIWL=10,DIWR=75,DIWF="W" D ^DIWP
.I COMM D ^DIWW S COMM=0 W !
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 %,%DT,%H,%I,%ZIS,C,COMM,CNT,DA,DIC,DIR,DIROUT,DIRUT,DIWF,DIWL,DIWR,DTOUT,DUOUT,LN,NODE,NODE1,NODE9,OK
K PG,PHARM,PHARM2,PHARMN,PHARMN2,POP,PSD,PSDA,PSDATE,PSDED,PSDEV,PSDN,PSDOUT,PSDR,PSDRG,PSDRN,PSDS,PSDSD,PSDSN,PSDT
K QTY,RPDT,TEXT,TYP,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
K ^TMP("PSDERCP",$J)
D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
Q
HDR ;prints header information
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 !,?15,"CS RESOLVED ERROR/ADJ LOG REPORT",?70,"PAGE: ",PG
W !,?15,"NAOU: ",PSDSN,!,?15,"Period From: ",$P(PSDATE,"^")," to: ",$P(PSDATE,"^",2),!,?15,"Run Date: ",RPDT
W !!,"LOG #",?10,"QUANTITY",?22,"DATE",?35,"ERR/ADJ TYPE",!,?5,"LOGGED BY",?45,"RESOLVED BY",!,LN,!
Q
SAVE ;saves variables for queueing
S (ZTSAVE("PSDSD"),ZTSAVE("PSDED"),ZTSAVE("PSDATE"),ZTSAVE("PSDS"),ZTSAVE("PSDSN"))=""
Q
PSDERCP ;BIR/BJW-CS Resolved Error Log Report ; 6 Feb 98
+1 ;;3.0; CONTROLLED SUBSTANCES ;**8**;13 Feb 97
+2 ;**Y2K compliance**,"P" added to date input string
+3 IF '$DATA(PSDSITE)
DO ^PSDSET
IF '$DATA(PSDSITE)
QUIT
+4 SET OK=$SELECT($DATA(^XUSEC("PSDMGR",DUZ)):1,$DATA(^XUSEC("PSD ERROR",DUZ)):2,1:0)
+5 IF 'OK
WRITE $CHAR(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to",!,?12,"the pending Controlled Substances error log.",!!,"PSDMGR or PSD ERROR security key required.",!
KILL OK
QUIT
+6 SET PSDS=$PIECE(PSDSITE,U,3)
SET PSDSN=$PIECE(PSDSITE,U,4)
IF $PIECE(PSDSITE,U,5)
GOTO DATE
ASKD ;ask disp location
+1 WRITE !!,"You may select a Dispensing Site at the prompt.",!
+2 WRITE !
KILL DIC,DA
SET DIC=58.8
SET DIC(0)="QEAZ"
+3 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 Dispensing Site: "
SET DIC("B")=PSDSN
+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="AEP"
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
DEV ;select device
+1 WRITE !!,"This report is designed for a 80 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^PSDERCP"
SET ZTDESC="CS Resolved Error Log Report"
DO SAVE
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END
+5 USE IO
START ;start looping
+1 KILL ^TMP("PSDERCP",$JOB)
+2 DO NOW^%DTC
SET Y=X
XECUTE ^DD("DD")
SET RPDT=Y
+3 KILL LN
SET (COMM,CNT,PG,PSDOUT)=0
SET $PIECE(LN,"-",80)=""
+4 FOR PSD=PSDSD:0
SET PSD=$ORDER(^PSD(58.89,"AE",PSD))
IF 'PSD!(PSD>PSDED)
QUIT
FOR PSDA=0:0
SET PSDA=$ORDER(^PSD(58.89,"AE",PSD,PSDS,PSDA))
IF 'PSDA
QUIT
Begin DoDot:1
+5 IF '$DATA(^PSD(58.89,+PSDA,0))
QUIT
SET NODE=^PSD(58.89,+PSDA,0)
+6 SET PSDN=+$PIECE(NODE,"^",2)
IF '$DATA(^PSD(58.81,+PSDN,0))
QUIT
SET NODE1=^PSD(58.81,+PSDN,0)
SET PSDR=+$PIECE(NODE1,"^",5)
+7 SET NODE9=$GET(^PSD(58.81,+PSDN,9))
SET PHARM=$SELECT(+$PIECE(NODE9,"^",2):+$PIECE(NODE9,"^",2),+$PIECE(NODE9,"^",8):+$PIECE(NODE9,"^",8),1:"")
+8 SET PHARM2=+$PIECE(NODE,"^",4)
+9 SET PSDRN=$SELECT($PIECE($GET(^PSDRUG(+PSDR,0)),"^")]"":$PIECE($GET(^PSDRUG(+PSDR,0)),"^"),1:"#"_+PSDR_" DRUG NAME MISSING")
+10 SET QTY=$PIECE(NODE1,"^",6)
SET PHARMN=$SELECT($PIECE($GET(^VA(200,+PHARM,0)),"^")]"":$PIECE(^(0),"^"),1:"UNKNOWN")
SET PHARMN2=$SELECT($PIECE($GET(^VA(200,+PHARM2,0)),"^")]"":$PIECE(^(0),"^"),1:"UNKNOWN")
+11 SET PSDT=$EXTRACT(PSD,4,5)_"/"_$EXTRACT(PSD,6,7)_"/"_$EXTRACT(PSD,2,3)
SET TYP=+$PIECE(NODE1,"^",2)
SET TYP=$PIECE($GET(^PSD(58.84,+TYP,0)),"^")
+12 SET COMM=$SELECT($DATA(^PSD(58.89,PSDA,1,0)):1,1:0)
+13 SET ^TMP("PSDERCP",$JOB,PSDRN,PSDA)=QTY_"^"_PHARMN_"^"_PHARMN2_"^"_PSDT_"^"_TYP_"^"_COMM
SET CNT=CNT+1
End DoDot:1
+14 IF CNT=0
DO HDR
WRITE !!,?10,"*** NO CONTROLLED SUBSTANCES RESOLVED ERRORS/ADJUSTMENTS ***",!!
GOTO DONE
PRINT ;prints data
+1 SET COMM=0
DO HDR
IF PSDOUT
QUIT
+2 SET PSDRN=""
FOR
SET PSDRN=$ORDER(^TMP("PSDERCP",$JOB,PSDRN))
IF PSDRN=""
QUIT
IF $Y+4>IOSL
DO HDR
IF PSDOUT
QUIT
WRITE !,?2,"=> ",PSDRN,!
FOR PSDA=0:0
SET PSDA=$ORDER(^TMP("PSDERCP",$JOB,PSDRN,PSDA))
IF 'PSDA
QUIT
Begin DoDot:1
+3 IF $Y+4>IOSL
DO HDR
IF PSDOUT
QUIT
WRITE !,?2,"=> ",PSDRN,!
+4 SET NODE=^TMP("PSDERCP",$JOB,PSDRN,PSDA)
WRITE !,PSDA,?10,$JUSTIFY($PIECE(NODE,"^"),6),?20,$PIECE(NODE,"^",4),?35,$PIECE(NODE,"^",5),!,?5,$PIECE(NODE,"^",2),?45,$PIECE(NODE,"^",3),!
+5 IF $PIECE(NODE,"^",6)
WRITE ?5,"Resolution: "
SET COMM=1
KILL ^UTILITY($JOB,"W")
FOR TEXT=0:0
SET TEXT=$ORDER(^PSD(58.89,PSDA,1,TEXT))
IF 'TEXT
QUIT
IF $Y+4>IOSL
DO HDR
IF PSDOUT
QUIT
SET X=$GET(^PSD(58.89,PSDA,1,TEXT,0))
SET DIWL=10
SET DIWR=75
SET DIWF="W"
DO ^DIWP
+6 IF COMM
DO ^DIWW
SET COMM=0
WRITE !
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 ;
+1 KILL %,%DT,%H,%I,%ZIS,C,COMM,CNT,DA,DIC,DIR,DIROUT,DIRUT,DIWF,DIWL,DIWR,DTOUT,DUOUT,LN,NODE,NODE1,NODE9,OK
+2 KILL PG,PHARM,PHARM2,PHARMN,PHARMN2,POP,PSD,PSDA,PSDATE,PSDED,PSDEV,PSDN,PSDOUT,PSDR,PSDRG,PSDRN,PSDS,PSDSD,PSDSN,PSDT
+3 KILL QTY,RPDT,TEXT,TYP,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
+4 KILL ^TMP("PSDERCP",$JOB)
+5 DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+6 QUIT
HDR ;prints header information
+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 !,?15,"CS RESOLVED ERROR/ADJ LOG REPORT",?70,"PAGE: ",PG
+3 WRITE !,?15,"NAOU: ",PSDSN,!,?15,"Period From: ",$PIECE(PSDATE,"^")," to: ",$PIECE(PSDATE,"^",2),!,?15,"Run Date: ",RPDT
+4 WRITE !!,"LOG #",?10,"QUANTITY",?22,"DATE",?35,"ERR/ADJ TYPE",!,?5,"LOGGED BY",?45,"RESOLVED BY",!,LN,!
+5 QUIT
SAVE ;saves variables for queueing
+1 SET (ZTSAVE("PSDSD"),ZTSAVE("PSDED"),ZTSAVE("PSDATE"),ZTSAVE("PSDS"),ZTSAVE("PSDSN"))=""
+2 QUIT