PSDADJIN ;B'ham ISC/LTL,JPW - Balance Initializer for NAOU ; 16 Feb 94
;;3.0; CONTROLLED SUBSTANCES ;**66**;13 Feb 97;Build 3
I '$D(PSDSITE) D ^PSDSET G:'$D(PSDSITE) QUIT
N D1,D2,DIC,DIE,DINUM,D0,D1,DLAYGO,DR,DIR,DIRUT,DTOUT,DUOUT,NODE,PSAC,PSDAT,PSDLOC,PSDLOCN,DA,PSDRUG,PSDRUGN,PSDS,PSDPKG,PSDBKU,PSAQ,PSDR,PSDREC,PSDT,X,Y,%,%H,%I
LOOK S DIC="^PSD(58.8,",DIC(0)="AEMQZ",DIC("A")="Select NAOU: ",DIC("S")="I $P($G(^(0)),U,3)=+PSDSITE,$P($G(^(0)),U,2)[""N"",'$P(^(0),""^"",7),$S('$D(^(""I"")):1,+^(""I"")>DT:1,'^(""I""):1,1:0)"
D ^DIC K DIC G:$D(DTOUT)!($D(DUOUT))!(Y<1) QUIT S PSDLOC=+Y,PSDLOCN=$P(Y,U,2),PSDS=+$P(Y(0),"^",4)
I '+$P($G(^PSD(58.8,PSDLOC,2)),"^",5) W !!,"This NAOU does not maintain a perpetual inventory balance to initialize.",!! K PSDLOC,PSDLOCN,PSDS G LOOK
CHKD I '$O(^PSD(58.8,PSDLOC,1,0)) W !!,"There are no drugs in ",PSDLOCN G QUIT
S DIR(0)="Y",DIR("A",1)="This option will set all balances to zero before initializing.",DIR("A")="Are you sure you want to proceed"
D ^DIR K DIR G:Y'=1 QUIT
W !!,"Give me a second to alphabetize.",!
S PSDRUG=0,PSDRUGN=""
F S PSDRUG=$O(^PSD(58.8,PSDLOC,1,PSDRUG)) Q:'PSDRUG D
.Q:'$D(^PSD(58.8,+PSDLOC,1,+PSDRUG,0))!($P($G(^PSDRUG(+PSDRUG,0)),"^")']"")
.S PSDPKG=$P($G(^PSD(58.8,+PSDS,1,+PSDRUG,0)),"^",9),PSDBKU=$P($G(^(0)),"^",8)
.S ^TMP("PSDB",$J,$P($G(^PSDRUG(+PSDRUG,0)),U),PSDRUG)=PSDPKG_"^"_PSDBKU,$P(^PSD(58.8,+PSDLOC,1,+PSDRUG,0),U,4)=0 K Y
W @IOF
F PSAC=1:1 S PSDRUGN=$O(^TMP("PSDB",$J,PSDRUGN)) Q:PSDRUGN']"" S PSDRUG=$O(^TMP("PSDB",$J,PSDRUGN,0)) D G:$D(DIRUT) QUIT
.Q:'$G(^PSD(58.8,PSDLOC,1,PSDRUG,0))
.;S (PSD,PSD(1))=0
.;F S PSD=$O(^PSD(58.81,"AD",4,+PSDLOC,PSD)) S:$P($G(^PSD(58.81,+PSD,0)),U,5)=PSDRUG PSD(1)=1 Q:$G(PSD(1))!('PSD)
.;Q:'$G(PSD(1))
.S NODE=$G(^TMP("PSDB",$J,PSDRUGN,PSDRUG))
.S DIE="^PSD(58.8,+PSDLOC,1,",DA(1)=PSDLOC,DA=PSDRUG
.F L +^PSD(58.8,+PSDLOC,1,+PSDRUG,0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) I Q
.D NOW^%DTC S PSDAT=+%
.W !!,PSDRUGN,!!,"Package Size: ",$P($G(NODE),"^")," Breakdown Unit: ",$P($G(NODE),"^",2),!
.S DIR(0)="NA^0:999999:2",DIR("A")="Initial Balance: " D ^DIR K DIR
.Q:$D(DIRUT) S PSDREC=Y
.S DR="3////"_PSDREC D ^DIE
.S $P(^PSD(58.8,PSDLOC,1,PSDRUG,0),"^",17)=1
.L -^PSD(58.8,+PSDLOC,1,+PSDRUG,0)
.Q:$G(PSDREC)']""
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="1////0;7////^S X=PSDREC" D ^DIE
.W !!,"Updating beginning balance 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////11;2////^S X=PSDLOC;3////^S X=PSDAT;4////^S X=PSDRUG;5////^S X=PSDREC;6////^S X=DUZ;9////0;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,DA(2)=PSDLOC,DA(1)=PSDRUG D ^DIC K DIC,DA,DLAYGO,Y
REP S DIR(0)="Y",DIR("A")="Would you like a report of current balances"
S DIR("B")="Yes" D ^DIR K DIR D:Y=1
.S NAOU=PSDLOC,NAOUN=PSDLOCN D DEV^PSDBAN
QUIT K ^TMP("PSDB",$J) Q
PSDADJIN ;B'ham ISC/LTL,JPW - Balance Initializer for NAOU ; 16 Feb 94
+1 ;;3.0; CONTROLLED SUBSTANCES ;**66**;13 Feb 97;Build 3
+2 IF '$DATA(PSDSITE)
DO ^PSDSET
IF '$DATA(PSDSITE)
GOTO QUIT
+3 NEW D1,D2,DIC,DIE,DINUM,D0,D1,DLAYGO,DR,DIR,DIRUT,DTOUT,DUOUT,NODE,PSAC,PSDAT,PSDLOC,PSDLOCN,DA,PSDRUG,PSDRUGN,PSDS,PSDPKG,PSDBKU,PSAQ,PSDR,PSDREC,PSDT,X,Y,%,%H,%I
LOOK SET DIC="^PSD(58.8,"
SET DIC(0)="AEMQZ"
SET DIC("A")="Select NAOU: "
SET DIC("S")="I $P($G(^(0)),U,3)=+PSDSITE,$P($G(^(0)),U,2)[""N"",'$P(^(0),""^"",7),$S('$D(^(""I"")):1,+^(""I"")>DT:1,'^(""I""):1,1:0)"
+1 DO ^DIC
KILL DIC
IF $DATA(DTOUT)!($DATA(DUOUT))!(Y<1)
GOTO QUIT
SET PSDLOC=+Y
SET PSDLOCN=$PIECE(Y,U,2)
SET PSDS=+$PIECE(Y(0),"^",4)
+2 IF '+$PIECE($GET(^PSD(58.8,PSDLOC,2)),"^",5)
WRITE !!,"This NAOU does not maintain a perpetual inventory balance to initialize.",!!
KILL PSDLOC,PSDLOCN,PSDS
GOTO LOOK
CHKD IF '$ORDER(^PSD(58.8,PSDLOC,1,0))
WRITE !!,"There are no drugs in ",PSDLOCN
GOTO QUIT
+1 SET DIR(0)="Y"
SET DIR("A",1)="This option will set all balances to zero before initializing."
SET DIR("A")="Are you sure you want to proceed"
+2 DO ^DIR
KILL DIR
IF Y'=1
GOTO QUIT
+3 WRITE !!,"Give me a second to alphabetize.",!
+4 SET PSDRUG=0
SET PSDRUGN=""
+5 FOR
SET PSDRUG=$ORDER(^PSD(58.8,PSDLOC,1,PSDRUG))
IF 'PSDRUG
QUIT
Begin DoDot:1
+6 IF '$DATA(^PSD(58.8,+PSDLOC,1,+PSDRUG,0))!($PIECE($GET(^PSDRUG(+PSDRUG,0)),"^")']"")
QUIT
+7 SET PSDPKG=$PIECE($GET(^PSD(58.8,+PSDS,1,+PSDRUG,0)),"^",9)
SET PSDBKU=$PIECE($GET(^(0)),"^",8)
+8 SET ^TMP("PSDB",$JOB,$PIECE($GET(^PSDRUG(+PSDRUG,0)),U),PSDRUG)=PSDPKG_"^"_PSDBKU
SET $PIECE(^PSD(58.8,+PSDLOC,1,+PSDRUG,0),U,4)=0
KILL Y
End DoDot:1
+9 WRITE @IOF
+10 FOR PSAC=1:1
SET PSDRUGN=$ORDER(^TMP("PSDB",$JOB,PSDRUGN))
IF PSDRUGN']""
QUIT
SET PSDRUG=$ORDER(^TMP("PSDB",$JOB,PSDRUGN,0))
Begin DoDot:1
+11 IF '$GET(^PSD(58.8,PSDLOC,1,PSDRUG,0))
QUIT
+12 ;S (PSD,PSD(1))=0
+13 ;F S PSD=$O(^PSD(58.81,"AD",4,+PSDLOC,PSD)) S:$P($G(^PSD(58.81,+PSD,0)),U,5)=PSDRUG PSD(1)=1 Q:$G(PSD(1))!('PSD)
+14 ;Q:'$G(PSD(1))
+15 SET NODE=$GET(^TMP("PSDB",$JOB,PSDRUGN,PSDRUG))
+16 SET DIE="^PSD(58.8,+PSDLOC,1,"
SET DA(1)=PSDLOC
SET DA=PSDRUG
+17 FOR
LOCK +^PSD(58.8,+PSDLOC,1,+PSDRUG,0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
IF $TEST
QUIT
+18 DO NOW^%DTC
SET PSDAT=+%
+19 WRITE !!,PSDRUGN,!!,"Package Size: ",$PIECE($GET(NODE),"^")," Breakdown Unit: ",$PIECE($GET(NODE),"^",2),!
+20 SET DIR(0)="NA^0:999999:2"
SET DIR("A")="Initial Balance: "
DO ^DIR
KILL DIR
+21 IF $DATA(DIRUT)
QUIT
SET PSDREC=Y
+22 SET DR="3////"_PSDREC
DO ^DIE
+23 SET $PIECE(^PSD(58.8,PSDLOC,1,PSDRUG,0),"^",17)=1
+24 LOCK -^PSD(58.8,+PSDLOC,1,+PSDRUG,0)
+25 IF $GET(PSDREC)']""
QUIT
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="1////0;7////^S X=PSDREC"
DO ^DIE
+3 WRITE !!,"Updating beginning balance 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////11;2////^S X=PSDLOC;3////^S X=PSDAT;4////^S X=PSDRUG;5////^S X=PSDREC;6////^S X=DUZ;9////0;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
SET DA(2)=PSDLOC
SET DA(1)=PSDRUG
DO ^DIC
KILL DIC,DA,DLAYGO,Y
End DoDot:1
IF $DATA(DIRUT)
GOTO QUIT
REP SET DIR(0)="Y"
SET DIR("A")="Would you like a report of current balances"
+1 SET DIR("B")="Yes"
DO ^DIR
KILL DIR
IF Y=1
Begin DoDot:1
+2 SET NAOU=PSDLOC
SET NAOUN=PSDLOCN
DO DEV^PSDBAN
End DoDot:1
QUIT KILL ^TMP("PSDB",$JOB)
QUIT