forked from sanua/VocabularyUpdate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate_LOINC_Part2.gradle
More file actions
388 lines (318 loc) · 14.7 KB
/
Update_LOINC_Part2.gradle
File metadata and controls
388 lines (318 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
**************************************
* ICD10CM Vocabulary update. Part 2 *
* Version 0.0.6 *
**************************************
*/
group 'com.sci.vocabulary'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
/*repositories {
mavenLocal()
mavenCentral()
}*/
/*dependencies {
compile 'org.apache.poi:poi:3.9'
compile 'org.apache.poi:poi-ooxml:3.9'
}*/
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.apache.poi:poi:3.9'
classpath 'org.apache.poi:poi-ooxml:3.9'
}
}
/**
* Auxiliary classes. TODO: Further should be used java-defined and compiled only
*/
public class StringBuilderWrapper implements java.lang.Appendable {
private static final String IDENT_CHAR = " " *4
private StringBuilder wrapped
public StringBuilderWrapper() {
wrapped = new StringBuilder()
}
public StringBuilderWrapper(String value) {
this()
wrapped.append(IDENT_CHAR).append(value)
}
@Override
Appendable append(CharSequence csq) throws IOException {
wrapped.append(IDENT_CHAR).append(csq)
return this
}
@Override
Appendable append(CharSequence csq, int start, int end) throws IOException {
wrapped.append(IDENT_CHAR).append(csq, start, end)
return this
}
@Override
Appendable append(char c) throws IOException {
wrapped.append(IDENT_CHAR).append(c)
return this
}
@Override
String toString() {
return wrapped.toString()
}
}
// Load ICD10CM properties
Properties props = new Properties()
props.load(new FileInputStream("$project.rootDir/Update_ICD10CM.properties"))
props.each {prop ->
project.ext.set(prop.key, prop.value)
}
props.load(new FileInputStream("$project.rootDir/Update_ICD10CM_Part2.properties"))
props.each {prop ->
project.ext.set(prop.key, prop.value)
}
def tempDir = File.createTempDir()
tempDir.deleteOnExit()
task prepareManualTable(description: project.properties['prepareTable.description']) << {
println '\n\n*****************************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '*****************************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def filesBasePath="${projectDir}\\${project.properties['basePath']}"
def log_file = "${filesBasePath}\\${project.properties['prepareTable.logFileName']}"
def stream_log_file = "${filesBasePath}\\${project.properties['prepareTable.streamLogFileName']}"
def stream_error_file = "${filesBasePath}\\${project.properties['prepareTable.streamErrFileName']}"
def db = [un: project.properties['db.userName'],
pw: project.properties['db.password'],
tns: project.properties['db.tnsName'],
sqlfile: "${filesBasePath}\\${project.properties['prepareTable.sqlFileName']}",
tableName: "${project.properties['manualTableName']}",
logfile: log_file]
def sout = new StringBuilderWrapper(), serr = new StringBuilderWrapper()
def sqlplus= """sqlplus.exe ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile} ${db.tableName}""".execute()
sqlplus.consumeProcessOutput(sout, serr)
sqlplus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Write to console
System.out.println(sout.toString())
// Write to logfile
File f = new File(stream_log_file)
f.write(sout.toString())
// Write to error file
f = new File(stream_error_file)
f.write(serr.toString())
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
task importTable (dependsOn: prepareManualTable, description: project.properties['importTable.description']) << {
println '\n\n*****************************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '*****************************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def filesBasePath="${projectDir}\\${project.properties['basePath']}"
def dataFile = "${filesBasePath}\\${project.properties['importTable.dataFileName']}"
def logFile = "${filesBasePath}\\${project.properties['importTable.logFileName']}"
def discardFile = "${filesBasePath}\\${project.properties['importTable.discardFileName']}"
def badFile = "${filesBasePath}\\${project.properties['importTable.badFileName']}"
def stream_log_file = "${filesBasePath}\\${project.properties['importTable.streamLogFileName']}"
def stream_error_file = "${filesBasePath}\\${project.properties['importTable.streamErrFileName']}"
def bosOut = new ByteArrayOutputStream(), bosErr = new ByteArrayOutputStream()
def sout = new StringBuilderWrapper(), serr = new StringBuilderWrapper()
exec {
executable "sqlldr.exe"
args "USERID=${project.properties['db.userName']}/${project.properties['db.password']}@${project.properties['db.tnsName']} " +
"CONTROL=${filesBasePath}\\${project.properties['importTable.controlFileName']} DATA=$dataFile LOG=$logFile DISCARD=$discardFile BAD=$badFile"
standardOutput = bosOut
errorOutput = bosErr
}
def bisOut = new ByteArrayInputStream(bosOut.toByteArray())
bisOut.withReader { out->
out.eachLine {
sout.append(it).append('\n')
}
}
def bisErr = new ByteArrayInputStream(bosErr.toByteArray())
bisErr.withReader { out ->
out.eachLine {
serr.append(it).append('\n')
}
}
// Write to console
System.out.println(sout.toString())
// Write to logfile
File f = new File(stream_log_file)
f.write(sout.toString())
// Write to error file
f = new File(stream_error_file)
f.write(serr.toString())
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will run 'Load stage' script.
* Seems it's is specific for each vocabulary.
*/
task runLoadStage(dependsOn: importTable, description: project.properties['loadStage.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def log_file = "${tempDir.getPath()}\\${project.properties['loadStage.logFileName']}"
def stream_log_file = "${tempDir.getPath()}\\${project.properties['loadStage.streamLogFileName']}"
def stream_error_file = "${tempDir.getPath()}\\${project.properties['loadStage.streamErrFileName']}"
def db = [un: project.properties['db.userName'],
pw: project.properties['db.password'],
tns: project.properties['db.tnsName'],
sqlfile: "${project.properties['basePath']}\\${project.properties['loadStage.sqlFileName']}",
logfile: log_file]
def sout = new StringBuilderWrapper(), serr = new StringBuilderWrapper()
def sqlplus= """sqlplus.exe ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile}""".execute()
sqlplus.consumeProcessOutput(sout, serr)
sqlplus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Write to console
System.out.println(sout.toString())
// Write to logfile
File f = new File(stream_log_file)
f.write(sout.toString())
// Write to error file
f = new File(stream_error_file)
f.write(serr.toString())
/* Check for errors */
if (project.properties['stop.on.error'].toBoolean() && (sqlplus.exitValue() != 0 || (serr != null && serr.toString().length() > 0))) {
throw new GradleException(String.format(project.properties['error.message.with.code'], sqlplus.exitValue(), name))
}
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will run 'Genetic update' script.
* It's common for all updated vocabularies and located in '\Vocabulary-v5.0\working\generic_update.sql' file.
*/
task runGenericUpdate(dependsOn: runLoadStage, description: project.properties['genericUpdate.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def log_file = "${tempDir.getPath()}\\${project.properties['genericUpdate.logFileName']}"
def stream_log_file = "${tempDir.getPath()}\\${project.properties['genericUpdate.streamLogFileName']}"
def stream_error_file = "${tempDir.getPath()}\\${project.properties['genericUpdate.streamErrFileName']}"
def db = [un: project.properties['db.userName'],
pw: project.properties['db.password'],
tns: project.properties['db.tnsName'],
sqlfile: "${project.properties['basePath']}\\${project.properties['genericUpdate.sqlFileName']}",
logfile: log_file]
def sout = new StringBuilderWrapper(), serr = new StringBuilderWrapper()
def sqlplus= """sqlplus.exe ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile}""".execute()
sqlplus.consumeProcessOutput(sout, serr)
sqlplus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Write to console
System.out.println(sout.toString())
// Write to logfile
File f = new File(stream_log_file)
f.write(sout.toString())
// Write to error file
f = new File(stream_error_file)
f.write(serr.toString())
/* Check for errors */
if (project.properties['stop.on.error'].toBoolean() && (sqlplus.exitValue() != 0 || (serr != null && serr.toString().length() > 0))) {
throw new GradleException(String.format(project.properties['error.message.with.code'], sqlplus.exitValue(), name))
}
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will run scripts which allows to see the vocabulary update results
*/
task checkUpdateResults(dependsOn: runGenericUpdate, description: project.properties['checkUpdateResults.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def log_file = "${tempDir.getPath()}\\${project.properties['checkUpdateResults.logFileName']}"
def stream_log_file = "${tempDir.getPath()}\\${project.properties['checkUpdateResults.streamLogFileName']}"
def stream_error_file = "${tempDir.getPath()}\\${project.properties['checkUpdateResults.streamErrFileName']}"
def db = [un: project.properties['db.userName'],
pw: project.properties['db.password'],
tns: project.properties['db.tnsName'],
sqlfile: "${project.properties['basePath']}\\${project.properties['checkUpdateResults.sqlFileName']}",
logfile: log_file]
def sout = new StringBuilderWrapper(), serr = new StringBuilderWrapper()
def sqlplus= """sqlplus.exe ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile}""".execute()
sqlplus.consumeProcessOutput(sout, serr)
sqlplus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Write to console
System.out.println(sout.toString())
// Write to logfile
File f = new File(stream_log_file)
f.write(sout.toString())
// Write to error file
f = new File(stream_error_file)
f.write(serr.toString())
/* Check for errors */
if (project.properties['stop.on.error'].toBoolean() && (sqlplus.exitValue() != 0 || (serr != null && serr.toString().length() > 0))) {
throw new GradleException(String.format(project.properties['error.message.with.code'], sqlplus.exitValue(), name))
}
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* Bootstrap action
*
* TODO: Needs to find solution to measure whole task chain execution.
* TODO: This one via doFirst/doLast actions isn't working.
*/
task startUpdate(dependsOn: checkUpdateResults, description: project.properties['startUpdate.description']) {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
println "Continue updating of '${project.properties['vocabulary.display.name']}' vocabulary..."
// Start action checkpoint
def timeStart = System.currentTimeMillis()
doLast {
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "\n\nTotal time elapsed: ${timeElapsed} seconds."
println "Updating of '${project.properties['vocabulary.display.name']}' vocabulary completed successfully..."
println '***********************************************'
println '* *'
println "* '${description}' action is done... *"
println '* *'
println '***********************************************\n'
}
}