PSDNRGS ;BIR/JPW-Receive Green Sheet for NAOU ; 17 Jan 2017 9:42 AM
;;3.0;CONTROLLED SUBSTANCES;**56,66,65,81**;13 Feb 97;Build 11
I '$D(PSDSITE) D ^PSDSET Q:'$D(PSDSITE)
N AKUNITS
S OK=$S($D(^XUSEC("PSJ RNURSE",DUZ)):1,$D(^XUSEC("PSD NURSE",DUZ)):1,$D(^XUSEC("PSJ RPHARM",DUZ)):2,$D(^XUSEC("PSJ PHARM TECH",DUZ)):2,1:0)
I 'OK W $C(7),!!,?9,"** Please contact your Coordinator for access to complete",!,?12,"narcotic orders.",!!,"PSJ RNURSE, PSD NURSE, PSJ RPHARM, or PSJ PHARM TECH security key required.",! K OK Q
I $P($G(^VA(200,DUZ,20)),U,4)']"" N XQH S XQH="PSD ESIG" D EN^XQH Q
W !!,"Receive Controlled Substances Orders and Green Sheet" S PSDUZ=DUZ,PSDUZN=$S($P($G(^VA(200,PSDUZ,0)),"^")]"":$P(^(0),"^"),1:"")
N X,X1 D SIG^XUSESIG Q:X1=""
ASKN ;ask naou
W ! K DA,DIC S DIC=58.8,DIC(0)="QEAZ",DIC("A")="Select NAOU: "
S:OK=1 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)"
S:OK=2 DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>DT:1,1:0),$P(^(0),""^"",2)=""N"""
D ^DIC K DIC G:Y<0 END S AOU=+Y,AOUN=$P(Y,"^",2)
GS ;select green sheet #
W ! K DA,DIC S DIC("A")="Select the Green Sheet #: ",DIC=58.81,DIC(0)="QEASZ",D="D"
S DIC("S")="I $P(^(0),""^"",11),$P(^(0),""^"",11)<12"
D IX^DIC K DIC G:Y<0 ASKN S PSDA=+Y
;--------------------------------------------------
; AKD = Y(0) piece 3 = Pointer to DRUG ACCOUNTABILITY STATS (#58.8)
; file.
; AKD(1) = Y(0) piece 5 = Pointer to DRUG (#50) file in DRUG
; ACCOUNTABILITY (#58.8) file. DRUG (#50) ien is DINUM'ed for
; DRUG field PSD(58.8,AKD,1,AKD1)
; AKUNITS = DRUG ACCOUNTABILITY file <> Subfile DRUG <> subfield
; BREAKDOWN UNIT (Free Text).
D
. N AKD,AKD1
. S AKD=$P(Y(0),"^",3),AKD1=$P(Y(0),"^",5)
. S AKUNITS=$P(^PSD(58.8,AKD,1,AKD1,0),"^",8)
. W !,AKUNITS ; display at line beginning
ORD S STAT=+$P(Y(0),"^",11),PSDPN=$P(Y(0),"^",17),STATN="" I STAT S STATN=$P($G(^PSD(58.82,STAT,0)),"^")
S ORD=+$P(Y(0),"^",20),NAOU=+$P(Y(0),"^",18),NAOUN=$P($G(^PSD(58.8,NAOU,0)),"^"),PSDR=+$P(Y(0),"^",5),PSDRN=$P($G(^PSDRUG(PSDR,0)),"^"),QTY=+$P(Y(0),"^",6)
; >> RJS - *65
L +^PSD(58.81,PSDA):$S($G(DILOCKTM)>0:DILOCKTM,1:3)
I '$T W !,"The Green Sheet # ",PSDPN," is currently in use by another user",!,"Please select another Green Sheet.",! G GS
I $D(^PSD(58.81,PSDA,4)),+$P(^(4),"^",3) S QTY=$P(^(4),"^",3)
I AOU'=NAOU W $C(7),!!,"The Green Sheet # ",PSDPN," is assigned to ",NAOUN,".",!,"Please select another Green Sheet.",! L -^PSD(58.81,PSDA) G GS ; <RJS - *65
I '$D(^PSD(58.8,NAOU,1,PSDR,3,ORD,0)) W $C(7),!!,"There's no data on ",NAOUN," for Green Sheet # ",PSDPN,".",!,"Contact your Pharmacy Coordinator for assistance.",! L -^PSD(58.81,PSDA) G END ; <RJS - *65
I STAT'=3 W $C(7),!!,"This Green Sheet has a status of "_$S(STATN]"":STATN,1:"UNKNOWN")_".",!,"Please select another Green Sheet.",! L -^PSD(58.81,PSDA) G GS ; RJS - *65
D NOW^%DTC S (RECD,Y)=+$E(%,1,12) X ^DD("DD") S RECDT=Y
REC ;receive at order level in 58.8
W !!,"Accessing ",PSDRN," information...",!!
;K DA,DIR,DIRUT S DIR(0)="58.81,27",DIR("B")=QTY D ^DIR K DIR I $D(DIRUT) W !!,"Quantity not entered. No action taken.",!,"This order remains ",STATN,!! L -^PSD(58.81,PSDA) G END ; < RJS - *65
K DA,DIR,DIRUT D S DIR(0)="58.81,27",DIR("B")=QTY D ^DIR K DIR I $D(DIRUT) W !!,"Quantity not entered. No action taken.",!,"This order remains ",STATN,!! L -^PSD(58.81,PSDA) G END
. S DIR("A")="QUANTITY RECEIVED ("_AKUNITS_")" ; display units in prompt
S RQTY=Y I RQTY'=QTY W $C(7),!!,"The quantity received does not match the quantity dispensed.",!,"This order must be returned to pharmacy for investigation.",!! L -^PSD(58.81,PSDA) G GS ;< RJS - *65
K DA,DIE,DR S DA=ORD,DA(1)=PSDR,DA(2)=NAOU
S DIE="^PSD(58.8,"_DA(2)_",1,"_DA(1)_",3,"
S DR=$S(OK=1:"6////"_PSDUZ,1:"6RECEIVED BY NURSE")_";20////"_QTY_";15////"_RECD_";10////4;22////"_$P($G(^PSD(58.8,NAOU,1,PSDR,0)),U,4)_";25////"_$P($G(^PSD(58.8,NAOU,1,PSDR,0)),U,4) D ^DIE K DA,DIE,DR
I ($D(Y))!($D(DTOUT)) W $C(7),!!,"*** THIS ORDER HAS NOT BEEN RECEIVED ***",!,"Receiving nurses name must be entered.",!!,"The status remains "_STATN,! L -^PSD(58.81,PSDA) G END ;< RJS - *65
UPDATE ;update 58.8 and 58.81
;updating drug balance in 58.8
F L +^PSD(58.8,NAOU,1,PSDR,0):$S($G(DILOCKTM)>0:DILOCKTM,1:3) I Q
;PSD*3*56;REMOVED CHECK FOR PATIENT ID
S $P(^PSD(58.8,NAOU,1,PSDR,0),"^",4)=$P(^PSD(58.8,NAOU,1,PSDR,0),"^",4)+QTY
L -^PSD(58.8,NAOU,1,PSDR,0)
;update transaction file (58.81)
S OREC=$P($G(^PSD(58.8,NAOU,1,PSDR,3,ORD,0)),"^",7)
K DA,DIE,DR S DA=PSDA,DIE=58.81
S DR="10////"_$S('$P($G(^PSD(58.8,NAOU,2)),U,5):4,$P($G(^PSD(58.81,PSDA,9)),U):4,1:13)_";20////"_OREC_";21////"_RECD_";27////"_QTY_";I OK=1 S Y=""@1"";15COMMENTS;@1"
D ^DIE K DA,DIE,DR
I OK=2 S $P(^PSD(58.81,PSDA,1),"^",11)=PSDUZ
W !!,"Updating your records now..."
;update worksheet file (58.85) to be purged
S DA=+$O(^PSD(58.85,"AD",NAOU,PSDR,ORD,0)) I DA,$D(^PSD(58.85,DA,0)) K DIE,DR S DIE=58.85,DR="6////4" D ^DIE K DA,DIE,DR
W "done.",!!
S STAT=$P($G(^PSD(58.81,PSDA,0)),"^",11) W ?5,"*** Your Green Sheet #"_PSDPN_" is now "_$S($P($G(^PSD(58.82,STAT,0)),"^")]"":$P(^(0),"^"),1:"UNKNOWN")_" ***",!
L -^PSD(58.81,PSDA) ;< RJS - *65
G GS
END K %,%DT,%H,%I,AOU,AOUN,D,DA,DIC,DIE,DR,DTOUT,DUOUT
K NAOU,NAOUN,OK,ORD,OREC,PSDPN,PSDR,PSDRN,PSDUZ,PSDUZN,QTY,RECD,RECDT,RQTY,STAT,STATN,SUB,PSDA,X,Y
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSDNRGS 5531 printed Dec 13, 2024@01:46:59 Page 2
PSDNRGS ;BIR/JPW-Receive Green Sheet for NAOU ; 17 Jan 2017 9:42 AM
+1 ;;3.0;CONTROLLED SUBSTANCES;**56,66,65,81**;13 Feb 97;Build 11
+2 IF '$DATA(PSDSITE)
DO ^PSDSET
if '$DATA(PSDSITE)
QUIT
+3 NEW AKUNITS
+4 SET OK=$SELECT($DATA(^XUSEC("PSJ RNURSE",DUZ)):1,$DATA(^XUSEC("PSD NURSE",DUZ)):1,$DATA(^XUSEC("PSJ RPHARM",DUZ)):2,$DATA(^XUSEC("PSJ PHARM TECH",DUZ)):2,1:0)
+5 IF 'OK
WRITE $CHAR(7),!!,?9,"** Please contact your Coordinator for access to complete",!,?12,"narcotic orders.",!!,"PSJ RNURSE, PSD NURSE, PSJ RPHARM, or PSJ PHARM TECH security key required.",!
KILL OK
QUIT
+6 IF $PIECE($GET(^VA(200,DUZ,20)),U,4)']""
NEW XQH
SET XQH="PSD ESIG"
DO EN^XQH
QUIT
+7 WRITE !!,"Receive Controlled Substances Orders and Green Sheet"
SET PSDUZ=DUZ
SET PSDUZN=$SELECT($PIECE($GET(^VA(200,PSDUZ,0)),"^")]"":$PIECE(^(0),"^"),1:"")
+8 NEW X,X1
DO SIG^XUSESIG
if X1=""
QUIT
ASKN ;ask naou
+1 WRITE !
KILL DA,DIC
SET DIC=58.8
SET DIC(0)="QEAZ"
SET DIC("A")="Select NAOU: "
+2 if OK=1
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)"
+3 if OK=2
SET DIC("S")="I $P(^(0),""^"",3)=+PSDSITE,$S('$D(^(""I"")):1,'^(""I""):1,+^(""I"")>DT:1,1:0),$P(^(0),""^"",2)=""N"""
+4 DO ^DIC
KILL DIC
if Y<0
GOTO END
SET AOU=+Y
SET AOUN=$PIECE(Y,"^",2)
GS ;select green sheet #
+1 WRITE !
KILL DA,DIC
SET DIC("A")="Select the Green Sheet #: "
SET DIC=58.81
SET DIC(0)="QEASZ"
SET D="D"
+2 SET DIC("S")="I $P(^(0),""^"",11),$P(^(0),""^"",11)<12"
+3 DO IX^DIC
KILL DIC
if Y<0
GOTO ASKN
SET PSDA=+Y
+4 ;--------------------------------------------------
+5 ; AKD = Y(0) piece 3 = Pointer to DRUG ACCOUNTABILITY STATS (#58.8)
+6 ; file.
+7 ; AKD(1) = Y(0) piece 5 = Pointer to DRUG (#50) file in DRUG
+8 ; ACCOUNTABILITY (#58.8) file. DRUG (#50) ien is DINUM'ed for
+9 ; DRUG field PSD(58.8,AKD,1,AKD1)
+10 ; AKUNITS = DRUG ACCOUNTABILITY file <> Subfile DRUG <> subfield
+11 ; BREAKDOWN UNIT (Free Text).
+12 Begin DoDot:1
+13 NEW AKD,AKD1
+14 SET AKD=$PIECE(Y(0),"^",3)
SET AKD1=$PIECE(Y(0),"^",5)
+15 SET AKUNITS=$PIECE(^PSD(58.8,AKD,1,AKD1,0),"^",8)
+16 ; display at line beginning
WRITE !,AKUNITS
End DoDot:1
ORD SET STAT=+$PIECE(Y(0),"^",11)
SET PSDPN=$PIECE(Y(0),"^",17)
SET STATN=""
IF STAT
SET STATN=$PIECE($GET(^PSD(58.82,STAT,0)),"^")
+1 SET ORD=+$PIECE(Y(0),"^",20)
SET NAOU=+$PIECE(Y(0),"^",18)
SET NAOUN=$PIECE($GET(^PSD(58.8,NAOU,0)),"^")
SET PSDR=+$PIECE(Y(0),"^",5)
SET PSDRN=$PIECE($GET(^PSDRUG(PSDR,0)),"^")
SET QTY=+$PIECE(Y(0),"^",6)
+2 ; >> RJS - *65
+3 LOCK +^PSD(58.81,PSDA):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
+4 IF '$TEST
WRITE !,"The Green Sheet # ",PSDPN," is currently in use by another user",!,"Please select another Green Sheet.",!
GOTO GS
+5 IF $DATA(^PSD(58.81,PSDA,4))
IF +$PIECE(^(4),"^",3)
SET QTY=$PIECE(^(4),"^",3)
+6 ; <RJS - *65
IF AOU'=NAOU
WRITE $CHAR(7),!!,"The Green Sheet # ",PSDPN," is assigned to ",NAOUN,".",!,"Please select another Green Sheet.",!
LOCK -^PSD(58.81,PSDA)
GOTO GS
+7 ; <RJS - *65
IF '$DATA(^PSD(58.8,NAOU,1,PSDR,3,ORD,0))
WRITE $CHAR(7),!!,"There's no data on ",NAOUN," for Green Sheet # ",PSDPN,".",!,"Contact your Pharmacy Coordinator for assistance.",!
LOCK -^PSD(58.81,PSDA)
GOTO END
+8 ; RJS - *65
IF STAT'=3
WRITE $CHAR(7),!!,"This Green Sheet has a status of "_$SELECT(STATN]"":STATN,1:"UNKNOWN")_".",!,"Please select another Green Sheet.",!
LOCK -^PSD(58.81,PSDA)
GOTO GS
+9 DO NOW^%DTC
SET (RECD,Y)=+$EXTRACT(%,1,12)
XECUTE ^DD("DD")
SET RECDT=Y
REC ;receive at order level in 58.8
+1 WRITE !!,"Accessing ",PSDRN," information...",!!
+2 ;K DA,DIR,DIRUT S DIR(0)="58.81,27",DIR("B")=QTY D ^DIR K DIR I $D(DIRUT) W !!,"Quantity not entered. No action taken.",!,"This order remains ",STATN,!! L -^PSD(58.81,PSDA) G END ; < RJS - *65
+3 KILL DA,DIR,DIRUT
Begin DoDot:1
+4 ; display units in prompt
SET DIR("A")="QUANTITY RECEIVED ("_AKUNITS_")"
End DoDot:1
SET DIR(0)="58.81,27"
SET DIR("B")=QTY
DO ^DIR
KILL DIR
IF $DATA(DIRUT)
WRITE !!,"Quantity not entered. No action taken.",!,"This order remains ",STATN,!!
LOCK -^PSD(58.81,PSDA)
GOTO END
+5 ;< RJS - *65
SET RQTY=Y
IF RQTY'=QTY
WRITE $CHAR(7),!!,"The quantity received does not match the quantity dispensed.",!,"This order must be returned to pharmacy for investigation.",!!
LOCK -^PSD(58.81,PSDA)
GOTO GS
+6 KILL DA,DIE,DR
SET DA=ORD
SET DA(1)=PSDR
SET DA(2)=NAOU
+7 SET DIE="^PSD(58.8,"_DA(2)_",1,"_DA(1)_",3,"
+8 SET DR=$SELECT(OK=1:"6////"_PSDUZ,1:"6RECEIVED BY NURSE")_";20////"_QTY_";15////"_RECD_";10////4;22////"_$PIECE($GET(^PSD(58.8,NAOU,1,PSDR,0)),U,4)_";25////"_$PIECE($GET(^PSD(58.8,NAOU,1,PSDR,0)),U,4)
DO ^DIE
KILL DA,DIE,DR
+9 ;< RJS - *65
IF ($DATA(Y))!($DATA(DTOUT))
WRITE $CHAR(7),!!,"*** THIS ORDER HAS NOT BEEN RECEIVED ***",!,"Receiving nurses name must be entered.",!!,"The status remains "_STATN,!
LOCK -^PSD(58.81,PSDA)
GOTO END
UPDATE ;update 58.8 and 58.81
+1 ;updating drug balance in 58.8
+2 FOR
LOCK +^PSD(58.8,NAOU,1,PSDR,0):$SELECT($GET(DILOCKTM)>0:DILOCKTM,1:3)
IF $TEST
QUIT
+3 ;PSD*3*56;REMOVED CHECK FOR PATIENT ID
+4 SET $PIECE(^PSD(58.8,NAOU,1,PSDR,0),"^",4)=$PIECE(^PSD(58.8,NAOU,1,PSDR,0),"^",4)+QTY
+5 LOCK -^PSD(58.8,NAOU,1,PSDR,0)
+6 ;update transaction file (58.81)
+7 SET OREC=$PIECE($GET(^PSD(58.8,NAOU,1,PSDR,3,ORD,0)),"^",7)
+8 KILL DA,DIE,DR
SET DA=PSDA
SET DIE=58.81
+9 SET DR="10////"_$SELECT('$PIECE($GET(^PSD(58.8,NAOU,2)),U,5):4,$PIECE($GET(^PSD(58.81,PSDA,9)),U):4,1:13)_";20////"_OREC_";21////"_RECD_";27////"_QTY_";I OK=1 S Y=""@1"";15COMMENTS;@1"
+10 DO ^DIE
KILL DA,DIE,DR
+11 IF OK=2
SET $PIECE(^PSD(58.81,PSDA,1),"^",11)=PSDUZ
+12 WRITE !!,"Updating your records now..."
+13 ;update worksheet file (58.85) to be purged
+14 SET DA=+$ORDER(^PSD(58.85,"AD",NAOU,PSDR,ORD,0))
IF DA
IF $DATA(^PSD(58.85,DA,0))
KILL DIE,DR
SET DIE=58.85
SET DR="6////4"
DO ^DIE
KILL DA,DIE,DR
+15 WRITE "done.",!!
+16 SET STAT=$PIECE($GET(^PSD(58.81,PSDA,0)),"^",11)
WRITE ?5,"*** Your Green Sheet #"_PSDPN_" is now "_$SELECT($PIECE($GET(^PSD(58.82,STAT,0)),"^")]"":$PIECE(^(0),"^"),1:"UNKNOWN")_" ***",!
+17 ;< RJS - *65
LOCK -^PSD(58.81,PSDA)
+18 GOTO GS
END KILL %,%DT,%H,%I,AOU,AOUN,D,DA,DIC,DIE,DR,DTOUT,DUOUT
+1 KILL NAOU,NAOUN,OK,ORD,OREC,PSDPN,PSDR,PSDRN,PSDUZ,PSDUZN,QTY,RECD,RECDT,RQTY,STAT,STATN,SUB,PSDA,X,Y
+2 QUIT