186 lines
8.2 KiB
Mathematica
186 lines
8.2 KiB
Mathematica
PSBVDLU1 ;BIRMINGHAM/EFC-VIRTUAL DUE LIST (VDL) UTILITIES ;Mar 2004
|
|
;;3.0;BAR CODE MED ADMIN;**13,32**;Mar 2004;Build 32
|
|
;
|
|
; Reference/IA
|
|
; EN^PSJBCMA1/2829
|
|
;
|
|
ODDSCH(PSBTABX) ;
|
|
I (PSBOST'<PSBWBEG)&(PSBOST'>PSBWEND) D ADD(PSBREC,PSBOTXT,PSBOST,PSBDDS,PSBSOLS,PSBADDS,PSBTABX) ;Include start date/time as admin
|
|
S PSBQUIT=0,PSBCDT=PSBOST F S PSBCDT=$$FMADD^XLFDT(PSBCDT,"","",PSBFREQ) Q:PSBQUIT=1 D
|
|
.I $P(PSBCDT,".",2)="" S PSBCDT=PSBCDT-1_".24"
|
|
.I PSBCDT>PSBWEND S PSBQUIT=1 Q
|
|
.I PSBCDT'<PSBWBEG,PSBCDT<PSBOSP D ADD(PSBREC,PSBOTXT,PSBCDT,PSBDDS,PSBSOLS,PSBADDS,PSBTABX) Q
|
|
Q
|
|
GETFREQ(PSBDFN,PSBORDN) ;
|
|
K ^TMP("PSJ1",$J)
|
|
D EN^PSJBCMA1(PSBDFN,PSBORDN,1)
|
|
S PSBFREQ=$P(^TMP("PSJ1",$J,4),U,11)
|
|
S PSBSCHBR=$P(^TMP("PSJ1",$J,2),"^",5)
|
|
I $$PSBDCHK1^PSBVT1(PSBSCHBR) S PSBFREQ=""
|
|
K ^TMP("PSJ1",$J)
|
|
Q PSBFREQ
|
|
;
|
|
GETADMIN(PSBDFN,PSBORDN,PSBSTRT,PSBFREQ,PSBEVDT) ;
|
|
;Determine administration times of an odd schedule for today
|
|
N PSBADMIN
|
|
K ^TMP("PSB",$J,"GETADMIN")
|
|
D EN^PSJBCMA1(PSBDFN,PSBORDN,1)
|
|
S PSBADMIN=$P(^TMP("PSJ1",$J,4),U,9),PSBFREQ=$P(^TMP("PSJ1",$J,4),U,11),^TMP("PSB",$J,"GETADMIN",0)=PSBADMIN
|
|
I $E(PSBFREQ)'?1N K ^TMP("PSJ1",$J) Q $G(^TMP("PSB",$J,"GETADMIN",0))
|
|
I PSBFREQ=0 K ^TMP("PSJ1",$J) Q $G(^TMP("PSB",$J,"GETADMIN",0))
|
|
I PSBSTRT'<PSBEVDT S PSBADMIN=$E($P(PSBSTRT,".",2)_"0000",1,4),^TMP("PSB",$J,"GETADMIN",0)=PSBADMIN
|
|
S PSBCDT=PSBSTRT,(PSBADTMX,PSBQUIT)=0 F S PSBCDT=$$FMADD^XLFDT(PSBCDT,"","",PSBFREQ) D Q:PSBQUIT=1
|
|
.I $P(PSBCDT,".",2)="" S PSBCDT=PSBCDT-1_".24"
|
|
.I (PSBCDT\1)>(PSBEVDT\1) S PSBQUIT=1 Q
|
|
.I (PSBCDT\1)=(PSBEVDT\1) S PSBADMIN=PSBADMIN_$S(PSBADMIN="":"",1:"-")_$E($P(PSBCDT,".",2)_"0000",1,4)
|
|
.S ^TMP("PSB",$J,"GETADMIN",PSBADTMX)=PSBADMIN
|
|
.S:($L(PSBADMIN)+5)>255 PSBADTMX=PSBADTMX+1,PSBADMIN=""
|
|
K ^TMP("PSJ1",$J),PSBADTMX
|
|
Q $G(^TMP("PSB",$J,"GETADMIN",0))
|
|
;
|
|
ADD(PSBREC,PSBSI,PSBDT,PSBDD,PSBSOL,PSBADD,PSBTAB) ;
|
|
;
|
|
; Description: Add order to ^TMP("PSB",$J,PSBTAB,...) for RPC Return RESULTS
|
|
;
|
|
; PSBREC=order hdr from above
|
|
; PSBSI=special instructions
|
|
; PSBDT=admin date/time
|
|
; PSBDD=Dispense Drugs
|
|
; PSBSOL=Solutions
|
|
; PSBADD=Additives
|
|
;
|
|
N PSB
|
|
S PSBDT=$E(PSBDT,1,12),PSBQR=0
|
|
S PSB=$O(^TMP("PSB",$J,PSBTAB,""),-1) ; Get next node
|
|
S $P(PSBREC,U,14)=PSBDT ; Admin Time sits in ^14
|
|
I $P(PSBREC,U,5)'="O" S X=$O(^PSB(53.79,"AORD",DFN,PSBONX,PSBDT,0)) D:X
|
|
.S $P(PSBREC,U,12)=X
|
|
.K PSBLCK L +^PSB(53.79,X):1 I L -^PSB(53.79,X) S PSBLCK=1
|
|
.S PSBSTUS=$P(^PSB(53.79,X,0),U,9),$P(PSBREC,U,13)=$S(PSBSTUS="N":"",(PSBSTUS="")&$G(PSBLCK):"U",1:PSBSTUS),$P(PSBREC,U,23)=$P(^PSB(53.79,X,0),U,10),$P(PSBREC,U,24)=$P(^PSB(53.79,X,0),U,7)
|
|
.I $D(^PSB(53.79,X)) I PSBDOSEF="PATCH",PSBSTUS="G",PSBDT=$P(^PSB(53.79,X,.1),U,3),PSBQRR=0 S PSBQR=1
|
|
.I PSBSTUS="G",$G(PSBFLAG) D CHECK ;Get the correct dispense drug
|
|
I ($P(PSBREC,U,5)="O") D
|
|
.S X=$O(^PSB(53.79,"AORDX",DFN,PSBONX,"")) Q:X=""
|
|
.S Y=$O(^PSB(53.79,"AORDX",DFN,PSBONX,X,"")) Q:Y="" S $P(PSBREC,U,12)=Y
|
|
.K PSBLCK L +^PSB(53.79,Y):1 I L -^PSB(53.79,Y) S PSBLCK=1
|
|
.S PSBSTUS=$P(^PSB(53.79,Y,0),U,9),$P(PSBREC,U,13)=$S(PSBSTUS="N":"",(PSBSTUS="")&$G(PSBLCK):"U",1:PSBSTUS),$P(PSBREC,U,24)=$P(^PSB(53.79,Y,0),U,7)
|
|
.I $D(^PSB(53.79,Y)) I PSBDOSEF="PATCH",PSBSTUS="G",PSBDT=$P(^PSB(53.79,Y,.1),U,3),PSBQRR=0 S PSBQR=1
|
|
.I PSBSTUS="G",$G(PSBFLAG) D CHECK
|
|
Q:PSBQR=1
|
|
S $P(PSBREC,U,25)=0 I $G(PSBTRFL),$P(PSBREC,U,11)]"",$P(PSBREC,U,11)'<$G(PSBNTDT),$P(PSBREC,U,11)'>$G(PSBTRDT) S $P(PSBREC,U,25)=1
|
|
S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBREC ; Order Hdr
|
|
I $P(PSBREC,U,12)]"" S PSBONVDL($P(PSBREC,U,12))=""
|
|
S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBSI ; Special Instructions
|
|
; add dispense drugs
|
|
I $D(PSBDDA) S X="" F S X=$O(PSBDDA(X)) Q:X="" S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBDDA(X)
|
|
S PSBCHDT=0
|
|
I (PSBTAB'["CVRSHT"),(PSBONX["V"),(PSBOSTS="D"),($G(PSBFOR)="") D Q ;get infusing bag from DCed but not DEed orders
|
|
.D PSJ^PSBVT(PSBX)
|
|
.D INFUSING^PSBVDLU2 I PSBCOMP=0 Q
|
|
.I $D(PSBSOLA) S X="" F S X=$O(PSBSOLA(X)) Q:X="" S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBSOLA(X)
|
|
.I $D(PSBADA) S X="" F S X=$O(PSBADA(X)) Q:X="" S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBADA(X)
|
|
.S X="" F S X=$O(PSBPORA(PSBONX,X)) S PSBUID=$P(PSBPORA(PSBONX,X),U,1) Q:PSBUID]"" Q:X=""
|
|
.I PSBUID["P" Q
|
|
.I PSBUID["WS" D
|
|
..S PSBNODE=$O(^PSB(53.79,"AUID",DFN,X,PSBUID,""))
|
|
..S PSBUIDA(PSBUID)="ID"_U_PSBUID
|
|
..S X=0 F S X=$O(^PSB(53.79,PSBNODE,.6,X)) Q:'X S PSBUIDA(PSBUID)=PSBUIDA(PSBUID)_U_"ADD;"_$P(^PSB(53.79,PSBNODE,.6,X,0),U,1)
|
|
..S X=0 F S X=$O(^PSB(53.79,PSBNODE,.7,X)) Q:'X S PSBUIDA(PSBUID)=PSBUIDA(PSBUID)_U_"SOL;"_$P(^PSB(53.79,PSBNODE,.7,X,0),U,1)
|
|
.S PSBSONX=PSBONX
|
|
.I '$D(PSBUIDA(PSBUID)) S PSBCKOR="" F S PSBCKOR=$O(PSBPORA(PSBSONX,PSBCKOR)) Q:PSBCKOR="" D CLEAN^PSBVT,PSJ1^PSBVT(DFN,PSBCKOR) Q:$D(PSBUIDA(PSBUID))
|
|
.S PSBONX=PSBSONX
|
|
.S:$D(PSBUIDA(PSBUID)) PSB=PSB+2,^TMP("PSB",$J,PSBTAB,PSB-1)=PSBUIDA(PSBUID),^TMP("PSB",$J,PSBTAB,PSB)="END"
|
|
.D CLEAN^PSBVT,PSJ1^PSBVT(DFN,$O(PSBPORA("")))
|
|
; add additives
|
|
I $D(PSBADA) S X="" F S X=$O(PSBADA(X)) Q:X="" S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBADA(X)
|
|
; add solutions
|
|
I $D(PSBSOLA) S X="" F S X=$O(PSBSOLA(X)) Q:X="" S $P(PSBSOLA(X),U,5)="",PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=PSBSOLA(X)
|
|
I PSBONX["V" D EN^PSBPOIV(DFN,PSBONX) ; get bags
|
|
I $D(^TMP("PSBAR",$J)) S PSBUID=DFN_"V"_99999 F S PSBUID=$O(^TMP("PSBAR",$J,PSBUID),-1) Q:PSBUID="" D
|
|
.S PSBUIDS=^TMP("PSBAR",$J,PSBUID)
|
|
.I $P(PSBUIDS,U,1)="I",$P(PSBUIDS,U,2)'="I",$P(PSBUIDS,U,2)'="S" Q ; bag has invalid IV parameter, is not infusing or stopped
|
|
.I $P(PSBUIDS,U,2)'="I",$P(PSBUIDS,U,2)'="S",$P(PSBUIDS,U,8)'="" Q ; label is no longer valid, bag is not infusing or stopped
|
|
.I $P(PSBUIDS,U,2)="C" Q ; bag is completed
|
|
.I $P(PSBUIDS,U,2)="G" Q ; bag is given (PBTAB)
|
|
.S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)=$P(PSBUIDS,U,10,999)
|
|
K ^TMP("PSBAR",$J)
|
|
S PSB=PSB+1,^TMP("PSB",$J,PSBTAB,PSB)="END"
|
|
S ^TMP("PSB",$J,PSBTAB,0)=PSB
|
|
Q
|
|
;
|
|
CHECK S FILE=53.795,PSBNODE=.5,PSBIENS=X_","
|
|
F I=0:0 S I=$O(^PSB(53.79,X,PSBNODE,I)) Q:'I S $P(PSBDDS,U,3,4)=$$GET1^DIQ(FILE,I_","_PSBIENS,.01,"I")_U_$$GET1^DIQ(FILE,I_","_PSBIENS,.01)
|
|
Q
|
|
;
|
|
VNURSE(PSBTAB) ;add initials of verifying pharmacist/verifying nurse
|
|
F PSBLP=1:1:$P(^TMP("PSB",$J,PSBTAB,0),U,1) S X=^TMP("PSB",$J,PSBTAB,PSBLP) I $P(X,U)=DFN D
|
|
.K ^TMP("PSJ1",$J)
|
|
.D PSJ1^PSBVT(DFN,$P(X,U,2))
|
|
.S $P(^TMP("PSB",$J,PSBTAB,PSBLP),U,19)=$S(PSBVNI]"":PSBVNI,1:"***")
|
|
K PSBLP,PSBTAB
|
|
Q
|
|
;
|
|
OKAY(PSBSTRT,PSBADMIN,PSBSCH,PSBORDER,PSBDRUG,PSBFREQ,PSBOSTS) ;
|
|
;
|
|
; Description: Determines if an order schedule is valid for
|
|
; the date in PSBADMIN (i.e. Q4D, is it valid today)
|
|
;
|
|
; PSBSTRT: Start Date of order (Time ignored)
|
|
; PSBADMIN: Date of administration to check (Time ignored)
|
|
; PSBSCH: Schedule (i.e. MO-WE-FR@0900 or Q48H...)
|
|
; PSBORDER: Order reference
|
|
; PSBDRUG: Drug ordered (Orderable Item)
|
|
; PSBOSTS: The status of the order
|
|
;
|
|
N PSBOKAY,PSBDAYS,PSBDOW
|
|
S PSBOSTS=$G(PSBOSTS)
|
|
;
|
|
S PSBOKAY=0 ; Default Flag
|
|
I PSBFREQ'="",PSBFREQ'="D",PSBFREQ'>1440 Q 1
|
|
;PRN and ONE TIMES show everyday
|
|
I (PSBSCHT="P")!(PSBSCHT="O") Q 1
|
|
S PSBDAYS=$$DAYS(PSBSCH)
|
|
;
|
|
I PSBDAYS=1 S PSBOKAY=1 Q PSBOKAY ; Order is everyday
|
|
;
|
|
; find out if today is a good day for multi days
|
|
S PSBOKAY=0,PSBRDTE=PSBSTRT
|
|
S PSBADBR=PSBADMIN\1
|
|
S PSBENR=(PSBADMIN\1)+1
|
|
I PSBDAYS>1 D Q PSBOKAY
|
|
.I PSBADBR=(PSBSTRT\1) S PSBOKAY=1
|
|
.F S PSBRDTE=$$FMADD^XLFDT(PSBRDTE,"","",PSBFREQ) Q:PSBRDTE>PSBENR D
|
|
..I $P(PSBRDTE,".",2)="" S PSBRDTE=PSBRDTE-1_".24"
|
|
..I PSBRDTE\1=PSBADBR S PSBOKAY=1
|
|
..I PSBOKAY="1" Q
|
|
;
|
|
; Try the MO-WE-FR@0800 thing as last resort
|
|
S X=PSBADMIN D H^%DTC I %Y=-1 D Q PSBOKAY ; Error
|
|
.S PSBOKAY=0
|
|
.Q:PSBOSTS="E"
|
|
.Q:$G(PSBMHND)="PSBOMH"
|
|
.D ERROR^PSBMLU($G(PSBORDER,"UNKNOWN"),$G(PSBDRUG,""),DFN,"Unable to determine schedule "_PSBSCH,PSBSCH)
|
|
S PSBDOW=$P("SU^MO^TU^WE^TH^FR^SA",U,%Y+1)
|
|
I $F(PSBSCH,PSBDOW)>0 S PSBOKAY=1 Q PSBOKAY
|
|
S PSBOKAY=0
|
|
Q PSBOKAY
|
|
;
|
|
DAYS(PSB) ; Return days between doses (-1: error, 1:everyday 2: QOD...)
|
|
;
|
|
; Is it a PRN
|
|
I PSB?.E1"PRN".E Q 1 ; Straight PRN - As Needed
|
|
;
|
|
S PSB=$TR(PSB," ","")
|
|
I PSB?2.4N.E Q 1
|
|
S X=PSBFREQ/1440 Q X
|
|
;
|
|
Q
|
|
;
|
|
LAST ;
|
|
S PSBCC=0
|
|
S ZZ="" F S ZZ=$O(^PSB(53.79,X,.3,ZZ),-1) Q:'ZZ Q:PSBFLAG=1 S PSBDATA2=$G(^(ZZ,0)) D
|
|
.S PSBCC=PSBCC+1
|
|
.I (PSBCC=2)!($P($P(PSBDATA2,U)," ")="Refused:")!($P($P(PSBDATA2,U)," ")="Held:") S $P(PSBREC,U,11)=$P(PSBDATA2,U,3),PSBFLAG=1
|
|
Q
|
|
;
|