source: FOIAVistA/trunk/r/ORDER_ENTRY_RESULTS_REPORTING-OR-OCX--ORRC--ORRJ/ORB3TIM2.m@ 1757

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

initial load of FOIAVistA 6/30/08 version

File size: 6.0 KB
Line 
1ORB3TIM2 ; slc/CLA - Routine to trigger time-related notifications ;3/30/01 07:41 [1/3/05 8:21am]
2 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**102,215,251,265**;Dec 17, 1997;Build 17
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5EXPIR ;trigger expiring order notifs
6 N EDT,EXDT,EXORN,ORBDNR,ORPT,ORBRSLT,RXORD,ORLASTDT,X,Y,%DT
7 N OIFILE,ORBY,ORBZ,ORBI,ORSCH,ORSCHFIL,ONETIME,ORST,ORNG,ORDT,ORDW,ORHOL
8 N EXOI,ORBLST,ORBERR,OITXT,PTLOC,ORSDT,ORNOW,ORLDT
9 ;
10 S ORNOW=$$NOW^XLFDT
11 ;
12 I '$D(^XTMP("ORB LAST EXPIRE")) D ;holds last dt EXPIR processed
13 .S ^XTMP("ORB LAST EXPIRE",0)=$$FMADD^XLFDT(ORNOW,7,"","","")_U
14 ;
15 ;determine number of days to return orders using day of week & holidays
16 F ORNG=1:1 D I ORHOL=0,ORDW=0 Q
17 .S ORDW=$S($H-4+ORNG#7>4:1,1:0) ;if Sat or Sun, ORDW=0
18 .S ORDT=$$FMADD^XLFDT(DT,ORNG)
19 .K DIC S DIC="^HOLIDAY(",X=ORDT D ^DIC
20 .S ORHOL=$S(+$G(Y)>0:1,1:0) ;if ORDT is a holiday, ORHOL=0
21 S %DT="",X="T+"_ORNG D ^%DT
22 S EDT=Y_".2400"
23 K DIC
24 ;
25 ;get DNR OIs:
26 S OIFILE=$$TERMLKUP^ORB31(.ORBY,"DNR")
27 ;
28 ;get local admin schedules for ONE TIME MED:
29 S ORSCHFIL=$$TERMLKUP^ORB31(.ORBZ,"ONE TIME MED")
30 ;
31 ;examine expiring orders:
32 S ORLASTDT=$P(^XTMP("ORB LAST EXPIRE",0),U,2)
33 S EXDT=$S($L(ORLASTDT):ORLASTDT,1:ORNOW)
34 F S EXDT=$O(^OR(100,"AE",EXDT)) Q:(EXDT="") D Q:ORBRSLT<0
35 .S ORBRSLT=$$FMDIFF^XLFDT(EDT,$P(EXDT,".")_".2400",2) ;diff in seconds
36 .Q:ORBRSLT<0
37 .S EXORN="" F S EXORN=$O(^OR(100,"AE",EXDT,EXORN)) Q:EXORN="" D
38 ..;
39 ..;Quit if isn't at least next day after order's Date of Last Activity:
40 ..S ORLDT=$P(^OR(100,EXORN,3),U)
41 ..Q:$$FMDIFF^XLFDT(ORNOW,ORLDT)<1
42 ..;
43 ..Q:$D(^XTMP("ORB LAST EXPIRE",EXORN)) ;quit if order already processed
44 ..S ^XTMP("ORB LAST EXPIRE",EXORN)=EXDT
45 ..;
46 ..S ORPT=$$PT^ORQOR2(EXORN) ; get pt assoc w/order
47 ..Q:+$G(ORPT)<1
48 ..;
49 ..Q:+$G(^DPT(ORPT,.35))>0 ; quit if pt deceased - DBIA #10035
50 ..;
51 ..S PTLOC=$G(^DPT(+$G(ORPT),.1)),PTLOC=$S($L(PTLOC):PTLOC,1:"OUTPT")
52 ..;
53 ..; is expiring order a DNR order:
54 ..I $D(ORBY),(+$G(OIFILE)=101.43) D
55 ...F ORBI=1:1:ORBY D
56 ....S ORBDNR=$P(ORBY(ORBI),U) I ORBDNR=$$OI^ORQOR2(EXORN) D
57 .....S ORST=$P($$STATUS^ORQOR2(EXORN),U,2)
58 .....I ORST'="DISCONTINUED",ORST'="COMPLETE",ORST'="EXPIRED",ORST'="CANCELLED",ORST'="DISCONTINUED/EDIT" D
59 ......D EN^ORB3(45,ORPT,EXORN,"","",EXORN_"@") ;trigger DNR notif
60 ..;
61 ..; is expiring order a flagged oi:
62 ..S EXOI=$$OI^ORQOR2(EXORN) I +$G(EXOI)>0 D
63 ...I $L(PTLOC),PTLOC'="OUTPT" D
64 ....D ENVAL^XPAR(.ORBLST,"ORB OI EXPIRING - INPT","`"_EXOI,.ORBERR)
65 ....I 'ORBERR,'$G(ORBLST) D ENVAL^XPAR(.ORBLST,"ORB OI EXPIRING - INPT PR","`"_EXOI,.ORBERR)
66 ....I 'ORBERR,$G(ORBLST)>0 D
67 .....S OITXT=$P(^ORD(101.43,EXOI,0),U)
68 .....S ORSDT=$P(^OR(100,EXORN,0),U,8),ORSDT=$$FMTE^XLFDT(ORSDT,"2P")
69 .....D EN^ORB3(64,ORPT,EXORN,"","["_PTLOC_"] Order expiring: "_OITXT_" "_ORSDT,EXORN_"@") ;trigger Expiring Flagged OI - INPT notification
70 ...;
71 ...I $L(PTLOC),PTLOC="OUTPT" D
72 ....D ENVAL^XPAR(.ORBLST,"ORB OI EXPIRING - OUTPT","`"_EXOI,.ORBERR)
73 ....I 'ORBERR,$G(ORBLST)>0 D
74 .....S OITXT=$P(^ORD(101.43,EXOI,0),U)
75 .....S ORSDT=$P(^OR(100,EXORN,0),U,8),ORSDT=$$FMTE^XLFDT(ORSDT,"2P")
76 .....D EN^ORB3(65,ORPT,EXORN,"","["_PTLOC_"] Order expiring: "_OITXT_" "_ORSDT,EXORN_"@") ;trigger Expiring Flagged OI - OUTPT notification
77 ..;
78 ..;is expiring order a med order:
79 ..S RXORD=$$DGRX^ORQOR2(EXORN)
80 ..I $L(RXORD) D ;if expiring order is a med order
81 ...;
82 ...N DFN S DFN=ORPT
83 ...D ADM^VADPT2
84 ...;
85 ...I (RXORD="OUTPATIENT MEDICATIONS")!(+$G(VADMVT)<1&(RXORD'="CLINIC ORDERS")) D
86 ....D EN^ORB3(72,ORPT,EXORN,"","",EXORN_"@") ;trigger outpt notif
87 ...;
88 ...Q:RXORD="OUTPATIENT MEDICATIONS" ;quit if an outpt med
89 ...Q:+$G(VADMVT)<1&(RXORD'="CLINIC ORDERS") ;quit if an outpt
90 ...;
91 ...K VADMVT
92 ...;
93 ...;is schedule for the order a ONE TIME MED:
94 ...S ONETIME=0
95 ...I $D(ORBZ),(+$G(ORSCHFIL)=51.1) F ORBI=1:1:ORBZ D
96 ....S ORSCH=$P(ORBZ(ORBI),U,2)
97 ....I ORSCH=$$VALUE^ORCSAVE2(EXORN,"SCHEDULE") S ONETIME=1 Q
98 ...Q:+$G(ONETIME)=1 ;quit if one time med
99 ...;
100 ...;check if this is an IMO order and what it is,send an M.E.-OUTPT alert
101 ...I RXORD="CLINIC ORDERS" D Q
102 ....N ORDLG,ORDG,ORDLGNM,FLAG,ORX
103 ....S FLAG=0
104 ....S ORDLG=$P($G(^OR(100,EXORN,0)),U,5) Q:$P(ORDLG,";",2)'="ORD(101.41,"
105 ....S ORDLGNM=$P($G(^ORD(101.41,+ORDLG,0)),U)
106 ....S ORDG=$P($G(^ORD(101.41,+ORDLG,0)),U,2)
107 ....I ORDLGNM="PSJ OR PAT OE"!(ORDLGNM="PSJI OR PAT FLUID OE") S FLAG=1
108 ....I 'FLAG F ORX="INPATIENT MEDICATIONS","IV MEDICATIONS","UNIT DOSE MEDICATIONS","CLINIC ORDERS" I $$UPPER^ORU(ORDG)=ORX D
109 .....S FLAG=1
110 .....I ORX="IV MEDICATIONS",(+$$IVRENEW(EXORN)=0) S FLAG=0
111 .....I ORX="UNIT DOSE MEDICATIONS",(+$$UDRENEW(EXORN,EXDT)=0) S FLAG=0
112 ....I FLAG D EN^ORB3(72,ORPT,EXORN,"","",EXORN_"@") ;trigger outpt notif
113 ...;
114 ...;quit if inpt/unit dose med and med is not renewable:
115 ...I RXORD="UNIT DOSE MEDICATIONS",(+$$UDRENEW(EXORN,EXDT)=0) Q
116 ...;
117 ...;quit if IV med and med is not renewable:
118 ...I RXORD="IV MEDICATIONS",(+$$IVRENEW(EXORN)=0) Q
119 ...;
120 ...D EN^ORB3(47,ORPT,EXORN,"","",EXORN_"@") ;trigger notif
121 S ^XTMP("ORB LAST EXPIRE",0)=$$FMADD^XLFDT(ORNOW,7,"","","")_U_$$NOW^XLFDT
122 D EXCLN(ORNOW)
123 Q
124UDRENEW(EXORN,EXDT) ;extr function returns 1 if med is renewable, 0 if not
125 N ORNOW,ORSLT,ORSTATUS
126 S ORSLT=0
127 S ORSTATUS=$P($$STATUS^ORQOR2(EXORN),U,2)
128 I ORSTATUS="ACTIVE" Q 1 ;renewable if "active"
129 I ORSTATUS="HOLD" Q 1 ;renewable if "on hold"
130 I ORSTATUS="EXPIRED" D
131 .S ORNOW=$$NOW^XLFDT
132 .;renewable if expired w/in past 4 days:
133 .I $$FMDIFF^XLFDT(ORNOW,EXDT,1)<4 S ORSLT=1
134 Q ORSLT
135 ;
136IVRENEW(EXORN) ;extr function returns 1 if med is renewable, 0 if not
137 N ORSLT,ORSTATUS
138 S ORSLT=0
139 S ORSTATUS=$P($$STATUS^ORQOR2(EXORN),U,2)
140 I ORSTATUS="ACTIVE" Q 1 ;renewable if "active"
141 I ORSTATUS="HOLD" Q 1 ;renewable if "on hold"
142 I ORSTATUS="EXPIRED" Q 1 ;renewable if "expired"
143 Q ORSLT
144 ;
145EXCLN(ORNOW) ;clean up old entires in ^XTMP("ORB LAST EXPIRE")
146 N ORN,ORDT
147 S ORN=1
148 F S ORN=$O(^XTMP("ORB LAST EXPIRE",ORN)) Q:ORN="" D
149 .S ORDT=$G(^XTMP("ORB LAST EXPIRE",ORN))
150 .I $L(ORDT),(ORDT<ORNOW) D
151 ..K ^XTMP("ORB LAST EXPIRE",ORN)
152 Q
Note: See TracBrowser for help on using the repository browser.