source: WorldVistAEHR/trunk/r/ORDER_ENTRY_RESULTS_REPORTING-OR-OCX--ORRC--ORRJ/ORB3TIM1.m@ 1042

Last change on this file since 1042 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 5.2 KB
Line 
1ORB3TIM1 ; slc/CLA - Routine to trigger time-related notifications ;6/28/00 12:00 [ 04/02/97 11:12 AM ]
2 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**31,64,74,88,102,143,179**;Dec 17, 1997
3TNOTIFS ;process time-driven notifications - called by ORMTIM01
4 ;
5 ;Do not process DIV for param - ORMTIM01 is initiated by postmaster:
6 Q:$$GET^XPAR("SYS^PKG","ORB SYSTEM ENABLE/DISABLE",1,"I")="D"
7 N ORLASTQ,ORNOW,ORERR
8 S ORNOW=$$NOW^XLFDT
9 S ORLASTQ=$$GET^XPAR("SYS","ORB LAST QUEUE DATE",1,"I")
10 ;
11 D NPO
12 D UNVER
13 D UVMED
14 D EXPIR^ORB3TIM2
15 D PUT^XPAR("SYS","ORB LAST QUEUE DATE",1,ORNOW,.ORERR)
16 Q
17NPO ;trigger NPO diet > 72 hours notifications
18 N ORNPO,ORPT,INVDT,ORDG,ORNUM,ORBDT,OREDT
19 N OIFILE,ORBY,ORBI,ORST,ORSDT
20 ;
21 S ^XTMP("ORBNPO",0)=$$FMADD^XLFDT(ORNOW,1,"","","")_"^"_ORNOW
22 ;
23 ;get NPO OIs:
24 S OIFILE=$$TERMLKUP^ORB31(.ORBY,"NPO")
25 ;
26 Q:'$D(ORBY) ;quit if no link between NPO and local OI
27 S:'$G(ORLASTQ) ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-96","","")
28 S ORBDT=$$FMADD^XLFDT(ORLASTQ,"","-72","","")
29 S OREDT=$$FMADD^XLFDT(ORNOW,"","-72","","")
30 F S ORBDT=$O(^OR(100,"AF",ORBDT)) Q:(ORBDT="")!(ORBDT>OREDT) D
31 .S ORNUM="" F S ORNUM=$O(^OR(100,"AF",ORBDT,ORNUM)) Q:ORNUM="" D
32 ..Q:$D(^XTMP("ORBNPO",ORNUM))
33 ..; determine if NPO order:
34 ..I +$G(OIFILE)=101.43 F ORBI=1:1:ORBY D
35 ...S ORNPO=$P(ORBY(ORBI),U) I ORNPO=$$OI^ORQOR2(ORNUM) D
36 ....S ORSDT=$P($G(^OR(100,ORNUM,0)),U,8)
37 ....S ^XTMP("ORBNPO",ORNUM)=$S($L(ORSDT):ORSDT,1:ORBDT)_U_0
38 ;
39 ;loop thru XTMP looking for NPO orders with start d/t > 72
40 S ORNUM=0 F S ORNUM=$O(^XTMP("ORBNPO",ORNUM)) Q:+$G(ORNUM)<1 D
41 .S ORSDT=$P(^XTMP("ORBNPO",ORNUM),U)
42 .I $P(^XTMP("ORBNPO",ORNUM),U,2)=0 D ;if alert not already triggered
43 ..Q:ORSDT>OREDT ;quit if start date more recent than 72 hours ago
44 ..S ORPT=$P($G(^OR(100,ORNUM,0)),U,2) I ORPT]"" D
45 ...S ORST=$P($$STATUS^ORQOR2(ORNUM),U,2)
46 ...I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="UNRELEASED",ORST'="CHANGED",ORST'="CANCELLED",ORST'="LAPSED",ORST'="SCHEDULED" D
47 ....D EN^ORB3(31,+ORPT,ORNUM,"","",ORNUM_"@") ;trigger NPO>72 notif
48 ....S $P(^XTMP("ORBNPO",ORNUM),U,2)=1 ;alert triggered
49 .;
50 .I $G(ORSDT)<$$FMADD^XLFDT(ORNOW,"-7","","","") D
51 ..K ^XTMP("ORBNPO",ORNUM) ;kill XTMP if order start d/t > 7 days
52 Q
53UNVER ;trigger unverified order (by nurse) notif
54 N ORPT,INVDT,ORDG,ORNUM,ORBDT,OREDT,ORST,ORX,ORACT,ORDELAY
55 ;
56 ;if not queued via ORMTIM01 recently, look for past 48 hours:
57 S:'$G(ORLASTQ) ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-48","","")
58 ;
59 ;get number of hours delay before trigger:
60 S ORDELAY=$$GET^XPAR("ALL","ORB UNVERIFIED ORDER",1,"I")
61 ;
62 ;look for orders unverified after <parameter value> hours:
63 S ORBDT=$$FMADD^XLFDT(ORLASTQ,"",-ORDELAY,"","")
64 S OREDT=$$FMADD^XLFDT(ORNOW,"",-ORDELAY,"","")
65 ;
66 F S ORBDT=$O(^OR(100,"AF",ORBDT)) Q:(ORBDT="")!(ORBDT>OREDT) D
67 .S ORNUM="" F S ORNUM=$O(^OR(100,"AF",ORBDT,ORNUM)) Q:ORNUM="" D
68 ..S ORPT=$P($G(^OR(100,ORNUM,0)),U,2) I ORPT]"" D
69 ...;The following filters match those in UVN1^ORQ11 so notif triggers
70 ...;and orders displayed via alert follow-up action are in sync:
71 ...S ORX=$G(^OR(100,ORNUM,0))
72 ...Q:'$L(ORX)
73 ...Q:$P(ORX,U,12)="O" ;quit if outpatient order
74 ...Q:$L($P(ORX,U,17)) ;quit if someone has released order
75 ...S ORST=$P($$STATUS^ORQOR2(ORNUM),U,2)
76 ...I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="UNRELEASED",ORST'="CHANGED",ORST'="CANCELLED",ORST'="LAPSED" D
77 ....Q:'$D(^OR(100,ORNUM,8))
78 ....Q:$P(^OR(100,ORNUM,8,$P(^OR(100,ORNUM,8,0),U,3),0),U,8) ;quit if someone has verified order
79 ....D EN^ORB3(59,+ORPT,ORNUM,"","",ORNUM_"@")
80 Q
81UVMED ;trigger unverified med (by nurse) notif
82 N DG,ORGRP,ORPT,INVDT,ORNUM,ORBDT,OREDT,ORST,ORX,ORACT,ORDELAY
83 ;
84 ;if not queued via ORMTIM01 recently, look for past 48 hours:
85 S:'$G(ORLASTQ) ORLASTQ=$$FMADD^XLFDT(ORNOW,"","-48","","")
86 ;
87 ;get number of hours delay before trigger:
88 S ORDELAY=$$GET^XPAR("ALL","ORB UNVERIFIED MED ORDER",1,"I")
89 ;
90 ;look for meds unverified after <parameter value> hours:
91 S ORBDT=$$FMADD^XLFDT(ORLASTQ,"",-ORDELAY,"","")
92 S OREDT=$$FMADD^XLFDT(ORNOW,"",-ORDELAY,"","")
93 ;
94 F S ORBDT=$O(^OR(100,"AF",ORBDT)) Q:(ORBDT="")!(ORBDT>OREDT) D
95 .S ORNUM="" F S ORNUM=$O(^OR(100,"AF",ORBDT,ORNUM)) Q:ORNUM="" D
96 ..S ORPT=$P($G(^OR(100,ORNUM,0)),U,2) I ORPT]"" D
97 ...;The following filters match those in UVN1^ORQ11 so notif triggers
98 ...;and orders displayed via alert follow-up action are in sync:
99 ...S ORX=$G(^OR(100,ORNUM,0))
100 ...Q:'$L(ORX)
101 ...Q:'$L($$DGRX^ORQOR2(+ORNUM)) ;quit if not a pharmacy order
102 ...Q:$P(ORX,U,12)="O" ;quit if outpatient order
103 ...Q:$L($P(ORX,U,17)) ;quit if someone has released order
104 ...S ORST=$P($$STATUS^ORQOR2(ORNUM),U,2)
105 ...I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="UNRELEASED",ORST'="CHANGED",ORST'="CANCELLED",ORST'="LAPSED" D
106 ....Q:'$D(^OR(100,ORNUM,8))
107 ....Q:$P(^OR(100,ORNUM,8,$P(^OR(100,ORNUM,8,0),U,3),0),U,8) ;quit if someone has verified order
108 ....D EN^ORB3(48,+ORPT,ORNUM,"","",ORNUM_"@")
109 Q
110GRP(DG) ;Setup display groups
111 ;DG=Display group to expand
112 N STK,MEM,I
113 S ORGRP(DG)="",STK=1,STK(STK)=DG_"^0",STK(0)=0,MEM=0
114 F I=0:0 S MEM=$O(^ORD(100.98,+STK(STK),1,MEM)) D @$S(+MEM'>0:"POP",1:"PROC") Q:STK<1
115 Q
116POP S STK=STK-1,MEM=$P(STK(STK),"^",2) Q
117PROC S $P(STK(STK),"^",2)=MEM,DG=$P(^ORD(100.98,+STK(STK),1,MEM,0),"^",1)
118 S ORGRP(DG)="",STK=STK+1,STK(STK)=DG_"^0",MEM=0
119 Q
Note: See TracBrowser for help on using the repository browser.