PSGWSC ;BHAM ISC/PTD,CML-Cost Report for Single Item for Selected Date Range ; 11 Aug 93 / 7:52 AM
;;2.3; Automatic Replenishment/Ward Stock ;;4 JAN 94
W !?5,"Before printing this report, be sure accurate data exists for drug cost.",!?5,"Use ""Prepare AMIS Data"": ""Enter AMIS Data for All Drugs/All AOUs"".",!!
BDT S %DT="AEX",%DT("A")="BEGINNING date for report: " D ^%DT K %DT G:Y<0 END^PSGWSC1 S BDT=Y
EDT S %DT="AEX",%DT(0)=BDT,%DT("A")="ENDING date for report: " D ^%DT K %DT G:Y<0 END^PSGWSC1 S EDT=Y
D SEL^PSGWUTL1 G:'$D(SEL) END^PSGWSC1 G:SEL="I" AOUCNT
ASKAOU F JJ=0:0 S DIC="^PSI(58.1,",DIC(0)="QEAM" D ^DIC K DIC Q:Y<0 S AOULP(+Y)=""
I '$D(AOULP)&(X'="^ALL") G END^PSGWSC1
I X="^ALL" F AOU=0:0 S AOU=$O(^PSI(58.1,AOU)) Q:'AOU S AOULP(AOU)=""
AOUCNT G:'$D(AOULP) END^PSGWSC1 S AOUCNT=0 F JJ=0:0 S JJ=$O(AOULP(JJ)) Q:'JJ S AOUCNT=AOUCNT+1
ASKITEM W ! S DIC="^PSDRUG(",DIC(0)="QEAOM",DIC("A")="Select ITEM: ",DIC("S")="I $S('$D(^(""I"")):1,+^(""I"")>DT:1,1:0)" D ^DIC K DIC G:Y<0 END^PSGWSC1 S ITNAM=$P(Y,"^",2),DRGNM=$P(Y,"^")
S CHK=0 F JJ=0:0 S JJ=$O(AOULP(JJ)) Q:'JJ I $D(^PSI(58.1,JJ,1,"B",DRGNM)) S CHK=1 Q
I 'CHK W !!,*7,"This ITEM is not defined in the "_$S(AOUCNT>1:"AOUs",1:"AOU")_" you have selected!" G ASKITEM
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^PSGWSC1
I $D(IO("Q")) K IO("Q") S ZTRTN="ENQ^PSGWSC",ZTDESC="Print Cost for Single Item" S:$D(AOULP) ZTSAVE("AOULP(")="" F G="BDT","EDT","ITNAM","DRGNM","SEL","IGDA" S:$D(@G) ZTSAVE(G)=""
I D ^%ZTLOAD,HOME^%ZIS K ZTSK S QFLG=1 G DONE^PSGWSC1
U IO
;
ENQ ;ENTRY POINT WHEN QUEUED
;CREATE ARRAY OF INVENTORY NUMBERS THAT FALL IN DATE RANGE.
K ^TMP("PSGWSC",$J),^TMP("PSGWINV",$J) S INVN=0,AOU=0
F J=0:0 S INVN=$O(^PSI(58.19,INVN)) Q:'INVN S INVDT=$P($P(^PSI(58.19,INVN,0),"^"),".") I (INVDT'<BDT)&(INVDT'>EDT) S ^TMP("PSGWINV",$J,INVN)=""
AOU S AOU=$O(AOULP(AOU)) G:'AOU ^PSGWSC1
DRUG S DRGDA=$O(^PSI(58.1,AOU,1,"B",DRGNM,0)) G:'DRGDA AOU
;
AR ;AUTOMATIC REPLENISHMENT INVENTORIES
S DRGQD=0 G:'$O(^PSI(58.1,AOU,1,DRGDA,1,0)) OD S INVDA=0
INVLP S INVDA=$O(^PSI(58.1,AOU,1,DRGDA,1,INVDA)) G:'INVDA OD
I $D(^TMP("PSGWINV",$J,INVDA)) S QD=$P(^PSI(58.1,AOU,1,DRGDA,1,INVDA,0),"^",5),DRGQD=DRGQD+QD G INVLP
E G INVLP
;
OD ;ON DEMAND REQUESTS
G:'$O(^PSI(58.1,AOU,1,DRGDA,5,0)) RET S ODA=0
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),"^"),".")
I (ODT'<BDT)&(ODT'>EDT) S QD=$P(^PSI(58.1,AOU,1,DRGDA,5,ODA,0),"^",2),DRGQD=DRGQD+QD G ODLP
E G ODLP
;
RET ;RETURNS
G:'$O(^PSI(58.1,AOU,1,DRGDA,3,0)) CHKDTA S RETDT=0
RETLP S RETDT=$O(^PSI(58.1,AOU,1,DRGDA,3,RETDT)) G:'RETDT CHKDTA
I (RETDT'<BDT)&(RETDT'>EDT) S QD=$P(^PSI(58.1,AOU,1,DRGDA,3,RETDT,0),"^",2),DRGQD=DRGQD-QD G RETLP
E G RETLP
;
CHKDTA ;DETERMINE TOTAL COST FOR DRGQD OF SELECTED DRUG
G:DRGQD=0 AOU S INC=0 I $D(^PSDRUG(DRGNM,660)) S LOC1=^(660)
E S INC=1
I $D(^PSDRUG(DRGNM,"PSG")) S LOC2=^("PSG")
E S INC=1
I $D(LOC1),($P(LOC1,"^",6)="") S INC=1
I $D(LOC2),($P(LOC2,"^",3)="") S INC=1
COST I INC=0 S DRGCST=DRGQD*($P(LOC1,"^",6))
E S DRGCST="NO DATA"
SETGL S ^TMP("PSGWSC",$J,AOU)=DRGQD_"^"_DRGCST G AOU
;
PSGWSC ;BHAM ISC/PTD,CML-Cost Report for Single Item for Selected Date Range ; 11 Aug 93 / 7:52 AM
+1 ;;2.3; Automatic Replenishment/Ward Stock ;;4 JAN 94
+2 WRITE !?5,"Before printing this report, be sure accurate data exists for drug cost.",!?5,"Use ""Prepare AMIS Data"": ""Enter AMIS Data for All Drugs/All AOUs"".",!!
BDT SET %DT="AEX"
SET %DT("A")="BEGINNING date for report: "
DO ^%DT
KILL %DT
IF Y<0
GOTO END^PSGWSC1
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^PSGWSC1
SET EDT=Y
+1 DO SEL^PSGWUTL1
IF '$DATA(SEL)
GOTO END^PSGWSC1
IF SEL="I"
GOTO AOUCNT
ASKAOU FOR JJ=0:0
SET DIC="^PSI(58.1,"
SET DIC(0)="QEAM"
DO ^DIC
KILL DIC
IF Y<0
QUIT
SET AOULP(+Y)=""
+1 IF '$DATA(AOULP)&(X'="^ALL")
GOTO END^PSGWSC1
+2 IF X="^ALL"
FOR AOU=0:0
SET AOU=$ORDER(^PSI(58.1,AOU))
IF 'AOU
QUIT
SET AOULP(AOU)=""
AOUCNT IF '$DATA(AOULP)
GOTO END^PSGWSC1
SET AOUCNT=0
FOR JJ=0:0
SET JJ=$ORDER(AOULP(JJ))
IF 'JJ
QUIT
SET AOUCNT=AOUCNT+1
ASKITEM WRITE !
SET DIC="^PSDRUG("
SET DIC(0)="QEAOM"
SET DIC("A")="Select ITEM: "
SET DIC("S")="I $S('$D(^(""I"")):1,+^(""I"")>DT:1,1:0)"
DO ^DIC
KILL DIC
IF Y<0
GOTO END^PSGWSC1
SET ITNAM=$PIECE(Y,"^",2)
SET DRGNM=$PIECE(Y,"^")
+1 SET CHK=0
FOR JJ=0:0
SET JJ=$ORDER(AOULP(JJ))
IF 'JJ
QUIT
IF $DATA(^PSI(58.1,JJ,1,"B",DRGNM))
SET CHK=1
QUIT
+2 IF 'CHK
WRITE !!,*7,"This ITEM is not defined in the "_$SELECT(AOUCNT>1:"AOUs",1:"AOU")_" you have selected!"
GOTO ASKITEM
+3 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^PSGWSC1
+1 IF $DATA(IO("Q"))
KILL IO("Q")
SET ZTRTN="ENQ^PSGWSC"
SET ZTDESC="Print Cost for Single Item"
IF $DATA(AOULP)
SET ZTSAVE("AOULP(")=""
FOR G="BDT","EDT","ITNAM","DRGNM","SEL","IGDA"
IF $DATA(@G)
SET ZTSAVE(G)=""
+2 IF $TEST
DO ^%ZTLOAD
DO HOME^%ZIS
KILL ZTSK
SET QFLG=1
GOTO DONE^PSGWSC1
+3 USE IO
+4 ;
ENQ ;ENTRY POINT WHEN QUEUED
+1 ;CREATE ARRAY OF INVENTORY NUMBERS THAT FALL IN DATE RANGE.
+2 KILL ^TMP("PSGWSC",$JOB),^TMP("PSGWINV",$JOB)
SET INVN=0
SET AOU=0
+3 FOR J=0:0
SET INVN=$ORDER(^PSI(58.19,INVN))
IF 'INVN
QUIT
SET INVDT=$PIECE($PIECE(^PSI(58.19,INVN,0),"^"),".")
IF (INVDT'<BDT)&(INVDT'>EDT)
SET ^TMP("PSGWINV",$JOB,INVN)=""
AOU SET AOU=$ORDER(AOULP(AOU))
IF 'AOU
GOTO ^PSGWSC1
DRUG SET DRGDA=$ORDER(^PSI(58.1,AOU,1,"B",DRGNM,0))
IF 'DRGDA
GOTO AOU
+1 ;
AR ;AUTOMATIC REPLENISHMENT INVENTORIES
+1 SET DRGQD=0
IF '$ORDER(^PSI(58.1,AOU,1,DRGDA,1,0))
GOTO OD
SET INVDA=0
INVLP SET INVDA=$ORDER(^PSI(58.1,AOU,1,DRGDA,1,INVDA))
IF 'INVDA
GOTO OD
+1 IF $DATA(^TMP("PSGWINV",$JOB,INVDA))
SET QD=$PIECE(^PSI(58.1,AOU,1,DRGDA,1,INVDA,0),"^",5)
SET DRGQD=DRGQD+QD
GOTO INVLP
+2 IF '$TEST
GOTO INVLP
+3 ;
OD ;ON DEMAND REQUESTS
+1 IF '$ORDER(^PSI(58.1,AOU,1,DRGDA,5,0))
GOTO RET
SET ODA=0
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 IF (ODT'<BDT)&(ODT'>EDT)
SET QD=$PIECE(^PSI(58.1,AOU,1,DRGDA,5,ODA,0),"^",2)
SET DRGQD=DRGQD+QD
GOTO ODLP
+2 IF '$TEST
GOTO ODLP
+3 ;
RET ;RETURNS
+1 IF '$ORDER(^PSI(58.1,AOU,1,DRGDA,3,0))
GOTO CHKDTA
SET RETDT=0
RETLP SET RETDT=$ORDER(^PSI(58.1,AOU,1,DRGDA,3,RETDT))
IF 'RETDT
GOTO CHKDTA
+1 IF (RETDT'<BDT)&(RETDT'>EDT)
SET QD=$PIECE(^PSI(58.1,AOU,1,DRGDA,3,RETDT,0),"^",2)
SET DRGQD=DRGQD-QD
GOTO RETLP
+2 IF '$TEST
GOTO RETLP
+3 ;
CHKDTA ;DETERMINE TOTAL COST FOR DRGQD OF SELECTED DRUG
+1 IF DRGQD=0
GOTO AOU
SET INC=0
IF $DATA(^PSDRUG(DRGNM,660))
SET LOC1=^(660)
+2 IF '$TEST
SET INC=1
+3 IF $DATA(^PSDRUG(DRGNM,"PSG"))
SET LOC2=^("PSG")
+4 IF '$TEST
SET INC=1
+5 IF $DATA(LOC1)
IF ($PIECE(LOC1,"^",6)="")
SET INC=1
+6 IF $DATA(LOC2)
IF ($PIECE(LOC2,"^",3)="")
SET INC=1
COST IF INC=0
SET DRGCST=DRGQD*($PIECE(LOC1,"^",6))
+1 IF '$TEST
SET DRGCST="NO DATA"
SETGL SET ^TMP("PSGWSC",$JOB,AOU)=DRGQD_"^"_DRGCST
GOTO AOU
+1 ;