source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLUOPT1.m@ 1705

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

initial load of FOIAVistA 6/30/08 version

File size: 7.7 KB
Line 
1HLUOPT1 ;AISC/SAW - Purging Entries in file #772 and #773 ;02/04/2004 09:58
2 ;;1.6;HEALTH LEVEL SEVEN;**10,13,21,36,19,47,62,109,108**;Oct 13, 1995
3 ;
4 ; Purge data of the HL7 message in file #772 and #773.
5 ;
6 ; Patch 47 - For Purging Option scheduled on a recurring basis,
7 ; numbers of days kept for various Status of message are stored
8 ; in file #869.3, fields 41, 42, and 43. Default values for these
9 ; fields are 7, 30, and 90, respectively.
10 ;
11 ; Patch 36 - a message will never be purged if the new field, "Don't
12 ; Purge" (#772,15), is set to 1.
13 ;
14PURGE ;
15 ; HLPDT("COMP") - 'completed' status cutoff date
16 ; HLPDT("WAIT") - 'awaiting ack' status cutoff date
17 ; HLPDT("ERR") - 'error' status cutoff date
18 ; (=0 means don't delete msgs in 'error' status)
19 ; HLPDT("ALL") - all other status (except 'error') cutoff date
20 N HLPDT,HLTASK,HLEXIT
21 ;
22 S (HLTASK,HLEXIT)=0
23 D INIT(.HLPDT,.HLTASK,.HLEXIT) Q:HLEXIT
24 ;
25 ; HL*1.6*109 lock logic...
26 L +^HL("HLUOPT1"):2 I '$T D:'$D(ZTQUEUED) LOCKTELL^HLUOPT4 QUIT ;->
27 L -^HL("HLUOPT1") ; Locked again at the top of DQ
28 ;
29 ; HL*1.6*109
30 I '$D(ZTQUEUED) I $$BTE^HLCSMON("Press RETURN to "_$S(HLTASK:"queue job",1:"start purging")_", or enter '^' to exit... ",1) D QUIT ;->
31 . I HLTASK W " no task started..."
32 . I 'HLTASK W " exiting..."
33 ;
34 I HLTASK D TASKIT Q
35 K HLTASK,HLEXIT ; not needed
36 D DQ
37 ;
38 Q
39 ;
40INIT(HLPDT,HLTASK,HLEXIT) ; Get data from file #869.3
41 D INIT^HLUOPT4 ; HL*1.6*109
42 Q
43 ;
44TASKIT ; Queue task to run in the background
45 N ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
46 S ZTRTN="DQ^HLUOPT1",ZTIO="",ZTSAVE("HLPDT(")="",ZTDTH=$H
47 S ZTDESC="Purge HL7 message text on or before "_$$FMTE^XLFDT(HLPDT("COMP"),"5D")
48 D ^%ZTLOAD
49 I $D(ZTSK) W !," Task #",ZTSK," queued to run now...",! Q ; HL*1.6*109
50 W !," Queuing of Purge task failed.",! ; HL*1.6*109
51 Q
52DQ ; Entry point for running purge of HL7 message text
53 N HLDELCNT,HLEXIT,HLOOPCT
54 ;
55 S HLOOPCT=0
56 ;
57 ; HL*1.6*109
58 N XTMP D XTMPBEGN^HLUOPT4
59 ;
60 ; Lock to ensures no other purge job can run...
61 L +^HL("HLUOPT1"):10 I '$T D QUIT ;->
62 . D XTMPUPD^HLUOPT4(.XTMP,"NO-LOCK","DONE")
63 . I $D(ZTQUEUED) S ZTREQ="@"
64 ;
65 ; Purge 773s...
66 S (HLDELCNT,HLEXIT)=0
67 D CHK773(.HLPDT,.HLDELCNT,.HLEXIT)
68 ;
69 ; Update piece 4 of file's zero node...
70 D UPDP4(773)
71 ;
72 ; Purge 772s...
73 I 'HLEXIT D CHK772(.HLPDT,.HLDELCNT,.HLEXIT)
74 ;
75 ; Update piece 4 of file's zero node...
76 D UPDP4(772)
77 ;
78 ; HL*1.6*109
79 L -^HL("HLUOPT1")
80 ;
81 D XTMPUPD^HLUOPT4(.XTMP,"FINISHED","DONE")
82 I $D(ZTQUEUED) S ZTREQ="@" Q
83 ;
84 W !!," #",HLDELCNT," entries purged...",! ; HL*1.6*109
85 ;
86 Q
87 ;
88UPDP4(FNO) ; Update piece 4 of file's zero node...
89 N GBL,NODE,NODEL,P4
90 S GBL=$S(+FNO=772:"^HL(772,0)",+FNO=773:"^HLMA(0)",1:"") QUIT:GBL']"" ;->
91 S NODEL=$G(XTMP(+FNO,"DEL")) QUIT:NODEL'>0 ;->
92 L +@GBL:30 ; If don't get lock, update piece 4 anyway...
93 S NODE=$G(@GBL) ; Get node...
94 S P4=$P(NODE,U,4)-NODEL,P4=$S(P4>0:+P4,1:"") ; Recalc piece 4...
95 S $P(NODE,U,4)=P4 ; Reset node's piece 4...
96 S @GBL=NODE ; Store in file's zero node...
97 L -@GBL
98 Q
99 ;
100CHK773(HLPDT,HLDELCNT,HLEXIT) ; Check file 773
101 N FPDATE,HLIEN,HLPTR,HLMADT,HLY,HLMADT1,HLLT773
102 ;
103 ; HL*1.6*109
104 I '$G(HLTASK) W !,"Looping through file 773..."
105 D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","START-773")
106 ;
107 ;calculate cuttoff date for records reserved by Fast Purge - records with a more recent FAST PURGE DT/TM then this should be left to the Fast Purge to delete
108 S FPDATE=$$FMADD^XLFDT(DT,-2)
109 ;
110 S HLLT773=$O(^HLMA(";"),-1) ; last ien for 773
111 S HLIEN=0
112 F S HLIEN=$O(^HLMA(HLIEN)) Q:'HLIEN D Q:HLEXIT Q:$$FAIL(773) ;HL*1.6*109
113 . D CHK4STOP(.HLEXIT) Q:HLEXIT
114 . S XTMP(773,"REV")=$G(XTMP(773,"REV"))+1,XTMP(773,"LAST")=HLIEN,XTMP(773,"FAIL")=$G(XTMP(773,"FAIL"))+1 ; HL*1.6*109
115 . ;
116 . ;check if the record is reserved for FAST PURGE
117 . I ($P($G(^HLMA(HLIEN,2)),"^",2)\1)>FPDATE Q
118 . ;
119 . S HLPTR=+$G(^HLMA(HLIEN,0)) Q:'HLPTR
120 . S HLMADT=+$G(^HL(772,HLPTR,0))
121 . ;HLY=status, HLMADT1=processed date
122 . S HLY=+$G(^HLMA(HLIEN,"P")),HLMADT1=+$G(^("S"))
123 . ;error status, quit if flag set to no
124 . I HLY>3,HLY<8,'HLPDT("ERR") Q
125 . ;check if date entered is less than purge all date
126 . I HLMADT<HLPDT("ALL") D KILL773(HLIEN,HLLT773,.HLDELCNT) Q
127 . ;pending, being generated, awaiting processing, or no processed date
128 . I HLY=1!(HLY>7)!('HLMADT1) Q
129 . ;awaiting ack, no purge date or date>purge date
130 . I HLY=2,HLMADT1>HLPDT("WAIT") Q
131 . ;successfully transmitted
132 . I HLY=3,HLMADT1>HLPDT("COMP") Q
133 . ;error status
134 . I HLY>3,HLY<8,HLMADT1>HLPDT("ERR") Q
135 . D KILL773(HLIEN,HLLT773,.HLDELCNT)
136 D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","END-773") ; HL*1.6*109
137 Q
138KILL773(HLIEN,HLLT773,HLDELCNT) ; delete in file 773
139 ;
140 ; quit if don't purge flag is set or the entry is the last one
141 Q:$G(^HLMA(HLIEN,2))!(HLIEN=HLLT773)
142 ;
143 S X=$G(^HLMA(+HLIEN,0)),X=+$G(^HL(772,+X,0)),XTMP(773,"LAST","TIME")=$S(X?7N1"."1.N:+X,1:"")
144 ;
145 D DEL773^HLUOPT3(HLIEN) ; Purge w/direct kills...
146 ;
147 S HLDELCNT=HLDELCNT+1
148 ;
149 S XTMP(773,"DEL")=$G(XTMP(773,"DEL"))+1,XTMP(773,"FAIL")=0
150 ;
151 Q
152 ;
153CHK772(HLPDT,HLDELCNT,HLEXIT) ; Check file 772 for parents and children
154 N FPDATE,HLOOP2,HLPTR,HLINK,HLIEN,HLMADT,HLY,HLLT772
155 ;
156 ; HL*1.6*109
157 I '$G(HLTASK) W !,"Looping through file 772..."
158 D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","START-772")
159 ;
160 ;calculate cuttoff date for records reserved by Fast Purge - records with a more recent FAST PURGE DT/TM then this should be left to the Fast Purge to delete
161 S FPDATE=$$FMADD^XLFDT(DT,-2)
162 ;
163 S HLLT772=$O(^HL(772,";"),-1) ; last ien for 772
164 F HLOOP2=1:1:2 D Q:HLEXIT ; Kill children first, then parents
165 . S XTMP(772,"FAIL")=0 ; HL*1.6*109
166 . S HLPTR=0
167 . F S HLPTR=$O(^HL(772,"B",HLPTR)) Q:HLPTR'>0 D Q:HLEXIT Q:$$FAIL(772) ; HL*1.6*109
168 . . D CHK4STOP(.HLEXIT) Q:HLEXIT
169 . . S HLIEN=0
170 . . F S HLIEN=$O(^HL(772,"B",HLPTR,HLIEN)) Q:'HLIEN D
171 . . . S XTMP(772,"REV")=$G(XTMP(772,"REV"))+1,XTMP(772,"LAST")=HLIEN,XTMP(772,"FAIL")=$G(XTMP(772,"FAIL"))+1 ; HL*1.6*109
172 ... ;
173 ... ;check if the record is reserved for FAST PURGE
174 ... I ($P($G(^HL(772,+HLIEN,2)),"^",2)\1)>FPDATE Q
175 ... ;
176 . . . S HLMADT=+$G(^HL(772,+HLIEN,0)) Q:'HLMADT
177 . . . I HLMADT>HLPDT("COMP") Q
178 . . . S HLY=$P($G(^HL(772,HLIEN,"P")),U)
179 . . . I HLY?1U S HLY=$TR(HLY,"PASE",1234)
180 . . . I HLY>3,HLY<8,'HLPDT("ERR") Q
181 . . . I HLMADT<HLPDT("ALL") D KILL772(HLIEN,HLLT772,.HLDELCNT) Q
182 . . . I HLY=3,HLMADT>HLPDT("COMP") Q
183 . . . I HLY=2,HLMADT>HLPDT("WAIT") Q
184 . . . I HLY>3,HLY<8,HLMADT>HLPDT("ERR") Q
185 . . . I HLY=1!(HLY>7) Q
186 . . . I $O(^HL(772,"AI",HLIEN,HLIEN)) Q
187 . . . D KILL772(HLIEN,HLLT772,.HLDELCNT)
188 D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","END-772") ; HL*1.6*109
189 S HLINK=0
190 F S HLINK=$O(^HL(772,"A-XMIT-OUT",HLINK)) Q:'HLINK D
191 . S HLIEN=0
192 . F S HLIEN=$O(^HL(772,"A-XMIT-OUT",HLINK,HLIEN)) Q:'HLIEN D
193 . . I '$D(^HL(772,HLIEN)) K ^HL(772,"A-XMIT-OUT",HLINK,HLIEN)
194 Q
195KILL772(HLIEN,HLLT772,HLDELCNT) ;
196 ;
197 ; quit if the corresponding entry in #773 exists
198 I $O(^HLMA("B",HLIEN,0)) Q
199 ;
200 ; quit if don't purge flag is set or the entry is the last one
201 Q:+$G(^HL(772,HLIEN,2))!(HLIEN=HLLT772)
202 ;
203 N XMDUZ,XMK,XMZ,DIK,DA,HLX
204 ;
205 S HLX=$G(^HL(772,HLIEN,0))
206 S XMZ=$P(HLX,U,5)
207 I XMZ S XMK=1,XMDUZ=.5 D KLQ^XMA1B
208 ;
209 S XTMP(772,"LAST","TIME")=$S(+HLX?7N1"."1.N:+HLX,1:"")
210 ;
211 D DEL772^HLUOPT3(+HLIEN)
212 ;
213 S HLDELCNT=HLDELCNT+1
214 S XTMP(772,"DEL")=$G(XTMP(772,"DEL"))+1,XTMP(772,"FAIL")=0 ; HL*1.6*109
215 ;
216 Q
217 ;
218CHK4STOP(HLEXIT) ;
219 ; HL*1.6*109 modified from 60 to 120...
220 ;
221 S HLOOPCT=HLOOPCT+1
222 I '$D(ZTQUEUED) W:'(HLOOPCT#2000) "."
223 ;
224 S:$G(HLEXIT("LASTCHK"))']"" HLEXIT("LASTCHK")=$H
225 ;
226 Q:$$HDIFF^XLFDT($H,$G(HLEXIT("LASTCHK")),2)<120
227 ;
228 ; HL*1.6*109 modified...
229 I $$S^%ZTLOAD D Q
230 . S HLEXIT=1
231 . D XTMPUPD^HLUOPT4(.XTMP,"ABORTED-TASKMAN","CHK4STOP")
232 ;
233 S HLEXIT("LASTCHK")=$H
234 ;
235 D XTMPUPD^HLUOPT4(.XTMP,"RUNNING","CHK4STOP") ; HL*1.6*109
236 ;
237 Q
238 ;
239FAIL(FILE) ; Has number entries w/o purging any been exceeded?
240 QUIT $S($G(XTMP(FILE,"FAIL"))>200000:1,1:"")
241 ;
Note: See TracBrowser for help on using the repository browser.