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

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

xpath wrapper for MXML

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