PSDOPTI ;BIR/LTL - Review OP Transactions by Inventory Type ; 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 ^PSDRUG( are covered by DBIA221
;References to ^PSI(58.16 are covered by DBIA213
;References to ^PSRX( are covered by DBIA986
S CNT=0 W !!,"You may select one, several, or ^ALL Inventory Types."
N PSDI S PSDI=0
INV F S DIC="^PSI(58.16,",DIC(0)="AEQ",DIC("A")="Please Select Inventory Type: " W ! D ^DIC K DIC G:X'="^ALL"&(Y<1)&('CNT) END Q:Y<0 S PSDI(+Y)=$P(Y,U,2),CNT=CNT+1
I X="^ALL" F S PSDI=$O(^PSI(58.16,PSDI)) Q:'PSDI S PSDI(PSDI)=$P($G(^PSI(58.16,PSDI,0)),U)
S CNT=0 W !!,"Now, you may select one, several, or ^ALL drugs."
CHKD F S DIC="^PSD(58.8,+PSDLOC,1,",DIC(0)="AEQ",DIC("A")="Please Select "_PSDLOCN_"'s Drug: ",DIC("S")="I $S($G(^(""I"")):$G(^(""I""))>DT,1:1)" W ! D ^DIC K DIC G:X'="^ALL"&(Y<1)&('CNT) END Q:Y<0 D
.I '$O(^PSD(58.81,"F",+Y,0)) W !!,"There have been no transactions for this drug.",!! Q
.S PSD(1)=0 F S PSD(1)=$O(^PSD(58.8,PSDLOC,1,+Y,2,PSD(1))) S:$D(PSDI(+PSD(1))) PSD(2)=PSD(1) Q:$G(PSD(2))!('PSD(1))
.I '$G(PSD(2)) W !!,"Not in selected Inventory Type(s)",!! Q
.S PSD=$P($G(^PSDRUG(+Y,0)),U),CNT=CNT+1
.S PSD=$S(PSD]"":PSD,1:"UNKNOWN DRUG #"_+Y)
.S ^TMP("PSD",$J,PSDI(PSD(2)),PSD,+Y)="" K PSD
I X="^ALL" F S PSDU=$O(^PSD(58.8,+PSDLOC,1,PSDU)) Q:'PSDU D
.Q:'$O(^PSD(58.81,"F",PSDU,0))
.S PSD(1)=0 F S PSD(1)=$O(^PSD(58.8,PSDLOC,1,PSDU,2,PSD(1))) S:$D(PSDI(+PSD(1))) PSD(2)=PSD(1) Q:$G(PSD(2))!('PSD(1))
.Q:'$G(PSD(2))
.S PSD=$P($G(^PSDRUG(PSDU,0)),U)
.S PSD=$S(PSD]"":PSD,1:"UNKNOWN DRUG #"_PSDU)
.S ^TMP("PSD",$J,PSDI(PSD(2)),PSD,PSDU)="" K PSD
S DIR(0)="S^1:Sort by Rx #;2:Sort by Date Posted"
S DIR("A")="Within Drug, Sort by",DIR("B")=1
S DIR("?")="For each drug, do you want the transactions listed in the order they were posted or by Rx #?"
D ^DIR K DIR G:$D(DIRUT) END I Y=1 S PSDI=1 G ^PSDOPTX
S DIR(0)="D^2910501:NOW:AEPT",DIR("A")="Beginning date@time",DIR("?")="I will list Outpatient transactions for your selected drug(s) within your selected date@time range" W ! D ^DIR G:Y<1 END
S (PSDT,PSDTB)=Y,PSDTB(2)=Y(0),DIR(0)="D^"_PSDT_":NOW:AEPT"
S DIR("A")="Ending date@time"
W ! D ^DIR K DIR G:Y<1 END S PSDTB(1)=Y,PSDTB(3)=Y(0)
S:'$P(PSDTB(1),".",2) PSDTB(1)=PSDTB(1)+.999999
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^PSDOPTI",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 (PSD,PSDU)=0
F S PSD=$O(^TMP("PSD",$J,PSD)) Q:PSD']"" F S PSDU=$O(^TMP("PSD",$J,PSD,PSDU)) Q:PSDU']"" S PSDU(1)=$O(^TMP("PSD",$J,PSD,PSDU,0)) D G:PSDOUT END S PSDT=PSDTB,PSDT(1)=0
LOOP .F S PSDT=$O(^PSD(58.81,"ACT",PSDT)) W:$E(IOST)="C" "." Q:'PSDT!(PSDT>PSDTB(1)) D:$O(^PSD(58.81,"ACT",PSDT,0))=PSDLOC&($O(^PSD(58.81,"ACT",PSDT,PSDLOC,0))=PSDU(1))&($O(^PSD(58.81,"ACT",PSDT,PSDLOC,+PSDU(1),6,0))) Q:PSDOUT
..S PSDR(3)=+$O(^PSD(58.81,"ACT",PSDT,PSDLOC,+PSDU(1),6,0))
..S PSDR(2)=$G(^PSD(58.81,PSDR(3),0))
..S PSDR(4)=$G(^PSD(58.81,PSDR(3),6))
..D:$Y+6>IOSL HEADER Q:PSDOUT
..S PSDT(1)=$G(PSDT(1))+1 W:PSDT(1)=1 !,PSDU,?60,PSD,!
..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)
..N 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 ",PSDTB(2)," to ",PSDTB(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("PSDT"),ZTSAVE("PSDTB"),ZTSAVE("PSDTB("),ZTSAVE("PSDLOC"))=""
Q
PSDOPTI ;BIR/LTL - Review OP Transactions by Inventory Type ; 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 ^PSDRUG( are covered by DBIA221
+6 ;References to ^PSI(58.16 are covered by DBIA213
+7 ;References to ^PSRX( are covered by DBIA986
+8 SET CNT=0
WRITE !!,"You may select one, several, or ^ALL Inventory Types."
+9 NEW PSDI
SET PSDI=0
INV FOR
SET DIC="^PSI(58.16,"
SET DIC(0)="AEQ"
SET DIC("A")="Please Select Inventory Type: "
WRITE !
DO ^DIC
KILL DIC
IF X'="^ALL"&(Y<1)&('CNT)
GOTO END
IF Y<0
QUIT
SET PSDI(+Y)=$PIECE(Y,U,2)
SET CNT=CNT+1
+1 IF X="^ALL"
FOR
SET PSDI=$ORDER(^PSI(58.16,PSDI))
IF 'PSDI
QUIT
SET PSDI(PSDI)=$PIECE($GET(^PSI(58.16,PSDI,0)),U)
+2 SET CNT=0
WRITE !!,"Now, you may select one, several, or ^ALL drugs."
CHKD FOR
SET DIC="^PSD(58.8,+PSDLOC,1,"
SET DIC(0)="AEQ"
SET DIC("A")="Please Select "_PSDLOCN_"'s Drug: "
SET DIC("S")="I $S($G(^(""I"")):$G(^(""I""))>DT,1:1)"
WRITE !
DO ^DIC
KILL DIC
IF X'="^ALL"&(Y<1)&('CNT)
GOTO END
IF Y<0
QUIT
Begin DoDot:1
+1 IF '$ORDER(^PSD(58.81,"F",+Y,0))
WRITE !!,"There have been no transactions for this drug.",!!
QUIT
+2 SET PSD(1)=0
FOR
SET PSD(1)=$ORDER(^PSD(58.8,PSDLOC,1,+Y,2,PSD(1)))
IF $DATA(PSDI(+PSD(1)))
SET PSD(2)=PSD(1)
IF $GET(PSD(2))!('PSD(1))
QUIT
+3 IF '$GET(PSD(2))
WRITE !!,"Not in selected Inventory Type(s)",!!
QUIT
+4 SET PSD=$PIECE($GET(^PSDRUG(+Y,0)),U)
SET CNT=CNT+1
+5 SET PSD=$SELECT(PSD]"":PSD,1:"UNKNOWN DRUG #"_+Y)
+6 SET ^TMP("PSD",$JOB,PSDI(PSD(2)),PSD,+Y)=""
KILL PSD
End DoDot:1
+7 IF X="^ALL"
FOR
SET PSDU=$ORDER(^PSD(58.8,+PSDLOC,1,PSDU))
IF 'PSDU
QUIT
Begin DoDot:1
+8 IF '$ORDER(^PSD(58.81,"F",PSDU,0))
QUIT
+9 SET PSD(1)=0
FOR
SET PSD(1)=$ORDER(^PSD(58.8,PSDLOC,1,PSDU,2,PSD(1)))
IF $DATA(PSDI(+PSD(1)))
SET PSD(2)=PSD(1)
IF $GET(PSD(2))!('PSD(1))
QUIT
+10 IF '$GET(PSD(2))
QUIT
+11 SET PSD=$PIECE($GET(^PSDRUG(PSDU,0)),U)
+12 SET PSD=$SELECT(PSD]"":PSD,1:"UNKNOWN DRUG #"_PSDU)
+13 SET ^TMP("PSD",$JOB,PSDI(PSD(2)),PSD,PSDU)=""
KILL PSD
End DoDot:1
+14 SET DIR(0)="S^1:Sort by Rx #;2:Sort by Date Posted"
+15 SET DIR("A")="Within Drug, Sort by"
SET DIR("B")=1
+16 SET DIR("?")="For each drug, do you want the transactions listed in the order they were posted or by Rx #?"
+17 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO END
IF Y=1
SET PSDI=1
GOTO ^PSDOPTX
+18 SET DIR(0)="D^2910501:NOW:AEPT"
SET DIR("A")="Beginning date@time"
SET DIR("?")="I will list Outpatient transactions for your selected drug(s) within your selected date@time range"
WRITE !
DO ^DIR
IF Y<1
GOTO END
+19 SET (PSDT,PSDTB)=Y
SET PSDTB(2)=Y(0)
SET DIR(0)="D^"_PSDT_":NOW:AEPT"
+20 SET DIR("A")="Ending date@time"
+21 WRITE !
DO ^DIR
KILL DIR
IF Y<1
GOTO END
SET PSDTB(1)=Y
SET PSDTB(3)=Y(0)
+22 IF '$PIECE(PSDTB(1),".",2)
SET PSDTB(1)=PSDTB(1)+.999999
+23 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^PSDOPTI"
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 (PSD,PSDU)=0
+2 FOR
SET PSD=$ORDER(^TMP("PSD",$JOB,PSD))
IF PSD']""
QUIT
FOR
SET PSDU=$ORDER(^TMP("PSD",$JOB,PSD,PSDU))
IF PSDU']""
QUIT
SET PSDU(1)=$ORDER(^TMP("PSD",$JOB,PSD,PSDU,0))
Begin DoDot:1
LOOP FOR
SET PSDT=$ORDER(^PSD(58.81,"ACT",PSDT))
IF $EXTRACT(IOST)="C"
WRITE "."
IF 'PSDT!(PSDT>PSDTB(1))
QUIT
IF $ORDER(^PSD(58.81,"ACT",PSDT,0))=PSDLOC&($ORDER(^PSD(58.81,"ACT",PSDT,PSDLOC,0))=PSDU(1))&($ORDER(^PSD(58.81,"ACT",PSDT,PSDLOC,+PSDU(1),6,0)))
Begin DoDot:2
+1 SET PSDR(3)=+$ORDER(^PSD(58.81,"ACT",PSDT,PSDLOC,+PSDU(1),6,0))
+2 SET PSDR(2)=$GET(^PSD(58.81,PSDR(3),0))
+3 SET PSDR(4)=$GET(^PSD(58.81,PSDR(3),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,?60,PSD,!
+6 SET Y=$EXTRACT($PIECE(PSDR(2),U,4),1,12)
XECUTE ^DD("DD")
WRITE !,Y,?19
+7 SET DFN=$PIECE($GET(^PSRX(+$PIECE(PSDR(4),U),0)),U,2)
+8 NEW C
SET Y=DFN
SET C=$PIECE(^DD(58.81,73,0),U,2)
DO Y^DIQ
+9 WRITE $PIECE(PSDR(4),U,5),?28,Y
+10 DO PID^VADPT6
WRITE " ("_VA("BID")_")",?60
+11 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
+12 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
+13 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
+14 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
+15 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")
+16 WRITE !,LN,!
End DoDot:2
IF PSDOUT
QUIT
End DoDot:1
IF PSDOUT
GOTO END
SET PSDT=PSDTB
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 ",PSDTB(2)," to ",PSDTB(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("PSDT"),ZTSAVE("PSDTB"),ZTSAVE("PSDTB("),ZTSAVE("PSDLOC"))=""
+3 QUIT