PSDPLOG1 ;BIR/JPW,LTL-CS Inspector's Log (cont'd) ; 31 May 95
;;3.0; CONTROLLED SUBSTANCES ;**22,28**;13 Feb 97
;
;References to ^PSD(58.8, covered by DBIA2711
;References to ^PSD(58.81 are covered by DBIA2808
;References to ^PSDRUG( are covered by DBIA221
;References to ^PSI(58.16 are covered by DBIA213
;References to ^PSI(58.2( are covered by DBIA213
;
START ;compile data
K ^TMP("PSDLOG",$J) S (PSDCNT,PSDOUT)=0
I $D(PSDG) F PSD=0:0 S PSD=$O(PSDG(PSD)) Q:'PSD F PSDN=0:0 S PSDN=$O(^PSI(58.2,PSD,3,PSDN)) Q:'PSDN I $D(^PSD(58.8,PSDN,0)),'$P(^(0),"^",7),$P(^(0),"^",3)=+PSDSITE S NAOU(PSDN)="",CNT=CNT+1
I $D(ALL) F PSD=0:0 S PSD=$O(^PSD(58.8,PSD)) Q:'PSD I $D(^PSD(58.8,PSD,0)),$P(^(0),"^",2)="N",$P(^(0),"^",3)=+PSDSITE,'$P(^(0),"^",7) S NAOU(+PSD)=""
F STAT=2.99:0 S STAT=$O(^PSD(58.8,"AC",STAT)) Q:('STAT)!(STAT>5) F PSD=0:0 S PSD=$O(^PSD(58.8,"AC",STAT,PSD)) Q:'PSD D LOOP
S STAT=10 F PSD=0:0 S PSD=$O(^PSD(58.8,"AC",STAT,PSD)) Q:'PSD D LOOP
;PSD*3*28 22JUN00 (DAVE BLOCKER) ;perpetual Inventory
S STAT=13 F PSD=0:0 S PSD=$O(^PSD(58.8,"AC",STAT,PSD)) Q:'PSD I $P($G(^PSD(58.8,+PSD,2)),"^",5)'="" D LOOP
I $G(PSDRET) F PSDN=PSDSD:0 S PSDN=$O(^PSD(58.81,"ACT",PSDN)) Q:'PSDN!(PSDOUT) F JJ=0:0 S JJ=$O(^PSD(58.81,"ACT",PSDN,JJ)) Q:'JJ!(PSDOUT) D
.F PSDR=0:0 S PSDR=$O(^PSD(58.81,"ACT",PSDN,JJ,PSDR)) Q:'PSDR!(PSDOUT) F PSDA=0:0 S PSDA=$O(^PSD(58.81,"ACT",PSDN,JJ,PSDR,3,PSDA)) Q:'PSDA!(PSDOUT) S PSDOK="#" D
..Q:'$D(^PSD(58.81,+PSDA,0)) S NODE=^PSD(58.81,PSDA,0),NODE3=$G(^(3))
..S PSDRN=$S($P($G(^PSDRUG(+PSDR,0)),"^")]"":$P(^(0),"^"),1:"ZZ"_PSDR)
..S PSD=+$P(NODE,"^",18) Q:'$D(NAOU(PSD))
..S PSDNA=$S($P($G(^PSD(58.8,+PSD,0)),"^")]"":$P(^(0),"^"),1:"ZZ/"_PSD)
..S NUM=$S($P(NODE,"^",17)]"":$P(NODE,"^",17),1:"UNKNOWN"),QTY=+$P(NODE3,"^",2),EXP=$P(NODE,"^",15),EXPD="" I EXP S Y=EXP X ^DD("DD") S EXPD=Y
..S Y=$E(PSDN,1,7) X ^DD("DD") S PSDDT=Y
..D SET
G:$D(ZTQUEUED) PRTQUE
I ASKN G PRINT^PSDPLOG3 Q
G PRINT^PSDPLOG2
Q
PRTQUE ;queues print after compile
K ZTSAVE,ZTIO S ZTIO=PSDIO,ZTRTN=$S(ASKN:"PRINT^PSDPLOG3",1:"PRINT^PSDPLOG2"),ZTDESC="Print Narcotic Inspector Log",ZTDTH=$H
S (ZTSAVE("^TMP(""PSDLOG"",$J,"),ZTSAVE("CNT"),ZTSAVE("ASK"),ZTSAVE("ASKN"))=""
D ^%ZTLOAD K ^TMP("PSDLOG",$J),ZTSK
END K %,%DT,%H,%I,%ZIS,ALL,ASK,ASKN,CNT,DA,DIC,DIE,DIR,DIROUT,DIRUT,DR,DTOUT,DUOUT,EXP,EXPD,JJ,NAOU,NODE,NODE3,NUM
K OK,PSD,PSDA,PSDCNT,PSDDT,PSDG,PSDIO,PSDOK,PSDOUT,PSDN,PSDNA,PSDPT,PSDR,PSDRN,PSDRD,PSDRDT,PSDRET,PSDSD,PSDST,PSDT,PSDTR
K QTY,SEL,STAT,STATN,TYP,TYPN,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
K ^TMP("PSDLOG",$J) D ^%ZISC
S:$D(ZTQUEUED) ZTREQ="@"
Q
LOOP ;starts drug loop
F PSDR=0:0 S PSDR=$O(^PSD(58.8,"AC",STAT,PSD,PSDR)) Q:'PSDR D
.F PSDA=0:0 S PSDA=$O(^PSD(58.8,"AC",STAT,PSD,PSDR,PSDA)) Q:'PSDA I $D(^PSD(58.8,PSD,1,PSDR,3,PSDA,0)) S NODE=^PSD(58.8,PSD,1,PSDR,3,PSDA,0) D
..;DAVE B (PSD*3*22) Check for matching ORDER STATUSs
..;First check 58.8's order node for status inconsistency
..S STAT1=$P(NODE,"^",11),STAT2=$P(NODE,"^",12)
..I ($G(STAT1)=6)!($G(STAT1)=7)!($G(STAT1)=8)!($G(STAT1)=9)!($G(STAT1)=11)!($G(STAT1)=12) Q
..I $G(STAT2)>0 Q
..;Then check the transaction file for matching status.
..Q:'$D(NAOU(PSD)) S PSDNA=$S($P($G(^PSD(58.8,+PSD,0)),"^")]"":$P(^(0),"^"),1:"ZZ/"_PSD)
..S PSDOK=$S(STAT=3:"**",STAT=10:"*",1:""),PSDTR=$P(NODE,"^",17) I STAT=10 Q:$D(^PSD(58.81,"AE",PSDTR))
..S PSDRN=$S($P($G(^PSDRUG(PSDR,0)),"^")]"":$P(^(0),"^"),1:"ZZ/"_PSDR),STAT1=+$P(NODE,"^",11),STATN=$S($P($G(^PSD(58.82,STAT1,0)),"^")]"":$P(^(0),"^"),1:"UNKNOWN")
..S QTY=$P(NODE,"^",19),NUM=$S($P(NODE,"^",16)]"":$P(NODE,"^",16),1:"UNKNOWN"),EXP=$P(NODE,"^",10),EXPD="" I EXP S Y=EXP X ^DD("DD") S EXPD=Y
..S PSDST=$P(NODE,"^",14),PSDDT="" I PSDST S Y=$E(PSDST,1,7) X ^DD("DD") S PSDDT=Y
..D SET
Q
SET ;sets ^tmp
S PSDCNT=PSDCNT+1
I ASKN D LOOP0 Q
S:ASK="D" ^TMP("PSDLOG",$J,PSDNA,PSDRN,NUM,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
S:ASK="N" ^TMP("PSDLOG",$J,PSDNA,NUM,PSDRN,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
Q
LOOP0 ;sets sort for inventory type sort
I '$O(^PSD(58.8,PSD,1,PSDR,2,0)) S TYPN="ZZ** NO INVENTORY TYPE DATA **" D LOOP1 Q
;F NAOU=0:0 S NAOU=$O(NAOU(NAOU)) Q:'NAOU
F TYP=0:0 S TYP=$O(^PSD(58.8,+PSD,1,PSDR,2,TYP)) Q:'TYP S TYPN=$S($P($G(^PSI(58.16,+TYP,0)),"^")]"":$P(^(0),"^"),1:"TYPE NAME MISSING") D LOOP1
Q
LOOP1 ;S:ASK="D" ^TMP("PSDLOG",$J,PSDNA,TYPN,PSDRN,NUM,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
S:'$G(TYP) TYP=999999
D:ASK="D"
.S ^TMP("PSDLOG",$J,"B",PSDNA,PSD)="",^TMP("PSDLOG",$J,PSD,+TYP)=0
.S ^TMP("PSDLOG",$J,PSD,"B",TYPN,+TYP)=""
.S ^TMP("PSDLOG",$J,PSD,+TYP,PSDR,NUM,PSDCNT)=QTY_U_PSDDT_U_EXPD_U_PSDOK
.S ^TMP("PSDLOG",$J,PSD,+TYP,"B",PSDRN,PSDR)=""
;S:ASK="N" ^TMP("PSDLOG",$J,PSDNA,TYPN,NUM,PSDRN,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
D:ASK="N"
.S ^TMP("PSDLOG",$J,"B",PSDNA,PSD)="",^TMP("PSDLOG",$J,PSD,+TYP)=0
.S ^TMP("PSDLOG",$J,PSD,"B",TYPN,+TYP)=""
.S ^TMP("PSDLOG",$J,PSD,+TYP,NUM,PSDR,PSDCNT)=QTY_U_PSDDT_U_EXPD_U_PSDOK_U_PSDRN
Q
PSDPLOG1 ;BIR/JPW,LTL-CS Inspector's Log (cont'd) ; 31 May 95
+1 ;;3.0; CONTROLLED SUBSTANCES ;**22,28**;13 Feb 97
+2 ;
+3 ;References to ^PSD(58.8, covered by DBIA2711
+4 ;References to ^PSD(58.81 are covered by DBIA2808
+5 ;References to ^PSDRUG( are covered by DBIA221
+6 ;References to ^PSI(58.16 are covered by DBIA213
+7 ;References to ^PSI(58.2( are covered by DBIA213
+8 ;
START ;compile data
+1 KILL ^TMP("PSDLOG",$JOB)
SET (PSDCNT,PSDOUT)=0
+2 IF $DATA(PSDG)
FOR PSD=0:0
SET PSD=$ORDER(PSDG(PSD))
IF 'PSD
QUIT
FOR PSDN=0:0
SET PSDN=$ORDER(^PSI(58.2,PSD,3,PSDN))
IF 'PSDN
QUIT
IF $DATA(^PSD(58.8,PSDN,0))
IF '$PIECE(^(0),"^",7)
IF $PIECE(^(0),"^",3)=+PSDSITE
SET NAOU(PSDN)=""
SET CNT=CNT+1
+3 IF $DATA(ALL)
FOR PSD=0:0
SET PSD=$ORDER(^PSD(58.8,PSD))
IF 'PSD
QUIT
IF $DATA(^PSD(58.8,PSD,0))
IF $PIECE(^(0),"^",2)="N"
IF $PIECE(^(0),"^",3)=+PSDSITE
IF '$PIECE(^(0),"^",7)
SET NAOU(+PSD)=""
+4 FOR STAT=2.99:0
SET STAT=$ORDER(^PSD(58.8,"AC",STAT))
IF ('STAT)!(STAT>5)
QUIT
FOR PSD=0:0
SET PSD=$ORDER(^PSD(58.8,"AC",STAT,PSD))
IF 'PSD
QUIT
DO LOOP
+5 SET STAT=10
FOR PSD=0:0
SET PSD=$ORDER(^PSD(58.8,"AC",STAT,PSD))
IF 'PSD
QUIT
DO LOOP
+6 ;PSD*3*28 22JUN00 (DAVE BLOCKER) ;perpetual Inventory
+7 SET STAT=13
FOR PSD=0:0
SET PSD=$ORDER(^PSD(58.8,"AC",STAT,PSD))
IF 'PSD
QUIT
IF $PIECE($GET(^PSD(58.8,+PSD,2)),"^",5)'=""
DO LOOP
+8 IF $GET(PSDRET)
FOR PSDN=PSDSD:0
SET PSDN=$ORDER(^PSD(58.81,"ACT",PSDN))
IF 'PSDN!(PSDOUT)
QUIT
FOR JJ=0:0
SET JJ=$ORDER(^PSD(58.81,"ACT",PSDN,JJ))
IF 'JJ!(PSDOUT)
QUIT
Begin DoDot:1
+9 FOR PSDR=0:0
SET PSDR=$ORDER(^PSD(58.81,"ACT",PSDN,JJ,PSDR))
IF 'PSDR!(PSDOUT)
QUIT
FOR PSDA=0:0
SET PSDA=$ORDER(^PSD(58.81,"ACT",PSDN,JJ,PSDR,3,PSDA))
IF 'PSDA!(PSDOUT)
QUIT
SET PSDOK="#"
Begin DoDot:2
+10 IF '$DATA(^PSD(58.81,+PSDA,0))
QUIT
SET NODE=^PSD(58.81,PSDA,0)
SET NODE3=$GET(^(3))
+11 SET PSDRN=$SELECT($PIECE($GET(^PSDRUG(+PSDR,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ"_PSDR)
+12 SET PSD=+$PIECE(NODE,"^",18)
IF '$DATA(NAOU(PSD))
QUIT
+13 SET PSDNA=$SELECT($PIECE($GET(^PSD(58.8,+PSD,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ/"_PSD)
+14 SET NUM=$SELECT($PIECE(NODE,"^",17)]"":$PIECE(NODE,"^",17),1:"UNKNOWN")
SET QTY=+$PIECE(NODE3,"^",2)
SET EXP=$PIECE(NODE,"^",15)
SET EXPD=""
IF EXP
SET Y=EXP
XECUTE ^DD("DD")
SET EXPD=Y
+15 SET Y=$EXTRACT(PSDN,1,7)
XECUTE ^DD("DD")
SET PSDDT=Y
+16 DO SET
End DoDot:2
End DoDot:1
+17 IF $DATA(ZTQUEUED)
GOTO PRTQUE
+18 IF ASKN
GOTO PRINT^PSDPLOG3
QUIT
+19 GOTO PRINT^PSDPLOG2
+20 QUIT
PRTQUE ;queues print after compile
+1 KILL ZTSAVE,ZTIO
SET ZTIO=PSDIO
SET ZTRTN=$SELECT(ASKN:"PRINT^PSDPLOG3",1:"PRINT^PSDPLOG2")
SET ZTDESC="Print Narcotic Inspector Log"
SET ZTDTH=$HOROLOG
+2 SET (ZTSAVE("^TMP(""PSDLOG"",$J,"),ZTSAVE("CNT"),ZTSAVE("ASK"),ZTSAVE("ASKN"))=""
+3 DO ^%ZTLOAD
KILL ^TMP("PSDLOG",$JOB),ZTSK
END KILL %,%DT,%H,%I,%ZIS,ALL,ASK,ASKN,CNT,DA,DIC,DIE,DIR,DIROUT,DIRUT,DR,DTOUT,DUOUT,EXP,EXPD,JJ,NAOU,NODE,NODE3,NUM
+1 KILL OK,PSD,PSDA,PSDCNT,PSDDT,PSDG,PSDIO,PSDOK,PSDOUT,PSDN,PSDNA,PSDPT,PSDR,PSDRN,PSDRD,PSDRDT,PSDRET,PSDSD,PSDST,PSDT,PSDTR
+2 KILL QTY,SEL,STAT,STATN,TYP,TYPN,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE,ZTSK
+3 KILL ^TMP("PSDLOG",$JOB)
DO ^%ZISC
+4 IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+5 QUIT
LOOP ;starts drug loop
+1 FOR PSDR=0:0
SET PSDR=$ORDER(^PSD(58.8,"AC",STAT,PSD,PSDR))
IF 'PSDR
QUIT
Begin DoDot:1
+2 FOR PSDA=0:0
SET PSDA=$ORDER(^PSD(58.8,"AC",STAT,PSD,PSDR,PSDA))
IF 'PSDA
QUIT
IF $DATA(^PSD(58.8,PSD,1,PSDR,3,PSDA,0))
SET NODE=^PSD(58.8,PSD,1,PSDR,3,PSDA,0)
Begin DoDot:2
+3 ;DAVE B (PSD*3*22) Check for matching ORDER STATUSs
+4 ;First check 58.8's order node for status inconsistency
+5 SET STAT1=$PIECE(NODE,"^",11)
SET STAT2=$PIECE(NODE,"^",12)
+6 IF ($GET(STAT1)=6)!($GET(STAT1)=7)!($GET(STAT1)=8)!($GET(STAT1)=9)!($GET(STAT1)=11)!($GET(STAT1)=12)
QUIT
+7 IF $GET(STAT2)>0
QUIT
+8 ;Then check the transaction file for matching status.
+9 IF '$DATA(NAOU(PSD))
QUIT
SET PSDNA=$SELECT($PIECE($GET(^PSD(58.8,+PSD,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ/"_PSD)
+10 SET PSDOK=$SELECT(STAT=3:"**",STAT=10:"*",1:"")
SET PSDTR=$PIECE(NODE,"^",17)
IF STAT=10
IF $DATA(^PSD(58.81,"AE",PSDTR))
QUIT
+11 SET PSDRN=$SELECT($PIECE($GET(^PSDRUG(PSDR,0)),"^")]"":$PIECE(^(0),"^"),1:"ZZ/"_PSDR)
SET STAT1=+$PIECE(NODE,"^",11)
SET STATN=$SELECT($PIECE($GET(^PSD(58.82,STAT1,0)),"^")]"":$PIECE(^(0),"^"),1:"UNKNOWN")
+12 SET QTY=$PIECE(NODE,"^",19)
SET NUM=$SELECT($PIECE(NODE,"^",16)]"":$PIECE(NODE,"^",16),1:"UNKNOWN")
SET EXP=$PIECE(NODE,"^",10)
SET EXPD=""
IF EXP
SET Y=EXP
XECUTE ^DD("DD")
SET EXPD=Y
+13 SET PSDST=$PIECE(NODE,"^",14)
SET PSDDT=""
IF PSDST
SET Y=$EXTRACT(PSDST,1,7)
XECUTE ^DD("DD")
SET PSDDT=Y
+14 DO SET
End DoDot:2
End DoDot:1
+15 QUIT
SET ;sets ^tmp
+1 SET PSDCNT=PSDCNT+1
+2 IF ASKN
DO LOOP0
QUIT
+3 IF ASK="D"
SET ^TMP("PSDLOG",$JOB,PSDNA,PSDRN,NUM,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
+4 IF ASK="N"
SET ^TMP("PSDLOG",$JOB,PSDNA,NUM,PSDRN,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
+5 QUIT
LOOP0 ;sets sort for inventory type sort
+1 IF '$ORDER(^PSD(58.8,PSD,1,PSDR,2,0))
SET TYPN="ZZ** NO INVENTORY TYPE DATA **"
DO LOOP1
QUIT
+2 ;F NAOU=0:0 S NAOU=$O(NAOU(NAOU)) Q:'NAOU
+3 FOR TYP=0:0
SET TYP=$ORDER(^PSD(58.8,+PSD,1,PSDR,2,TYP))
IF 'TYP
QUIT
SET TYPN=$SELECT($PIECE($GET(^PSI(58.16,+TYP,0)),"^")]"":$PIECE(^(0),"^"),1:"TYPE NAME MISSING")
DO LOOP1
+4 QUIT
LOOP1 ;S:ASK="D" ^TMP("PSDLOG",$J,PSDNA,TYPN,PSDRN,NUM,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
+1 IF '$GET(TYP)
SET TYP=999999
+2 IF ASK="D"
Begin DoDot:1
+3 SET ^TMP("PSDLOG",$JOB,"B",PSDNA,PSD)=""
SET ^TMP("PSDLOG",$JOB,PSD,+TYP)=0
+4 SET ^TMP("PSDLOG",$JOB,PSD,"B",TYPN,+TYP)=""
+5 SET ^TMP("PSDLOG",$JOB,PSD,+TYP,PSDR,NUM,PSDCNT)=QTY_U_PSDDT_U_EXPD_U_PSDOK
+6 SET ^TMP("PSDLOG",$JOB,PSD,+TYP,"B",PSDRN,PSDR)=""
End DoDot:1
+7 ;S:ASK="N" ^TMP("PSDLOG",$J,PSDNA,TYPN,NUM,PSDRN,PSDCNT)=QTY_"^"_PSDDT_"^"_EXPD_"^"_PSDOK
+8 IF ASK="N"
Begin DoDot:1
+9 SET ^TMP("PSDLOG",$JOB,"B",PSDNA,PSD)=""
SET ^TMP("PSDLOG",$JOB,PSD,+TYP)=0
+10 SET ^TMP("PSDLOG",$JOB,PSD,"B",TYPN,+TYP)=""
+11 SET ^TMP("PSDLOG",$JOB,PSD,+TYP,NUM,PSDR,PSDCNT)=QTY_U_PSDDT_U_EXPD_U_PSDOK_U_PSDRN
End DoDot:1
+12 QUIT