ORB3TIM1 ; slc/CLA - Routine to trigger time-related notifications ;6/28/00 12:00 [ 04/02/97 11:12 AM ]
;;3.0;ORDER ENTRY/RESULTS REPORTING;**31,64,74,88,102,143,179**;Dec 17, 1997
TNOTIFS ;process time-driven notifications - called by ORMTIM01
;
;Do not process DIV for param - ORMTIM01 is initiated by postmaster:
Q:$$GET^XPAR("SYS^PKG","ORB SYSTEM ENABLE/DISABLE",1,"I")="D"
N ORLASTQ,ORNOW,ORERR
S ORNOW=$$NOW^XLFDT
S ORLASTQ=$$GET^XPAR("SYS","ORB LAST QUEUE DATE",1,"I")
;
D NPO
D UNVER
D UVMED
D EXPIR^ORB3TIM2
D PUT^XPAR("SYS","ORB LAST QUEUE DATE",1,ORNOW,.ORERR)
Q
NPO ;trigger NPO diet > 72 hours notifications
N ORNPO,ORPT,INVDT,ORDG,ORNUM,ORBDT,OREDT
N OIFILE,ORBY,ORBI,ORST,ORSDT
;
S ^XTMP("ORBNPO",0)=$$FMADD^XLFDT(ORNOW,1,"","","")_"^"_ORNOW
;
;get NPO OIs:
S OIFILE=$$TERMLKUP^ORB31(.ORBY,"NPO")
;
Q:'$D(ORBY) ;quit if no link between NPO and local OI
S:'$G(ORLASTQ) ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-96","","")
S ORBDT=$$FMADD^XLFDT(ORLASTQ,"","-72","","")
S OREDT=$$FMADD^XLFDT(ORNOW,"","-72","","")
F S ORBDT=$O(^OR(100,"AF",ORBDT)) Q:(ORBDT="")!(ORBDT>OREDT) D
.S ORNUM="" F S ORNUM=$O(^OR(100,"AF",ORBDT,ORNUM)) Q:ORNUM="" D
..Q:$D(^XTMP("ORBNPO",ORNUM))
..; determine if NPO order:
..I +$G(OIFILE)=101.43 F ORBI=1:1:ORBY D
...S ORNPO=$P(ORBY(ORBI),U) I ORNPO=$$OI^ORQOR2(ORNUM) D
....S ORSDT=$P($G(^OR(100,ORNUM,0)),U,8)
....S ^XTMP("ORBNPO",ORNUM)=$S($L(ORSDT):ORSDT,1:ORBDT)_U_0
;
;loop thru XTMP looking for NPO orders with start d/t > 72
S ORNUM=0 F S ORNUM=$O(^XTMP("ORBNPO",ORNUM)) Q:+$G(ORNUM)<1 D
.S ORSDT=$P(^XTMP("ORBNPO",ORNUM),U)
.I $P(^XTMP("ORBNPO",ORNUM),U,2)=0 D ;if alert not already triggered
..Q:ORSDT>OREDT ;quit if start date more recent than 72 hours ago
..S ORPT=$P($G(^OR(100,ORNUM,0)),U,2) I ORPT]"" D
...S ORST=$P($$STATUS^ORQOR2(ORNUM),U,2)
...I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="UNRELEASED",ORST'="CHANGED",ORST'="CANCELLED",ORST'="LAPSED",ORST'="SCHEDULED" D
....D EN^ORB3(31,+ORPT,ORNUM,"","",ORNUM_"@") ;trigger NPO>72 notif
....S $P(^XTMP("ORBNPO",ORNUM),U,2)=1 ;alert triggered
.;
.I $G(ORSDT)<$$FMADD^XLFDT(ORNOW,"-7","","","") D
..K ^XTMP("ORBNPO",ORNUM) ;kill XTMP if order start d/t > 7 days
Q
UNVER ;trigger unverified order (by nurse) notif
N ORPT,INVDT,ORDG,ORNUM,ORBDT,OREDT,ORST,ORX,ORACT,ORDELAY
;
;if not queued via ORMTIM01 recently, look for past 48 hours:
S:'$G(ORLASTQ) ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-48","","")
;
;get number of hours delay before trigger:
S ORDELAY=$$GET^XPAR("ALL","ORB UNVERIFIED ORDER",1,"I")
;
;look for orders unverified after <parameter value> hours:
S ORBDT=$$FMADD^XLFDT(ORLASTQ,"",-ORDELAY,"","")
S OREDT=$$FMADD^XLFDT(ORNOW,"",-ORDELAY,"","")
;
F S ORBDT=$O(^OR(100,"AF",ORBDT)) Q:(ORBDT="")!(ORBDT>OREDT) D
.S ORNUM="" F S ORNUM=$O(^OR(100,"AF",ORBDT,ORNUM)) Q:ORNUM="" D
..S ORPT=$P($G(^OR(100,ORNUM,0)),U,2) I ORPT]"" D
...;The following filters match those in UVN1^ORQ11 so notif triggers
...;and orders displayed via alert follow-up action are in sync:
...S ORX=$G(^OR(100,ORNUM,0))
...Q:'$L(ORX)
...Q:$P(ORX,U,12)="O" ;quit if outpatient order
...Q:$L($P(ORX,U,17)) ;quit if someone has released order
...S ORST=$P($$STATUS^ORQOR2(ORNUM),U,2)
...I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="UNRELEASED",ORST'="CHANGED",ORST'="CANCELLED",ORST'="LAPSED" D
....Q:'$D(^OR(100,ORNUM,8))
....Q:$P(^OR(100,ORNUM,8,$P(^OR(100,ORNUM,8,0),U,3),0),U,8) ;quit if someone has verified order
....D EN^ORB3(59,+ORPT,ORNUM,"","",ORNUM_"@")
Q
UVMED ;trigger unverified med (by nurse) notif
N DG,ORGRP,ORPT,INVDT,ORNUM,ORBDT,OREDT,ORST,ORX,ORACT,ORDELAY
;
;if not queued via ORMTIM01 recently, look for past 48 hours:
S:'$G(ORLASTQ) ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-48","","")
;
;get number of hours delay before trigger:
S ORDELAY=$$GET^XPAR("ALL","ORB UNVERIFIED MED ORDER",1,"I")
;
;look for meds unverified after <parameter value> hours:
S ORBDT=$$FMADD^XLFDT(ORLASTQ,"",-ORDELAY,"","")
S OREDT=$$FMADD^XLFDT(ORNOW,"",-ORDELAY,"","")
;
F S ORBDT=$O(^OR(100,"AF",ORBDT)) Q:(ORBDT="")!(ORBDT>OREDT) D
.S ORNUM="" F S ORNUM=$O(^OR(100,"AF",ORBDT,ORNUM)) Q:ORNUM="" D
..S ORPT=$P($G(^OR(100,ORNUM,0)),U,2) I ORPT]"" D
...;The following filters match those in UVN1^ORQ11 so notif triggers
...;and orders displayed via alert follow-up action are in sync:
...S ORX=$G(^OR(100,ORNUM,0))
...Q:'$L(ORX)
...Q:'$L($$DGRX^ORQOR2(+ORNUM)) ;quit if not a pharmacy order
...Q:$P(ORX,U,12)="O" ;quit if outpatient order
...Q:$L($P(ORX,U,17)) ;quit if someone has released order
...S ORST=$P($$STATUS^ORQOR2(ORNUM),U,2)
...I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="UNRELEASED",ORST'="CHANGED",ORST'="CANCELLED",ORST'="LAPSED" D
....Q:'$D(^OR(100,ORNUM,8))
....Q:$P(^OR(100,ORNUM,8,$P(^OR(100,ORNUM,8,0),U,3),0),U,8) ;quit if someone has verified order
....D EN^ORB3(48,+ORPT,ORNUM,"","",ORNUM_"@")
Q
GRP(DG) ;Setup display groups
;DG=Display group to expand
N STK,MEM,I
S ORGRP(DG)="",STK=1,STK(STK)=DG_"^0",STK(0)=0,MEM=0
F I=0:0 S MEM=$O(^ORD(100.98,+STK(STK),1,MEM)) D @$S(+MEM'>0:"POP",1:"PROC") Q:STK<1
Q
POP S STK=STK-1,MEM=$P(STK(STK),"^",2) Q
PROC S $P(STK(STK),"^",2)=MEM,DG=$P(^ORD(100.98,+STK(STK),1,MEM,0),"^",1)
S ORGRP(DG)="",STK=STK+1,STK(STK)=DG_"^0",MEM=0
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HORB3TIM1 5470 printed Dec 13, 2024@02:27:30 Page 2
ORB3TIM1 ; slc/CLA - Routine to trigger time-related notifications ;6/28/00 12:00 [ 04/02/97 11:12 AM ]
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**31,64,74,88,102,143,179**;Dec 17, 1997
TNOTIFS ;process time-driven notifications - called by ORMTIM01
+1 ;
+2 ;Do not process DIV for param - ORMTIM01 is initiated by postmaster:
+3 if $$GET^XPAR("SYS^PKG","ORB SYSTEM ENABLE/DISABLE",1,"I")="D"
QUIT
+4 NEW ORLASTQ,ORNOW,ORERR
+5 SET ORNOW=$$NOW^XLFDT
+6 SET ORLASTQ=$$GET^XPAR("SYS","ORB LAST QUEUE DATE",1,"I")
+7 ;
+8 DO NPO
+9 DO UNVER
+10 DO UVMED
+11 DO EXPIR^ORB3TIM2
+12 DO PUT^XPAR("SYS","ORB LAST QUEUE DATE",1,ORNOW,.ORERR)
+13 QUIT
NPO ;trigger NPO diet > 72 hours notifications
+1 NEW ORNPO,ORPT,INVDT,ORDG,ORNUM,ORBDT,OREDT
+2 NEW OIFILE,ORBY,ORBI,ORST,ORSDT
+3 ;
+4 SET ^XTMP("ORBNPO",0)=$$FMADD^XLFDT(ORNOW,1,"","","")_"^"_ORNOW
+5 ;
+6 ;get NPO OIs:
+7 SET OIFILE=$$TERMLKUP^ORB31(.ORBY,"NPO")
+8 ;
+9 ;quit if no link between NPO and local OI
if '$DATA(ORBY)
QUIT
+10 if '$GET(ORLASTQ)
SET ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-96","","")
+11 SET ORBDT=$$FMADD^XLFDT(ORLASTQ,"","-72","","")
+12 SET OREDT=$$FMADD^XLFDT(ORNOW,"","-72","","")
+13 FOR
SET ORBDT=$ORDER(^OR(100,"AF",ORBDT))
if (ORBDT="")!(ORBDT>OREDT)
QUIT
Begin DoDot:1
+14 SET ORNUM=""
FOR
SET ORNUM=$ORDER(^OR(100,"AF",ORBDT,ORNUM))
if ORNUM=""
QUIT
Begin DoDot:2
+15 if $DATA(^XTMP("ORBNPO",ORNUM))
QUIT
+16 ; determine if NPO order:
+17 IF +$GET(OIFILE)=101.43
FOR ORBI=1:1:ORBY
Begin DoDot:3
+18 SET ORNPO=$PIECE(ORBY(ORBI),U)
IF ORNPO=$$OI^ORQOR2(ORNUM)
Begin DoDot:4
+19 SET ORSDT=$PIECE($GET(^OR(100,ORNUM,0)),U,8)
+20 SET ^XTMP("ORBNPO",ORNUM)=$SELECT($LENGTH(ORSDT):ORSDT,1:ORBDT)_U_0
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+21 ;
+22 ;loop thru XTMP looking for NPO orders with start d/t > 72
+23 SET ORNUM=0
FOR
SET ORNUM=$ORDER(^XTMP("ORBNPO",ORNUM))
if +$GET(ORNUM)<1
QUIT
Begin DoDot:1
+24 SET ORSDT=$PIECE(^XTMP("ORBNPO",ORNUM),U)
+25 ;if alert not already triggered
IF $PIECE(^XTMP("ORBNPO",ORNUM),U,2)=0
Begin DoDot:2
+26 ;quit if start date more recent than 72 hours ago
if ORSDT>OREDT
QUIT
+27 SET ORPT=$PIECE($GET(^OR(100,ORNUM,0)),U,2)
IF ORPT]""
Begin DoDot:3
+28 SET ORST=$PIECE($$STATUS^ORQOR2(ORNUM),U,2)
+29 IF ORST'="DISCONTINUED"
IF ORST'="COMPLETE"
IF ORST'="EXPIRED"
IF ORST'="UNRELEASED"
IF ORST'="CHANGED"
IF ORST'="CANCELLED"
IF ORST'="LAPSED"
IF ORST'="SCHEDULED"
Begin DoDot:4
+30 ;trigger NPO>72 notif
DO EN^ORB3(31,+ORPT,ORNUM,"","",ORNUM_"@")
+31 ;alert triggered
SET $PIECE(^XTMP("ORBNPO",ORNUM),U,2)=1
End DoDot:4
End DoDot:3
End DoDot:2
+32 ;
+33 IF $GET(ORSDT)<$$FMADD^XLFDT(ORNOW,"-7","","","")
Begin DoDot:2
+34 ;kill XTMP if order start d/t > 7 days
KILL ^XTMP("ORBNPO",ORNUM)
End DoDot:2
End DoDot:1
+35 QUIT
UNVER ;trigger unverified order (by nurse) notif
+1 NEW ORPT,INVDT,ORDG,ORNUM,ORBDT,OREDT,ORST,ORX,ORACT,ORDELAY
+2 ;
+3 ;if not queued via ORMTIM01 recently, look for past 48 hours:
+4 if '$GET(ORLASTQ)
SET ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-48","","")
+5 ;
+6 ;get number of hours delay before trigger:
+7 SET ORDELAY=$$GET^XPAR("ALL","ORB UNVERIFIED ORDER",1,"I")
+8 ;
+9 ;look for orders unverified after <parameter value> hours:
+10 SET ORBDT=$$FMADD^XLFDT(ORLASTQ,"",-ORDELAY,"","")
+11 SET OREDT=$$FMADD^XLFDT(ORNOW,"",-ORDELAY,"","")
+12 ;
+13 FOR
SET ORBDT=$ORDER(^OR(100,"AF",ORBDT))
if (ORBDT="")!(ORBDT>OREDT)
QUIT
Begin DoDot:1
+14 SET ORNUM=""
FOR
SET ORNUM=$ORDER(^OR(100,"AF",ORBDT,ORNUM))
if ORNUM=""
QUIT
Begin DoDot:2
+15 SET ORPT=$PIECE($GET(^OR(100,ORNUM,0)),U,2)
IF ORPT]""
Begin DoDot:3
+16 ;The following filters match those in UVN1^ORQ11 so notif triggers
+17 ;and orders displayed via alert follow-up action are in sync:
+18 SET ORX=$GET(^OR(100,ORNUM,0))
+19 if '$LENGTH(ORX)
QUIT
+20 ;quit if outpatient order
if $PIECE(ORX,U,12)="O"
QUIT
+21 ;quit if someone has released order
if $LENGTH($PIECE(ORX,U,17))
QUIT
+22 SET ORST=$PIECE($$STATUS^ORQOR2(ORNUM),U,2)
+23 IF ORST'="DISCONTINUED"
IF ORST'="COMPLETE"
IF ORST'="EXPIRED"
IF ORST'="UNRELEASED"
IF ORST'="CHANGED"
IF ORST'="CANCELLED"
IF ORST'="LAPSED"
Begin DoDot:4
+24 if '$DATA(^OR(100,ORNUM,8))
QUIT
+25 ;quit if someone has verified order
if $PIECE(^OR(100,ORNUM,8,$PIECE(^OR(100,ORNUM,8,0),U,3),0),U,8)
QUIT
+26 DO EN^ORB3(59,+ORPT,ORNUM,"","",ORNUM_"@")
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+27 QUIT
UVMED ;trigger unverified med (by nurse) notif
+1 NEW DG,ORGRP,ORPT,INVDT,ORNUM,ORBDT,OREDT,ORST,ORX,ORACT,ORDELAY
+2 ;
+3 ;if not queued via ORMTIM01 recently, look for past 48 hours:
+4 if '$GET(ORLASTQ)
SET ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-48","","")
+5 ;
+6 ;get number of hours delay before trigger:
+7 SET ORDELAY=$$GET^XPAR("ALL","ORB UNVERIFIED MED ORDER",1,"I")
+8 ;
+9 ;look for meds unverified after <parameter value> hours:
+10 SET ORBDT=$$FMADD^XLFDT(ORLASTQ,"",-ORDELAY,"","")
+11 SET OREDT=$$FMADD^XLFDT(ORNOW,"",-ORDELAY,"","")
+12 ;
+13 FOR
SET ORBDT=$ORDER(^OR(100,"AF",ORBDT))
if (ORBDT="")!(ORBDT>OREDT)
QUIT
Begin DoDot:1
+14 SET ORNUM=""
FOR
SET ORNUM=$ORDER(^OR(100,"AF",ORBDT,ORNUM))
if ORNUM=""
QUIT
Begin DoDot:2
+15 SET ORPT=$PIECE($GET(^OR(100,ORNUM,0)),U,2)
IF ORPT]""
Begin DoDot:3
+16 ;The following filters match those in UVN1^ORQ11 so notif triggers
+17 ;and orders displayed via alert follow-up action are in sync:
+18 SET ORX=$GET(^OR(100,ORNUM,0))
+19 if '$LENGTH(ORX)
QUIT
+20 ;quit if not a pharmacy order
if '$LENGTH($$DGRX^ORQOR2(+ORNUM))
QUIT
+21 ;quit if outpatient order
if $PIECE(ORX,U,12)="O"
QUIT
+22 ;quit if someone has released order
if $LENGTH($PIECE(ORX,U,17))
QUIT
+23 SET ORST=$PIECE($$STATUS^ORQOR2(ORNUM),U,2)
+24 IF ORST'="DISCONTINUED"
IF ORST'="COMPLETE"
IF ORST'="EXPIRED"
IF ORST'="UNRELEASED"
IF ORST'="CHANGED"
IF ORST'="CANCELLED"
IF ORST'="LAPSED"
Begin DoDot:4
+25 if '$DATA(^OR(100,ORNUM,8))
QUIT
+26 ;quit if someone has verified order
if $PIECE(^OR(100,ORNUM,8,$PIECE(^OR(100,ORNUM,8,0),U,3),0),U,8)
QUIT
+27 DO EN^ORB3(48,+ORPT,ORNUM,"","",ORNUM_"@")
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+28 QUIT
GRP(DG) ;Setup display groups
+1 ;DG=Display group to expand
+2 NEW STK,MEM,I
+3 SET ORGRP(DG)=""
SET STK=1
SET STK(STK)=DG_"^0"
SET STK(0)=0
SET MEM=0
+4 FOR I=0:0
SET MEM=$ORDER(^ORD(100.98,+STK(STK),1,MEM))
DO @$SELECT(+MEM'>0:"POP",1:"PROC")
if STK<1
QUIT
+5 QUIT
POP SET STK=STK-1
SET MEM=$PIECE(STK(STK),"^",2)
QUIT
PROC SET $PIECE(STK(STK),"^",2)=MEM
SET DG=$PIECE(^ORD(100.98,+STK(STK),1,MEM,0),"^",1)
+1 SET ORGRP(DG)=""
SET STK=STK+1
SET STK(STK)=DG_"^0"
SET MEM=0
+2 QUIT