malac-utils 1.3.2__tar.gz → 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {malac_utils-1.3.2/malac_utils.egg-info → malac_utils-1.4.0}/PKG-INFO +1 -1
- malac_utils-1.4.0/malac/utils/__init__.py +2 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/malac/utils/date.py +3 -0
- malac_utils-1.4.0/malac/utils/exceptions.py +10 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/malac/utils/fhirpath.py +13 -6
- malac_utils-1.4.0/malac/utils/html.py +176 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0/malac_utils.egg-info}/PKG-INFO +1 -1
- {malac_utils-1.3.2 → malac_utils-1.4.0}/malac_utils.egg-info/SOURCES.txt +2 -0
- malac_utils-1.3.2/malac/utils/__init__.py +0 -2
- {malac_utils-1.3.2 → malac_utils-1.4.0}/LICENSE +0 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/README.md +0 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/malac_utils.egg-info/dependency_links.txt +0 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/malac_utils.egg-info/requires.txt +0 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/malac_utils.egg-info/top_level.txt +0 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/pyproject.toml +0 -0
- {malac_utils-1.3.2 → malac_utils-1.4.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: malac-utils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: Mapping Language Compiler Utils
|
|
5
5
|
Author-email: cdeHealth-Team <contact-project+cdehealth-malac-hd-52276676-issue-@incoming.gitlab.com>
|
|
6
6
|
Project-URL: Homepage, https://gitlab.com/cdehealth/malac-hd
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exception hierarchy for MaLaC-HD-generated code
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
class MappingExecutionError(Exception):
|
|
6
|
+
"""Base class for errors raised while executing a mapping."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CheckFailedError(MappingExecutionError):
|
|
10
|
+
"""Error in case a check clause failed."""
|
|
@@ -7,6 +7,7 @@ import math
|
|
|
7
7
|
from urllib.parse import urlparse
|
|
8
8
|
|
|
9
9
|
from . import date as dateutil
|
|
10
|
+
from . import html
|
|
10
11
|
|
|
11
12
|
time_units = ["year", "years", "month", "months", "week", "weeks", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds", "millisecond", "milliseconds"]
|
|
12
13
|
|
|
@@ -100,6 +101,8 @@ class FHIRPathUtils(object):
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
def get(self, val, *attrs, **options):
|
|
104
|
+
if len(attrs) == 1 and options.get("strip", False):
|
|
105
|
+
return [html.strip_tags(val)]
|
|
103
106
|
attr = attrs[0]
|
|
104
107
|
try:
|
|
105
108
|
result = getattr(val, attr) or []
|
|
@@ -119,10 +122,6 @@ class FHIRPathUtils(object):
|
|
|
119
122
|
prefix = getattr(val, key)
|
|
120
123
|
if prefix and attr.lower() == (prefix + key[:-10]).lower():
|
|
121
124
|
result = getattr(val, key[:-10]) or []
|
|
122
|
-
if result != [] and len(attrs) == 1 and options.get("strip", False):
|
|
123
|
-
result = str(result).strip()
|
|
124
|
-
if result == "":
|
|
125
|
-
result = []
|
|
126
125
|
result = result if isinstance(result, list) else [result]
|
|
127
126
|
if len(attrs) == 1:
|
|
128
127
|
return result
|
|
@@ -563,6 +562,14 @@ class FHIRPathUtils(object):
|
|
|
563
562
|
else:
|
|
564
563
|
return [-1]
|
|
565
564
|
|
|
565
|
+
def lastIndexOf(self, val, other):
|
|
566
|
+
val = self.string_value(val)
|
|
567
|
+
other = self.string_value(self.single_value(other, str, self.model.string))
|
|
568
|
+
if val == [] or other == []:
|
|
569
|
+
return []
|
|
570
|
+
else:
|
|
571
|
+
return [val.rfind(other)]
|
|
572
|
+
|
|
566
573
|
def concat(self, val, other):
|
|
567
574
|
val = self.string_value(self.single_value(val))
|
|
568
575
|
other = self.string_value(self.single_value(other))
|
|
@@ -1018,12 +1025,12 @@ class FHIRPathUtils(object):
|
|
|
1018
1025
|
result = "true" if self.boolean_value(val) else "false"
|
|
1019
1026
|
elif isinstance(val, self.model.integer) or isinstance(val, int):
|
|
1020
1027
|
if isinstance(val, self.model.integer):
|
|
1021
|
-
result = val.value
|
|
1028
|
+
result = str(val.value)
|
|
1022
1029
|
else:
|
|
1023
1030
|
result = str(val)
|
|
1024
1031
|
elif isinstance(val, self.model.decimal) or isinstance(val, decimal.Decimal):
|
|
1025
1032
|
if isinstance(val, self.model.decimal):
|
|
1026
|
-
result = val.value
|
|
1033
|
+
result = str(val.value)
|
|
1027
1034
|
else:
|
|
1028
1035
|
result = str(val)
|
|
1029
1036
|
elif isinstance(val, dateutil.PartialDate):
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import logging
|
|
3
|
+
from html import escape as html_escape
|
|
4
|
+
from html.parser import HTMLParser
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
def _attr(name, value):
|
|
9
|
+
return f' {name}="{html_escape(str(value))}"'
|
|
10
|
+
|
|
11
|
+
def _handle_tr(tr):
|
|
12
|
+
html = ""
|
|
13
|
+
attrs = ""
|
|
14
|
+
if tr.ID:
|
|
15
|
+
attrs += _attr("id", tr.ID)
|
|
16
|
+
if tr.styleCode:
|
|
17
|
+
attrs += _attr("class", tr.styleCode)
|
|
18
|
+
html += "<tr %s>" % attrs
|
|
19
|
+
for th in tr.th:
|
|
20
|
+
html += _handle_tdh(th, "th")
|
|
21
|
+
for td in tr.td:
|
|
22
|
+
html += _handle_tdh(td, "td")
|
|
23
|
+
html += "</tr>"
|
|
24
|
+
return html
|
|
25
|
+
|
|
26
|
+
def _handle_tdh(tdh, tag):
|
|
27
|
+
html = ""
|
|
28
|
+
attrs = ""
|
|
29
|
+
if tdh.ID:
|
|
30
|
+
attrs += _attr("id", tdh.ID)
|
|
31
|
+
if tdh.styleCode:
|
|
32
|
+
attrs += _attr("class", tdh.styleCode)
|
|
33
|
+
html += f"<{tag}%s>" % attrs
|
|
34
|
+
html += _handle_content(tdh)
|
|
35
|
+
html += f"</{tag}>"
|
|
36
|
+
return html
|
|
37
|
+
|
|
38
|
+
def _handle_content(elem):
|
|
39
|
+
html = ""
|
|
40
|
+
for content in elem.content_:
|
|
41
|
+
if content.category == 1:
|
|
42
|
+
html += html_escape(content.value)
|
|
43
|
+
elif content.category == 2:
|
|
44
|
+
if content.name == "br":
|
|
45
|
+
html += f'<br />'
|
|
46
|
+
else:
|
|
47
|
+
logger.warning("Skipping unhandled simple narrative content '%s'", content.name)
|
|
48
|
+
elif content.category == 3:
|
|
49
|
+
attrs = ""
|
|
50
|
+
if getattr(content.value, "ID", None):
|
|
51
|
+
attrs += _attr("id", content.value.ID)
|
|
52
|
+
if content.name == "table":
|
|
53
|
+
html += "<table%s>" % attrs
|
|
54
|
+
if content.value.thead:
|
|
55
|
+
html += "<thead>"
|
|
56
|
+
for tr in content.value.thead.tr:
|
|
57
|
+
html += _handle_tr(tr)
|
|
58
|
+
html += "</thead>"
|
|
59
|
+
if content.value.tfoot:
|
|
60
|
+
html += "<tfoot>"
|
|
61
|
+
for tr in content.value.tfoot.tr:
|
|
62
|
+
html += _handle_tr(tr)
|
|
63
|
+
html += "</tfoot>"
|
|
64
|
+
for tbody in content.value.tbody or [None]:
|
|
65
|
+
html += "<tbody>"
|
|
66
|
+
for tr in (tbody.tr if tbody else []):
|
|
67
|
+
html += _handle_tr(tr)
|
|
68
|
+
html += "</tbody>"
|
|
69
|
+
html += "</table>"
|
|
70
|
+
elif content.name == "content":
|
|
71
|
+
if content.value.styleCode == "Italics":
|
|
72
|
+
attrs += ' class="italics"'
|
|
73
|
+
elif content.value.styleCode:
|
|
74
|
+
attrs += _attr("class", content.value.styleCode)
|
|
75
|
+
html += "<span%s>" % attrs
|
|
76
|
+
html += _handle_content(content.value)
|
|
77
|
+
html += "</span>"
|
|
78
|
+
elif content.name == "paragraph":
|
|
79
|
+
if content.value.styleCode:
|
|
80
|
+
attrs += _attr("class", content.value.styleCode)
|
|
81
|
+
html += "<p%s>" % attrs
|
|
82
|
+
html += _handle_content(content.value)
|
|
83
|
+
html += "</p>"
|
|
84
|
+
elif content.name == "sup":
|
|
85
|
+
html += "<sup%s>" % attrs
|
|
86
|
+
html += _handle_content(content.value)
|
|
87
|
+
html += "</sup>"
|
|
88
|
+
elif content.name == "footnote":
|
|
89
|
+
html += '<span class="footnote"%s>' % attrs
|
|
90
|
+
html += _handle_content(content.value)
|
|
91
|
+
html += "</span>"
|
|
92
|
+
elif content.name == "renderMultiMedia":
|
|
93
|
+
html += '<img%s%s />' % (_attr("src", content.value.referencedObject), attrs)
|
|
94
|
+
elif content.name == "br":
|
|
95
|
+
html += f'<br />'
|
|
96
|
+
elif content.name == "caption":
|
|
97
|
+
html += "<caption%s>" % attrs
|
|
98
|
+
html += _handle_content(content.value)
|
|
99
|
+
html += "</caption>"
|
|
100
|
+
elif content.name == "list":
|
|
101
|
+
if content.value.listType in [None, "unordered"]:
|
|
102
|
+
if content.value.styleCode:
|
|
103
|
+
attrs += _attr("style", f"list-style-type:{content.value.styleCode.lower()}")
|
|
104
|
+
html += "<ul%s>" % attrs
|
|
105
|
+
for item in content.value.item:
|
|
106
|
+
html += "<li>"
|
|
107
|
+
html += _handle_content(item)
|
|
108
|
+
html += "</li>"
|
|
109
|
+
html += "</ul>"
|
|
110
|
+
elif content.value.listType == "ordered":
|
|
111
|
+
styleCodeTrans = {"LittleRoman": "i", "BigRoman": "I", "LittleAlpha": "a", "BigAlpha": "A", "Arabic": "1"}
|
|
112
|
+
listType = styleCodeTrans.get(content.value.styleCode)
|
|
113
|
+
if listType:
|
|
114
|
+
attrs += f' type="{listType}"'
|
|
115
|
+
html += "<ol%s>" % attrs
|
|
116
|
+
for item in content.value.item:
|
|
117
|
+
html += "<li>"
|
|
118
|
+
html += _handle_content(item)
|
|
119
|
+
html += "</li>"
|
|
120
|
+
html += "</ol>"
|
|
121
|
+
else:
|
|
122
|
+
html += _handle_content(content.value)
|
|
123
|
+
else:
|
|
124
|
+
logger.warning("Skipping unhandled narrative content category %s", content.category)
|
|
125
|
+
return html
|
|
126
|
+
|
|
127
|
+
def strucdoctext2html(module, strucdoctext):
|
|
128
|
+
html = _handle_content(strucdoctext)
|
|
129
|
+
div = module.Flow(content_=[module.MixedContainer(1, 0, "", html)])
|
|
130
|
+
div.original_tagname_ = "div"
|
|
131
|
+
div.valueOf_ = ""
|
|
132
|
+
return div
|
|
133
|
+
|
|
134
|
+
def ed2html(module, ed):
|
|
135
|
+
# TODO: improve
|
|
136
|
+
div = module.Flow(content_=[module.MixedContainer(1, 0, "", f"<v3:reference>{ed.reference.value}</v3:reference>")])
|
|
137
|
+
div.original_tagname_ = "div"
|
|
138
|
+
div.valueOf_ = ""
|
|
139
|
+
return div
|
|
140
|
+
|
|
141
|
+
def ed2markdown(module, ed):
|
|
142
|
+
# TODO: improve
|
|
143
|
+
return module.markdown(value=f"<v3:reference>{ed.reference.value}</v3:reference>")
|
|
144
|
+
|
|
145
|
+
def strucdoctext2markdown(module, strucdoctext):
|
|
146
|
+
# TODO: implement properly
|
|
147
|
+
return module.markdown(value=strip_tags(strucdoctext))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def strip_tags(val):
|
|
151
|
+
class MLStripper(HTMLParser):
|
|
152
|
+
def __init__(self):
|
|
153
|
+
super().__init__()
|
|
154
|
+
self.reset()
|
|
155
|
+
self.strict = False
|
|
156
|
+
self.convert_charrefs= True
|
|
157
|
+
self.text = io.StringIO()
|
|
158
|
+
def handle_data(self, d):
|
|
159
|
+
self.text.write(d)
|
|
160
|
+
self.text.write(" ")
|
|
161
|
+
def get_data(self):
|
|
162
|
+
return self.text.getvalue()
|
|
163
|
+
|
|
164
|
+
html = _handle_content(val)
|
|
165
|
+
s = MLStripper()
|
|
166
|
+
s.feed(html)
|
|
167
|
+
text = s.get_data()
|
|
168
|
+
text = " ".join(text.split())
|
|
169
|
+
return text
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def builddiv(module, content):
|
|
173
|
+
div = module.Flow(content_=[module.MixedContainer(1, 0, "", content)])
|
|
174
|
+
div.original_tagname_ = "div"
|
|
175
|
+
div.valueOf_ = ""
|
|
176
|
+
return div
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: malac-utils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: Mapping Language Compiler Utils
|
|
5
5
|
Author-email: cdeHealth-Team <contact-project+cdehealth-malac-hd-52276676-issue-@incoming.gitlab.com>
|
|
6
6
|
Project-URL: Homepage, https://gitlab.com/cdehealth/malac-hd
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|