PSDADJ ;BIR/LTL-Adjustments ; 8 Aug 94
;;3.0; CONTROLLED SUBSTANCES ;**16,66**;13 Feb 97;Build 3
;
;References to ^PSD(58.8, supported by DBIA2711
;References to ^PSD(58.81 are supported by DBIA2808
;References to ^PSDRUG( supported by DBIA #221
;
I '$D(PSDSITE) D ^PSDSET G:'$D(PSDSITE) QUIT
I '$D(^XUSEC("PSDMGR",DUZ)) W !!,"Sorry, you need the PSDMGR Security key to do adjustments.",!! G QUIT
I $P($G(^VA(200,DUZ,20)),U,4)']"" N XQH S XQH="PSD ESIG" D EN^XQH G QUIT
N DIC,DIE,DINUM,D0,D1,DLAYGO,DR,DIR,DIRUT,DTOUT,DUOUT,PSDAT,PSDB,PSDEX,PSDLOC,PSDLOCN,DA,PSDRUG,PSDRUGN,PSDOK,PSDS,PSAQ,PSDR,PSDREC,PSDT,X,Y,%,%H,%I
S DIR(0)="Y",DIR("A")="Review",DIR("B")="No",DIR("?")="If you answer yes, you will be shown all adjustments performed within a selected time range." D ^DIR K DIR G:$D(DIRUT) QUIT G:Y=1 ^PSDADJR
S PSDLOC=$P(PSDSITE,U,3),PSDLOCN=$P(PSDSITE,U,4)
G:$P(PSDSITE,U,5) CHKD
LOOK S DIC="^PSD(58.8,",DIC(0)="AEQ",DIC("A")="Select Dispensing Site: "
S DIC("S")="I $P($G(^(0)),U,3)=+PSDSITE,$S($P($G(^(0)),U,2)[""M"":1,$P($G(^(0)),U,2)[""S"":1,1:0),$S('$D(^(""I"")):1,+^(""I"")>DT:1,'^(""I""):1,1:0)"
S DIC("B")=$P(PSDSITE,U,4)
D ^DIC K DIC G:$D(DTOUT)!($D(DUOUT))!(Y<1) QUIT
S PSDLOC=+Y,PSDLOCN=$P(Y,U,2)
S $P(PSDSITE,U,3)=+Y,$P(PSDSITE,U,4)=$P(Y,U,2)
CHKD I '$O(^PSD(58.8,PSDLOC,1,0)) W !!,"There are no drugs in ",PSDLOCN G QUIT
N X,X1 D SIG^XUSESIG I X1="" G QUIT
F S DIC="^PSD(58.8,PSDLOC,1,",DIC(0)="AEMQZ",DIC("A")="Select "_PSDLOCN_" drug: ",DIC("S")="I $S($P($G(^(0)),U,14):$P($G(^(0)),U,14)>DT,1:1)",DA(1)=PSDLOC W ! D ^DIC K DIC G:Y<1 QUIT D G:$D(DIRUT) QUIT D:$D(PSDEX) DEST^PSDGSRV1 K PSDEX
.S PSDRUG=+Y,PSDRUGN=$P($G(^PSDRUG(+Y,0)),U)
.;DAVE B (28APR99) Moving lock of PSD(58.8,LOC,1,DRUG) up.
.F L +^PSD(58.8,+PSDLOC,1,+PSDRUG,0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) I Q
.S PSAQ=$P($G(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,4)
.W !!,"Current Balance: ",PSAQ,?40
.W "Breakdown Unit: ",$P($G(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,8),!
.S DIR(0)="N^"_-PSAQ_":999999:2" S DIR("A")="Enter adjustment quantity (with '-' if negative)" D ^DIR K DIR Q:$D(DIRUT)
.S PSDREC=Y
.S DIR(0)="F^1:45",DIR("A")="Please enter reason for adjustment" W ! D ^DIR K DIR Q:$D(DIRUT) S PSDR=Y
POST .S DIR(0)="Y",DIR("A")="OK to post",DIR("B")="Yes",DIR("?")="Answer 'YES' to adjust your inventory balance, 'NO' or '^' to quit." W ! D ^DIR K DIR D:Y=1 L -^PSD(58.8,+PSDLOC,1,+PSDRUG,0) K PSDRUG Q
..W !!,"There were ",$S($P($G(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,4):$P($G(^(0)),U,4),1:0)," on hand.",?40,"There are now ",$P($G(^(0)),U,4)+PSDREC," on hand.",!
..;F L +^PSD(58.8,+PSDLOC,1,+PSDRUG,0):0 I Q
..D NOW^%DTC S PSDAT=+%
..S PSAQ=$P($G(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,4)
..S $P(^PSD(58.8,+PSDLOC,1,+PSDRUG,0),U,4)=PSDREC+PSAQ
..L -^PSD(58.8,+PSDLOC,1,+PSDRUG,0)
MON ..S:'$D(^PSD(58.8,+PSDLOC,1,+PSDRUG,5,0)) ^(0)="^58.801A^^"
..I '$D(^PSD(58.8,+PSDLOC,1,+PSDRUG,5,$E(DT,1,5)*100,0)) S DIC="^PSD(58.8,+PSDLOC,1,+PSDRUG,5,",DIC(0)="LM",DLAYGO=58.8,(X,DINUM)=$E(DT,1,5)*100,DA(2)=PSDLOC,DA(1)=PSDRUG D ^DIC K DIC,DLAYGO
..S DIE="^PSD(58.8,+PSDLOC,1,+PSDRUG,5,",DA(2)=PSDLOC,DA(1)=PSDRUG,DA=$E(DT,1,5)*100,DR="7////^S X=$P($G(^(0)),U,5)+PSDREC" D ^DIE
..W !,"Updating monthly adjustments and transaction history.",!
TR ..F L +^PSD(58.81,0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) I Q
FIND ..S PSDT=$P(^PSD(58.81,0),U,3)+1 I $D(^PSD(58.81,PSDT)) S $P(^PSD(58.81,0),U,3)=$P(^PSD(58.81,0),U,3)+1 G FIND
..S DIC="^PSD(58.81,",DIC(0)="L",DLAYGO=58.81,(DINUM,X)=PSDT D ^DIC K DIC,DLAYGO L -^PSD(58.81,0)
..S DIE="^PSD(58.81,",DA=PSDT,DR="1////9;2////^S X=PSDLOC;3////^S X=PSDAT;4////^S X=PSDRUG;5////^S X=PSDREC;6////^S X=DUZ;9////^S X=PSAQ;15////^S X=PSDR;100////1" D ^DIE K DIE
..S:'$D(^PSD(58.8,+PSDLOC,1,+PSDRUG,4,0)) ^(0)="^58.800119PA^^"
..S DIC="^PSD(58.8,+PSDLOC,1,+PSDRUG,4,",DIC(0)="L",DLAYGO=58.8
..S (X,DINUM)=PSDT
..S DA(2)=PSDLOC,DA(1)=PSDRUG D ^DIC K DIC,DA,DLAYGO S Y=1
..I PSDREC<0 S DIR(0)="Y",DIR("A")="To be destroyed",DIR("B")="No" D ^DIR K DIR I Y=1 S PSDEX=1,PSDA=PSDT,PSDOK=1
QUIT Q
PSDADJ ;BIR/LTL-Adjustments ; 8 Aug 94
+1 ;;3.0; CONTROLLED SUBSTANCES ;**16,66**;13 Feb 97;Build 3
+2 ;
+3 ;References to ^PSD(58.8, supported by DBIA2711
+4 ;References to ^PSD(58.81 are supported by DBIA2808
+5 ;References to ^PSDRUG( supported by DBIA #221
+6 ;
+7 IF '$DATA(PSDSITE)
DO ^PSDSET
IF '$DATA(PSDSITE)
GOTO QUIT
+8 IF '$DATA(^XUSEC("PSDMGR",DUZ))
WRITE !!,"Sorry, you need the PSDMGR Security key to do adjustments.",!!
GOTO QUIT
+9 IF $PIECE($GET(^VA(200,DUZ,20)),U,4)']""
NEW XQH
SET XQH="PSD ESIG"
DO EN^XQH
GOTO QUIT
+10 NEW DIC,DIE,DINUM,D0,D1,DLAYGO,DR,DIR,DIRUT,DTOUT,DUOUT,PSDAT,PSDB,PSDEX,PSDLOC,PSDLOCN,DA,PSDRUG,PSDRUGN,PSDOK,PSDS,PSAQ,PSDR,PSDREC,PSDT,X,Y,%,%H,%I
+11 SET DIR(0)="Y"
SET DIR("A")="Review"
SET DIR("B")="No"
SET DIR("?")="If you answer yes, you will be shown all adjustments performed within a selected time range."
DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO QUIT
IF Y=1
GOTO ^PSDADJR
+12 SET PSDLOC=$PIECE(PSDSITE,U,3)
SET PSDLOCN=$PIECE(PSDSITE,U,4)
+13 IF $PIECE(PSDSITE,U,5)
GOTO CHKD
LOOK SET DIC="^PSD(58.8,"
SET DIC(0)="AEQ"
SET DIC("A")="Select Dispensing Site: "
+1 SET DIC("S")="I $P($G(^(0)),U,3)=+PSDSITE,$S($P($G(^(0)),U,2)[""M"":1,$P($G(^(0)),U,2)[""S"":1,1:0),$S('$D(^(""I"")):1,+^(""I"")>DT:1,'^(""I""):1,1:0)"
+2 SET DIC("B")=$PIECE(PSDSITE,U,4)
+3 DO ^DIC
KILL DIC
IF $DATA(DTOUT)!($DATA(DUOUT))!(Y<1)
GOTO QUIT
+4 SET PSDLOC=+Y
SET PSDLOCN=$PIECE(Y,U,2)
+5 SET $PIECE(PSDSITE,U,3)=+Y
SET $PIECE(PSDSITE,U,4)=$PIECE(Y,U,2)
CHKD IF '$ORDER(^PSD(58.8,PSDLOC,1,0))
WRITE !!,"There are no drugs in ",PSDLOCN
GOTO QUIT
+1 NEW X,X1
DO SIG^XUSESIG
IF X1=""
GOTO QUIT
+2 FOR
SET DIC="^PSD(58.8,PSDLOC,1,"
SET DIC(0)="AEMQZ"
SET DIC("A")="Select "_PSDLOCN_" drug: "
SET DIC("S")="I $S($P($G(^(0)),U,14):$P($G(^(0)),U,14)>DT,1:1)"
SET DA(1)=PSDLOC
WRITE !
DO ^DIC
KILL DIC
IF Y<1
GOTO QUIT
Begin DoDot:1
+3 SET PSDRUG=+Y
SET PSDRUGN=$PIECE($GET(^PSDRUG(+Y,0)),U)
+4 ;DAVE B (28APR99) Moving lock of PSD(58.8,LOC,1,DRUG) up.
+5 FOR
LOCK +^PSD(58.8,+PSDLOC,1,+PSDRUG,0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
IF $TEST
QUIT
+6 SET PSAQ=$PIECE($GET(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,4)
+7 WRITE !!,"Current Balance: ",PSAQ,?40
+8 WRITE "Breakdown Unit: ",$PIECE($GET(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,8),!
+9 SET DIR(0)="N^"_-PSAQ_":999999:2"
SET DIR("A")="Enter adjustment quantity (with '-' if negative)"
DO ^DIR
KILL DIR
IF $DATA(DIRUT)
QUIT
+10 SET PSDREC=Y
+11 SET DIR(0)="F^1:45"
SET DIR("A")="Please enter reason for adjustment"
WRITE !
DO ^DIR
KILL DIR
IF $DATA(DIRUT)
QUIT
SET PSDR=Y
POST SET DIR(0)="Y"
SET DIR("A")="OK to post"
SET DIR("B")="Yes"
SET DIR("?")="Answer 'YES' to adjust your inventory balance, 'NO' or '^' to quit."
WRITE !
DO ^DIR
KILL DIR
IF Y=1
Begin DoDot:2
+1 WRITE !!,"There were ",$SELECT($PIECE($GET(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,4):$PIECE($GET(^(0)),U,4),1:0)," on hand.",?40,"There are now ",$PIECE($GET(^(0)),U,4)+PSDREC," on hand.",!
+2 ;F L +^PSD(58.8,+PSDLOC,1,+PSDRUG,0):0 I Q
+3 DO NOW^%DTC
SET PSDAT=+%
+4 SET PSAQ=$PIECE($GET(^PSD(58.8,+PSDLOC,1,+PSDRUG,0)),U,4)
+5 SET $PIECE(^PSD(58.8,+PSDLOC,1,+PSDRUG,0),U,4)=PSDREC+PSAQ
+6 LOCK -^PSD(58.8,+PSDLOC,1,+PSDRUG,0)
MON IF '$DATA(^PSD(58.8,+PSDLOC,1,+PSDRUG,5,0))
SET ^(0)="^58.801A^^"
+1 IF '$DATA(^PSD(58.8,+PSDLOC,1,+PSDRUG,5,$EXTRACT(DT,1,5)*100,0))
SET DIC="^PSD(58.8,+PSDLOC,1,+PSDRUG,5,"
SET DIC(0)="LM"
SET DLAYGO=58.8
SET (X,DINUM)=$EXTRACT(DT,1,5)*100
SET DA(2)=PSDLOC
SET DA(1)=PSDRUG
DO ^DIC
KILL DIC,DLAYGO
+2 SET DIE="^PSD(58.8,+PSDLOC,1,+PSDRUG,5,"
SET DA(2)=PSDLOC
SET DA(1)=PSDRUG
SET DA=$EXTRACT(DT,1,5)*100
SET DR="7////^S X=$P($G(^(0)),U,5)+PSDREC"
DO ^DIE
+3 WRITE !,"Updating monthly adjustments and transaction history.",!
TR FOR
LOCK +^PSD(58.81,0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
IF $TEST
QUIT
FIND SET PSDT=$PIECE(^PSD(58.81,0),U,3)+1
IF $DATA(^PSD(58.81,PSDT))
SET $PIECE(^PSD(58.81,0),U,3)=$PIECE(^PSD(58.81,0),U,3)+1
GOTO FIND
+1 SET DIC="^PSD(58.81,"
SET DIC(0)="L"
SET DLAYGO=58.81
SET (DINUM,X)=PSDT
DO ^DIC
KILL DIC,DLAYGO
LOCK -^PSD(58.81,0)
+2 SET DIE="^PSD(58.81,"
SET DA=PSDT
SET DR="1////9;2////^S X=PSDLOC;3////^S X=PSDAT;4////^S X=PSDRUG;5////^S X=PSDREC;6////^S X=DUZ;9////^S X=PSAQ;15////^S X=PSDR;100////1"
DO ^DIE
KILL DIE
+3 IF '$DATA(^PSD(58.8,+PSDLOC,1,+PSDRUG,4,0))
SET ^(0)="^58.800119PA^^"
+4 SET DIC="^PSD(58.8,+PSDLOC,1,+PSDRUG,4,"
SET DIC(0)="L"
SET DLAYGO=58.8
+5 SET (X,DINUM)=PSDT
+6 SET DA(2)=PSDLOC
SET DA(1)=PSDRUG
DO ^DIC
KILL DIC,DA,DLAYGO
SET Y=1
+7 IF PSDREC<0
SET DIR(0)="Y"
SET DIR("A")="To be destroyed"
SET DIR("B")="No"
DO ^DIR
KILL DIR
IF Y=1
SET PSDEX=1
SET PSDA=PSDT
SET PSDOK=1
End DoDot:2
LOCK -^PSD(58.8,+PSDLOC,1,+PSDRUG,0)
KILL PSDRUG
QUIT
End DoDot:1
IF $DATA(DIRUT)
GOTO QUIT
IF $DATA(PSDEX)
DO DEST^PSDGSRV1
KILL PSDEX
QUIT QUIT