PSGWEXR ;BHAM ISC/CML-Drug Expiration Date Report by Selected Date Range/AOU ; 26 Oct 95 8:12AM
;;2.3; Automatic Replenishment/Ward Stock ;**5,6**;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
S LPDT=BDT I BDT#100=1 S LPDT=LPDT-1
I '$O(^PSI(58.1,"AEXP",LPDT-1))!($O(^PSI(58.1,"AEXP",LPDT-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","LPDT" 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)
F EXDT=LPDT-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,LPDT,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
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSGWEXR 3333 printed Dec 13, 2024@01:39:19 Page 2
PSGWEXR ;BHAM ISC/CML-Drug Expiration Date Report by Selected Date Range/AOU ; 26 Oct 95 8:12AM
+1 ;;2.3; Automatic Replenishment/Ward Stock ;**5,6**;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 SET LPDT=BDT
IF BDT#100=1
SET LPDT=LPDT-1
+2 IF '$ORDER(^PSI(58.1,"AEXP",LPDT-1))!($ORDER(^PSI(58.1,"AEXP",LPDT-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","LPDT"
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)
+2 FOR EXDT=LPDT-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,LPDT,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