malac-utils 1.1.1__tar.gz → 1.3.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.1.1/malac_utils.egg-info → malac_utils-1.3.0}/PKG-INFO +3 -2
- malac_utils-1.3.0/malac/utils/__init__.py +2 -0
- malac_utils-1.3.0/malac/utils/date.py +22 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/malac/utils/fhirpath.py +38 -14
- {malac-utils-1.1.1 → malac_utils-1.3.0/malac_utils.egg-info}/PKG-INFO +3 -2
- {malac-utils-1.1.1 → malac_utils-1.3.0}/malac_utils.egg-info/SOURCES.txt +1 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/pyproject.toml +1 -1
- malac-utils-1.1.1/malac/utils/__init__.py +0 -2
- {malac-utils-1.1.1 → malac_utils-1.3.0}/LICENSE +0 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/README.md +0 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/malac_utils.egg-info/dependency_links.txt +0 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/malac_utils.egg-info/requires.txt +0 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/malac_utils.egg-info/top_level.txt +0 -0
- {malac-utils-1.1.1 → malac_utils-1.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: malac-utils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.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
|
|
@@ -24,6 +24,7 @@ Requires-Python: >=3.10
|
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: python-dateutil>=2.8.2
|
|
27
|
+
Dynamic: license-file
|
|
27
28
|
|
|
28
29
|
# MaLaC Utils
|
|
29
30
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import dateutil.parser
|
|
3
|
+
|
|
4
|
+
class PartialDate:
|
|
5
|
+
|
|
6
|
+
def __init__(self, value):
|
|
7
|
+
self.value = value
|
|
8
|
+
|
|
9
|
+
def isoformat(self):
|
|
10
|
+
return self.value
|
|
11
|
+
|
|
12
|
+
def parse(datestr):
|
|
13
|
+
datestr = getattr(datestr, "value", datestr)
|
|
14
|
+
if re.search("^[0-9]{1,6}$", datestr):
|
|
15
|
+
if len(datestr) > 4:
|
|
16
|
+
return PartialDate(datestr[0:4] + "-" + datestr[4:])
|
|
17
|
+
else:
|
|
18
|
+
return PartialDate(datestr)
|
|
19
|
+
elif len(datestr.split("-")) == 2:
|
|
20
|
+
return PartialDate(datestr)
|
|
21
|
+
else:
|
|
22
|
+
return dateutil.parser.parse(datestr)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import datetime
|
|
2
|
-
import dateutil
|
|
3
2
|
import inspect
|
|
4
3
|
import io
|
|
5
4
|
import re
|
|
@@ -7,7 +6,7 @@ import decimal
|
|
|
7
6
|
import math
|
|
8
7
|
from urllib.parse import urlparse
|
|
9
8
|
|
|
10
|
-
import dateutil
|
|
9
|
+
from . import date as dateutil
|
|
11
10
|
|
|
12
11
|
time_units = ["year", "years", "month", "months", "week", "weeks", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds", "millisecond", "milliseconds"]
|
|
13
12
|
|
|
@@ -122,6 +121,8 @@ class FHIRPathUtils(object):
|
|
|
122
121
|
result = getattr(val, key[:-10]) or []
|
|
123
122
|
if result != [] and len(attrs) == 1 and options.get("strip", False):
|
|
124
123
|
result = str(result).strip()
|
|
124
|
+
if result == "":
|
|
125
|
+
result = []
|
|
125
126
|
result = result if isinstance(result, list) else [result]
|
|
126
127
|
if len(attrs) == 1:
|
|
127
128
|
return result
|
|
@@ -131,7 +132,7 @@ class FHIRPathUtils(object):
|
|
|
131
132
|
def string_value(self, val):
|
|
132
133
|
if isinstance(val, str):
|
|
133
134
|
return val
|
|
134
|
-
elif isinstance(val, self.model.string) or isinstance(val, self.model.uri):
|
|
135
|
+
elif isinstance(val, self.model.string) or isinstance(val, self.model.uri) or isinstance(val, self.model.code) or isinstance(val, self.model.canonical) or isinstance(val, self.model.id):
|
|
135
136
|
return val.value
|
|
136
137
|
elif isinstance(val, self.model.div):
|
|
137
138
|
tmp = io.StringIO()
|
|
@@ -321,10 +322,8 @@ class FHIRPathUtils(object):
|
|
|
321
322
|
return []
|
|
322
323
|
else:
|
|
323
324
|
if isinstance(val_a, (str, self.model.string)) or isinstance(val_b, (str, self.model.string)):
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
elif isinstance(val_b, self.model.string):
|
|
327
|
-
val_b = val_b.value
|
|
325
|
+
val_a = self.string_value(val_a)
|
|
326
|
+
val_b = self.string_value(val_b)
|
|
328
327
|
return [val_a + val_b] # TODO check types and add support for quantity
|
|
329
328
|
|
|
330
329
|
def subtract(self, val_a, val_b):
|
|
@@ -508,7 +507,7 @@ class FHIRPathUtils(object):
|
|
|
508
507
|
if val == [] or regex == []:
|
|
509
508
|
return []
|
|
510
509
|
else:
|
|
511
|
-
return [re.fullmatch(
|
|
510
|
+
return [re.fullmatch(regex, val) is not None]
|
|
512
511
|
|
|
513
512
|
def contains(self, val, other):
|
|
514
513
|
val = self.string_value(val)
|
|
@@ -518,6 +517,24 @@ class FHIRPathUtils(object):
|
|
|
518
517
|
else:
|
|
519
518
|
return [other in val]
|
|
520
519
|
|
|
520
|
+
def replace(self, val, pattern, substitution):
|
|
521
|
+
val = self.string_value(val)
|
|
522
|
+
pattern = self.string_value(self.single_value(pattern, str, self.model.string))
|
|
523
|
+
substitution = self.string_value(self.single_value(substitution, str, self.model.string))
|
|
524
|
+
if val == [] or pattern == [] or substitution == []:
|
|
525
|
+
return []
|
|
526
|
+
else:
|
|
527
|
+
return [val.replace(pattern, substitution)]
|
|
528
|
+
|
|
529
|
+
def replaceMatches(self, val, regex, substitution):
|
|
530
|
+
val = self.string_value(val)
|
|
531
|
+
regex = self.string_value(self.single_value(regex, str, self.model.string))
|
|
532
|
+
substitution = self.string_value(self.single_value(substitution, str, self.model.string))
|
|
533
|
+
if val == [] or regex == [] or substitution == []:
|
|
534
|
+
return []
|
|
535
|
+
else:
|
|
536
|
+
return [re.sub(regex, substitution, val)]
|
|
537
|
+
|
|
521
538
|
def startswith(self, val, other):
|
|
522
539
|
val = self.string_value(val)
|
|
523
540
|
other = self.string_value(self.single_value(other, str, self.model.string))
|
|
@@ -547,13 +564,20 @@ class FHIRPathUtils(object):
|
|
|
547
564
|
return [-1]
|
|
548
565
|
|
|
549
566
|
def concat(self, val, other):
|
|
550
|
-
val = self.string_value(self.single_value(val
|
|
551
|
-
other = self.string_value(self.single_value(other
|
|
567
|
+
val = self.string_value(self.single_value(val))
|
|
568
|
+
other = self.string_value(self.single_value(other))
|
|
552
569
|
if val == []:
|
|
553
570
|
val = ""
|
|
554
571
|
if other == []:
|
|
555
572
|
other = ""
|
|
556
573
|
return [val + other]
|
|
574
|
+
|
|
575
|
+
def split(self, val, separator):
|
|
576
|
+
val = self.string_value(self.single_value(val))
|
|
577
|
+
separator = self.string_value(self.single_value(separator))
|
|
578
|
+
if val == [] or separator == []:
|
|
579
|
+
return []
|
|
580
|
+
return val.split(separator)
|
|
557
581
|
|
|
558
582
|
def skip(self, val, count):
|
|
559
583
|
count = self.single_value(count, int, self.model.integer)
|
|
@@ -740,7 +764,7 @@ class FHIRPathUtils(object):
|
|
|
740
764
|
key = val
|
|
741
765
|
elif isinstance(val, self.model.dateTime) or isinstance(val, datetime.datetime):
|
|
742
766
|
val = val.value if isinstance(val, self.model.dateTime) else val
|
|
743
|
-
key = dateutil.
|
|
767
|
+
key = dateutil.parse(val) if isinstance(val, str) else val
|
|
744
768
|
if isinstance(val, str):
|
|
745
769
|
prec = -1 * len(val.split(":"))
|
|
746
770
|
if key.tzinfo:
|
|
@@ -755,7 +779,7 @@ class FHIRPathUtils(object):
|
|
|
755
779
|
if isinstance(key, str):
|
|
756
780
|
prec = len(key.split("-"))
|
|
757
781
|
if prec == 3:
|
|
758
|
-
key = dateutil.
|
|
782
|
+
key = dateutil.parse(key).date()
|
|
759
783
|
else:
|
|
760
784
|
prec = 3
|
|
761
785
|
type_ = "date"
|
|
@@ -1107,7 +1131,7 @@ class FHIRPathUtils(object):
|
|
|
1107
1131
|
return []
|
|
1108
1132
|
elif isinstance(val, self.model.dateTime) or isinstance(val, datetime.datetime):
|
|
1109
1133
|
if isinstance(val, self.model.dateTime):
|
|
1110
|
-
result = self.model.date(value=dateutil.
|
|
1134
|
+
result = self.model.date(value=dateutil.parse(val.value).date().isoformat())
|
|
1111
1135
|
else:
|
|
1112
1136
|
result = self.model.date(value=val.date().isoformat())
|
|
1113
1137
|
return [result]
|
|
@@ -1142,7 +1166,7 @@ class FHIRPathUtils(object):
|
|
|
1142
1166
|
elif isinstance(val, self.model.string) or isinstance(val, str):
|
|
1143
1167
|
try:
|
|
1144
1168
|
if "T" in val or not "-" in val: # support for CDA dates
|
|
1145
|
-
return [self.model.dateTime(value=dateutil.
|
|
1169
|
+
return [self.model.dateTime(value=dateutil.parse(val).isoformat())]
|
|
1146
1170
|
else:
|
|
1147
1171
|
return [self.model.dateTime(value=datetime.datetime.strptime(val,"-".join("%Y-%m-%d".split("-")[:len(val.split("-"))])).isoformat())]
|
|
1148
1172
|
except:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: malac-utils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.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
|
|
@@ -24,6 +24,7 @@ Requires-Python: >=3.10
|
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
Requires-Dist: python-dateutil>=2.8.2
|
|
27
|
+
Dynamic: license-file
|
|
27
28
|
|
|
28
29
|
# MaLaC Utils
|
|
29
30
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|