malac-utils 1.1.1__tar.gz → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: malac-utils
3
- Version: 1.1.1
3
+ Version: 1.2.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,2 @@
1
+
2
+ __version__ = "1.2.0"
@@ -0,0 +1,21 @@
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
+ if re.search("^[0-9]{1,6}$", datestr):
14
+ if len(datestr) > 4:
15
+ return PartialDate(datestr[0:4] + "-" + datestr[4:])
16
+ else:
17
+ return PartialDate(datestr)
18
+ elif len(datestr.split("-")) == 2:
19
+ return PartialDate(datestr)
20
+ else:
21
+ 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.parser
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
 
@@ -131,7 +130,7 @@ class FHIRPathUtils(object):
131
130
  def string_value(self, val):
132
131
  if isinstance(val, str):
133
132
  return val
134
- elif isinstance(val, self.model.string) or isinstance(val, self.model.uri):
133
+ elif isinstance(val, self.model.string) or isinstance(val, self.model.uri) or isinstance(val, self.model.code):
135
134
  return val.value
136
135
  elif isinstance(val, self.model.div):
137
136
  tmp = io.StringIO()
@@ -321,10 +320,8 @@ class FHIRPathUtils(object):
321
320
  return []
322
321
  else:
323
322
  if isinstance(val_a, (str, self.model.string)) or isinstance(val_b, (str, self.model.string)):
324
- if isinstance(val_a, self.model.string):
325
- val_a = val_a.value
326
- elif isinstance(val_b, self.model.string):
327
- val_b = val_b.value
323
+ val_a = self.string_value(val_a)
324
+ val_b = self.string_value(val_b)
328
325
  return [val_a + val_b] # TODO check types and add support for quantity
329
326
 
330
327
  def subtract(self, val_a, val_b):
@@ -547,8 +544,8 @@ class FHIRPathUtils(object):
547
544
  return [-1]
548
545
 
549
546
  def concat(self, val, other):
550
- val = self.string_value(self.single_value(val, str, self.model.string))
551
- other = self.string_value(self.single_value(other, str, self.model.string))
547
+ val = self.string_value(self.single_value(val))
548
+ other = self.string_value(self.single_value(other))
552
549
  if val == []:
553
550
  val = ""
554
551
  if other == []:
@@ -740,7 +737,7 @@ class FHIRPathUtils(object):
740
737
  key = val
741
738
  elif isinstance(val, self.model.dateTime) or isinstance(val, datetime.datetime):
742
739
  val = val.value if isinstance(val, self.model.dateTime) else val
743
- key = dateutil.parser.parse(val) if isinstance(val, str) else val
740
+ key = dateutil.parse(val) if isinstance(val, str) else val
744
741
  if isinstance(val, str):
745
742
  prec = -1 * len(val.split(":"))
746
743
  if key.tzinfo:
@@ -755,7 +752,7 @@ class FHIRPathUtils(object):
755
752
  if isinstance(key, str):
756
753
  prec = len(key.split("-"))
757
754
  if prec == 3:
758
- key = dateutil.parser.parse(key).date()
755
+ key = dateutil.parse(key).date()
759
756
  else:
760
757
  prec = 3
761
758
  type_ = "date"
@@ -1107,7 +1104,7 @@ class FHIRPathUtils(object):
1107
1104
  return []
1108
1105
  elif isinstance(val, self.model.dateTime) or isinstance(val, datetime.datetime):
1109
1106
  if isinstance(val, self.model.dateTime):
1110
- result = self.model.date(value=dateutil.parser.parse(val.value).date().isoformat())
1107
+ result = self.model.date(value=dateutil.parse(val.value).date().isoformat())
1111
1108
  else:
1112
1109
  result = self.model.date(value=val.date().isoformat())
1113
1110
  return [result]
@@ -1142,7 +1139,7 @@ class FHIRPathUtils(object):
1142
1139
  elif isinstance(val, self.model.string) or isinstance(val, str):
1143
1140
  try:
1144
1141
  if "T" in val or not "-" in val: # support for CDA dates
1145
- return [self.model.dateTime(value=dateutil.parser.parse(val).isoformat())]
1142
+ return [self.model.dateTime(value=dateutil.parse(val).isoformat())]
1146
1143
  else:
1147
1144
  return [self.model.dateTime(value=datetime.datetime.strptime(val,"-".join("%Y-%m-%d".split("-")[:len(val.split("-"))])).isoformat())]
1148
1145
  except:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: malac-utils
3
- Version: 1.1.1
3
+ Version: 1.2.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
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
4
  malac/utils/__init__.py
5
+ malac/utils/date.py
5
6
  malac/utils/fhirpath.py
6
7
  malac_utils.egg-info/PKG-INFO
7
8
  malac_utils.egg-info/SOURCES.txt
@@ -1,2 +0,0 @@
1
-
2
- __version__ = "1.1.1"
File without changes
File without changes
File without changes
File without changes