PSGAP0 ;BIR/CML3-ACTION PROFILE ;20 May 98 / 12:36 PM
;;5.0; INPATIENT MEDICATIONS ;**8,58,111**;16 DEC 97
;
; Reference to ^PS(55 is supported by DBIA# 2191
;
GOD ; gather order data
S ND=$G(^PS(55,PSGP,5,PSJJORD,0)),ND2=$G(^(2)),SI=$P($G(^(6)),"^"),DRG=$G(^(.2)) ;WS=$S(DRG&PSGAPWD:$D(^PSI(58.1,"D",+DRG,PSGAPWD)),1:0),DRG=$G(^PS(50.7,+DRG,0))
;S NF=$P(DRG,"^",9)
S X=$$NFWS^PSJUTL1(PSGP,PSJJORD_"U",PSGAPWD) S NF=$P(X,U),WS=$P(X,U,2),SM=$S('$P(X,U,3):0,$P(X,U,4):1,1:2)
N X,PSG
D DRGDISP^PSJLMUT1(PSGP,PSJJORD_"U",40,0,.PSG,1)
S DRG=PSG(1),DRG=$S(DRG["NOT FOUND":"z",1:DRG)
S ST=$P(ND,"^",9),ND=$P(ND,"^",7),SD=$P(ND2,"^",2),FD=$P(ND2,"^",4)
I STP'=9999999\1,(SD>STP) Q
F X="SD","FD" S @X=$E($$ENDTC^PSGMI(@X),1,5)
;
S Y=SI S:Y]"" Y=$$ENSET^PSGSICHK(Y) S X=ND_U_$E(DRG,1,20),^TMP($J,$E(PSGAPWDN,1,20),TM,PN,X,+PSJJORD)=ST_U_SD_U_FD_U_WS_U_SM_U_NF S:Y]"" ^(PSJJORD,1)=Y
Q
;
PAT ;
;;S RB=$G(^DPT(PSGP,.101)),TM="zz" S:RB]"" TM=$S('$D(PSGAPTM):"zz",1:$O(^PS(57.7,"AWRT",PSGAPWD,RB,0))) I PSGAPWDN="" S PSGAPWDN="* NF *"
S RB=$G(^DPT(PSGP,.101)) S:RB]"" TM=$S('$D(PSGAPTM):"zz",1:$O(^PS(57.7,"AWRT",PSGAPWD,RB,0))) S:$G(TM)="" TM="zz" I PSGAPWDN="" S PSGAPWDN="* NF *"
I $D(PSGAPTM) S ATM="",ATM=$O(PSGAPTM(ATM)) I ATM'="ALL" Q:'$D(PSGAPTM(+TM))
S:TM'="zz" TM=^PS(57.7,PSGAPWD,1,TM,0)
S PSJACNWP=1 D PSJAC2^PSJAC(1),NOW^%DTC S PSGDT=%,PND=PSGP(0),PN=$S($G(PSJSEL("RBP"))="R":RB,1:"")_"^"_$E($P(PND,"^"),1,20)_"^"_PSGP
I '$G(STT) S STT=PSGDT,STP=9999999
S:PSGMTYPE[1 PSGMTYPE="2,3,4,5,6"
I PSGMTYPE[2 D
. F STRT=STT:0 S STRT=$O(^PS(55,PSGP,5,"AUS",STRT)) Q:'STRT F PSJJORD=0:0 S PSJJORD=$O(^PS(55,PSGP,5,"AUS",STRT,PSJJORD)) Q:'PSJJORD D GOD
. S XTYPE=2,PST="S" D ^PSGAPIV
N XTYPE F XTYPE=3:1:6 I PSGMTYPE[XTYPE S PST=$S(XTYPE=3:"P",XTYPE=4:"A",XTYPE=5:"H",1:"C") D ^PSGAPIV
I PSGMTYPE[3 S XTYPE=3,PST="S" D ^PSGAPIV ;* Find syringe type iv
I $D(^TMP($J,$E(PSGAPWDN,1,20),TM,PN)) D
. ;naked reference on line below refers to full global reference on line above
. S ^(PN)=$P(PSJPSEX,"^",2)_"^"_$E($P(PSJPDOB,"^",2),1,10)_";"_PSJPAGE_"^"_VA("PID")_"^"_PSJPDX_"^"_$S(PSJPRB]"":PSJPRB,1:"*NF*")_"^"_$E($P(PSJPAD,"^",2),1,10)_"^"_$E($P(PSJPTD,"^",2),1,10)_"^"_+PSJPWT
. S:($G(PSJSEL("WG"))="^OTHER") ^TMP("PSGAP0",$J,"OUTPT",PSGP)=""
Q
;
GDT ;
K %DT S %DT="EFTX",Y=-1,%DT(0)=$S(N["R":PSGDT,1:STT) F W !!,"Enter ",N," date/time: " R X:DTIME W:'$T $C(7) S:'$T X="^" Q:"^"[X D DTM:X?1."?",^%DT Q:Y>0
I X'="^" S:N["R" STT=$S(Y'>0:PSGDT,Y#1:+$E(Y,1,12),1:Y+.0002)-.0001 S:N["O" STP=$S(Y'>0:9999999,Y#1:+$E(Y,1,12),1:Y+.24)
K %DT Q
;
EN ; entry point
I PSGSS'="P" D NOW^%DTC S PSGDT=%,DT=$$DT^XLFDT F N="START","STOP" D GDT I X="^" S PSJSTOP=1 Q
I PSGSS'="P" Q:X="^" S:'$P(STP,".",2) $P(STP,".",2)=24 S:'$P(STT,".",2) $P(STT,".",2)="0001"
S PSJSTOP=$$MEDTYPE^PSJMDIR($G(PSGWD)) Q:PSJSTOP S PSGMTYPE=Y
K ZTSAVE S:PSGSS'="P" (ZTSAVE("STT"),ZTSAVE("STP"))="" F X="PSGP","PSGSS","PSGAPWD","PSGAPWG","PSGAPWDN","PSGAPWGN","PSGPAT(","PSGAPTM(","PSGMTYPE","PSGPTMP","PSJSEL(","PSJOS","PPAGE" S ZTSAVE(X)=""
W !,"...this may take a few minutes...(you should QUEUE this report)..."
S PSGTIR="ENQ^PSGAP0",ZTDESC="ACTION PROFILE" D ENDEV^PSGTI S:POP PSJSTOP=1 Q:POP!$D(IO("Q"))
;
ENQ ; queued entry point
K ^TMP("PSGAP0",$J) N RB,ATM,TM,DRGI,DRGN,DRGT,ON,PST,PSIVUP,PSJORIFN,QST,SLS,XTYPE
D @("P"_PSGSS),^PSGAPP D ^%ZISC K ^TMP("PSGAP0",$J)
Q
;
PG ;
I $G(PSJSEL("WG"))="^OTHER" D CLIN Q
F PSGAPWD=0:0 S PSGAPWD=$O(^PS(57.5,"AC",PSGAPWG,PSGAPWD)) Q:'PSGAPWD I $D(^DIC(42,PSGAPWD,0)),$P(^(0),"^")]"" S PSGAPWDN=$P(^(0),"^") D PW
Q
;
CLIN ;
F INDEX="AIVC","AUDC" S STOP=0 F S STOP=$O(^PS(55,INDEX,STOP)) Q:'STOP S CLIN=0 F S CLIN=$O(^PS(55,INDEX,STOP,CLIN)) Q:'CLIN D
. S DFN=0 F S DFN=$O(^PS(55,INDEX,STOP,CLIN,DFN)) Q:'DFN I '$D(^TMP("PSGAP0",$J,"OUTPT",DFN)) D
.. S PSGP=DFN,Q=STOP N STOP D PAT
Q
;
PW ;
F PSGP=0:0 S PSGP=$O(^DPT("CN",PSGAPWDN,PSGP)) Q:'PSGP D
.S Q=$O(^PS(55,PSGP,5,"AUS",STT)) I Q D PAT Q
.S Q=$O(^PS(55,PSGP,"IV","AIS",STT)) I Q D PAT
Q
;
PP ;
F PSGP=0:0 S PSGP=$O(PSGPAT(PSGP)) Q:'PSGP S PSGAPWDN=$P($G(^DPT(PSGP,.1)),"^") S:PSGAPWDN]"" PSGAPWD=+$O(^DIC(42,"B",PSGAPWDN,0)) D PAT
Q
;
DTM ;
S Y=%DT(0) D D^DIQ S T=$P(Y,"@",2),Y=$P(Y,",")
W !!?2,"If a ",N," date is entered, an action profile will print for only those",!,"patients that have at least one active order with a ",$S(N["A":"STOP",1:"START")," DATE on or ",$S(N["A":"after",1:"before"),!,"the ",N," date entered."
W !?2,"Entry is not required. If neither date is entered, all patients with active",!,"orders will print (for the ward(s) chosen). Enter an up-arrow (^) to exit."
W !?2,"If you wish to enter a ",$S(N["R":"start",1:"stop")," date of ",Y,", you must enter a TIME of day",!,"of ",T," or greater. Any date after ",Y," does not need time entered.",! S Y=-1 Q
PSGAP0 ;BIR/CML3-ACTION PROFILE ;20 May 98 / 12:36 PM
+1 ;;5.0; INPATIENT MEDICATIONS ;**8,58,111**;16 DEC 97
+2 ;
+3 ; Reference to ^PS(55 is supported by DBIA# 2191
+4 ;
GOD ; gather order data
+1 ;WS=$S(DRG&PSGAPWD:$D(^PSI(58.1,"D",+DRG,PSGAPWD)),1:0),DRG=$G(^PS(50.7,+DRG,0))
SET ND=$GET(^PS(55,PSGP,5,PSJJORD,0))
SET ND2=$GET(^(2))
SET SI=$PIECE($GET(^(6)),"^")
SET DRG=$GET(^(.2))
+2 ;S NF=$P(DRG,"^",9)
+3 SET X=$$NFWS^PSJUTL1(PSGP,PSJJORD_"U",PSGAPWD)
SET NF=$PIECE(X,U)
SET WS=$PIECE(X,U,2)
SET SM=$SELECT('$PIECE(X,U,3):0,$PIECE(X,U,4):1,1:2)
+4 NEW X,PSG
+5 DO DRGDISP^PSJLMUT1(PSGP,PSJJORD_"U",40,0,.PSG,1)
+6 SET DRG=PSG(1)
SET DRG=$SELECT(DRG["NOT FOUND":"z",1:DRG)
+7 SET ST=$PIECE(ND,"^",9)
SET ND=$PIECE(ND,"^",7)
SET SD=$PIECE(ND2,"^",2)
SET FD=$PIECE(ND2,"^",4)
+8 IF STP'=9999999\1
IF (SD>STP)
QUIT
+9 FOR X="SD","FD"
SET @X=$EXTRACT($$ENDTC^PSGMI(@X),1,5)
+10 ;
+11 SET Y=SI
IF Y]""
SET Y=$$ENSET^PSGSICHK(Y)
SET X=ND_U_$EXTRACT(DRG,1,20)
SET ^TMP($JOB,$EXTRACT(PSGAPWDN,1,20),TM,PN,X,+PSJJORD)=ST_U_SD_U_FD_U_WS_U_SM_U_NF
IF Y]""
SET ^(PSJJORD,1)=Y
+12 QUIT
+13 ;
PAT ;
+1 ;;S RB=$G(^DPT(PSGP,.101)),TM="zz" S:RB]"" TM=$S('$D(PSGAPTM):"zz",1:$O(^PS(57.7,"AWRT",PSGAPWD,RB,0))) I PSGAPWDN="" S PSGAPWDN="* NF *"
+2 SET RB=$GET(^DPT(PSGP,.101))
IF RB]""
SET TM=$SELECT('$DATA(PSGAPTM):"zz",1:$ORDER(^PS(57.7,"AWRT",PSGAPWD,RB,0)))
IF $GET(TM)=""
SET TM="zz"
IF PSGAPWDN=""
SET PSGAPWDN="* NF *"
+3 IF $DATA(PSGAPTM)
SET ATM=""
SET ATM=$ORDER(PSGAPTM(ATM))
IF ATM'="ALL"
IF '$DATA(PSGAPTM(+TM))
QUIT
+4 IF TM'="zz"
SET TM=^PS(57.7,PSGAPWD,1,TM,0)
+5 SET PSJACNWP=1
DO PSJAC2^PSJAC(1)
DO NOW^%DTC
SET PSGDT=%
SET PND=PSGP(0)
SET PN=$SELECT($GET(PSJSEL("RBP"))="R":RB,1:"")_"^"_$EXTRACT($PIECE(PND,"^"),1,20)_"^"_PSGP
+6 IF '$GET(STT)
SET STT=PSGDT
SET STP=9999999
+7 IF PSGMTYPE[1
SET PSGMTYPE="2,3,4,5,6"
+8 IF PSGMTYPE[2
Begin DoDot:1
+9 FOR STRT=STT:0
SET STRT=$ORDER(^PS(55,PSGP,5,"AUS",STRT))
IF 'STRT
QUIT
FOR PSJJORD=0:0
SET PSJJORD=$ORDER(^PS(55,PSGP,5,"AUS",STRT,PSJJORD))
IF 'PSJJORD
QUIT
DO GOD
+10 SET XTYPE=2
SET PST="S"
DO ^PSGAPIV
End DoDot:1
+11 NEW XTYPE
FOR XTYPE=3:1:6
IF PSGMTYPE[XTYPE
SET PST=$SELECT(XTYPE=3:"P",XTYPE=4:"A",XTYPE=5:"H",1:"C")
DO ^PSGAPIV
+12 ;* Find syringe type iv
IF PSGMTYPE[3
SET XTYPE=3
SET PST="S"
DO ^PSGAPIV
+13 IF $DATA(^TMP($JOB,$EXTRACT(PSGAPWDN,1,20),TM,PN))
Begin DoDot:1
+14 ;naked reference on line below refers to full global reference on line above
+15 SET ^(PN)=$PIECE(PSJPSEX,"^",2)_"^"_$EXTRACT($PIECE(PSJPDOB,"^",2),1,10)_";"_PSJPAGE_"^"_VA("PID")_"^"_PSJPDX_"^"_$SELECT(PSJPRB]"":PSJPRB,1:"*NF*")_"^"_$EXTRACT($PIECE(PSJPAD,"^",2),1,10)_"^"_$EXTRACT($PIECE(PSJPTD,"^",2),1,10)_"^"_+PS
JPWT
+16 IF ($GET(PSJSEL("WG"))="^OTHER")
SET ^TMP("PSGAP0",$JOB,"OUTPT",PSGP)=""
End DoDot:1
+17 QUIT
+18 ;
GDT ;
+1 KILL %DT
SET %DT="EFTX"
SET Y=-1
SET %DT(0)=$SELECT(N["R":PSGDT,1:STT)
FOR
WRITE !!,"Enter ",N," date/time: "
READ X:DTIME
IF '$TEST
WRITE $CHAR(7)
IF '$TEST
SET X="^"
IF "^"[X
QUIT
IF X?1."?"
DO DTM
DO ^%DT
IF Y>0
QUIT
+2 IF X'="^"
IF N["R"
SET STT=$SELECT(Y'>0:PSGDT,Y#1:+$EXTRACT(Y,1,12),1:Y+.0002)-.0001
IF N["O"
SET STP=$SELECT(Y'>0:9999999,Y#1:+$EXTRACT(Y,1,12),1:Y+.24)
+3 KILL %DT
QUIT
+4 ;
EN ; entry point
+1 IF PSGSS'="P"
DO NOW^%DTC
SET PSGDT=%
SET DT=$$DT^XLFDT
FOR N="START","STOP"
DO GDT
IF X="^"
SET PSJSTOP=1
QUIT
+2 IF PSGSS'="P"
IF X="^"
QUIT
IF '$PIECE(STP,".",2)
SET $PIECE(STP,".",2)=24
IF '$PIECE(STT,".",2)
SET $PIECE(STT,".",2)="0001"
+3 SET PSJSTOP=$$MEDTYPE^PSJMDIR($GET(PSGWD))
IF PSJSTOP
QUIT
SET PSGMTYPE=Y
+4 KILL ZTSAVE
IF PSGSS'="P"
SET (ZTSAVE("STT"),ZTSAVE("STP"))=""
FOR X="PSGP","PSGSS","PSGAPWD","PSGAPWG","PSGAPWDN","PSGAPWGN","PSGPAT(","PSGAPTM(","PSGMTYPE","PSGPTMP","PSJSEL(","PSJOS","PPAGE"
SET ZTSAVE(X)=""
+5 WRITE !,"...this may take a few minutes...(you should QUEUE this report)..."
+6 SET PSGTIR="ENQ^PSGAP0"
SET ZTDESC="ACTION PROFILE"
DO ENDEV^PSGTI
IF POP
SET PSJSTOP=1
IF POP!$DATA(IO("Q"))
QUIT
+7 ;
ENQ ; queued entry point
+1 KILL ^TMP("PSGAP0",$JOB)
NEW RB,ATM,TM,DRGI,DRGN,DRGT,ON,PST,PSIVUP,PSJORIFN,QST,SLS,XTYPE
+2 DO @("P"_PSGSS)
DO ^PSGAPP
DO ^%ZISC
KILL ^TMP("PSGAP0",$JOB)
+3 QUIT
+4 ;
PG ;
+1 IF $GET(PSJSEL("WG"))="^OTHER"
DO CLIN
QUIT
+2 FOR PSGAPWD=0:0
SET PSGAPWD=$ORDER(^PS(57.5,"AC",PSGAPWG,PSGAPWD))
IF 'PSGAPWD
QUIT
IF $DATA(^DIC(42,PSGAPWD,0))
IF $PIECE(^(0),"^")]""
SET PSGAPWDN=$PIECE(^(0),"^")
DO PW
+3 QUIT
+4 ;
CLIN ;
+1 FOR INDEX="AIVC","AUDC"
SET STOP=0
FOR
SET STOP=$ORDER(^PS(55,INDEX,STOP))
IF 'STOP
QUIT
SET CLIN=0
FOR
SET CLIN=$ORDER(^PS(55,INDEX,STOP,CLIN))
IF 'CLIN
QUIT
Begin DoDot:1
+2 SET DFN=0
FOR
SET DFN=$ORDER(^PS(55,INDEX,STOP,CLIN,DFN))
IF 'DFN
QUIT
IF '$DATA(^TMP("PSGAP0",$JOB,"OUTPT",DFN))
Begin DoDot:2
+3 SET PSGP=DFN
SET Q=STOP
NEW STOP
DO PAT
End DoDot:2
End DoDot:1
+4 QUIT
+5 ;
PW ;
+1 FOR PSGP=0:0
SET PSGP=$ORDER(^DPT("CN",PSGAPWDN,PSGP))
IF 'PSGP
QUIT
Begin DoDot:1
+2 SET Q=$ORDER(^PS(55,PSGP,5,"AUS",STT))
IF Q
DO PAT
QUIT
+3 SET Q=$ORDER(^PS(55,PSGP,"IV","AIS",STT))
IF Q
DO PAT
End DoDot:1
+4 QUIT
+5 ;
PP ;
+1 FOR PSGP=0:0
SET PSGP=$ORDER(PSGPAT(PSGP))
IF 'PSGP
QUIT
SET PSGAPWDN=$PIECE($GET(^DPT(PSGP,.1)),"^")
IF PSGAPWDN]""
SET PSGAPWD=+$ORDER(^DIC(42,"B",PSGAPWDN,0))
DO PAT
+2 QUIT
+3 ;
DTM ;
+1 SET Y=%DT(0)
DO D^DIQ
SET T=$PIECE(Y,"@",2)
SET Y=$PIECE(Y,",")
+2 WRITE !!?2,"If a ",N," date is entered, an action profile will print for only those",!,"patients that have at least one active order with a ",$SELECT(N["A":"STOP",1:"START")," DATE on or ",$SELECT(N["A":"after",1:"before"),!,"the ",N," date ent
ered."
+3 WRITE !?2,"Entry is not required. If neither date is entered, all patients with active",!,"orders will print (for the ward(s) chosen). Enter an up-arrow (^) to exit."
+4 WRITE !?2,"If you wish to enter a ",$SELECT(N["R":"start",1:"stop")," date of ",Y,", you must enter a TIME of day",!,"of ",T," or greater. Any date after ",Y," does not need time entered.",!
SET Y=-1
QUIT