PSDRFR ;BIR/JPW,LTL,BJW-Nurse RF Return to stock ; 11 May 98
;;3.0; CONTROLLED SUBSTANCES ;**5,7,25,53,60**;13 Feb 97
;modified to set variables psdret,psdar for return date
;Reference to ^PSD(58.8 are covered by DBIA #2711
;Reference to ^PSD(58.81 are covered by DBIA #2808
;Reference to ^PSDRUG( are covered by DBIA #221
I '$D(PSDSITE) D ^PSDSET Q:'$D(PSDSITE)
;S OK=$S($D(^XUSEC("PSJ RNURSE",DUZ)):1,1:0) I 'OK W $C(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to order",!,?12,"narcotic supplies.",! K OK Q
I $P($G(^VA(200,DUZ,20)),U,4)']"" N XQH S XQH="PSD ESIG" D EN^XQH G END
S PSDUZ=DUZ,(MSG,MSG1)=0,Y=DT X ^DD("DD") S REQD=Y
NURSE N X,X1 D SIG^XUSESIG I X1="" G END
NAOU ;select NAOU to dispense from
I $G(NAOU) S PSDS=+$P(^PSD(58.8,NAOU,0),U,4) G PATIENT
W !!,"Please enter the ward from which the drug(s) was signed out."
K DA,DIC S DIC=58.8,DIC(0)="QEA",DIC("A")="Select Ward: "
S DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>DT:1,1:0),$P(^(0),""^"",2)=""N"",'$P(^(0),""^"",7)"
W ! D ^DIC K DIC G:Y<0 END S NAOU=+Y,NAOUN=$P(Y,"^",2)
I '$D(^PSD(58.8,NAOU,0)) S MSG=1 D MSG G END
I '$O(^PSD(58.8,NAOU,1,0)) S MSG=1,MSG1=2 D MSG G END
I '$P(^PSD(58.8,NAOU,0),U,4) S MSG=2 D MSG G END
S PSDS=+$P(^PSD(58.8,NAOU,0),"^",4),PSDS=PSDS_"^"_+$P(^PSD(58.8,+PSDS,0),"^",5) I '+PSDS S (MSG,MSG1)=1 D MSG G END
I '$D(^PSD(58.8,+PSDS,0)) S MSG=2 D MSG G END
I '$O(^PSD(58.8,+PSDS,1,0)) S MSG=2,MSG1=2 D MSG G END
;S TYPE=$P(^PSD(58.8,+PSDS,0),"^",2),OKTYP=$S(TYPE="M":1,TYPE="S":1,1:0) I 'OKTYP W !!,"Contact your Pharmacy Coordinator.",!,"The Pharmacy Dispensing Site is invalid for this NAOU." G END
PATIENT W !!,"Returns can only be recorded within "
S NAOU(1)=$S($P($G(^PSD(58.8,NAOU,6)),U,2):$P(^(6),U,2),1:12)
W NAOU(1)," hours after signing out a dose."
N DIC,DTOUT,DUOUT,X,Y,PSDOUT S DIC="^DPT(",DIC(0)="AEMQ"
S DIC("A")="Scan/Enter Patient: "
W ! D ^DIC K DIC G:Y<1 END S PAT=+Y
DRUG ;select drug
N DIR,PSD,PSDR,PSDQ,PSDDT
S DIR(0)="FAO^1:40",DIR("A")="Scan Drug Label or Enter Label # or Drug: "
W ! D ^DIR K DIR G:$D(DIRUT) END
MM ;
I $L(Y)=1,Y'=" " W $C(7),!!,"Please enter more than one character.",! G DRUG
I $O(^PSD(58.81,"D",Y,0)) D
.S PSD=0
.F S PSD=$O(^PSD(58.81,"D",Y,PSD)) Q:'PSD S PSD(1)=$G(^PSD(58.81,PSD,0)) I $P(PSD(1),U,11)>3,$P(PSD(1),U,18)=NAOU S PSDR=$P(PSD(1),U,5),PSDPN=$P(PSD(1),U,17),PSDTYP=17
I $D(PSDR),PSDR'=Y D
.I $D(^PSDRUG(Y)),$D(^PSD(58.8,NAOU,1,Y)) D
..S PSDDT=$$FMDIFF^DILIBF(DT,$P(PSD(1),U,4),"")
..I PSDDT>365 S PSDR=Y
.I '$D(^PSDRUG(Y)),$D(PSD(1)) D
..S PSDDT=$$FMDIFF^DILIBF(DT,$P(PSD(1),U,4),"")
..I PSDDT>365 K PSDR
.I '$D(^PSDRUG(Y)),'$D(^PSD(58.8,NAOU,1,Y)),'$D(PSDR) W $C(7),!!,"This is not a valid Pharmacy Dispensing number for this ward.",!! G END
D:'$G(PSDR) G:$D(DTOUT)!($D(DUOUT)) END G:Y<1 PATIENT
.S DIC="^PSD(58.8,NAOU,1,",DIC(0)="EMQSZ",DA(1)=NAOU
.W ! D ^DIC K DIC I $D(DTOUT)!($D(DUOUT))!(Y<1) W $C(7),!!,"This is not a valid Pharmacy Dispensing number for this ward.",!! Q
.S PSDR=+Y,PSDTYP=17
I '$G(PSDR) W $C(7),!!,"This is not a valid Pharmacy Dispensing number for this ward.",!! G END
W:$G(PSDR) !!,$P($G(^PSDRUG(PSDR,0)),U)
BAL S PSDR(1)=$G(^PSD(58.8,NAOU,1,PSDR,0)),OQTY=$P(PSDR(1),U,4)
;PSD*3*25 (DAVE B)
K PSDDAVE D ^PSDRFV I $G(PSDDAVE)=1 K PSDDAVE S PSDOUT=1 G END
I '$G(PSDA(1)) W !!,"No doses signed out",!! G END
S OQTY=$P($G(^PSD(58.81,PSDA(1),0)),U,6)
I $$FMADD^XLFDT(PSDA(3),"",NAOU(1))<$$NOW^XLFDT W !!,"The last dose was signed out at ",PSDA(2),", over ",NAOU(1)," hours ago.",!!,"It is too late to return to stock.",!! G END
I PSDA(4)'=DUZ W !!,"Sorry, only the person who signed out the dose can return to stock.",!! G END
W !!,"Starting Balance: "_$P(PSDR(1),U,4)_" "_$P(PSDR(1),U,8)
QTY S DIR(0)="NA^0:"_OQTY_":2"
S DIR("A")="Amount actually given at "_PSDA(2)_": "
W ! D ^DIR K DIR I $D(DIRUT)!(Y=OQTY) S PSDOUT=1 G END
S PSDQ=Y
S PSDRET=$$FMADD^XLFDT($$NOW^XLFDT,0)
S PSDAR(1)=$$FMTE^XLFDT(PSDRET,"2P")
WASTE I PSDQ'=OQTY D G:$G(PSDOUT) END
.S:'$D(PSDAR(1)) PSDAR(1)=""
.I (OQTY-PSDQ)>1 D Q:$G(PSDOUT) G REA
..S DIR(0)="N^1:"_(OQTY-PSDQ)_":2",DIR("A")="Amount returned at "_PSDAR(1)
..S DIR("B")=OQTY-PSDQ D ^DIR K DIR I $D(DIRUT) S PSDOUT=1 Q
..S WQTY=Y S:OQTY-WQTY PSDQ(1)=OQTY-WQTY
.S WQTY=$S('$G(PSDQ(2)):OQTY-PSDQ,1:OQTY-WQTY)
.W ?55,"Amount returned: ",WQTY,!
REA .S DIR(0)="58.81,15",DIR("B")="Not given, returned to stock"
.D ^DIR K DIR I $D(DIRUT) S PSDOUT=1 Q
.S PSDRE(1)=Y
;VMP OIFO BAY PINES;PSD*3.0*53;DISPLAY CORRECT BALANCE
N PSDRETQ
S PSDRETQ=WQTY,PSDQ=+$G(PSDQ(1))
D UPDATE^PSDRFX W !!,"Balance: ",$P(PSDR(1),U,4)+PSDRETQ," ",$P(PSDR(1),U,8),!!
;VMP OIFO BAY PINES;PSD*3.0*53;REMOVED CALL TO WASTE^PSDRFW
END I $G(PSDQ(2)),$G(PSDOUT) S $P(^PSD(58.81,PSDA(1),0),U,6)=PSDQ
W:$G(PSDOUT) !!,"No return recorded.",$C(7),!! K %,%DT,%H,%I,CNT,CNT1,DA,DIC,DIE,DINUM,DIR,DIROUT,DIRUT,DIWF,DIWL,DIWR,DR,DTOUT,DUOUT,LN,MSG,MSG1,PSDTYP
K NAOU,NAOUN,NBKU,NPKG,OK,OKTYP,ORD,PAT,PSDA,PSDAR,PSDEM,PSDOUT,PSDQTY,PSDRD,PSDR,PSDRE,PSDRET,PSDRN,PSDS,PSDT,PSDUZ,PSDUZN,PSDPN,REQD,TEXT,TYPE,WQTY,OQTY,PSDQ,WORD,X,Y,PSDRETQ
Q
MSG ;display error message
W $C(7),!!,?10,"Contact your Pharmacy Coordinator.",!,?10,"This "_$S(MSG=2:"Dispensing Site",MSG=1:"NAOU",1:"Drug")_" is missing "
W $S(MSG1=1:"Primary Disp. Site",MSG1=2:"stocked drugs",MSG1=3:"narcotic breakdown unit",MSG1=4:"narcotic package size",1:"data")_".",!
Q
PSDRFR ;BIR/JPW,LTL,BJW-Nurse RF Return to stock ; 11 May 98
+1 ;;3.0; CONTROLLED SUBSTANCES ;**5,7,25,53,60**;13 Feb 97
+2 ;modified to set variables psdret,psdar for return date
+3 ;Reference to ^PSD(58.8 are covered by DBIA #2711
+4 ;Reference to ^PSD(58.81 are covered by DBIA #2808
+5 ;Reference to ^PSDRUG( are covered by DBIA #221
+6 IF '$DATA(PSDSITE)
DO ^PSDSET
IF '$DATA(PSDSITE)
QUIT
+7 ;S OK=$S($D(^XUSEC("PSJ RNURSE",DUZ)):1,1:0) I 'OK W $C(7),!!,?9,"** Please contact your Pharmacy Coordinator for access to order",!,?12,"narcotic supplies.",! K OK Q
+8 IF $PIECE($GET(^VA(200,DUZ,20)),U,4)']""
NEW XQH
SET XQH="PSD ESIG"
DO EN^XQH
GOTO END
+9 SET PSDUZ=DUZ
SET (MSG,MSG1)=0
SET Y=DT
XECUTE ^DD("DD")
SET REQD=Y
NURSE NEW X,X1
DO SIG^XUSESIG
IF X1=""
GOTO END
NAOU ;select NAOU to dispense from
+1 IF $GET(NAOU)
SET PSDS=+$PIECE(^PSD(58.8,NAOU,0),U,4)
GOTO PATIENT
+2 WRITE !!,"Please enter the ward from which the drug(s) was signed out."
+3 KILL DA,DIC
SET DIC=58.8
SET DIC(0)="QEA"
SET DIC("A")="Select Ward: "
+4 SET DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>DT:1,1:0),$P(^(0),""^"",2)=""N"",'$P(^(0),""^"",7)"
+5 WRITE !
DO ^DIC
KILL DIC
IF Y<0
GOTO END
SET NAOU=+Y
SET NAOUN=$PIECE(Y,"^",2)
+6 IF '$DATA(^PSD(58.8,NAOU,0))
SET MSG=1
DO MSG
GOTO END
+7 IF '$ORDER(^PSD(58.8,NAOU,1,0))
SET MSG=1
SET MSG1=2
DO MSG
GOTO END
+8 IF '$PIECE(^PSD(58.8,NAOU,0),U,4)
SET MSG=2
DO MSG
GOTO END
+9 SET PSDS=+$PIECE(^PSD(58.8,NAOU,0),"^",4)
SET PSDS=PSDS_"^"_+$PIECE(^PSD(58.8,+PSDS,0),"^",5)
IF '+PSDS
SET (MSG,MSG1)=1
DO MSG
GOTO END
+10 IF '$DATA(^PSD(58.8,+PSDS,0))
SET MSG=2
DO MSG
GOTO END
+11 IF '$ORDER(^PSD(58.8,+PSDS,1,0))
SET MSG=2
SET MSG1=2
DO MSG
GOTO END
+12 ;S TYPE=$P(^PSD(58.8,+PSDS,0),"^",2),OKTYP=$S(TYPE="M":1,TYPE="S":1,1:0) I 'OKTYP W !!,"Contact your Pharmacy Coordinator.",!,"The Pharmacy Dispensing Site is invalid for this NAOU." G END
PATIENT WRITE !!,"Returns can only be recorded within "
+1 SET NAOU(1)=$SELECT($PIECE($GET(^PSD(58.8,NAOU,6)),U,2):$PIECE(^(6),U,2),1:12)
+2 WRITE NAOU(1)," hours after signing out a dose."
+3 NEW DIC,DTOUT,DUOUT,X,Y,PSDOUT
SET DIC="^DPT("
SET DIC(0)="AEMQ"
+4 SET DIC("A")="Scan/Enter Patient: "
+5 WRITE !
DO ^DIC
KILL DIC
IF Y<1
GOTO END
SET PAT=+Y
DRUG ;select drug
+1 NEW DIR,PSD,PSDR,PSDQ,PSDDT
+2 SET DIR(0)="FAO^1:40"
SET DIR("A")="Scan Drug Label or Enter Label # or Drug: "
+3 WRITE !
DO ^DIR
KILL DIR
IF $DATA(DIRUT)
GOTO END
MM ;
+1 IF $LENGTH(Y)=1
IF Y'=" "
WRITE $CHAR(7),!!,"Please enter more than one character.",!
GOTO DRUG
+2 IF $ORDER(^PSD(58.81,"D",Y,0))
Begin DoDot:1
+3 SET PSD=0
+4 FOR
SET PSD=$ORDER(^PSD(58.81,"D",Y,PSD))
IF 'PSD
QUIT
SET PSD(1)=$GET(^PSD(58.81,PSD,0))
IF $PIECE(PSD(1),U,11)>3
IF $PIECE(PSD(1),U,18)=NAOU
SET PSDR=$PIECE(PSD(1),U,5)
SET PSDPN=$PIECE(PSD(1),U,17)
SET PSDTYP=17
End DoDot:1
+5 IF $DATA(PSDR)
IF PSDR'=Y
Begin DoDot:1
+6 IF $DATA(^PSDRUG(Y))
IF $DATA(^PSD(58.8,NAOU,1,Y))
Begin DoDot:2
+7 SET PSDDT=$$FMDIFF^DILIBF(DT,$PIECE(PSD(1),U,4),"")
+8 IF PSDDT>365
SET PSDR=Y
End DoDot:2
+9 IF '$DATA(^PSDRUG(Y))
IF $DATA(PSD(1))
Begin DoDot:2
+10 SET PSDDT=$$FMDIFF^DILIBF(DT,$PIECE(PSD(1),U,4),"")
+11 IF PSDDT>365
KILL PSDR
End DoDot:2
+12 IF '$DATA(^PSDRUG(Y))
IF '$DATA(^PSD(58.8,NAOU,1,Y))
IF '$DATA(PSDR)
WRITE $CHAR(7),!!,"This is not a valid Pharmacy Dispensing number for this ward.",!!
GOTO END
End DoDot:1
+13 IF '$GET(PSDR)
Begin DoDot:1
+14 SET DIC="^PSD(58.8,NAOU,1,"
SET DIC(0)="EMQSZ"
SET DA(1)=NAOU
+15 WRITE !
DO ^DIC
KILL DIC
IF $DATA(DTOUT)!($DATA(DUOUT))!(Y<1)
WRITE $CHAR(7),!!,"This is not a valid Pharmacy Dispensing number for this ward.",!!
QUIT
+16 SET PSDR=+Y
SET PSDTYP=17
End DoDot:1
IF $DATA(DTOUT)!($DATA(DUOUT))
GOTO END
IF Y<1
GOTO PATIENT
+17 IF '$GET(PSDR)
WRITE $CHAR(7),!!,"This is not a valid Pharmacy Dispensing number for this ward.",!!
GOTO END
+18 IF $GET(PSDR)
WRITE !!,$PIECE($GET(^PSDRUG(PSDR,0)),U)
BAL SET PSDR(1)=$GET(^PSD(58.8,NAOU,1,PSDR,0))
SET OQTY=$PIECE(PSDR(1),U,4)
+1 ;PSD*3*25 (DAVE B)
+2 KILL PSDDAVE
DO ^PSDRFV
IF $GET(PSDDAVE)=1
KILL PSDDAVE
SET PSDOUT=1
GOTO END
+3 IF '$GET(PSDA(1))
WRITE !!,"No doses signed out",!!
GOTO END
+4 SET OQTY=$PIECE($GET(^PSD(58.81,PSDA(1),0)),U,6)
+5 IF $$FMADD^XLFDT(PSDA(3),"",NAOU(1))<$$NOW^XLFDT
WRITE !!,"The last dose was signed out at ",PSDA(2),", over ",NAOU(1)," hours ago.",!!,"It is too late to return to stock.",!!
GOTO END
+6 IF PSDA(4)'=DUZ
WRITE !!,"Sorry, only the person who signed out the dose can return to stock.",!!
GOTO END
+7 WRITE !!,"Starting Balance: "_$PIECE(PSDR(1),U,4)_" "_$PIECE(PSDR(1),U,8)
QTY SET DIR(0)="NA^0:"_OQTY_":2"
+1 SET DIR("A")="Amount actually given at "_PSDA(2)_": "
+2 WRITE !
DO ^DIR
KILL DIR
IF $DATA(DIRUT)!(Y=OQTY)
SET PSDOUT=1
GOTO END
+3 SET PSDQ=Y
+4 SET PSDRET=$$FMADD^XLFDT($$NOW^XLFDT,0)
+5 SET PSDAR(1)=$$FMTE^XLFDT(PSDRET,"2P")
WASTE IF PSDQ'=OQTY
Begin DoDot:1
+1 IF '$DATA(PSDAR(1))
SET PSDAR(1)=""
+2 IF (OQTY-PSDQ)>1
Begin DoDot:2
+3 SET DIR(0)="N^1:"_(OQTY-PSDQ)_":2"
SET DIR("A")="Amount returned at "_PSDAR(1)
+4 SET DIR("B")=OQTY-PSDQ
DO ^DIR
KILL DIR
IF $DATA(DIRUT)
SET PSDOUT=1
QUIT
+5 SET WQTY=Y
IF OQTY-WQTY
SET PSDQ(1)=OQTY-WQTY
End DoDot:2
IF $GET(PSDOUT)
QUIT
GOTO REA
+6 SET WQTY=$SELECT('$GET(PSDQ(2)):OQTY-PSDQ,1:OQTY-WQTY)
+7 WRITE ?55,"Amount returned: ",WQTY,!
REA SET DIR(0)="58.81,15"
SET DIR("B")="Not given, returned to stock"
+1 DO ^DIR
KILL DIR
IF $DATA(DIRUT)
SET PSDOUT=1
QUIT
+2 SET PSDRE(1)=Y
End DoDot:1
IF $GET(PSDOUT)
GOTO END
+3 ;VMP OIFO BAY PINES;PSD*3.0*53;DISPLAY CORRECT BALANCE
+4 NEW PSDRETQ
+5 SET PSDRETQ=WQTY
SET PSDQ=+$GET(PSDQ(1))
+6 DO UPDATE^PSDRFX
WRITE !!,"Balance: ",$PIECE(PSDR(1),U,4)+PSDRETQ," ",$PIECE(PSDR(1),U,8),!!
+7 ;VMP OIFO BAY PINES;PSD*3.0*53;REMOVED CALL TO WASTE^PSDRFW
END IF $GET(PSDQ(2))
IF $GET(PSDOUT)
SET $PIECE(^PSD(58.81,PSDA(1),0),U,6)=PSDQ
+1 IF $GET(PSDOUT)
WRITE !!,"No return recorded.",$CHAR(7),!!
KILL %,%DT,%H,%I,CNT,CNT1,DA,DIC,DIE,DINUM,DIR,DIROUT,DIRUT,DIWF,DIWL,DIWR,DR,DTOUT,DUOUT,LN,MSG,MSG1,PSDTYP
+2 KILL NAOU,NAOUN,NBKU,NPKG,OK,OKTYP,ORD,PAT,PSDA,PSDAR,PSDEM,PSDOUT,PSDQTY,PSDRD,PSDR,PSDRE,PSDRET,PSDRN,PSDS,PSDT,PSDUZ,PSDUZN,PSDPN,REQD,TEXT,TYPE,WQTY,OQTY,PSDQ,WORD,X,Y,PSDRETQ
+3 QUIT
MSG ;display error message
+1 WRITE $CHAR(7),!!,?10,"Contact your Pharmacy Coordinator.",!,?10,"This "_$SELECT(MSG=2:"Dispensing Site",MSG=1:"NAOU",1:"Drug")_" is missing "
+2 WRITE $SELECT(MSG1=1:"Primary Disp. Site",MSG1=2:"stocked drugs",MSG1=3:"narcotic breakdown unit",MSG1=4:"narcotic package size",1:"data")_".",!
+3 QUIT