-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcda_2_html.groovy
152 lines (136 loc) · 3.62 KB
/
cda_2_html.groovy
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
import groovy.util.XmlSlurper
import groovy.xml.MarkupBuilder
def usage = """Usage:
groovy cda_2_html.groovy cda.xml
"""
def start = System.currentTimeMillis()
if (args.size() == 0)
{
println "\n"
println usage
return 0
}
def xml = new File(args[0])
def xml_string = xml.text
def cda = new XmlSlurper().parseText(xml_string)
def writer = new StringWriter()
def html = new MarkupBuilder(writer)
html.html(lang:'es') {
head() {
meta (charset:'utf-8')
meta ('http-equiv': "X-UA-Compatible", content: "IE=edge")
meta (name: "viewport", content: "width=device-width, initial-scale=1")
title (cda.title.text())
link (rel: "stylesheet", href: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", integrity: "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", crossorigin: "anonymous")
link (href: "http://fonts.googleapis.com/css?family=Roboto:100,300,400,700", rel: "stylesheet")
}
body() {
div(class: 'container') {
div(class: 'row') {
div(class: 'col-md-12') {
h1(cda.title.text())
}
}
div(class: 'row') {
div(class: 'col-md-6') {
h2('Patient')
span (
cda.recordTarget.patientRole.patient.name.children().collect{ it.text() }.join(' ')
)
}
div(class: 'col-md-6') {
h2('Author')
span (
cda.author.assignedAuthor.assignedPerson.name.children().collect{ it.text() }.join(' ')
)
}
}
if (!cda.component.structuredBody.isEmpty()) {
cda.component.structuredBody.component.each { component ->
div(class: 'row') {
div(class: 'col-md-12') {
h3(component.section.title.text())
if (!component.section.text.list.isEmpty()) {
make_list(html, component.section.text.list)
}
else if (!component.section.text.table.isEmpty()) {
make_table(html, component.section.text.list)
}
else {
span (
component.section.text.text()
)
}
}
}
}
}
else {
if (cda.component.nonXMLBody.text.@mediaType.text() == 'text/plain') {
span (
cda.component.nonXMLBody.text.text()
)
}
}
}
}
}
/**
* <list>
* <item>DOLOR DE CABEZA (Activo)</item>
* <item>MAREOS (Activo)</item>
* </list>
*/
def make_list(html, list) {
html.ul {
list.item.each {
li(it.text())
}
}
}
/**
<table>
<tbody>
<tr>
<th>PRODUCTO</th>
<th>CANTIDAD</th>
<th>CRONICO</th>
<th>TRAT_PROLONGADO</th>
</tr>
<tr>
<td>MATRIX 400mg Comp. x 10</td>
<td>36</td>
<td>12</td>
<td>N</td>
</tr>
<tr>
<td>TRIFAMOX 1000mg Comp. x 16</td>
<td>23</td>
<td>12</td>
<td>N</td>
</tr>
</tbody>
</table>
*/
def make_table(html, table) {
// TODO
}
def destination_path = 'html'
def destination = new File(destination_path)
if (!destination.exists())
{
println "\n"
println destination.absolutePath +" doesn't exists, trying to create it"
destination.mkdir()
}
String PS = System.getProperty("file.separator")
def out = new File( destination_path + PS + new java.text.SimpleDateFormat("yyyyMMddhhmmss'.html'").format(new Date()) )
printer = new java.io.PrintWriter(out, 'UTF-8')
printer.write(writer.toString())
printer.flush()
printer.close()
def now = System.currentTimeMillis()
println "\n"
println "HTML created "+ out.absolutePath
println "In ${now - start} ms"
print "\n"