PSDOPTX ;BIR/LTL - Review OP Transactions by Rx # ; 29 Aug 94
;;3.0; CONTROLLED SUBSTANCES ;**18,55**;13 Feb 97
;
;References to ^PSD(58.8, covered by DBIA2711
;References to DD(58.81 and ^PSD(58.81 are covered by DBIA2808
;References to ^PSRX( are covered by DBIA986
N C,PSDRX
BRX K DIC S DIC="^PSRX(",DIC(0)="AEQ",DIC("A")="Please select beginning Rx #: "
W ! D ^DIC G:Y<1 END S (PSDRX,PSDRX(4))=+Y,PSDRX(1)=$P(Y,U,2)
I '$O(^PSD(58.81,"AOP",+Y,0))&('$O(^PSD(58.81,"AOP",+Y))) W !!,"No transactions beginning from Rx # ",PSDRX(1),"." G BRX
ERX K DIC S DIC="^PSRX(",DIC(0)="AEQ",DIC("B")=$O(^PSRX(" "),-1),DIC("A")="Please select ending Rx #: "
W ! D ^DIC G:Y<1 END S PSDRX(2)=+Y,PSDRX(3)=$P(Y,U,2)
I PSDRX(2)<PSDRX W !!,"Ending Rx # must have been created after Rx # ",PSDRX(1),"." G ERX
K DIC
S Y=$P($G(^PSD(58.8,+PSDLOC,2)),"^",9),C=$P(^DD(58.8,24,0),"^",2) D Y^DIQ S PSDEV=Y
DEV ;asks device and queuing info
K IO("Q") N %ZIS,IOP,POP S %ZIS="Q",%ZIS("B")=PSDEV W ! D ^%ZIS I POP W !,"NO DEVICE SELECTED OR OUTPUT PRINTED!" Q
I $D(IO("Q")) N ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTDTH,ZTSK S ZTRTN="START^PSDOPTX",ZTDESC="Drug OP transaction review" D SAVE D ^%ZTLOAD,HOME^%ZIS S PSDOUT=1 G END
START ;compiles and prints output
U IO N LN,PSDR,PG S (PG,PSDOUT)=0 D HEADER S PSDU=0
G:$G(PSDI) ^PSDOPTZ
G:$O(^TMP("PSD",$J,PSDU))']"" ^PSDOPTY
S PSDRX=PSDRX-1
F S PSDU=$O(^TMP("PSD",$J,PSDU)) Q:PSDU']"" S PSDU(1)=$O(^TMP("PSD",$J,PSDU,0)) D G:PSDOUT END S PSDRX=PSDRX(4)-1,PSDT(1)=0
LOOP .F S PSDRX=$O(^PSD(58.81,"AOP",PSDRX)) W:$E(IOST)="C" "." Q:'PSDRX!(PSDRX>PSDRX(2)) S PSDRX(5)=0 F S PSDRX(5)=$O(^PSD(58.81,"AOP",PSDRX,PSDRX(5))) Q:'PSDRX(5) D Q:PSDOUT
..S PSDR(2)=$G(^PSD(58.81,PSDRX(5),0))
..Q:$P(PSDR(2),U,3)'=PSDLOC!($P(PSDR(2),U,5)'=PSDU(1))
..S PSDR(4)=$G(^PSD(58.81,PSDRX(5),6))
..D:$Y+6>IOSL HEADER Q:PSDOUT
..S PSDT(1)=$G(PSDT(1))+1 W:PSDT(1)=1 !,PSDU
..W:$P(PSDR(4),U,6)&($P(PSDR(2),U,7)'=$P(PSDR(4),U,6)) ?54,"RPH=> ",$E($P($G(^VA(200,+$P(PSDR(4),U,6),0)),U),1,20)
..S Y=$E($P(PSDR(2),U,4),1,12) X ^DD("DD") W !!,Y,?19
..S DFN=$P($G(^PSRX(+$P(PSDR(4),U),0)),U,2)
..K C S Y=DFN,C=$P(^DD(58.81,73,0),U,2) D Y^DIQ
..W $P(PSDR(4),U,5),?28,Y
..D PID^VADPT6 W " ("_VA("BID")_")",?60
..I $P(PSDR(4),U,2) S Y=$P($G(^PSRX(+$P(PSDR(4),U),1,+$P(PSDR(4),U,2),0)),U,18) X ^DD("DD") W Y
..I $P(PSDR(4),U,4) S Y=$P($G(^PSRX(+$P(PSDR(4),U),"P",+$P(PSDR(4),U,4),0)),U,19) X ^DD("DD") W Y
..I '$P(PSDR(4),U,2)&('$P(PSDR(4),U,4)) S Y=$P($G(^PSRX(+$P(PSDR(4),U),2)),U,13) X ^DD("DD") W Y
..W !,"Qty: ",$P(PSDR(2),U,6)," Bal: ",$P(PSDR(2),U,10)-$P(PSDR(2),U,6),?22,"RPH=> ",$P($G(^VA(200,+$P(PSDR(2),U,7),0)),U),?60
..W $S($P(PSDR(4),U,2):"Refill #"_$P(PSDR(4),U,2),$P(PSDR(4),U,4):"Partial #"_$P(PSDR(4),U,4),1:"Original")
..W !,LN,!
END W:$E(IOST)'="C" @IOF
I $E(IOST)="C",'PSDOUT S DIR(0)="EA",DIR("A")="END OF REPORT! Press <RET> to return to the menu." D ^DIR
D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
D KVAR^VADPT K IO("Q"),VA("PID"),VA("BID"),^TMP("PSD",$J)
Q
I $E(IOST,1,2)'="P-",PG S DIR(0)="E" D ^DIR K DIR I 'Y S PSDOUT=1 Q
I $$S^%ZTLOAD W !!,"Task #",$G(ZTSK),", ",$G(ZTDESC)," was stopped by ",$P($G(^VA(200,+$G(DUZ),0)),U),"." S PSDOUT=1
W:$Y @IOF S $P(LN,"-",81)="",PG=PG+1 W !,"Outpatient Activity from Rx # ",PSDRX(1)," to Rx # ",PSDRX(3),?70,"PAGE: ",PG,!,LN,!,"Date Posted",?19,"Rx#",?28,"Patient",?60,"Date Released",!,LN W:$G(PSDT(1)) !,PSDU," (continued)",!
Q
SAVE ;save queued variables
S ZTSAVE("^TMP(""PSD"",$J,")=""
S (ZTSAVE("PSDLOC"),ZTSAVE("PSDRX"),ZTSAVE("PSDRX("))=""
Q
PSDOPTX ;BIR/LTL - Review OP Transactions by Rx # ; 29 Aug 94
+1 ;;3.0; CONTROLLED SUBSTANCES ;**18,55**;13 Feb 97
+2 ;
+3 ;References to ^PSD(58.8, covered by DBIA2711
+4 ;References to DD(58.81 and ^PSD(58.81 are covered by DBIA2808
+5 ;References to ^PSRX( are covered by DBIA986
+6 NEW C,PSDRX
BRX KILL DIC
SET DIC="^PSRX("
SET DIC(0)="AEQ"
SET DIC("A")="Please select beginning Rx #: "
+1 WRITE !
DO ^DIC
IF Y<1
GOTO END
SET (PSDRX,PSDRX(4))=+Y
SET PSDRX(1)=$PIECE(Y,U,2)
+2 IF '$ORDER(^PSD(58.81,"AOP",+Y,0))&('$ORDER(^PSD(58.81,"AOP",+Y)))
WRITE !!,"No transactions beginning from Rx # ",PSDRX(1),"."
GOTO BRX
ERX KILL DIC
SET DIC="^PSRX("
SET DIC(0)="AEQ"
SET DIC("B")=$ORDER(^PSRX(" "),-1)
SET DIC("A")="Please select ending Rx #: "
+1 WRITE !
DO ^DIC
IF Y<1
GOTO END
SET PSDRX(2)=+Y
SET PSDRX(3)=$PIECE(Y,U,2)
+2 IF PSDRX(2)<PSDRX
WRITE !!,"Ending Rx # must have been created after Rx # ",PSDRX(1),"."
GOTO ERX
+3 KILL DIC
+4 SET Y=$PIECE($GET(^PSD(58.8,+PSDLOC,2)),"^",9)
SET C=$PIECE(^DD(58.8,24,0),"^",2)
DO Y^DIQ
SET PSDEV=Y
DEV ;asks device and queuing info
+1 KILL IO("Q")
NEW %ZIS,IOP,POP
SET %ZIS="Q"
SET %ZIS("B")=PSDEV
WRITE !
DO ^%ZIS
IF POP
WRITE !,"NO DEVICE SELECTED OR OUTPUT PRINTED!"
QUIT
+2 IF $DATA(IO("Q"))
NEW ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTDTH,ZTSK
SET ZTRTN="START^PSDOPTX"
SET ZTDESC="Drug OP transaction review"
DO SAVE
DO ^%ZTLOAD
DO HOME^%ZIS
SET PSDOUT=1
GOTO END
START ;compiles and prints output
+1 USE IO
NEW LN,PSDR,PG
SET (PG,PSDOUT)=0
DO HEADER
SET PSDU=0
+2 IF $GET(PSDI)
GOTO ^PSDOPTZ
+3 IF $ORDER(^TMP("PSD",$JOB,PSDU))']""
GOTO ^PSDOPTY
+4 SET PSDRX=PSDRX-1
+5 FOR
SET PSDU=$ORDER(^TMP("PSD",$JOB,PSDU))
IF PSDU']""
QUIT
SET PSDU(1)=$ORDER(^TMP("PSD",$JOB,PSDU,0))
Begin DoDot:1
LOOP FOR
SET PSDRX=$ORDER(^PSD(58.81,"AOP",PSDRX))
IF $EXTRACT(IOST)="C"
WRITE "."
IF 'PSDRX!(PSDRX>PSDRX(2))
QUIT
SET PSDRX(5)=0
FOR
SET PSDRX(5)=$ORDER(^PSD(58.81,"AOP",PSDRX,PSDRX(5)))
IF 'PSDRX(5)
QUIT
Begin DoDot:2
+1 SET PSDR(2)=$GET(^PSD(58.81,PSDRX(5),0))
+2 IF $PIECE(PSDR(2),U,3)'=PSDLOC!($PIECE(PSDR(2),U,5)'=PSDU(1))
QUIT
+3 SET PSDR(4)=$GET(^PSD(58.81,PSDRX(5),6))
+4 IF $Y+6>IOSL
DO HEADER
IF PSDOUT
QUIT
+5 SET PSDT(1)=$GET(PSDT(1))+1
IF PSDT(1)=1
WRITE !,PSDU
+6 IF $PIECE(PSDR(4),U,6)&($PIECE(PSDR(2),U,7)'=$PIECE(PSDR(4),U,6))
WRITE ?54,"RPH=> ",$EXTRACT($PIECE($GET(^VA(200,+$PIECE(PSDR(4),U,6),0)),U),1,20)
+7 SET Y=$EXTRACT($PIECE(PSDR(2),U,4),1,12)
XECUTE ^DD("DD")
WRITE !!,Y,?19
+8 SET DFN=$PIECE($GET(^PSRX(+$PIECE(PSDR(4),U),0)),U,2)
+9 KILL C
SET Y=DFN
SET C=$PIECE(^DD(58.81,73,0),U,2)
DO Y^DIQ
+10 WRITE $PIECE(PSDR(4),U,5),?28,Y
+11 DO PID^VADPT6
WRITE " ("_VA("BID")_")",?60
+12 IF $PIECE(PSDR(4),U,2)
SET Y=$PIECE($GET(^PSRX(+$PIECE(PSDR(4),U),1,+$PIECE(PSDR(4),U,2),0)),U,18)
XECUTE ^DD("DD")
WRITE Y
+13 IF $PIECE(PSDR(4),U,4)
SET Y=$PIECE($GET(^PSRX(+$PIECE(PSDR(4),U),"P",+$PIECE(PSDR(4),U,4),0)),U,19)
XECUTE ^DD("DD")
WRITE Y
+14 IF '$PIECE(PSDR(4),U,2)&('$PIECE(PSDR(4),U,4))
SET Y=$PIECE($GET(^PSRX(+$PIECE(PSDR(4),U),2)),U,13)
XECUTE ^DD("DD")
WRITE Y
+15 WRITE !,"Qty: ",$PIECE(PSDR(2),U,6)," Bal: ",$PIECE(PSDR(2),U,10)-$PIECE(PSDR(2),U,6),?22,"RPH=> ",$PIECE($GET(^VA(200,+$PIECE(PSDR(2),U,7),0)),U),?60
+16 WRITE $SELECT($PIECE(PSDR(4),U,2):"Refill #"_$PIECE(PSDR(4),U,2),$PIECE(PSDR(4),U,4):"Partial #"_$PIECE(PSDR(4),U,4),1:"Original")
+17 WRITE !,LN,!
End DoDot:2
IF PSDOUT
QUIT
End DoDot:1
IF PSDOUT
GOTO END
SET PSDRX=PSDRX(4)-1
SET PSDT(1)=0
END IF $EXTRACT(IOST)'="C"
WRITE @IOF
+1 IF $EXTRACT(IOST)="C"
IF 'PSDOUT
SET DIR(0)="EA"
SET DIR("A")="END OF REPORT! Press <RET> to return to the menu."
DO ^DIR
+2 DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+3 DO KVAR^VADPT
KILL IO("Q"),VA("PID"),VA("BID"),^TMP("PSD",$JOB)
+4 QUIT
+1 IF $EXTRACT(IOST,1,2)'="P-"
IF PG
SET DIR(0)="E"
DO ^DIR
KILL DIR
IF 'Y
SET PSDOUT=1
QUIT
+2 IF $$S^%ZTLOAD
WRITE !!,"Task #",$GET(ZTSK),", ",$GET(ZTDESC)," was stopped by ",$PIECE($GET(^VA(200,+$GET(DUZ),0)),U),"."
SET PSDOUT=1
+3 IF $Y
WRITE @IOF
SET $PIECE(LN,"-",81)=""
SET PG=PG+1
WRITE !,"Outpatient Activity from Rx # ",PSDRX(1)," to Rx # ",PSDRX(3),?70,"PAGE: ",PG,!,LN,!,"Date Posted",?19,"Rx#",?28,"Patient",?60,"Date Released",!,LN
IF $GET(PSDT(1))
WRITE !,PSDU," (continued)",!
+4 QUIT
SAVE ;save queued variables
+1 SET ZTSAVE("^TMP(""PSD"",$J,")=""
+2 SET (ZTSAVE("PSDLOC"),ZTSAVE("PSDRX"),ZTSAVE("PSDRX("))=""
+3 QUIT