tricc-oo 1.5.18__py3-none-any.whl → 1.5.20__py3-none-any.whl

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.
tests/test_cql.py CHANGED
@@ -11,13 +11,8 @@ class TestCql(unittest.TestCase):
11
11
  operator=TriccOperator.AND,
12
12
  reference=[
13
13
  TriccOperation(
14
- operator=TriccOperator.NOT,
15
- reference=[
16
- TriccOperation(
17
- operator=TriccOperator.ISNULL,
18
- reference=[TriccReference("p_weight")]
19
- )
20
- ]
14
+ operator=TriccOperator.ISNOTNULL,
15
+ reference=[TriccReference("p_weight")]
21
16
  ),
22
17
  TriccOperation(
23
18
  operator=TriccOperator.MORE,
@@ -46,6 +41,21 @@ class TestCql(unittest.TestCase):
46
41
  )
47
42
  self.assertEqual(str(dg_operation), str(dg_expected))
48
43
 
44
+ def test_implied_concat(self):
45
+ if_cql = "'A' & \"B\" & 'C'"
46
+ cc_operation = transform_cql_to_operation(if_cql)
47
+ cc_expected = TriccOperation(
48
+ operator=TriccOperator.CONCATENATE,
49
+ reference=[
50
+ TriccStatic(value='A'),
51
+ TriccReference("B"),
52
+ TriccStatic(value='C')
53
+ ]
54
+ )
55
+ self.assertEqual(str(cc_operation), str(cc_expected))
56
+
57
+
58
+
49
59
  def test_if(self):
50
60
  if_cql = "if AgeInDays() < 60 then 'newborn' else 'child'"
51
61
  if_operation = transform_cql_to_operation(if_cql)
@@ -3,7 +3,7 @@ from tricc_oo.converters.cql.cqlLexer import cqlLexer
3
3
  from tricc_oo.converters.cql.cqlParser import cqlParser
4
4
  from tricc_oo.converters.cql.cqlVisitor import cqlVisitor
5
5
  from tricc_oo.converters.utils import clean_name
6
- from tricc_oo.models.base import TriccOperator, TriccOperation, TriccStatic, TriccReference, not_clean, or_join, and_join
6
+ from tricc_oo.models.base import TriccOperator, TriccOperation, TriccStatic, TriccReference, not_clean, or_join, and_join, string_join
7
7
  import logging
8
8
 
9
9
  logger = logging.getLogger("default")
@@ -216,7 +216,11 @@ class cqlToXlsFormVisitor(cqlVisitor):
216
216
  if operator == TriccOperator.AND:
217
217
  return and_join([left, right])
218
218
  elif operator == TriccOperator.OR:
219
- return or_join([left, right])
219
+ return or_join([left, right])
220
+ elif operator == TriccOperator.CONCATENATE:
221
+ left = "" if left is None else left
222
+ right = "" if right is None else right
223
+ return string_join(left, right)
220
224
  else:
221
225
  op = TriccOperation(operator, [left, right])
222
226
  return op
@@ -287,10 +291,10 @@ class cqlToXlsFormVisitor(cqlVisitor):
287
291
  op_map = {
288
292
  '+': TriccOperator.PLUS,
289
293
  '-': TriccOperator.MINUS,
290
- '&': TriccOperator.AND
294
+ '&': TriccOperator.CONCATENATE
291
295
  }
292
296
  return self.__std_operator(op_map.get(op_text), ctx)
293
-
297
+
294
298
 
295
299
  def visitTypeExpression(self, ctx):
296
300
  to_type = ctx.getChild(2).getText()
tricc_oo/models/base.py CHANGED
@@ -203,7 +203,11 @@ class TriccGroup(TriccBaseModel):
203
203
  super().__init__(**data)
204
204
  if self.name is None:
205
205
  self.name = generate_id(str(data))
206
-
206
+
207
+ def gen_name(self):
208
+ if self.name is None:
209
+ self.name = get_rand_name(self.id)
210
+
207
211
  def get_name(self):
208
212
  result = str(super().get_name())
209
213
  name = getattr(self, 'name', None)
@@ -336,7 +340,8 @@ class TriccReference(TriccStatic):
336
340
 
337
341
  class TriccOperator(StrEnum):
338
342
  AND = 'and' # and between left and rights
339
- ADD_OR = 'and_or' # left and one of the righs
343
+ ADD_OR = 'and_or' # left and one of the righs
344
+ #ADD_STRING: 'add_string'
340
345
  OR = 'or' # or between left and rights
341
346
  NATIVE = 'native' #default left is native expression
342
347
  ISTRUE = 'istrue' # left is right
@@ -675,6 +680,30 @@ def and_join(argv):
675
680
  TriccOperator.AND,
676
681
  argv
677
682
  )
683
+
684
+
685
+ def string_join(left: Union[str, TriccOperation], right: Union[str, TriccOperation]) -> TriccOperation:
686
+ """
687
+ Concatenates two arguments (strings or TriccOperation) into a TriccOperation with CONCATENATE operator.
688
+ If either argument is a TriccOperation with CONCATENATE operator, its operands are merged into the result.
689
+ """
690
+ # Initialize operands list for the new TriccOperation
691
+ operands: List[Union[str, TriccOperation]] = []
692
+
693
+ # Check if left is a TriccOperation with CONCATENATE
694
+ if isinstance(left, TriccOperation) and left.operator == TriccOperator.CONCATENATE:
695
+ operands.extend(left.reference) # Merge left's operands
696
+ else:
697
+ operands.append(left) # Add left as-is
698
+
699
+ # Check if right is a TriccOperation with CONCATENATE
700
+ if isinstance(right, TriccOperation) and right.operator == TriccOperator.CONCATENATE:
701
+ operands.extend(right.reference) # Merge right's operands
702
+ else:
703
+ operands.append(right) # Add right as-is
704
+
705
+ # Return a new TriccOperation with the merged operands
706
+ return TriccOperation(operator=TriccOperator.CONCATENATE, reference=operands)
678
707
 
679
708
  # function that make a 2 part and
680
709
  # @param left part
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tricc-oo
3
- Version: 1.5.18
3
+ Version: 1.5.20
4
4
  Summary: Python library that converts CDSS L2 in L3
5
5
  Project-URL: Homepage, https://github.com/SwissTPH/tricc
6
6
  Project-URL: Issues, https://github.com/SwissTPH/tricc/issues
@@ -1,10 +1,10 @@
1
1
  tests/build.py,sha256=aGpylfQU60xPq0AJX-UQQRIxXd7Nxb7SLulVEfZt3aA,6483
2
- tests/test_cql.py,sha256=sxAYEtiiZ-naXVaKPDYHaQFVhbw0QnYy4_MCItgv1Do,6547
2
+ tests/test_cql.py,sha256=Ut7t02T7tDeYKwu4wpsSZkmIpDF0PP9rbTaV35JSeGw,6823
3
3
  tests/to_ocl.py,sha256=f_KeKF7N1tri9ChbtH1OShgHskt_T9Wj1IfaT6qJNGY,2247
4
4
  tricc_oo/__init__.py,sha256=Els6sDXpOJiGU1zp45rTXZgEKceq_XhRZDfrx1mIMGc,255
5
5
  tricc_oo/converters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  tricc_oo/converters/codesystem_to_ocl.py,sha256=-ZKMBeIvzgqmhJfnn6ptuwpnHQtuE-fCDDfKpfGvUSU,6066
7
- tricc_oo/converters/cql_to_operation.py,sha256=geAAS2KPA_eax30lKh56m5Lu9MTkvTUK8x9FAnWU3no,14424
7
+ tricc_oo/converters/cql_to_operation.py,sha256=uKNKtPWXBF25mBHJM39EF258ogP_75ikSNXRHDiLbrs,14646
8
8
  tricc_oo/converters/datadictionnary.py,sha256=WWKcTtKLfc4aduHcDBhr4JSfU2NqRMaslwX-wdZPIAw,3968
9
9
  tricc_oo/converters/drawio_type_map.py,sha256=I-UN-O1OKmNFnkHAJMEbPrew7r3K2_x5mKPUVM98F24,7545
10
10
  tricc_oo/converters/tricc_to_xls_form.py,sha256=bJVd-FLrivrCxGI6mO2i0V7GVVuJZdaDuwcEf3gHNR8,2327
@@ -15,7 +15,7 @@ tricc_oo/converters/cql/cqlListener.py,sha256=ketvj7XvO7t047S6A3_gTPvp2MlYk1bojm
15
15
  tricc_oo/converters/cql/cqlParser.py,sha256=hIUdR907WX24P2Jlrxk-H0IT94n51yh_ZsCmwQhnFas,414730
16
16
  tricc_oo/converters/cql/cqlVisitor.py,sha256=SWSDIqVYBhucR4VgLn_EPNs7LV9yCqsOmzFZ0bmRSGc,33865
17
17
  tricc_oo/models/__init__.py,sha256=Rdk1fsNXHrbmXTQD1O7i0NC_A6os648Ap6CtWRliOg8,92
18
- tricc_oo/models/base.py,sha256=hPY7w7ur-UTS9OvZb-xmvpjRF6mha_E0K4A9X1_eHKQ,24871
18
+ tricc_oo/models/base.py,sha256=jrOJuh4CufPXZo7qhRFUHpK4DXoPxKj8bxWvkOD7LXg,26172
19
19
  tricc_oo/models/calculate.py,sha256=60jSL8gbcTxqGYsZe1LoGZAdScIp6_suC88XlE0xg-c,7640
20
20
  tricc_oo/models/lang.py,sha256=SwKaoxyRhE7gH_ZlYyFXzGuTQ5RE19y47LWAA35zYxg,2338
21
21
  tricc_oo/models/ocl.py,sha256=ol35Gl1jCBp0Ven0yxOKzDIZkVL5Kx9uwaR_64pjxKI,8931
@@ -40,7 +40,7 @@ tricc_oo/visitors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
40
40
  tricc_oo/visitors/tricc.py,sha256=e_6itYSgtc6EF2sOCKFvP3nri1NuELzRah_mBJdRVik,101851
41
41
  tricc_oo/visitors/utils.py,sha256=Gol4JNozPEd30Q1l8IPIPhx5fqVyy9R81GofGVebgD8,484
42
42
  tricc_oo/visitors/xform_pd.py,sha256=jgjBLbfElVdi0NmClhw6NK6qNcIgWYm4KMXfVwiQwXM,9705
43
- tricc_oo-1.5.18.dist-info/METADATA,sha256=plF1mcu4Jthpk6S9eD5qZv3BPXsEnnoeFJb77nBONh8,7878
44
- tricc_oo-1.5.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
- tricc_oo-1.5.18.dist-info/top_level.txt,sha256=NvbfMNAiy9m4b1unBsqpeOQWh4IgA1Xa33BtKA4abxk,15
46
- tricc_oo-1.5.18.dist-info/RECORD,,
43
+ tricc_oo-1.5.20.dist-info/METADATA,sha256=uMzAQDMCD72DkDek2tI_JY97uUubu1aenPsn_2nlhqU,7878
44
+ tricc_oo-1.5.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
+ tricc_oo-1.5.20.dist-info/top_level.txt,sha256=NvbfMNAiy9m4b1unBsqpeOQWh4IgA1Xa33BtKA4abxk,15
46
+ tricc_oo-1.5.20.dist-info/RECORD,,