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

Last change on this file since 437 was 437, checked in by George Lilly, 12 years ago

batch processing release

File size: 6.7 KB
Line 
1C0CBAT   ; CCDCCR/GPL - CCR Batch utilities; 4/21/09
2 ;;0.1;CCDCCR;nopatch;noreleasedate
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 ;
23EN ; BATCH ENTRY POINT
24 ; PROCESSES THE SUBSCRIPTION FILE, EXTRACTING CCR VARIABLES FOR EACH
25 ; PATIENT WITH AN ACTIVE SUBSCRIPTION, AND IF CHECKSUMS INDICATE A CHANGE,
26 ; GENERATES A NEW CCR FOR THE PATIENT
27 ; UPDATES THE E2 CCR ELEMENTS FILE
28 ;
29 S C0CQT=1 ; QUIET MODE
30 S C0CBDT=$$NOW^XLFDT ; DATE OF THIS RUN
31 S C0CBF=177.301 ; FILE NUMBER OF C0C BATCH CONTROL FILE
32 S C0CBB=$NA(^TMP("C0CBATCH",C0CBDT)) ; BATCH WORK AREA
33 I $D(@C0CBB@(0)) D  ; ERROR SHOULDN'T EXIST
34 . W "WORK AREA ERROR",!
35 . B
36 S @C0CBB@(0)="V21" ; VERSION USED TO CREATE THIS WORK AREA
37 S C0CBH=$NA(@C0CBB@("HOTLIST")) ; BASE FOR HOT LIST
38 S C0CBS=$NA(^C0CS("B")) ; SUBSCRIPTION LIST BASE
39 D BLDHOT(C0CBH) ; BUILD THE HOT LIST
40 S C0CHN=$$COUNT(C0CBH) ;COUNT NUMBER IN HOT LIST
41 S C0CSN=$$COUNT(C0CBS) ;COUNT NUMBER OF PATIENTS WITH SUBSCRIPTIONS
42 S C0CFDA(C0CBF,"+1,",.01)=C0CBDT ; DATE KEY OF BATCH CONTROL
43 S C0CFDA(C0CBF,"+1,",.02)=C0CBDT ; BATCH ID IS DATE IN STRING FORM
44 S C0CFDA(C0CBF,"+1,",1)=C0CSN ; TOTAL SUBSCRIPTIONS
45 S C0CFDA(C0CBF,"+1,",2)=C0CHN ; TOTAL HOT LIST
46 D UPDIE ; CREATE THE BATCH RECORD
47 S C0CIEN=$O(^C0CB("B",C0CBDT,""))
48 S (C0CN,C0CNH)=0 ; COUNTERS FOR TOTAL AND HOT LIST
49 S C0CBCUR="" ; CURRENT PATIENT
50 ;F  S C0CBCUR=$O(@C0CBH@(C0CBCUR),-1) Q:C0CBCUR=""  D  ; HOT LIST LATEST FIRST
51 F  S C0CBCUR=$O(@C0CBH@(C0CBCUR)) Q:C0CBCUR=""  D  ; HOT LIST FIRST FIRST
52 . D ANALYZE^C0CRIMA(C0CBCUR,1,"LABLIMIT:T-760^VITLIMIT:T-760")
53 . D PUTRIM^C0CFM2(C0CBCUR)
54 . I $G(C0CCHK) D XPAT^C0CCCR(C0CBCUR) ; IF VARIABLES HAVE CHANGED GENERATE CCR
55 . S C0CN=C0CN+1 ; INCREMENT NUMBER IN TOTAL
56 . S C0CNH=C0CNH+1 ; INCREMENT HOT LIST TOTAL
57 . S C0CFDA(C0CBF,C0CIEN_",",1.1)=C0CN ;UPDATE TOTAL PROGRESS
58 . S C0CFDA(C0CBF,C0CIEN_",",2.1)=C0CNH ; UPDATE HOT LIST PROGRESS
59 . S C0CNOW=$$NOW^XLFDT
60 . S C0CFDA(C0CBF,C0CIEN_",",4)=C0CNOW
61 . S C0CELPS=$$FMDIFF^XLFDT(C0CNOW,C0CBDT,2) ; DIFFERENCE IN SECONDS
62 . S C0CAVG=C0CELPS/C0CN ; AVERAGE ELAPSED TIME
63 . S C0CFDA(C0CBF,C0CIEN_",",4.1)=C0CAVG
64 . S C0CETOT=C0CAVG*C0CSN ; EST TOT ELASPSED TIME
65 . S C0CEST=$$FMADD^XLFDT(C0CBDT,0,0,0,C0CETOT) ; ADD SECONDS TO BATCH START
66 . S C0CFDA(C0CBF,C0CIEN_",",4.2)=C0CEST ;ESTIMATED COMPLETION TIME
67 . D UPDIE ;
68 F  S C0CBCUR=$O(@C0CBS@(C0CBCUR)) Q:C0CBCUR=""  D  ; REMAINING SUBSCRIPTION LIST
69 . I $D(@C0CBH@(C0CBCUR)) Q  ; SKIP IF IN HOT LIST - ALREADY DONE
70 . D ANALYZE^C0CRIMA(C0CBCUR,1,"LABLIMIT:T-760^VITLIMIT:T-760")
71 . D PUTRIM^C0CFM2(C0CBCUR)
72 . I $G(C0CCHK) D XPAT^C0CCCR(C0CBCUR) ; IF VARIABLES HAVE CHANGED GENERATE CCR
73 . S C0CN=C0CN+1 ; INCREMENT NUMBER IN TOTAL
74 . S C0CFDA(C0CBF,C0CIEN_",",1.1)=C0CN ;UPDATE TOTAL PROGRESS
75 . S C0CNOW=$$NOW^XLFDT
76 . S C0CFDA(C0CBF,C0CIEN_",",4)=C0CNOW
77 . S C0CELPS=$$FMDIFF^XLFDT(C0CNOW,C0CBDT,2) ; DIFFERENCE IN SECONDS
78 . S C0CAVG=C0CELPS/C0CN ; AVERAGE ELAPSED TIME
79 . S C0CFDA(C0CBF,C0CIEN_",",4.1)=C0CAVG
80 . S C0CETOT=C0CAVG*C0CSN ; EST TOT ELASPSED TIME
81 . S C0CEST=$$FMADD^XLFDT(C0CBDT,0,0,0,C0CETOT) ; ADD SECONDS TO BATCH START
82 . S C0CFDA(C0CBF,C0CIEN_",",4.2)=C0CEST ;ESTIMATED COMPLETION TIME
83 . D UPDIE ;
84 Q
85 ;
86BLDHOT(ZHB) ; BUILD HOT LIST AT GLOBAL ZHB, PASSED BY NAME
87 ; SEARCHS FOR PATIENTS IN THE "AC" INDEX OF THE ORDER FILE
88 N ZDFN
89 S ZDFN=""
90 F  S ZDFN=$O(^OR(100,"AC",ZDFN)) Q:ZDFN=""  D  ; ALL PATIENTS IN THE AC INDX
91 . S ZZDFN=$P(ZDFN,";",1) ; FORMAT IS "N;DPT("
92 . I '$D(@C0CBS@(ZZDFN)) Q  ; SKIP IF NOT IN SUBSCRIPTION LIST
93 . S @ZHB@(ZZDFN)="" ;ADD PATIENT TO THE HOT LIST
94 Q
95 ;
96COUNT(ZB) ; EXTRINSIC THAT RETURNS THE NUMBER OF ARRAY ELEMENTS
97 N ZI,ZN
98 S ZN=0
99 S ZI=""
100 F  S ZI=$O(@ZB@(ZI)) Q:ZI=""  D  ;
101 . S ZN=ZN+1
102 Q ZN
103 ;
104UPDIEVARPTR(ZVAR,ZTYP) ;EXTRINSIC WHICH RETURNS THE POINTER TO ZVAR IN THE
105 ; CCR DICTIONARY. IT IS LAYGO, AS IT WILL ADD THE VARIABLE TO
106 ; THE CCR DICTIONARY IF IT IS NOT THERE. ZTYP IS REQUIRED FOR LAYGO
107 ;
108 N ZCCRD,ZVARN,C0CFDA2
109 S ZCCRD=170 ; FILE NUMBER FOR CCR DICTIONARY
110 S ZVARN=$O(^C0CDIC(170,"B",ZVAR,"")) ;FIND IEN OF VARIABLE
111 I ZVARN="" D  ; VARIABLE NOT IN CCR DICTIONARY - ADD IT
112 . I '$D(ZTYP) D  Q  ; WON'T ADD A VARIABLE WITHOUT A TYPE
113 . . W "CANNOT ADD VARIABLE WITHOUT A TYPE: ",ZVAR,!
114 . S C0CFDA2(ZCCRD,"?+1,",.01)=ZVAR ; NAME OF NEW VARIABLE
115 . S C0CFDA2(ZCCRD,"?+1,",12)=ZTYP ; TYPE EXTERNAL OF NEW VARIABLE
116 . D CLEAN^DILF ;MAKE SURE ERRORS ARE CLEAN
117 . D UPDATE^DIE("E","C0CFDA2","","ZERR") ;ADD VAR TO CCR DICTIONARY
118 . I $D(ZERR) D  ; LAYGO ERROR
119 . . W "ERROR ADDING "_ZC0CI_" TO CCR DICTIONARY",!
120 . E  D  ;
121 . . D CLEAN^DILF ; CLEAN UP
122 . . S ZVARN=$O(^C0CDIC(170,"B",ZVAR,"")) ;FIND IEN OF VARIABLE
123 . . W "ADDED ",ZVAR," TO CCR DICTIONARY, IEN:",ZVARN,!
124 Q ZVARN
125 ;
126UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
127 K ZERR
128 D CLEAN^DILF
129 D UPDATE^DIE("","C0CFDA","","ZERR")
130 I $D(ZERR) D  ;
131 . W "ERROR",!
132 . ZWR ZERR
133 . B
134 K C0CFDA
135 Q
136 ;
137SETFDA(C0CSN,C0CSV) ; INTERNAL ROUTINE TO MAKE AN FDA ENTRY FOR FIELD C0CSN
138 ; TO SET TO VALUE C0CSV.
139 ; C0CFDA,C0CC,C0CZX ARE ASSUMED FROM THE CALLING ROUTINE
140 ; C0CSN,C0CSV ARE PASSED BY VALUE
141 ;
142 N C0CSI,C0CSJ
143 S C0CSI=$$ZFILE(C0CSN,"C0CC") ; FILE NUMBER
144 S C0CSJ=$$ZFIELD(C0CSN,"C0CC") ; FIELD NUMBER
145 S C0CFDA(C0CSI,C0CZX_",",C0CSJ)=C0CSV
146 Q
147ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
148 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF C0CA(ZFN)
149 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
150 I '$D(ZTAB) S ZTAB="C0CA"
151 N ZR
152 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",1)
153 E  S ZR=""
154 Q ZR
155ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
156 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF C0CA(ZFN)
157 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
158 I '$D(ZTAB) S ZTAB="C0CA"
159 N ZR
160 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",2)
161 E  S ZR=""
162 Q ZR
163 ;
164ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
165 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF C0CA(ZFN)
166 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
167 I '$D(ZTAB) S ZTAB="C0CA"
168 N ZR
169 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",3)
170 E  S ZR=""
171 Q ZR
172 ;
Note: See TracBrowser for help on using the repository browser.