PSGWNU ;BHAM ISC/PTD,CML-Print Drugs (Items) with NO Usage for Selected Date Range ; 19 Mar 93 / 8:31 AM
;;2.3; Automatic Replenishment/Ward Stock ;;4 JAN 94
BDT S %DT="AEX",%DT("A")="BEGINNING date for report: " D ^%DT K %DT G:Y<0 END^PSGWNU1 S BDT=Y
EDT S %DT="AEX",%DT(0)=BDT,%DT("A")="ENDING date for report: " D ^%DT K %DT G:Y<0 END^PSGWNU1 S EDT=Y
D SEL^PSGWUTL1 G:'$D(SEL) END^PSGWNU1 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" EN
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 END^PSGWNU1
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)=""
EN G:'$D(AOULP) END^PSGWNU1 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 END^PSGWNU1
I $D(IO("Q")) K IO("Q") S PSGWIO=ION,ZTIO="" K ZTSAVE,ZTDTH,ZTSK S ZTRTN="ENQ^PSGWNU",ZTDESC="Compile Zero Usage" S:$D(AOULP) ZTSAVE("AOULP(")="" F G="BDT","EDT","AOU","PSGWIO","SEL","IGDA" S:$D(@G) ZTSAVE(G)=""
I D ^%ZTLOAD,HOME^%ZIS K ZTSK G END^PSGWNU1
U IO
;
ENQ ;ENTRY POINT WHEN QUEUED
K ^TMP("PSGWNU",$J) S AOU=""
AOU S AOU=$O(AOULP(AOU)) G:('AOU)&($D(ZTQUEUED)) PRTQUE G:'AOU ^PSGWNU1
DRUG ;LOOP THROUGH DRUGS FOR AOU
S DRGDA=0
DRGLP S DRGDA=$O(^PSI(58.1,AOU,1,DRGDA)) G:'DRGDA AOU S DRGNM=$P(^PSI(58.1,AOU,1,DRGDA,0),"^")
I '$O(^PSDRUG(DRGNM,0)) S DIK="^PSI(58.1,"_AOU_",1,",DA=DRGDA,DA(1)=AOU D ^DIK K DIK G DRGLP
S DRGNAME=$P(^PSDRUG(DRGNM,0),"^")
INACT I $P(^PSI(58.1,AOU,1,DRGDA,0),"^",10)="Y",$P(^(0),"^",3)="" S $P(^(0),"^",10)=""
I $P(^PSI(58.1,AOU,1,DRGDA,0),"^",3)'="" G DRGLP
;
AR ;AUTOMATIC REPLENISHMENT INVENTORIES
S (DRGQD,INVDA)=0,AR=""
INVLP S INVDA=$O(^PSI(58.1,AOU,1,DRGDA,1,INVDA)) G:'INVDA OD S ARDT=$S($D(^PSI(58.19,INVDA,0)):$P(^(0),"^"),1:"")
I 'ARDT,'$D(^PSI(58.19,INVDA,0)) S DIE="^PSI(58.1,AOU,1,DRGDA,1,",DA=INVDA,DA(1)=DRGDA,DA(2)=AOU,DR=".01///@" D ^DIE K DIE G INVLP
S QD=$P(^PSI(58.1,AOU,1,DRGDA,1,INVDA,0),"^",5) I (QD'="")&(QD>0)&(ARDT>AR) S AR=ARDT
I (ARDT'<BDT)&(ARDT'>EDT) S DRGQD=DRGQD+QD
G INVLP
;
OD ;ON DEMAND REQUESTS
S ODA=0,OD=""
ODLP S ODA=$O(^PSI(58.1,AOU,1,DRGDA,5,ODA)) G:'ODA RET S ODT=$P($P(^PSI(58.1,AOU,1,DRGDA,5,ODA,0),"^"),".")
S QD=$P(^PSI(58.1,AOU,1,DRGDA,5,ODA,0),"^",2) I (QD'="")&(QD>0)&(ODT>OD) S OD=ODT
I (ODT'<BDT)&(ODT'>EDT) S DRGQD=DRGQD+QD
G ODLP
;
RET ;RETURNS
S RETDT=0,RFLG="N"
RETLP S RETDT=$O(^PSI(58.1,AOU,1,DRGDA,3,RETDT)) G:'RETDT SETGL
I (RETDT'<BDT)&(RETDT'>EDT) S QD=$P(^PSI(58.1,AOU,1,DRGDA,3,RETDT,0),"^",2),DRGQD=DRGQD-QD,RFLG="Y"
G RETLP
;
SETGL S:DRGQD<1 ^TMP("PSGWNU",$J,AOU,DRGNAME)=AR_"^"_OD_"^"_RFLG_"^"_DRGQD_"^"_DRGNM G DRGLP
;
PRTQUE ;AFTER DATA IS COMPILED, QUEUE THE PRINT
K ZTSAVE,ZTIO S ZTIO=PSGWIO,ZTRTN="^PSGWNU1",ZTDESC="Print Zero Usage",ZTDTH=$H,ZTSAVE("^TMP(""PSGWNU"",$J,")="" F G="BDT","EDT","AOU","SEL","IGDA" S:$D(@G) ZTSAVE(G)=""
D ^%ZTLOAD K ^TMP("PSGWNU",$J) G END^PSGWNU1
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSGWNU 3254 printed Nov 22, 2024@16:49:48 Page 2
PSGWNU ;BHAM ISC/PTD,CML-Print Drugs (Items) with NO Usage for Selected Date Range ; 19 Mar 93 / 8:31 AM
+1 ;;2.3; Automatic Replenishment/Ward Stock ;;4 JAN 94
BDT SET %DT="AEX"
SET %DT("A")="BEGINNING date for report: "
DO ^%DT
KILL %DT
if Y<0
GOTO END^PSGWNU1
SET BDT=Y
EDT SET %DT="AEX"
SET %DT(0)=BDT
SET %DT("A")="ENDING date for report: "
DO ^%DT
KILL %DT
if Y<0
GOTO END^PSGWNU1
SET EDT=Y
+1 DO SEL^PSGWUTL1
if '$DATA(SEL)
GOTO END^PSGWNU1
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)
+2 if SEL="I"
GOTO EN
ASKAOU 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)=""
+1 IF '$DATA(AOULP)&(X'="^ALL")
GOTO END^PSGWNU1
+2 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)=""
EN if '$DATA(AOULP)
GOTO END^PSGWNU1
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 END^PSGWNU1
+1 IF $DATA(IO("Q"))
KILL IO("Q")
SET PSGWIO=ION
SET ZTIO=""
KILL ZTSAVE,ZTDTH,ZTSK
SET ZTRTN="ENQ^PSGWNU"
SET ZTDESC="Compile Zero Usage"
if $DATA(AOULP)
SET ZTSAVE("AOULP(")=""
FOR G="BDT","EDT","AOU","PSGWIO","SEL","IGDA"
if $DATA(@G)
SET ZTSAVE(G)=""
+2 IF $TEST
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
GOTO END^PSGWNU1
+3 USE IO
+4 ;
ENQ ;ENTRY POINT WHEN QUEUED
+1 KILL ^TMP("PSGWNU",$JOB)
SET AOU=""
AOU SET AOU=$ORDER(AOULP(AOU))
if ('AOU)&($DATA(ZTQUEUED))
GOTO PRTQUE
if 'AOU
GOTO ^PSGWNU1
DRUG ;LOOP THROUGH DRUGS FOR AOU
+1 SET DRGDA=0
DRGLP SET DRGDA=$ORDER(^PSI(58.1,AOU,1,DRGDA))
if 'DRGDA
GOTO AOU
SET DRGNM=$PIECE(^PSI(58.1,AOU,1,DRGDA,0),"^")
+1 IF '$ORDER(^PSDRUG(DRGNM,0))
SET DIK="^PSI(58.1,"_AOU_",1,"
SET DA=DRGDA
SET DA(1)=AOU
DO ^DIK
KILL DIK
GOTO DRGLP
+2 SET DRGNAME=$PIECE(^PSDRUG(DRGNM,0),"^")
INACT IF $PIECE(^PSI(58.1,AOU,1,DRGDA,0),"^",10)="Y"
IF $PIECE(^(0),"^",3)=""
SET $PIECE(^(0),"^",10)=""
+1 IF $PIECE(^PSI(58.1,AOU,1,DRGDA,0),"^",3)'=""
GOTO DRGLP
+2 ;
AR ;AUTOMATIC REPLENISHMENT INVENTORIES
+1 SET (DRGQD,INVDA)=0
SET AR=""
INVLP SET INVDA=$ORDER(^PSI(58.1,AOU,1,DRGDA,1,INVDA))
if 'INVDA
GOTO OD
SET ARDT=$SELECT($DATA(^PSI(58.19,INVDA,0)):$PIECE(^(0),"^"),1:"")
+1 IF 'ARDT
IF '$DATA(^PSI(58.19,INVDA,0))
SET DIE="^PSI(58.1,AOU,1,DRGDA,1,"
SET DA=INVDA
SET DA(1)=DRGDA
SET DA(2)=AOU
SET DR=".01///@"
DO ^DIE
KILL DIE
GOTO INVLP
+2 SET QD=$PIECE(^PSI(58.1,AOU,1,DRGDA,1,INVDA,0),"^",5)
IF (QD'="")&(QD>0)&(ARDT>AR)
SET AR=ARDT
+3 IF (ARDT'<BDT)&(ARDT'>EDT)
SET DRGQD=DRGQD+QD
+4 GOTO INVLP
+5 ;
OD ;ON DEMAND REQUESTS
+1 SET ODA=0
SET OD=""
ODLP SET ODA=$ORDER(^PSI(58.1,AOU,1,DRGDA,5,ODA))
if 'ODA
GOTO RET
SET ODT=$PIECE($PIECE(^PSI(58.1,AOU,1,DRGDA,5,ODA,0),"^"),".")
+1 SET QD=$PIECE(^PSI(58.1,AOU,1,DRGDA,5,ODA,0),"^",2)
IF (QD'="")&(QD>0)&(ODT>OD)
SET OD=ODT
+2 IF (ODT'<BDT)&(ODT'>EDT)
SET DRGQD=DRGQD+QD
+3 GOTO ODLP
+4 ;
RET ;RETURNS
+1 SET RETDT=0
SET RFLG="N"
RETLP SET RETDT=$ORDER(^PSI(58.1,AOU,1,DRGDA,3,RETDT))
if 'RETDT
GOTO SETGL
+1 IF (RETDT'<BDT)&(RETDT'>EDT)
SET QD=$PIECE(^PSI(58.1,AOU,1,DRGDA,3,RETDT,0),"^",2)
SET DRGQD=DRGQD-QD
SET RFLG="Y"
+2 GOTO RETLP
+3 ;
SETGL if DRGQD<1
SET ^TMP("PSGWNU",$JOB,AOU,DRGNAME)=AR_"^"_OD_"^"_RFLG_"^"_DRGQD_"^"_DRGNM
GOTO DRGLP
+1 ;
PRTQUE ;AFTER DATA IS COMPILED, QUEUE THE PRINT
+1 KILL ZTSAVE,ZTIO
SET ZTIO=PSGWIO
SET ZTRTN="^PSGWNU1"
SET ZTDESC="Print Zero Usage"
SET ZTDTH=$HOROLOG
SET ZTSAVE("^TMP(""PSGWNU"",$J,")=""
FOR G="BDT","EDT","AOU","SEL","IGDA"
if $DATA(@G)
SET ZTSAVE(G)=""
+2 DO ^%ZTLOAD
KILL ^TMP("PSGWNU",$JOB)
GOTO END^PSGWNU1
+3 ;