PSGWEXR ;BHAM ISC/CML-Drug Expiration Date Report by Selected Date Range/AOU ; 18 Jun 93 / 10:36 AM [ 09/28/95 11:55 AM ]
;;2.3; Automatic Replenishment/Ward Stock ;**5**;4 JAN 94
BDT S %DT="AEXT",%DT("A")="BEGINNING date for report: " D ^%DT K %DT G:Y<0 QUIT S BDT=Y
EDT S %DT="AEXT",%DT(0)=BDT,%DT("A")="ENDING date for report: " D ^%DT K %DT G:Y<0 QUIT S EDT=Y
I '$O(^PSI(58.1,"AEXP",BDT-1))!($O(^PSI(58.1,"AEXP",BDT-1))>EDT) W *7,!!,"NO DATA FOUND FOR THIS DATE RANGE!",! G BDT
EN D SEL^PSGWUTL1 G:'$D(SEL) QUIT I SEL="I" F JJ=0:0 S JJ=$O(AOULP(JJ)) Q:'JJ I $S('$D(^PSI(58.1,JJ,"I")):0,'^("I"):0,^("I")>DT:0,1:1) K AOULP(JJ)
G:SEL="I" AOUCNT
ASKAOU ;
F JJ=0:0 S DIC="^PSI(58.1,",DIC(0)="QEAM",DIC("S")="I $S('$D(^(""I"")):1,'^(""I""):1,^(""I"")>DT:1,1:0)" D ^DIC K DIC Q:Y<0 S AOULP(+Y)=""
I '$D(AOULP)&(X'="^ALL") G QUIT
I X="^ALL" F AOU=0:0 S AOU=$O(^PSI(58.1,AOU)) Q:'AOU I $S('$D(^PSI(58.1,AOU,"I")):1,'^("I"):1,^("I")>DT:1,1:0) S AOULP(AOU)=""
AOUCNT G:'$D(AOULP) QUIT S LOCFLG=0 S JJ="" F CNT=0:1 S JJ=$O(AOULP(JJ)) Q:'JJ S AOULP(JJ)=$P(^PSI(58.1,JJ,0),"^",6) S:AOULP(JJ) LOCFLG=1
;SORT=1 - DATE/DRUG/AOU SORT=2 - DATE/AOU/DRUG
S SORT="" I CNT>1 W !!?5,"Since you have chosen multiple AOUs,",!?5,"please select a sort order for the report:",!!?5,"(1) Date/Drug/AOU or (2) Date/AOU/Drug" D ASKSORT
G:SORT="^" QUIT
W !!,"The right margin for this report is 80.",!,"You may queue the report to print at a later time.",!!
DEV K %ZIS,IOP S %ZIS="QM",%ZIS("B")="" D ^%ZIS I POP W !,"NO DEVICE SELECTED OR REPORT PRINTED!" G QUIT
I $D(IO("Q")) K IO("Q") S PSGWIO=ION,ZTIO="" K ZTSAVE,ZTDTH,ZTSK
I S ZTRTN="START^PSGWEXR",ZTDESC="Print Drug Expiration Date Report" S:$D(AOULP) ZTSAVE("AOULP(")="" F G="BDT","EDT","CNT","PSGWIO","SORT","SEL","IGDA","LOCFLG" S:$D(@G) ZTSAVE(G)=""
I D ^%ZTLOAD,HOME^%ZIS K ZTSK G QUIT
U IO
;
START ;ENTRY POINT WHEN QUEUED
K ^TMP("PSGWEXR",$J) I BDT#100 S BDT=BDT-1
F EXDT=BDT-1:0 S EXDT=$O(^PSI(58.1,"AEXP",EXDT)) Q:'EXDT Q:EXDT>EDT F DRG=0:0 S DRG=$O(^PSI(58.1,"AEXP",EXDT,DRG)) Q:'DRG F AOU=0:0 S AOU=$O(^PSI(58.1,"AEXP",EXDT,DRG,AOU)) Q:'AOU I $D(AOULP(AOU)) D SET
I '$D(ZTQUEUED) G:LOCFLG PRINT^PSGWEXR2 G:'LOCFLG PRINT^PSGWEXR1
PRTQUE ;AFTER DATA IS COMPILED, QUEUE THE PRINT
K ZTSAVE,ZTIO S ZTIO=PSGWIO,ZTRTN=$S(LOCFLG:"PRINT^PSGWEXR2",1:"PRINT^PSGWEXR1"),ZTDESC="Print Drug Expiration Date Report",ZTDTH=$H,ZTSAVE("^TMP(""PSGWEXR"",$J,")=""
S:$D(AOULP) ZTSAVE("AOULP(")="" F G="BDT","EDT","CNT","SORT","SEL","IGDA" S:$D(@G) ZTSAVE(G)=""
D ^%ZTLOAD K ^TMP("PSGWEXR",$J)
QUIT K %,%H,%I,%Z,AOU,AOULP,AOUNM,BDT,DRG,DRGNM,EDT,EXDT,HDT,HH,JJ,LOC,LOCFLG,LN,PG,SEL,IGDA,X,Y,CNT,SORT,P1,PSGWIO,P2,G,TAB,ZTSK,IO("Q") D ^%ZISC
Q
SET ;
S DRGNM=$S($D(^PSDRUG(DRG,0)):$P(^(0),"^"),1:"DRUG NAME MISSING"),AOUNM=$S($D(^PSI(58.1,AOU,0)):$P(^(0),"^"),1:"AOU NAME MISSING")
S:SORT=1!(CNT<2) ^TMP("PSGWEXR",$J,EXDT,DRGNM,AOUNM)=AOU S:SORT=2 ^TMP("PSGWEXR",$J,EXDT,AOUNM,DRGNM)=AOU Q
ASKSORT ;
F JJ=0:0 R !!,"Enter '1' or '2' or ""^"" to Exit ==> ",SORT:DTIME S:'$T SORT="^" Q:"^"[SORT Q:SORT=1!(SORT=2) D HELP
S:SORT="" SORT="^" Q
HELP ;
W:SORT'?."?" *7," ??" W !!,?5,"Enter '1' to sort by Expiration Date, then Drug, then AOU.",!?5,"Enter '2' to sort by Expiration Date, then AOU, then Drug.",!?5,"Enter ""^"" to Exit." Q
PSGWEXR ;BHAM ISC/CML-Drug Expiration Date Report by Selected Date Range/AOU ; 18 Jun 93 / 10:36 AM [ 09/28/95 11:55 AM ]
+1 ;;2.3; Automatic Replenishment/Ward Stock ;**5**;4 JAN 94
BDT SET %DT="AEXT"
SET %DT("A")="BEGINNING date for report: "
DO ^%DT
KILL %DT
IF Y<0
GOTO QUIT
SET BDT=Y
EDT SET %DT="AEXT"
SET %DT(0)=BDT
SET %DT("A")="ENDING date for report: "
DO ^%DT
KILL %DT
IF Y<0
GOTO QUIT
SET EDT=Y
+1 IF '$ORDER(^PSI(58.1,"AEXP",BDT-1))!($ORDER(^PSI(58.1,"AEXP",BDT-1))>EDT)
WRITE *7,!!,"NO DATA FOUND FOR THIS DATE RANGE!",!
GOTO BDT
EN DO SEL^PSGWUTL1
IF '$DATA(SEL)
GOTO QUIT
IF SEL="I"
FOR JJ=0:0
SET JJ=$ORDER(AOULP(JJ))
IF 'JJ
QUIT
IF $SELECT('$DATA(^PSI(58.1,JJ,"I")):0,'^("I"):0,^("I")>DT:0,1:1)
KILL AOULP(JJ)
+1 IF SEL="I"
GOTO AOUCNT
ASKAOU ;
+1 FOR JJ=0:0
SET DIC="^PSI(58.1,"
SET DIC(0)="QEAM"
SET DIC("S")="I $S('$D(^(""I"")):1,'^(""I""):1,^(""I"")>DT:1,1:0)"
DO ^DIC
KILL DIC
IF Y<0
QUIT
SET AOULP(+Y)=""
+2 IF '$DATA(AOULP)&(X'="^ALL")
GOTO QUIT
+3 IF X="^ALL"
FOR AOU=0:0
SET AOU=$ORDER(^PSI(58.1,AOU))
IF 'AOU
QUIT
IF $SELECT('$DATA(^PSI(58.1,AOU,"I")):1,'^("I"):1,^("I")>DT:1,1:0)
SET AOULP(AOU)=""
AOUCNT IF '$DATA(AOULP)
GOTO QUIT
SET LOCFLG=0
SET JJ=""
FOR CNT=0:1
SET JJ=$ORDER(AOULP(JJ))
IF 'JJ
QUIT
SET AOULP(JJ)=$PIECE(^PSI(58.1,JJ,0),"^",6)
IF AOULP(JJ)
SET LOCFLG=1
+1 ;SORT=1 - DATE/DRUG/AOU SORT=2 - DATE/AOU/DRUG
+2 SET SORT=""
IF CNT>1
WRITE !!?5,"Since you have chosen multiple AOUs,",!?5,"please select a sort order for the report:",!!?5,"(1) Date/Drug/AOU or (2) Date/AOU/Drug"
DO ASKSORT
+3 IF SORT="^"
GOTO QUIT
+4 WRITE !!,"The right margin for this report is 80.",!,"You may queue the report to print at a later time.",!!
DEV KILL %ZIS,IOP
SET %ZIS="QM"
SET %ZIS("B")=""
DO ^%ZIS
IF POP
WRITE !,"NO DEVICE SELECTED OR REPORT PRINTED!"
GOTO QUIT
+1 IF $DATA(IO("Q"))
KILL IO("Q")
SET PSGWIO=ION
SET ZTIO=""
KILL ZTSAVE,ZTDTH,ZTSK
+2 IF $TEST
SET ZTRTN="START^PSGWEXR"
SET ZTDESC="Print Drug Expiration Date Report"
IF $DATA(AOULP)
SET ZTSAVE("AOULP(")=""
FOR G="BDT","EDT","CNT","PSGWIO","SORT","SEL","IGDA","LOCFLG"
IF $DATA(@G)
SET ZTSAVE(G)=""
+3 IF $TEST
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO QUIT
+4 USE IO
+5 ;
START ;ENTRY POINT WHEN QUEUED
+1 KILL ^TMP("PSGWEXR",$JOB)
IF BDT#100
SET BDT=BDT-1
+2 FOR EXDT=BDT-1:0
SET EXDT=$ORDER(^PSI(58.1,"AEXP",EXDT))
IF 'EXDT
QUIT
IF EXDT>EDT
QUIT
FOR DRG=0:0
SET DRG=$ORDER(^PSI(58.1,"AEXP",EXDT,DRG))
IF 'DRG
QUIT
FOR AOU=0:0
SET AOU=$ORDER(^PSI(58.1,"AEXP",EXDT,DRG,AOU))
IF 'AOU
QUIT
IF $DATA(AOULP(AOU))
DO SET
+3 IF '$DATA(ZTQUEUED)
IF LOCFLG
GOTO PRINT^PSGWEXR2
IF 'LOCFLG
GOTO PRINT^PSGWEXR1
PRTQUE ;AFTER DATA IS COMPILED, QUEUE THE PRINT
+1 KILL ZTSAVE,ZTIO
SET ZTIO=PSGWIO
SET ZTRTN=$SELECT(LOCFLG:"PRINT^PSGWEXR2",1:"PRINT^PSGWEXR1")
SET ZTDESC="Print Drug Expiration Date Report"
SET ZTDTH=$HOROLOG
SET ZTSAVE("^TMP(""PSGWEXR"",$J,")=""
+2 IF $DATA(AOULP)
SET ZTSAVE("AOULP(")=""
FOR G="BDT","EDT","CNT","SORT","SEL","IGDA"
IF $DATA(@G)
SET ZTSAVE(G)=""
+3 DO ^%ZTLOAD
KILL ^TMP("PSGWEXR",$JOB)
QUIT KILL %,%H,%I,%Z,AOU,AOULP,AOUNM,BDT,DRG,DRGNM,EDT,EXDT,HDT,HH,JJ,LOC,LOCFLG,LN,PG,SEL,IGDA,X,Y,CNT,SORT,P1,PSGWIO,P2,G,TAB,ZTSK,IO("Q")
DO ^%ZISC
+1 QUIT
SET ;
+1 SET DRGNM=$SELECT($DATA(^PSDRUG(DRG,0)):$PIECE(^(0),"^"),1:"DRUG NAME MISSING")
SET AOUNM=$SELECT($DATA(^PSI(58.1,AOU,0)):$PIECE(^(0),"^"),1:"AOU NAME MISSING")
+2 IF SORT=1!(CNT<2)
SET ^TMP("PSGWEXR",$JOB,EXDT,DRGNM,AOUNM)=AOU
IF SORT=2
SET ^TMP("PSGWEXR",$JOB,EXDT,AOUNM,DRGNM)=AOU
QUIT
ASKSORT ;
+1 FOR JJ=0:0
READ !!,"Enter '1' or '2' or ""^"" to Exit ==> ",SORT:DTIME
IF '$TEST
SET SORT="^"
IF "^"[SORT
QUIT
IF SORT=1!(SORT=2)
QUIT
DO HELP
+2 IF SORT=""
SET SORT="^"
QUIT
HELP ;
+1 IF SORT'?."?"
WRITE *7," ??"
WRITE !!,?5,"Enter '1' to sort by Expiration Date, then Drug, then AOU.",!?5,"Enter '2' to sort by Expiration Date, then AOU, then Drug.",!?5,"Enter ""^"" to Exit."
QUIT