source: ccr/trunk/p/C0CBAT.m@ 1638

Last change on this file since 1638 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CBAT.m1290
    /ccr/branches/ohum/p/C0CBAT.m1291-1543
    /ccr/branches/ohum/p/p/C0CBAT.m1287-1289
File size: 9.0 KB
Line 
1C0CBAT ; CCDCCR/GPL - CCR Batch utilities; 4/21/09
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ;Copyright 2009 George Lilly.
4 ;
5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU Affero General Public License as
7 ; published by the Free Software Foundation, either version 3 of the
8 ; License, or (at your option) any later version.
9 ;
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU Affero General Public License for more details.
14 ;
15 ; You should have received a copy of the GNU Affero General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
17 ;
18 ;
19 W "This is the CCR Batch Utility Library ",!
20 Q
21 ;
22STOP ; STOP A CURRENTLY RUNNING BATCH JOB
23 I '$D(^TMP("C0CBAT","RUNNING")) Q ;
24 W !,!,"HALTING CCR BATCH",!
25 S ^TMP("C0CBAT","STOP")="" ; SIGNAL JOB TO TERMINATE
26 H 10 ; WAIT TEN SECONDS FOR SIGNAL TO BE RECEIVED
27 I '$D(^TMP("C0CBAT","STOP")) D ; SIGNAL RECEIVED
28 . W "CCR BATCH JOB TERMINATING",!
29 E D ;
30 . K ^TMP("C0CBAT","STOP") ; STOP SIGNALING
31 . W !,"BATCH PROCESSING APPARENTLY NOT RUNNING",!
32 Q
33 ;
34START ; STARTS A TAKSMAN CCR BATCH JOB - FOR USE IN A MENU OPTION
35 ;
36 I $D(^TMP("C0CBAT","RUNNING")) D Q ; ONLY ONE ALLOWED AT A TIME
37 . W !,"CCR BATCH ALREADY RUNNING",!
38 . W !,"STOP FIRST WITH STOP^C0CBAT",!
39 N ZTRTN,ZTDESC,ZTDTH,ZTSAVE,ZTSK,ZTIO
40 S ZTRTN="EN^C0CBAT",ZTDESC="CCR Batch"
41 S ZTDTH=$H ;
42 ;S ZTDTH=$S(($P(ZTDTH,",",2)+10)\86400:(1+ZTDTH)_","_((($P(ZTDTH,",",2)+10)#86400)/100000),1:(+ZTDTH)_","_($P(ZTDTH,",",2)+10))
43 S ZTSAVE("C0C")="",ZTSAVE("C0C*")=""
44 S ZTIO="NULL" ;
45 W !,!,"CCR BATCH JOB STARTED",!
46 D ^%ZTLOAD
47 Q
48 ;
49EN ; BATCH ENTRY POINT
50 ; PROCESSES THE SUBSCRIPTION FILE, EXTRACTING CCR VARIABLES FOR EACH
51 ; PATIENT WITH AN ACTIVE SUBSCRIPTION, AND IF CHECKSUMS INDICATE A CHANGE,
52 ; GENERATES A NEW CCR FOR THE PATIENT
53 ; UPDATES THE E2 CCR ELEMENTS FILE
54 ;
55 S C0CQT=1 ; QUIET MODE
56 I $D(^TMP("C0CBAT","RUNNING")) Q ; ONLY ONE AT A TIME
57 S ^TMP("C0CBAT","RUNNING")="" ; RUNNING SIGNAL
58 S C0CBDT=$$NOW^XLFDT ; DATE OF THIS RUN
59 S C0CBF=177.301 ; FILE NUMBER OF C0C BATCH CONTROL FILE
60 S C0CBFR=177.3013 ; FILE NUMBER OF UPDATE SUBFILE
61 S C0CBB=$NA(^TMP("C0CBATCH",C0CBDT)) ; BATCH WORK AREA
62 I $D(@C0CBB@(0)) D ; ERROR SHOULDN'T EXIST
63 . W "WORK AREA ERROR",!
64 . S $EC=",U1,"
65 S @C0CBB@(0)="V22" ; VERSION USED TO CREATE THIS WORK AREA
66 S C0CBH=$NA(@C0CBB@("HOTLIST")) ; BASE FOR HOT LIST
67 S C0CBS=$NA(^C0CS("B")) ; SUBSCRIPTION LIST BASE
68 ;I $D(^C0CB("B",C0CDT)) D ; BATCH RECORD EXISTS
69 ;. H 10 ; HANG 10 SECONDS
70 ;. S C0CBDT=$$NOW^XLFDT ; NEW DATE FOR THIS RUN
71 ;. I $D(^C0CB("B",C0CDT)) B ;DIDN'T WORK
72 D BLDHOT(C0CBH) ; BUILD THE HOT LIST
73 S C0CHN=$$COUNT(C0CBH) ;COUNT NUMBER IN HOT LIST
74 S C0CSN=$$COUNT(C0CBS) ;COUNT NUMBER OF PATIENTS WITH SUBSCRIPTIONS
75 S C0CFDA(C0CBF,"+1,",.01)=C0CBDT ; DATE KEY OF BATCH CONTROL
76 S C0CFDA(C0CBF,"+1,",.02)=C0CBDT ; BATCH ID IS DATE IN STRING FORM
77 S C0CFDA(C0CBF,"+1,",1)=C0CSN ; TOTAL SUBSCRIPTIONS
78 S C0CFDA(C0CBF,"+1,",2)=C0CHN ; TOTAL HOT LIST
79 D UPDIE ; CREATE THE BATCH RECORD
80 S C0CIEN=$O(^C0CB("B",C0CBDT,""))
81 S (C0CN,C0CNH)=0 ; COUNTERS FOR TOTAL AND HOT LIST
82 S C0CBCUR="" ; CURRENT PATIENT
83 S C0CSTOP=0 ; STOP FLAG FOR HALTING BATCH SET ^TMP("C0CBAT","STOP")=""
84 ;F S C0CBCUR=$O(@C0CBH@(C0CBCUR),-1) Q:C0CBCUR="" D ; HOT LIST LATEST FIRST
85 F S C0CBCUR=$O(@C0CBH@(C0CBCUR)) Q:(C0CSTOP)!(C0CBCUR="") D ; HOT LIST FIRST
86 . D ANALYZE^C0CRIMA(C0CBCUR,1,"LABLIMIT:T-900^VITLIMIT:T-900")
87 . I $G(C0CCHK) D ;
88 . . D PUTRIM^C0CFM2(C0CBCUR)
89 . . D XPAT^C0CCCR(C0CBCUR) ; IF VARIABLES HAVE CHANGED GENERATE CCR
90 . . K C0CFDA
91 . . S C0CFDA(C0CBFR,"+1,"_C0CIEN_",",.01)=C0CBCUR
92 . . S C0CFDA(C0CBFR,"+1,"_C0CIEN_",",1)="Y"
93 . . S C0CFDA(C0CBFR,"+1,"_C0CIEN_",",2)=$G(^TMP("C0CCCR","FNAME",C0CBCUR))
94 . . D UPDIE ; CREATE UPDATE SUBFILE
95 . S C0CN=C0CN+1 ; INCREMENT NUMBER IN TOTAL
96 . S C0CNH=C0CNH+1 ; INCREMENT HOT LIST TOTAL
97 . S C0CFDA(C0CBF,C0CIEN_",",1.1)=C0CN ;UPDATE TOTAL PROGRESS
98 . S C0CFDA(C0CBF,C0CIEN_",",2.1)=C0CNH ; UPDATE HOT LIST PROGRESS
99 . S C0CNOW=$$NOW^XLFDT
100 . S C0CFDA(C0CBF,C0CIEN_",",4)=C0CNOW ; LAST UPDATED FIELD
101 . S C0CELPS=$$FMDIFF^XLFDT(C0CNOW,C0CBDT,2) ; DIFFERENCE IN SECONDS
102 . S C0CAVG=C0CELPS/C0CN ; AVERAGE ELAPSED TIME
103 . S C0CFDA(C0CBF,C0CIEN_",",4.1)=C0CAVG ; AVERAGE ELAPSED TIME
104 . S C0CETOT=C0CAVG*C0CSN ; EST TOT ELASPSED TIME
105 . S C0CEST=$$FMADD^XLFDT(C0CBDT,0,0,0,C0CETOT) ; ADD SECONDS TO BATCH START
106 . S C0CFDA(C0CBF,C0CIEN_",",4.2)=C0CEST ;ESTIMATED COMPLETION TIME
107 . S C0CFDA(C0CBF,C0CIEN_",",5)=C0CBCUR ; LAST RECORD PROCESSED
108 . D UPDIE ;
109 . I $D(^TMP("C0CBAT","STOP")) D ; IF STOP SIGNAL DETECTED
110 . . S C0CSTOP=1
111 . . K ^TMP("C0CBAT","STOP") ; SIGNAL RECEIVED
112 . H 1 ; GIVE OTHERS A CHANCE
113 F S C0CBCUR=$O(@C0CBS@(C0CBCUR)) Q:(C0CSTOP)!(C0CBCUR="") D ; SUBS LIST
114 . I $D(@C0CBH@(C0CBCUR)) Q ; SKIP IF IN HOT LIST - ALREADY DONE
115 . D ANALYZE^C0CRIMA(C0CBCUR,1,"LABLIMIT:T-760^VITLIMIT:T-760")
116 . I $G(C0CCHK) D ; IF CHECKSUMS HAVE CHANGED
117 . . D PUTRIM^C0CFM2(C0CBCUR)
118 . . D XPAT^C0CCCR(C0CBCUR) ; IF VARIABLES HAVE CHANGED GENERATE CCR
119 . . K C0CFDA
120 . . S C0CFDA(C0CBFR,"+1,"_C0CIEN_",",.01)=C0CBCUR
121 . . S C0CFDA(C0CBFR,"+1,"_C0CIEN_",",1)="Y"
122 . . S C0CFDA(C0CBFR,"+1,"_C0CIEN_",",2)=$G(^TMP("C0CCCR","FNAME",C0CBCUR))
123 . . D UPDIE ; CREATE UPDATE SUBFILE
124 . S C0CN=C0CN+1 ; INCREMENT NUMBER IN TOTAL
125 . S C0CFDA(C0CBF,C0CIEN_",",1.1)=C0CN ;UPDATE TOTAL PROGRESS
126 . S C0CNOW=$$NOW^XLFDT
127 . S C0CFDA(C0CBF,C0CIEN_",",4)=C0CNOW ; LAST UPDATED FIELD
128 . S C0CELPS=$$FMDIFF^XLFDT(C0CNOW,C0CBDT,2) ; DIFFERENCE IN SECONDS
129 . S C0CAVG=C0CELPS/C0CN ; AVERAGE ELAPSED TIME
130 . S C0CFDA(C0CBF,C0CIEN_",",4.1)=C0CAVG ; AVERAGE ELAPSED TIME
131 . S C0CETOT=C0CAVG*C0CSN ; EST TOT ELASPSED TIME
132 . S C0CEST=$$FMADD^XLFDT(C0CBDT,0,0,0,C0CETOT) ; ADD SECONDS TO BATCH START
133 . S C0CFDA(C0CBF,C0CIEN_",",4.2)=C0CEST ;ESTIMATED COMPLETION TIME
134 . S C0CFDA(C0CBF,C0CIEN_",",5)=C0CBCUR ;
135 . D UPDIE ;
136 . I $D(^TMP("C0CBAT","STOP")) D ; IF STOP SIGNAL DETECTED
137 . . S C0CSTOP=1
138 . . K ^TMP("C0CBAT","STOP") ; SIGNAL RECEIVED
139 . H 1 ; GIVE IT A BREAK
140 I (C0CSTOP) S C0CDISP="KILLED"
141 E S C0CDISP="FINISHED"
142 S C0CFDA(C0CBF,C0CIEN_",",6)=C0CDISP
143 D UPDIE ; SET DISPOSITION FIELD
144 K ^TMP("C0CBAT","RUNNING")
145 Q
146 ;
147BLDHOT(ZHB) ; BUILD HOT LIST AT GLOBAL ZHB, PASSED BY NAME
148 ; SEARCHS FOR PATIENTS IN THE "AC" INDEX OF THE ORDER FILE
149 N ZDFN
150 S ZDFN=""
151 F S ZDFN=$O(^OR(100,"AC",ZDFN)) Q:ZDFN="" D ; ALL PATIENTS IN THE AC INDX
152 . S ZZDFN=$P(ZDFN,";",1) ; FORMAT IS "N;DPT("
153 . I '$D(@C0CBS@(ZZDFN)) Q ; SKIP IF NOT IN SUBSCRIPTION LIST
154 . S @ZHB@(ZZDFN)="" ;ADD PATIENT TO THE HOT LIST
155 Q
156 ;
157COUNT(ZB) ; EXTRINSIC THAT RETURNS THE NUMBER OF ARRAY ELEMENTS
158 N ZI,ZN
159 S ZN=0
160 S ZI=""
161 F S ZI=$O(@ZB@(ZI)) Q:ZI="" D ;
162 . S ZN=ZN+1
163 Q ZN
164 ;
165UVARPTR(ZVAR,ZTYP) ;EXTRINSIC WHICH RETURNS THE POINTER TO ZVAR IN THE
166 ; CCR DICTIONARY. IT IS LAYGO, AS IT WILL ADD THE VARIABLE TO
167 ; THE CCR DICTIONARY IF IT IS NOT THERE. ZTYP IS REQUIRED FOR LAYGO
168 ;
169 N ZCCRD,ZVARN,C0CFDA2
170 S ZCCRD=170 ; FILE NUMBER FOR CCR DICTIONARY
171 S ZVARN=$O(^C0CDIC(170,"B",ZVAR,"")) ;FIND IEN OF VARIABLE
172 I ZVARN="" D ; VARIABLE NOT IN CCR DICTIONARY - ADD IT
173 . I '$D(ZTYP) D Q ; WON'T ADD A VARIABLE WITHOUT A TYPE
174 . . W "CANNOT ADD VARIABLE WITHOUT A TYPE: ",ZVAR,!
175 . S C0CFDA2(ZCCRD,"?+1,",.01)=ZVAR ; NAME OF NEW VARIABLE
176 . S C0CFDA2(ZCCRD,"?+1,",12)=ZTYP ; TYPE EXTERNAL OF NEW VARIABLE
177 . D CLEAN^DILF ;MAKE SURE ERRORS ARE CLEAN
178 . D UPDATE^DIE("E","C0CFDA2","","ZERR") ;ADD VAR TO CCR DICTIONARY
179 . I $D(ZERR) D ; LAYGO ERROR
180 . . W "ERROR ADDING "_ZC0CI_" TO CCR DICTIONARY",!
181 . E D ;
182 . . D CLEAN^DILF ; CLEAN UP
183 . . S ZVARN=$O(^C0CDIC(170,"B",ZVAR,"")) ;FIND IEN OF VARIABLE
184 . . W "ADDED ",ZVAR," TO CCR DICTIONARY, IEN:",ZVARN,!
185 Q ZVARN
186 ;
187UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
188 K ZERR
189 D CLEAN^DILF
190 D UPDATE^DIE("","C0CFDA","","ZERR")
191 I $D(ZERR) S $EC=",U1,"
192 K C0CFDA
193 Q
194 ;
195SETFDA(C0CSN,C0CSV) ; INTERNAL ROUTINE TO MAKE AN FDA ENTRY FOR FIELD C0CSN
196 ; TO SET TO VALUE C0CSV.
197 ; C0CFDA,C0CC,C0CZX ARE ASSUMED FROM THE CALLING ROUTINE
198 ; C0CSN,C0CSV ARE PASSED BY VALUE
199 ;
200 N C0CSI,C0CSJ
201 S C0CSI=$$ZFILE(C0CSN,"C0CC") ; FILE NUMBER
202 S C0CSJ=$$ZFIELD(C0CSN,"C0CC") ; FIELD NUMBER
203 S C0CFDA(C0CSI,C0CZX_",",C0CSJ)=C0CSV
204 Q
205ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
206 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF C0CA(ZFN)
207 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
208 I '$D(ZTAB) S ZTAB="C0CA"
209 N ZR
210 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",1)
211 E S ZR=""
212 Q ZR
213ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
214 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF C0CA(ZFN)
215 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
216 I '$D(ZTAB) S ZTAB="C0CA"
217 N ZR
218 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",2)
219 E S ZR=""
220 Q ZR
221 ;
222ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
223 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF C0CA(ZFN)
224 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
225 I '$D(ZTAB) S ZTAB="C0CA"
226 N ZR
227 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",3)
228 E S ZR=""
229 Q ZR
230 ;
Note: See TracBrowser for help on using the repository browser.