tricc-oo 1.5.13__py3-none-any.whl → 1.6.8__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.
Files changed (47) hide show
  1. tests/build.py +20 -28
  2. tests/test_build.py +260 -0
  3. tests/test_cql.py +48 -109
  4. tests/to_ocl.py +15 -17
  5. tricc_oo/__init__.py +0 -6
  6. tricc_oo/converters/codesystem_to_ocl.py +51 -40
  7. tricc_oo/converters/cql/cqlLexer.py +1 -0
  8. tricc_oo/converters/cql/cqlListener.py +1 -0
  9. tricc_oo/converters/cql/cqlParser.py +1 -0
  10. tricc_oo/converters/cql/cqlVisitor.py +1 -0
  11. tricc_oo/converters/cql_to_operation.py +129 -123
  12. tricc_oo/converters/datadictionnary.py +45 -54
  13. tricc_oo/converters/drawio_type_map.py +146 -65
  14. tricc_oo/converters/tricc_to_xls_form.py +58 -28
  15. tricc_oo/converters/utils.py +4 -4
  16. tricc_oo/converters/xml_to_tricc.py +296 -235
  17. tricc_oo/models/__init__.py +2 -1
  18. tricc_oo/models/base.py +333 -305
  19. tricc_oo/models/calculate.py +66 -51
  20. tricc_oo/models/lang.py +26 -27
  21. tricc_oo/models/ocl.py +146 -161
  22. tricc_oo/models/ordered_set.py +15 -19
  23. tricc_oo/models/tricc.py +149 -89
  24. tricc_oo/parsers/xml.py +15 -30
  25. tricc_oo/serializers/planuml.py +4 -6
  26. tricc_oo/serializers/xls_form.py +110 -153
  27. tricc_oo/strategies/input/base_input_strategy.py +28 -32
  28. tricc_oo/strategies/input/drawio.py +59 -71
  29. tricc_oo/strategies/output/base_output_strategy.py +151 -65
  30. tricc_oo/strategies/output/dhis2_form.py +908 -0
  31. tricc_oo/strategies/output/fhir_form.py +377 -0
  32. tricc_oo/strategies/output/html_form.py +224 -0
  33. tricc_oo/strategies/output/openmrs_form.py +694 -0
  34. tricc_oo/strategies/output/spice.py +106 -127
  35. tricc_oo/strategies/output/xls_form.py +322 -244
  36. tricc_oo/strategies/output/xlsform_cdss.py +627 -142
  37. tricc_oo/strategies/output/xlsform_cht.py +252 -125
  38. tricc_oo/strategies/output/xlsform_cht_hf.py +13 -24
  39. tricc_oo/visitors/tricc.py +1424 -1033
  40. tricc_oo/visitors/utils.py +16 -16
  41. tricc_oo/visitors/xform_pd.py +91 -89
  42. {tricc_oo-1.5.13.dist-info → tricc_oo-1.6.8.dist-info}/METADATA +128 -84
  43. tricc_oo-1.6.8.dist-info/RECORD +52 -0
  44. tricc_oo-1.6.8.dist-info/licenses/LICENSE +373 -0
  45. {tricc_oo-1.5.13.dist-info → tricc_oo-1.6.8.dist-info}/top_level.txt +0 -0
  46. tricc_oo-1.5.13.dist-info/RECORD +0 -46
  47. {tricc_oo-1.5.13.dist-info → tricc_oo-1.6.8.dist-info}/WHEEL +0 -0
@@ -1,38 +1,67 @@
1
- from strenum import StrEnum
2
- from tricc_oo.models.base import *
3
- from tricc_oo.models.calculate import *
1
+ from tricc_oo.models.base import (
2
+ TriccNodeType
3
+ )
4
4
 
5
+ from tricc_oo.models.calculate import (
6
+ TriccNodeBridge,
7
+ TriccNodeActivityEnd,
8
+ TriccNodeActivityStart,
9
+ TriccNodeEnd,
10
+ TriccNodeAdd,
11
+ TriccNodeCount,
12
+ TriccNodeWait,
13
+ TriccNodeCalculate,
14
+ TriccNodeRhombus,
15
+ TriccNodeExclusive,
16
+ TriccNodeProposedDiagnosis,
17
+ TriccNodeDiagnosis,
18
+ TriccNodeInput,
19
+ )
5
20
 
21
+ from tricc_oo.models.tricc import (
22
+ TriccNodeMainStart,
23
+ TriccNodeLinkIn,
24
+ TriccNodeGoTo,
25
+ TriccNodeSelectMultiple,
26
+ TriccNodeSelectNotAvailable,
27
+ TriccNodeText,
28
+ TriccNodeDecimal,
29
+ TriccNodeInteger,
30
+ TriccNodeDate,
31
+ TriccNodeSelectOne,
32
+ TriccNodeSelectYesNo,
33
+ TriccNodeNote,
34
+ )
6
35
  TYPE_MAP = {
7
36
  TriccNodeType.start: {
8
37
  "objects": ["UserObject", "object"],
9
- "attributes": ['process', 'parent', 'form_id','relevance',"priority"],
38
+ "attributes": ["process", "parent", "form_id", "relevance", "priority"],
10
39
  "mandatory_attributes": ["label"],
11
- "model": TriccNodeMainStart
40
+ "model": TriccNodeMainStart,
12
41
  },
13
42
  TriccNodeType.activity_start: {
14
43
  "objects": ["UserObject", "object"],
15
- "attributes": ['parent', 'parent', 'instance', 'relevance',"priority"],
44
+ "attributes": ["parent", "parent", "instance", "relevance", "priority"],
16
45
  "mandatory_attributes": ["label", "name"],
17
- "model": TriccNodeActivityStart
46
+ "model": TriccNodeActivityStart,
18
47
  },
19
48
  TriccNodeType.note: {
20
49
  "objects": ["UserObject", "object"],
21
- "attributes": ['relevance',"priority"],
50
+ "attributes": ["relevance", "priority", "context_type"],
22
51
  "mandatory_attributes": ["label", "name"],
23
- "model": TriccNodeNote
52
+ "model": TriccNodeNote,
24
53
  },
25
54
  TriccNodeType.hint: {
26
55
  "objects": ["UserObject", "object"],
27
56
  "attributes": [],
28
57
  "mandatory_attributes": ["label"],
29
- "model": None
58
+ "model": None,
30
59
  },
31
60
  TriccNodeType.help: {
32
61
  "objects": ["UserObject", "object"],
33
62
  "attributes": [],
34
63
  "mandatory_attributes": ["label"],
35
- "model": None
64
+ "model": None,
36
65
  },
37
66
  TriccNodeType.select_one: {
38
67
  "has_options": True,
@@ -44,11 +73,13 @@ TYPE_MAP = {
44
73
  "constraint",
45
74
  "constraint_message",
46
75
  "relevance",
47
- "priority"
48
-
76
+ "priority",
77
+ "trigger",
78
+ "default",
79
+ "context_type",
49
80
  ],
50
81
  "mandatory_attributes": ["label", "name", "list_name"],
51
- "model": TriccNodeSelectOne
82
+ "model": TriccNodeSelectOne,
52
83
  },
53
84
  TriccNodeType.select_multiple: {
54
85
  "has_options": True,
@@ -60,10 +91,13 @@ TYPE_MAP = {
60
91
  "constraint",
61
92
  "constraint_message",
62
93
  "relevance",
63
- "priority"
94
+ "priority",
95
+ "trigger",
96
+ "default",
97
+ "context_type",
64
98
  ],
65
99
  "mandatory_attributes": ["label", "name", "list_name"],
66
- "model": TriccNodeSelectMultiple
100
+ "model": TriccNodeSelectMultiple,
67
101
  },
68
102
  TriccNodeType.decimal: {
69
103
  "objects": ["UserObject", "object"],
@@ -75,10 +109,13 @@ TYPE_MAP = {
75
109
  "constraint_message",
76
110
  "required",
77
111
  "relevance",
78
- "priority"
112
+ "priority",
113
+ "trigger",
114
+ "default",
115
+ "context_type",
79
116
  ],
80
117
  "mandatory_attributes": ["label", "name"],
81
- "model": TriccNodeDecimal
118
+ "model": TriccNodeDecimal,
82
119
  },
83
120
  TriccNodeType.integer: {
84
121
  "objects": ["UserObject", "object"],
@@ -90,66 +127,99 @@ TYPE_MAP = {
90
127
  "constraint_message",
91
128
  "required",
92
129
  "relevance",
93
- "priority"
94
-
130
+ "priority",
131
+ "trigger",
132
+ "default",
133
+ "context_type",
95
134
  ],
96
135
  "mandatory_attributes": ["label", "name"],
97
- "model": TriccNodeInteger
136
+ "model": TriccNodeInteger,
98
137
  },
99
-
100
138
  TriccNodeType.text: {
101
139
  "objects": ["UserObject", "object"],
102
- "attributes": ["save", "relevance","priority"],
103
- "mandatory_attributes": ["label", 'name'],
104
- "model": TriccNodeText
140
+ "attributes": [
141
+ "save",
142
+ "relevance",
143
+ "priority",
144
+ "trigger",
145
+ "default",
146
+ "constraint",
147
+ "constraint_message",
148
+ "context_type",
149
+ ],
150
+ "mandatory_attributes": ["label", "name"],
151
+ "model": TriccNodeText,
105
152
  },
106
153
  TriccNodeType.date: {
107
154
  "objects": ["UserObject", "object"],
108
- "attributes": ["save", "relevance","priority"],
155
+ "attributes": [
156
+ "save",
157
+ "relevance",
158
+ "priority",
159
+ "trigger",
160
+ "default",
161
+ "constraint",
162
+ "constraint_message",
163
+ "context_type",
164
+ ],
109
165
  "mandatory_attributes": ["label", "name"],
110
- "model": TriccNodeDate
166
+ "model": TriccNodeDate,
111
167
  },
112
168
  TriccNodeType.add: {
113
169
  "objects": ["UserObject", "object"],
114
- "attributes": ["save", "expression"],
115
- "mandatory_attributes": ['label', "name"],
116
- "model": TriccNodeAdd
170
+ "attributes": ["save", "expression", "trigger"],
171
+ "mandatory_attributes": ["label", "name"],
172
+ "model": TriccNodeAdd,
117
173
  },
118
174
  TriccNodeType.count: {
119
175
  "objects": ["UserObject", "object"],
120
- "attributes": ["save", "expression"],
121
- "mandatory_attributes": ['label', "name"],
122
- "model": TriccNodeCount
176
+ "attributes": ["save", "expression", "trigger"],
177
+ "mandatory_attributes": ["label", "name"],
178
+ "model": TriccNodeCount,
123
179
  },
124
180
  TriccNodeType.calculate: {
125
181
  "objects": ["UserObject", "object"],
126
- "attributes": ["save", "reference"],
127
- "mandatory_attributes": [ "name", 'label'],
128
- "model": TriccNodeCalculate
182
+ "attributes": [
183
+ "save",
184
+ "reference",
185
+ "trigger",
186
+ "context_type",
187
+ "remote_reference",
188
+ ],
189
+ "mandatory_attributes": ["name", "label"],
190
+ "model": TriccNodeCalculate,
129
191
  },
192
+ # TODO: Make either reference or remote_reference mandatory
130
193
  TriccNodeType.rhombus: {
131
194
  "objects": ["UserObject", "object"],
132
- "attributes": ["save", "expression", 'label','priority'],
195
+ "attributes": [
196
+ "save",
197
+ "expression",
198
+ "remote_reference",
199
+ "label",
200
+ "priority",
201
+ "trigger",
202
+ ],
133
203
  "mandatory_attributes": ["reference"],
134
- "model": TriccNodeRhombus
204
+ "model": TriccNodeRhombus,
135
205
  },
136
206
  TriccNodeType.wait: {
137
207
  "objects": ["UserObject", "object"],
138
- "attributes": ["save", "expression"],
139
- "mandatory_attributes": ["reference", "name", 'label'],
140
- "model": TriccNodeWait
208
+ "attributes": ["save", "expression", "trigger"],
209
+ "mandatory_attributes": ["reference", "name", "label"],
210
+ "model": TriccNodeWait,
141
211
  },
142
212
  TriccNodeType.exclusive: {
143
213
  "objects": ["UserObject", "object"],
144
214
  "attributes": [],
145
215
  "mandatory_attributes": [],
146
- "model": TriccNodeExclusive
216
+ "model": TriccNodeExclusive,
147
217
  },
148
218
  TriccNodeType.not_available: {
149
219
  "objects": ["UserObject", "object"],
150
- "attributes": [],
220
+ "attributes": ["context_type"],
151
221
  "mandatory_attributes": ["label", "name", "list_name"],
152
- "model": TriccNodeSelectNotAvailable
222
+ "model": TriccNodeSelectNotAvailable,
153
223
  },
154
224
  TriccNodeType.select_yesno: {
155
225
  "objects": ["UserObject", "object"],
@@ -159,66 +229,77 @@ TYPE_MAP = {
159
229
  "filter",
160
230
  "constraint",
161
231
  "constraint_message",
162
- "relevance","priority"
232
+ "relevance",
233
+ "priority",
234
+ "trigger",
235
+ "default",
236
+ "context_type",
163
237
  ],
164
238
  "mandatory_attributes": ["label", "name", "list_name"],
165
- "model": TriccNodeSelectYesNo
239
+ "model": TriccNodeSelectYesNo,
166
240
  },
167
241
  TriccNodeType.link_out: {
168
242
  "objects": ["UserObject", "object"],
169
243
  "attributes": [],
170
244
  "mandatory_attributes": ["reference", "label", "name"],
171
- "model": TriccNodeNote
245
+ "model": TriccNodeNote,
172
246
  },
173
247
  TriccNodeType.link_in: {
174
248
  "objects": ["UserObject", "object"],
175
249
  "attributes": [],
176
250
  "mandatory_attributes": ["label", "name"],
177
- "model": TriccNodeLinkIn
251
+ "model": TriccNodeLinkIn,
178
252
  },
179
253
  TriccNodeType.goto: {
180
254
  "objects": ["UserObject", "object"],
181
- "attributes": ["instance","priority"],
255
+ "attributes": ["instance", "priority"],
182
256
  "mandatory_attributes": ["link", "label", "name"],
183
- "model": TriccNodeGoTo
257
+ "model": TriccNodeGoTo,
184
258
  },
185
259
  TriccNodeType.end: {
186
260
  "objects": ["UserObject", "object"],
187
- "attributes": ['process', 'name', 'label', 'hint'],
188
- "mandatory_attributes": ['label'],
189
- "model": TriccNodeEnd
261
+ "attributes": ["process", "name", "label", "hint"],
262
+ "mandatory_attributes": ["label"],
263
+ "model": TriccNodeEnd,
190
264
  },
191
265
  TriccNodeType.activity_end: {
192
266
  "objects": ["UserObject", "object"],
193
267
  "attributes": [],
194
268
  "mandatory_attributes": [],
195
- "model": TriccNodeActivityEnd
269
+ "model": TriccNodeActivityEnd,
196
270
  },
197
271
  TriccNodeType.bridge: {
198
272
  "objects": ["UserObject", "object"],
199
- "attributes": ["label","priority"],
273
+ "attributes": ["label", "priority"],
200
274
  "mandatory_attributes": [],
201
- "model": TriccNodeBridge
275
+ "model": TriccNodeBridge,
202
276
  },
203
277
  TriccNodeType.diagnosis: {
204
278
  "objects": ["UserObject", "object"],
205
279
  "attributes": ["save", "reference", "priority"],
206
- "mandatory_attributes": [ "name", 'label'],
207
- "model": TriccNodeDiagnosis
280
+ "mandatory_attributes": ["name", "label"],
281
+ "model": TriccNodeDiagnosis,
208
282
  },
209
283
  TriccNodeType.proposed_diagnosis: {
210
284
  "objects": ["UserObject", "object"],
211
- "attributes": ["save", "reference", "severity", "priority"],
212
- "mandatory_attributes": [ "name", 'label'],
213
- "model": TriccNodeProposedDiagnosis
285
+ "attributes": [
286
+ "save",
287
+ "remote_reference",
288
+ "reference",
289
+ "severity",
290
+ "priority",
291
+ "trigger",
292
+ ],
293
+ "mandatory_attributes": ["name", "label"],
294
+ "model": TriccNodeProposedDiagnosis,
214
295
  },
215
296
  TriccNodeType.input: {
216
297
  "objects": ["UserObject", "object"],
217
- "attributes": ["save", "reference","datatype"],
218
- "mandatory_attributes": [ "name", 'label'],
219
- "model": TriccNodeInput
298
+ "attributes": ["save", "reference", "datatype", "context_type"],
299
+ "mandatory_attributes": ["name", "label"],
300
+ "model": TriccNodeInput,
220
301
  },
221
- # TriccNodeType.number: {
302
+ # TriccNodeType.number: {
222
303
  # "objects": ["UserObject", "object"],
223
304
  # "attributes": ["constraint", "save", "constraint_message", "required"],
224
305
  # "mandatory_attributes": [],
@@ -1,9 +1,8 @@
1
- from operator import attrgetter
2
- import re
3
-
4
- from tricc_oo.converters.utils import clean_str,clean_name
5
- from tricc_oo.models import *
6
- from tricc_oo.visitors.tricc import clean_or_list, negate_term
1
+ import logging
2
+ from tricc_oo.converters.utils import clean_name
3
+ from tricc_oo.models.tricc import TriccNodeSelectOption, TRICC_TRUE_VALUE, TRICC_FALSE_VALUE, TriccNodeActivity
4
+ from tricc_oo.models.calculate import TriccNodeInput
5
+ from tricc_oo.models.base import TriccNodeBaseModel, TriccStatic, TriccReference
7
6
 
8
7
  # from babel import _
9
8
 
@@ -18,10 +17,13 @@ from tricc_oo.visitors.tricc import clean_or_list, negate_term
18
17
  TRICC_NEGATE = "not({})"
19
18
  # TRICC_NUMBER = "number({})"
20
19
  # TRICC_AND_EXPRESSION = '{0} and {1}'
21
- VERSION_SEPARATOR = '_Vv_'
20
+ VERSION_SEPARATOR = "_Vv_"
22
21
  INSTANCE_SEPARATOR = "_Ii_"
22
+ BOOLEAN_MAP = {
23
+ str(TRICC_TRUE_VALUE): 1,
24
+ str(TRICC_FALSE_VALUE): 0,
25
+ }
23
26
 
24
- import logging
25
27
 
26
28
  logger = logging.getLogger("default")
27
29
 
@@ -29,30 +31,58 @@ logger = logging.getLogger("default")
29
31
 
30
32
 
31
33
  def get_export_name(node, replace_dots=True):
32
- if isinstance(node, str):
33
- return clean_name(node, replace_dots=replace_dots)
34
- if node.export_name is None:
35
- node.gen_name()
34
+ if hasattr(node, 'export_name') and node.export_name is not None:
35
+ return node.export_name
36
+ elif isinstance(node, bool):
37
+ return BOOLEAN_MAP[str(TRICC_TRUE_VALUE)] if node else BOOLEAN_MAP[str(TRICC_FALSE_VALUE)]
38
+ elif isinstance(node, TriccReference):
39
+ logger.warning(f"Reference {node.value} use in export, bad serialiuation probable")
40
+ return str(node.value)
41
+ elif isinstance(node, (str, TriccStatic, TriccNodeSelectOption)):
36
42
  if isinstance(node, TriccNodeSelectOption):
37
- node.export_name = node.name
38
- elif node.last == False:
39
- node.export_name = clean_name(node.name + VERSION_SEPARATOR + str(node.version), replace_dots=replace_dots)
40
- # elif node.activity.instance>1:
41
- # if node.version:
42
- # node.export_name = clean_name(node.name + VERSION_SEPARATOR + str(node.version), replace_dots=replace_dots)
43
- # else:
44
- # node.export_name = clean_name(node.name + INSTANCE_SEPARATOR + str(node.activity.instance), replace_dots=replace_dots)
45
-
43
+ value = node.name
44
+ elif isinstance(node, TriccStatic):
45
+ value = node.value
46
+ if isinstance(value, TriccNodeSelectOption):
47
+ value = value.name
48
+ else:
49
+ value = node
50
+ if isinstance(value, bool): # or r.value in ('true', 'false')
51
+ export_name = BOOLEAN_MAP[str(TRICC_TRUE_VALUE)] if value else BOOLEAN_MAP[str(TRICC_FALSE_VALUE)]
52
+ elif value == TRICC_TRUE_VALUE:
53
+ export_name = BOOLEAN_MAP[str(TRICC_TRUE_VALUE)]
54
+ elif value == TRICC_FALSE_VALUE:
55
+ export_name = BOOLEAN_MAP[str(TRICC_FALSE_VALUE)]
56
+ elif value == '$this':
57
+ export_name = '.'
58
+ elif isinstance(value, str) and not isinstance(node, str):
59
+ export_name = f"'{value}'"
60
+ else:
61
+ export_name = value
62
+ if hasattr(node, 'export_name'):
63
+ node.export_name = export_name
64
+ return export_name
65
+ elif not hasattr(node, 'export_name'):
66
+ return node
67
+ else:
68
+ node.gen_name()
69
+ if isinstance(node, TriccNodeActivity) and getattr(node, 'instance', 1) > 1:
70
+ node.export_name = clean_name(
71
+ node.name + INSTANCE_SEPARATOR + str(node.instance),
72
+ replace_dots=replace_dots,
73
+ )
74
+ elif isinstance(node, TriccNodeSelectOption):
75
+ node.export_name = node.name
76
+ elif node.last is False:
77
+ node.export_name = clean_name(
78
+ node.name + VERSION_SEPARATOR + str(node.version),
79
+ replace_dots=replace_dots,
80
+ )
46
81
  elif isinstance(node, TriccNodeInput):
47
- node.export_name = clean_name('load.' +node.name, replace_dots=replace_dots)
82
+ node.export_name = clean_name("load." + node.name, replace_dots=replace_dots)
48
83
  else:
49
84
  node.export_name = clean_name(node.name, replace_dots=replace_dots)
50
-
51
- return node.export_name
52
-
53
-
54
-
55
-
85
+ return node.export_name
56
86
 
57
87
 
58
88
  def get_list_names(list):
@@ -1,11 +1,11 @@
1
1
  import logging
2
- import re
3
2
  import random
4
3
  import string
5
4
  import hashlib
6
5
  from markdownify import markdownify as md
7
6
  import warnings
8
7
  from bs4 import MarkupResemblesLocatorWarning
8
+
9
9
  warnings.filterwarnings("ignore", category=MarkupResemblesLocatorWarning)
10
10
  logger = logging.getLogger("default")
11
11
 
@@ -23,7 +23,7 @@ def clean_str(name, replace_dots=False):
23
23
 
24
24
  def clean_name(name, prefix="", replace_dots=False):
25
25
  name = clean_str(name, replace_dots)
26
- if name[0].isdigit():
26
+ if name and name[0].isdigit():
27
27
  name = "id_" + name
28
28
  elif name[0].isdigit() == "_":
29
29
  name = name[1:]
@@ -50,8 +50,8 @@ def get_rand_name(name=None, length=8):
50
50
 
51
51
  # the soup.text strips off the html formatting also
52
52
  def remove_html(string):
53
-
54
- if ' ' in string:
53
+
54
+ if " " in string:
55
55
  text = md(
56
56
  string,
57
57
  strip=["img", "table", "a"],