tricc-oo 1.0.1__py3-none-any.whl → 1.4.15__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/build.py +213 -0
- tests/test_cql.py +197 -0
- tests/to_ocl.py +51 -0
- {tricc → tricc_oo}/__init__.py +3 -1
- tricc_oo/converters/codesystem_to_ocl.py +169 -0
- tricc_oo/converters/cql/cqlLexer.py +822 -0
- tricc_oo/converters/cql/cqlListener.py +1632 -0
- tricc_oo/converters/cql/cqlParser.py +11204 -0
- tricc_oo/converters/cql/cqlVisitor.py +913 -0
- tricc_oo/converters/cql_to_operation.py +402 -0
- tricc_oo/converters/datadictionnary.py +115 -0
- tricc_oo/converters/drawio_type_map.py +222 -0
- tricc_oo/converters/tricc_to_xls_form.py +61 -0
- tricc_oo/converters/utils.py +65 -0
- tricc_oo/converters/xml_to_tricc.py +1003 -0
- tricc_oo/models/__init__.py +4 -0
- tricc_oo/models/base.py +732 -0
- tricc_oo/models/calculate.py +216 -0
- tricc_oo/models/ocl.py +281 -0
- tricc_oo/models/ordered_set.py +125 -0
- tricc_oo/models/tricc.py +418 -0
- tricc_oo/parsers/xml.py +138 -0
- tricc_oo/serializers/__init__.py +0 -0
- tricc_oo/serializers/xls_form.py +745 -0
- tricc_oo/strategies/__init__.py +0 -0
- tricc_oo/strategies/input/__init__.py +0 -0
- tricc_oo/strategies/input/base_input_strategy.py +111 -0
- tricc_oo/strategies/input/drawio.py +317 -0
- tricc_oo/strategies/output/base_output_strategy.py +148 -0
- tricc_oo/strategies/output/spice.py +365 -0
- tricc_oo/strategies/output/xls_form.py +697 -0
- tricc_oo/strategies/output/xlsform_cdss.py +189 -0
- tricc_oo/strategies/output/xlsform_cht.py +200 -0
- tricc_oo/strategies/output/xlsform_cht_hf.py +334 -0
- tricc_oo/visitors/__init__.py +0 -0
- tricc_oo/visitors/tricc.py +2198 -0
- tricc_oo/visitors/utils.py +17 -0
- tricc_oo/visitors/xform_pd.py +264 -0
- tricc_oo-1.4.15.dist-info/METADATA +219 -0
- tricc_oo-1.4.15.dist-info/RECORD +46 -0
- {tricc_oo-1.0.1.dist-info → tricc_oo-1.4.15.dist-info}/WHEEL +1 -1
- tricc_oo-1.4.15.dist-info/top_level.txt +2 -0
- tricc/converters/mc_to_tricc.py +0 -542
- tricc/converters/tricc_to_xls_form.py +0 -553
- tricc/converters/utils.py +0 -44
- tricc/converters/xml_to_tricc.py +0 -740
- tricc/models/tricc.py +0 -1093
- tricc/parsers/xml.py +0 -81
- tricc/serializers/xls_form.py +0 -364
- tricc/strategies/input/base_input_strategy.py +0 -80
- tricc/strategies/input/drawio.py +0 -246
- tricc/strategies/input/medalcreator.py +0 -168
- tricc/strategies/output/base_output_strategy.py +0 -92
- tricc/strategies/output/xls_form.py +0 -194
- tricc/strategies/output/xlsform_cdss.py +0 -46
- tricc/strategies/output/xlsform_cht.py +0 -106
- tricc/visitors/tricc.py +0 -375
- tricc_oo-1.0.1.dist-info/LICENSE +0 -78
- tricc_oo-1.0.1.dist-info/METADATA +0 -229
- tricc_oo-1.0.1.dist-info/RECORD +0 -26
- tricc_oo-1.0.1.dist-info/top_level.txt +0 -2
- venv/bin/vba_extract.py +0 -78
- {tricc → tricc_oo}/converters/__init__.py +0 -0
- {tricc → tricc_oo}/models/lang.py +0 -0
- {tricc/serializers → tricc_oo/parsers}/__init__.py +0 -0
- {tricc → tricc_oo}/serializers/planuml.py +0 -0
tricc/converters/mc_to_tricc.py
DELETED
|
@@ -1,542 +0,0 @@
|
|
|
1
|
-
import base64
|
|
2
|
-
import os
|
|
3
|
-
import re
|
|
4
|
-
from curses.ascii import isalnum, isalpha, isdigit
|
|
5
|
-
|
|
6
|
-
from numpy import isnan
|
|
7
|
-
|
|
8
|
-
from tricc.converters.utils import OPERATION_LIST, clean_name, remove_html
|
|
9
|
-
from tricc.models.tricc import *
|
|
10
|
-
from tricc.parsers.xml import (get_edges_list, get_mxcell,
|
|
11
|
-
get_mxcell_parent_list, get_tricc_type,
|
|
12
|
-
get_tricc_type_list)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import logging
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger("default")
|
|
18
|
-
MC_NODE_NAME = "id_{}"
|
|
19
|
-
|
|
20
|
-
def create_activity(full_order, name, media_path, json_nodes, last_page):
|
|
21
|
-
# step can be
|
|
22
|
-
# - list of id
|
|
23
|
-
# - list of group
|
|
24
|
-
# - older/neonat group
|
|
25
|
-
groups = []
|
|
26
|
-
nodes = []
|
|
27
|
-
if last_page is None:
|
|
28
|
-
|
|
29
|
-
prev = TriccNodeMainStart(id = generate_id())
|
|
30
|
-
|
|
31
|
-
else:
|
|
32
|
-
prev =TriccNodeActivityStart(id = generate_id())
|
|
33
|
-
|
|
34
|
-
activity = TriccNodeActivity(
|
|
35
|
-
root= prev,
|
|
36
|
-
name=name,
|
|
37
|
-
id=get_mc_name(name),
|
|
38
|
-
label=name
|
|
39
|
-
)
|
|
40
|
-
prev.activity = activity
|
|
41
|
-
prev.group = activity
|
|
42
|
-
activity.group = activity
|
|
43
|
-
if last_page is not None:
|
|
44
|
-
set_prev_next_node(last_page.nodes[len(last_page.nodes)-1],activity)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if isinstance(full_order, Dict): # Older/neonal
|
|
49
|
-
|
|
50
|
-
if "older" in full_order:
|
|
51
|
-
group = create_group('older',activity)
|
|
52
|
-
gr_nodes = create_node_list(full_order['older'], json_nodes = json_nodes, root=prev, group = group, activity = activity)
|
|
53
|
-
if len(gr_nodes)>0:
|
|
54
|
-
nodes.extend(gr_nodes)
|
|
55
|
-
prev=gr_nodes[len(gr_nodes)-1]
|
|
56
|
-
groups.append( group)
|
|
57
|
-
if "neonat" in full_order:
|
|
58
|
-
group = create_group('neonat',activity)
|
|
59
|
-
gr_nodes = create_node_list(full_order['neonat'], json_nodes = json_nodes, root=prev, group = group, activity = activity)
|
|
60
|
-
if len(gr_nodes)>0:
|
|
61
|
-
nodes.extend(gr_nodes)
|
|
62
|
-
prev=gr_nodes[len(gr_nodes)-1]
|
|
63
|
-
groups.append( group)
|
|
64
|
-
elif isinstance(full_order, list) and len(full_order)>0: # simple list of tuple
|
|
65
|
-
if isinstance(full_order[0], (int, str)):
|
|
66
|
-
gr_nodes = create_node_list(full_order, json_nodes = json_nodes, root=prev, activity = activity)
|
|
67
|
-
if len(gr_nodes)>0:
|
|
68
|
-
nodes.extend(gr_nodes)
|
|
69
|
-
prev=gr_nodes[len(gr_nodes)-1]
|
|
70
|
-
elif "data" in full_order[0]:
|
|
71
|
-
for grp in full_order:
|
|
72
|
-
group = create_group(grp['title'],activity)
|
|
73
|
-
gr_nodes = create_node_list(grp['data'], json_nodes = json_nodes, root=prev, group = group, activity = activity)
|
|
74
|
-
if len(gr_nodes)>0:
|
|
75
|
-
nodes.extend(gr_nodes)
|
|
76
|
-
groups.append( group)
|
|
77
|
-
prev=gr_nodes[len(gr_nodes)-1]
|
|
78
|
-
if len(nodes)>0:
|
|
79
|
-
activity.groups = groups
|
|
80
|
-
activity.nodes = nodes
|
|
81
|
-
return activity
|
|
82
|
-
|
|
83
|
-
else:
|
|
84
|
-
logger.warning("no node found for that activity {0}".format(name))
|
|
85
|
-
|
|
86
|
-
def get_mc_name(name, prefix = False):
|
|
87
|
-
|
|
88
|
-
if prefix != False:
|
|
89
|
-
return f"{prefix}.{name}"
|
|
90
|
-
elif isinstance(name, str) and not isdigit(name[0]):
|
|
91
|
-
return name
|
|
92
|
-
else:
|
|
93
|
-
return MC_NODE_NAME.format(name)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def create_node( json_node, relevance = '' ,activity = None, group = None):
|
|
97
|
-
if 'type' not in json_node or json_node['type'] == 'QuestionsSequence' or (json_node['type'] == 'Question' and 'formula' in json_node ) or json_node['type'] == 'FinalDiagnosis' :
|
|
98
|
-
|
|
99
|
-
sub_type = 'qual' if 'type' not in json_node else 'diag' if json_node['type'] == 'FinalDiagnosis' else 'out' if json_node['type'] == 'QuestionsSequence' else 'flag'
|
|
100
|
-
|
|
101
|
-
node = TriccNodeCalculate(
|
|
102
|
-
id = str(json_node['id']),
|
|
103
|
-
name = get_mc_name(json_node['id'],sub_type),
|
|
104
|
-
label= dict(json_node['label']),
|
|
105
|
-
group=group if group is not None else activity,
|
|
106
|
-
activity=activity
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
elif json_node['type'] == 'Question':
|
|
110
|
-
if json_node['value_format']=="Integer":
|
|
111
|
-
node = TriccNodeInteger(
|
|
112
|
-
id = str(json_node['id']),
|
|
113
|
-
name = get_mc_name(json_node['id']),
|
|
114
|
-
label= dict(json_node['label']),
|
|
115
|
-
required = 1 if 'is_mandatory' in json_node and json_node["is_mandatory"]==True else None,
|
|
116
|
-
group=group if group is not None else activity,
|
|
117
|
-
activity=activity
|
|
118
|
-
)
|
|
119
|
-
elif json_node['value_format']=="String":
|
|
120
|
-
node = TriccNodeText(
|
|
121
|
-
id = str(json_node['id']),
|
|
122
|
-
name = get_mc_name(json_node['id']),
|
|
123
|
-
label= dict(json_node['label']),
|
|
124
|
-
required = 1 if 'is_mandatory' in json_node and json_node["is_mandatory"]==True else None,
|
|
125
|
-
group=group if group is not None else activity,
|
|
126
|
-
activity=activity
|
|
127
|
-
)
|
|
128
|
-
elif json_node['value_format']=="Date":
|
|
129
|
-
node = TriccNodeDate(
|
|
130
|
-
id = str(json_node['id']),
|
|
131
|
-
name = get_mc_name(json_node['id']),
|
|
132
|
-
label= dict(json_node['label']),
|
|
133
|
-
required = 1 if 'is_mandatory' in json_node and json_node["is_mandatory"]==True else None,
|
|
134
|
-
group=group if group is not None else activity,
|
|
135
|
-
activity=activity
|
|
136
|
-
)
|
|
137
|
-
elif json_node['value_format']=="Float":
|
|
138
|
-
node = TriccNodeDecimal(
|
|
139
|
-
id = str(json_node['id']),
|
|
140
|
-
name = get_mc_name(json_node['id']),
|
|
141
|
-
label= dict(json_node['label']),
|
|
142
|
-
required = 1 if 'is_mandatory' in json_node and json_node["is_mandatory"]==True else None,
|
|
143
|
-
group=group if group is not None else activity,
|
|
144
|
-
activity=activity
|
|
145
|
-
)
|
|
146
|
-
else:
|
|
147
|
-
node = TriccNodeSelectOne(
|
|
148
|
-
id = str(json_node['id']),
|
|
149
|
-
name = get_mc_name(json_node['id']),
|
|
150
|
-
list_name = get_mc_name(json_node['id']),
|
|
151
|
-
label= dict(json_node['label']),
|
|
152
|
-
required = 1 if 'is_mandatory' in json_node and json_node["is_mandatory"]==True else None,
|
|
153
|
-
group=group if group is not None else activity,
|
|
154
|
-
activity=activity
|
|
155
|
-
)
|
|
156
|
-
node.options = get_options(json_node['answers'],node)
|
|
157
|
-
if len(node.options) == 0:
|
|
158
|
-
logger.warning("SelectOne {} without options, value_format : {}".format(str(json_node['label']), json_node['value_format']))
|
|
159
|
-
|
|
160
|
-
return node
|
|
161
|
-
def create_node_list(full_order, json_nodes, activity,root=None,group = None, relevance = None):
|
|
162
|
-
nodes = []
|
|
163
|
-
prev = root
|
|
164
|
-
for elm in full_order:
|
|
165
|
-
json_node = json_nodes[str(elm)]
|
|
166
|
-
node = create_node(json_node, relevance, activity, group)
|
|
167
|
-
if node is not None:
|
|
168
|
-
if root is not None:
|
|
169
|
-
set_prev_next_node(root,node)
|
|
170
|
-
#prev=node
|
|
171
|
-
nodes.append(node)
|
|
172
|
-
#if isinstance(node, TriccNodeSelectOne):
|
|
173
|
-
# nodes.extend([value for value in node.options.values()])
|
|
174
|
-
return nodes
|
|
175
|
-
|
|
176
|
-
def create_group(name,activity, relevance = None):
|
|
177
|
-
return TriccGroup(
|
|
178
|
-
id=name,
|
|
179
|
-
relevance = relevance,
|
|
180
|
-
label = name,
|
|
181
|
-
name = get_mc_name(name),
|
|
182
|
-
group= activity
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
def get_options(answers,node):
|
|
186
|
-
options = {}
|
|
187
|
-
i = 0
|
|
188
|
-
for key, elm in answers.items():
|
|
189
|
-
options[i]= TriccNodeSelectOption(
|
|
190
|
-
id= elm['id'],
|
|
191
|
-
label = dict(elm['label']),
|
|
192
|
-
name= get_mc_name(elm['id']),
|
|
193
|
-
select = node,
|
|
194
|
-
list_name= get_mc_name(node.id),
|
|
195
|
-
ref_def= elm['reference'] if 'reference' in elm else None
|
|
196
|
-
)
|
|
197
|
-
i+=1
|
|
198
|
-
return options
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
OPERATORS = {
|
|
202
|
-
'more_or_equal':"{0}>={1}",
|
|
203
|
-
'between':"{0}>={1} and {0}<{2}",
|
|
204
|
-
'less':"{0}<{1}",
|
|
205
|
-
}
|
|
206
|
-
MC_IF_EXP = "if({0},{1},{2})"
|
|
207
|
-
|
|
208
|
-
MC_AND_EXP = "({0}) and ({1}) "
|
|
209
|
-
MC_COND_EXP = "${{{0}}} = '{1}'"
|
|
210
|
-
|
|
211
|
-
# int((today()-date(${date_naissance})) div 30.4)
|
|
212
|
-
|
|
213
|
-
def get_expression(node, json_node,all_nodes, prefix = ''):
|
|
214
|
-
ref_str = None
|
|
215
|
-
reference = []
|
|
216
|
-
formula = None
|
|
217
|
-
|
|
218
|
-
if 'formula' in json_node:
|
|
219
|
-
if json_node['formula'] == 'ToMonth':
|
|
220
|
-
ref_str='birth_date'
|
|
221
|
-
formula = "int((today()-date(${{{}}})) div 30.4)"
|
|
222
|
-
elif json_node['formula'] == 'ToDay':
|
|
223
|
-
ref_str='birth_date'
|
|
224
|
-
formula = "int((today()-date(${{{}}})))"
|
|
225
|
-
elif isinstance(json_node['formula'],list) and len(json_node['formula'])==1 :
|
|
226
|
-
ref_str=json_node['formula'][0]
|
|
227
|
-
formula = "${{{}}}"
|
|
228
|
-
elif json_node['formula'].startswith('[') and json_node['formula'].endswith(']'):
|
|
229
|
-
ref_str=json_node['formula'][1:-1]
|
|
230
|
-
formula = "${{{}}}"
|
|
231
|
-
else:
|
|
232
|
-
logger.warning('reference {} not found for {}'.format(json_node['formula'], json_node['id']))
|
|
233
|
-
return None, None
|
|
234
|
-
|
|
235
|
-
if ref_str is not None:
|
|
236
|
-
ref = resolve_reference(ref_str, all_nodes, prefix)
|
|
237
|
-
if ref is not None:
|
|
238
|
-
|
|
239
|
-
expression = "''"
|
|
240
|
-
if 'answers' in json_node and len(json_node['answers'].keys())>0:
|
|
241
|
-
for key, item in json_node['answers'].items():
|
|
242
|
-
item_exp = None
|
|
243
|
-
values = item['value'].split(',')
|
|
244
|
-
if item['operator'] in OPERATORS :
|
|
245
|
-
if item['operator'] == 'between':
|
|
246
|
-
reference = [*reference,ref,ref]
|
|
247
|
-
else:
|
|
248
|
-
reference = [*reference,ref]
|
|
249
|
-
|
|
250
|
-
expression = MC_IF_EXP.format(
|
|
251
|
-
OPERATORS[item['operator']].format("__formula__",*values),
|
|
252
|
-
f"'{get_mc_name(item['id'])}'",
|
|
253
|
-
expression)
|
|
254
|
-
|
|
255
|
-
elif item['operator'] is not None:
|
|
256
|
-
logger.warning('operator {} not found'.format(item['operator']))
|
|
257
|
-
return None, None
|
|
258
|
-
else:
|
|
259
|
-
pass
|
|
260
|
-
expression = expression.replace('__formula__', formula )
|
|
261
|
-
else:
|
|
262
|
-
expression = formula
|
|
263
|
-
reference = [*reference,ref]
|
|
264
|
-
if reference is None or len(reference) == 0:
|
|
265
|
-
logger.warning('empty reference')
|
|
266
|
-
if node.reference is None:
|
|
267
|
-
|
|
268
|
-
node.reference = reference
|
|
269
|
-
node.expression_reference=expression
|
|
270
|
-
elif node.expression_reference is not None and expression is not None :
|
|
271
|
-
node.reference = [*node.reference,*reference]
|
|
272
|
-
node.expression_reference = MC_AND_EXP.format(node.expression_reference,expression)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return None, None
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
def build_relevance(all_nodes, age_node, js_nodes, prefix = ''):
|
|
281
|
-
for node in all_nodes:
|
|
282
|
-
cur_node = node
|
|
283
|
-
json_node = js_nodes[str(cur_node.id)] if str(cur_node.id) in js_nodes else None
|
|
284
|
-
if json_node is not None:
|
|
285
|
-
cut_off_expr = generate_cut_off_exp(cur_node, age_node, json_node)
|
|
286
|
-
if cut_off_expr is not None:
|
|
287
|
-
rhombus = get_relevance_rhombus(cur_node,age_node,cut_off_expr, None, None )
|
|
288
|
-
if rhombus is not None:
|
|
289
|
-
set_prev_next_node(rhombus, cur_node)
|
|
290
|
-
cur_node = rhombus
|
|
291
|
-
if 'conditions' in json_node :
|
|
292
|
-
process_relevance(cur_node, all_nodes,age_node,json_node['conditions'], prefix )
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
def generate_cut_off_exp(node, age_node, js_parent):
|
|
298
|
-
cond_exp=None
|
|
299
|
-
ans_calc=None
|
|
300
|
-
has_cut_off = False
|
|
301
|
-
if 'cut_off_start' in js_parent or 'cut_off_end' in js_parent:
|
|
302
|
-
has_cut_off = True
|
|
303
|
-
if 'cut_off_start' in js_parent and js_parent['cut_off_start'] is not None:
|
|
304
|
-
cond_exp = OPERATORS['more_or_equal'].format('${{{}}}',js_parent['cut_off_start'])
|
|
305
|
-
if 'cut_off_end' in js_parent and js_parent['cut_off_end'] is not None:
|
|
306
|
-
cut_off_s = OPERATORS['less'].format('${{{}}}',js_parent['cut_off_end'])
|
|
307
|
-
if cond_exp is not None:
|
|
308
|
-
cond_exp = MC_AND_EXP.format(cond_exp,cut_off_s)
|
|
309
|
-
else:
|
|
310
|
-
cond_exp = cut_off_s
|
|
311
|
-
return cond_exp
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
def fetch_reference(all_nodes, prefix = ''):
|
|
316
|
-
calculate_nodes = list(filter(lambda node: issubclass(node.__class__, TriccNodeCalculateBase), all_nodes))
|
|
317
|
-
for node in calculate_nodes:
|
|
318
|
-
if isinstance(node.reference, str):
|
|
319
|
-
ref = resolve_reference(node.reference, all_nodes, prefix)
|
|
320
|
-
if ref is not None:
|
|
321
|
-
node.reference = [ref]
|
|
322
|
-
else:
|
|
323
|
-
logger.warning("reference {} not found for node {}".format(node.reference, node.id))
|
|
324
|
-
elif isinstance(node.reference, list) and len(node.reference)>0 and isinstance(node.reference[0], str):
|
|
325
|
-
str_refs = node.reference
|
|
326
|
-
refs=[]
|
|
327
|
-
for str_ref in str_refs:
|
|
328
|
-
ref = resolve_reference(str_ref, all_nodes, prefix)
|
|
329
|
-
if ref is not None:
|
|
330
|
-
refs.append(ref)
|
|
331
|
-
else:
|
|
332
|
-
break
|
|
333
|
-
if len(refs) == len(str_refs):
|
|
334
|
-
node.reference = refs
|
|
335
|
-
elif node.reference is not None and not issubclass(node.__class__, TriccBaseModel):
|
|
336
|
-
logger.warning(f"unsuported ref {node.reference.__class__}")
|
|
337
|
-
|
|
338
|
-
def fetch_condition(all_nodes, js_nodes, prefix=''):
|
|
339
|
-
age_node = resolve_reference("p_age_day", all_nodes, prefix)
|
|
340
|
-
for node in all_nodes:
|
|
341
|
-
if node.id in js_nodes:
|
|
342
|
-
js_node = js_nodes[str(node.id)]
|
|
343
|
-
get_expression(node,js_node, all_nodes, prefix)
|
|
344
|
-
|
|
345
|
-
if 'conditions' in js_node:
|
|
346
|
-
process_condition(node,all_nodes,age_node, js_node['conditions'],prefix)
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
def process_relevance(node,all_nodes, age_node, conditions, prefix = ''):
|
|
351
|
-
reference = []
|
|
352
|
-
expr = None
|
|
353
|
-
cond_params = []
|
|
354
|
-
pure_refs = []
|
|
355
|
-
for condition in conditions:
|
|
356
|
-
# save the param for factorisation
|
|
357
|
-
val = None
|
|
358
|
-
ref = resolve_reference(condition['node_id'], all_nodes, prefix)
|
|
359
|
-
if isinstance(ref, TriccNodeSelectOne):
|
|
360
|
-
val = resolve_reference(condition['answer_id'], list(ref.options.values()), prefix)
|
|
361
|
-
elif 'answer_id' in condition:
|
|
362
|
-
val = None
|
|
363
|
-
expr = f"${{}} = '{condition['answer_id']}'"
|
|
364
|
-
cut_off_exp = generate_cut_off_exp(node, age_node, condition)
|
|
365
|
-
|
|
366
|
-
if expr is None and cut_off_exp is None:
|
|
367
|
-
pure_refs.append(ref if val is None else val)
|
|
368
|
-
else:
|
|
369
|
-
rhombus = get_relevance_rhombus(node,age_node,cut_off_exp, (ref if val is None else val), expr )
|
|
370
|
-
if rhombus is not None:
|
|
371
|
-
|
|
372
|
-
pure_refs.append(rhombus)
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
for pure_ref in pure_refs:
|
|
376
|
-
set_prev_next_node(pure_ref,node)
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
def get_relevance_rhombus(node,age_node,cut_off_exp, ref, ref_expr ):
|
|
381
|
-
expr = None
|
|
382
|
-
reference = []
|
|
383
|
-
prev = []
|
|
384
|
-
# Merge exp
|
|
385
|
-
if ref_expr is not None:
|
|
386
|
-
reference = [ref]
|
|
387
|
-
if cut_off_exp is not None:
|
|
388
|
-
expr = MC_AND_EXP.format(ref_expr,cut_off_exp)
|
|
389
|
-
else:
|
|
390
|
-
expr = ref_expr
|
|
391
|
-
else:
|
|
392
|
-
if cut_off_exp is not None :
|
|
393
|
-
expr = cut_off_exp
|
|
394
|
-
if ref is not None:
|
|
395
|
-
prev = [ref]
|
|
396
|
-
|
|
397
|
-
# Merge ref
|
|
398
|
-
|
|
399
|
-
if cut_off_exp is not None:
|
|
400
|
-
nb_age_ref = len(re.findall("\{\}", cut_off_exp))
|
|
401
|
-
if nb_age_ref == 2:
|
|
402
|
-
reference = [*reference,age_node, age_node]
|
|
403
|
-
elif nb_age_ref == 1:
|
|
404
|
-
reference = [*reference,age_node]
|
|
405
|
-
else:
|
|
406
|
-
logger.error(f"something not right with cut off {cut_off_exp}")
|
|
407
|
-
|
|
408
|
-
if len(reference)>0 and expr is not None:
|
|
409
|
-
rhombus = TriccNodeRhombus(
|
|
410
|
-
id=generate_id(),
|
|
411
|
-
activity=node.activity,
|
|
412
|
-
group=node.activity,
|
|
413
|
-
reference = reference,
|
|
414
|
-
expression_reference = expr,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
)
|
|
418
|
-
for prev_node in [*reference]:
|
|
419
|
-
set_prev_next_node(prev_node,rhombus )
|
|
420
|
-
if ref is not None:
|
|
421
|
-
set_prev_next_node(ref,rhombus )
|
|
422
|
-
|
|
423
|
-
return rhombus
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
PREV_STAGE = {
|
|
428
|
-
"id":"",
|
|
429
|
-
"flag":"id",
|
|
430
|
-
"out":"flag",
|
|
431
|
-
"qual":"out",
|
|
432
|
-
"diag":"quat"
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
def resolve_reference(ref, all_nodes, prefix = ''):
|
|
437
|
-
if isinstance(ref, (str,int)):
|
|
438
|
-
refs = list(filter(lambda n: n.name.endswith( str(ref)) and not isinstance(n, TriccGroup) and (prefix == '' or n.name.startswith(prefix)) , all_nodes))
|
|
439
|
-
if len(refs)==1:
|
|
440
|
-
return refs[0]
|
|
441
|
-
elif len(refs)>1:
|
|
442
|
-
logger.warning("reference {} found multiple times ".format( ref))
|
|
443
|
-
elif prefix != '':
|
|
444
|
-
return resolve_reference(ref, all_nodes, prefix = PREV_STAGE.get(prefix,''))
|
|
445
|
-
else:
|
|
446
|
-
logger.warning("reference {} not found".format( ref))
|
|
447
|
-
|
|
448
|
-
else:
|
|
449
|
-
logger.warning("reference not a string ({})".format(ref.__class__))
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
##### deprecated #############################################################################3
|
|
453
|
-
##### deprecated #############################################################################3
|
|
454
|
-
##### deprecated #############################################################################3
|
|
455
|
-
##### deprecated #############################################################################3
|
|
456
|
-
##### deprecated #############################################################################3
|
|
457
|
-
##### deprecated #############################################################################3
|
|
458
|
-
def process_condition(node,all_nodes, age_node, conditions, prefix = ''):
|
|
459
|
-
reference = []
|
|
460
|
-
expression = None
|
|
461
|
-
for condition in conditions:
|
|
462
|
-
ref = resolve_reference(condition['node_id'], all_nodes, prefix)
|
|
463
|
-
if isinstance(ref, TriccNodeSelectOne):
|
|
464
|
-
val = resolve_reference(condition['answer_id'], list(ref.options.values()), prefix)
|
|
465
|
-
else:
|
|
466
|
-
val = None
|
|
467
|
-
if val is not None:
|
|
468
|
-
process_cut_off(node, age_node, condition,expression = None,reference = [val])
|
|
469
|
-
elif ref is not None and 'answer_id' in condition:
|
|
470
|
-
process_cut_off(node, age_node, condition,
|
|
471
|
-
expression = MC_COND_EXP.format("{{}}",get_mc_name(condition['answer_id'])),reference = [ref])
|
|
472
|
-
elif ref is not None:
|
|
473
|
-
process_cut_off_old(node, age_node, condition,expression = None,reference = [ref])
|
|
474
|
-
|
|
475
|
-
def process_cut_off_old(node, age_node, js_parent,expression = None,reference = []):
|
|
476
|
-
cond_exp = ''
|
|
477
|
-
ans_calc=None
|
|
478
|
-
has_cut_off = False
|
|
479
|
-
if 'cut_off_start' in js_parent or 'cut_off_end' in js_parent:
|
|
480
|
-
has_cut_off = True
|
|
481
|
-
reference = [*reference, age_node]
|
|
482
|
-
if 'cut_off_start' in js_parent and js_parent['cut_off_start'] is not None:
|
|
483
|
-
cond_exp = OPERATORS['more_or_equal'].format('${{{}}}',js_parent['cut_off_start'])
|
|
484
|
-
if 'cut_off_end' in js_parent and js_parent['cut_off_end'] is not None:
|
|
485
|
-
cut_off_s = OPERATORS['less'].format('${{{}}}',js_parent['cut_off_end'])
|
|
486
|
-
if cond_exp != '':
|
|
487
|
-
cond_exp = MC_AND_EXP.format(cond_exp,cut_off_s)
|
|
488
|
-
else:
|
|
489
|
-
cond_exp = cut_off_s
|
|
490
|
-
if cond_exp != '' and expression is not None:
|
|
491
|
-
cond_exp = MC_AND_EXP.format(expression,cond_exp)
|
|
492
|
-
elif expression is not None and isinstance(expression,str) :
|
|
493
|
-
cond_exp = expression
|
|
494
|
-
elif expression is not None:
|
|
495
|
-
logger.warning("expression with a wrong type")
|
|
496
|
-
elif reference is not None and isinstance(reference, list) and len(reference)>0 :
|
|
497
|
-
#just a previous node
|
|
498
|
-
ans_calc = TriccNodeCalculate(
|
|
499
|
-
id=generate_id(),
|
|
500
|
-
prev_nodes=reference,
|
|
501
|
-
activity = node.activity,
|
|
502
|
-
group = node.activity
|
|
503
|
-
)
|
|
504
|
-
set_prev_next_node(reference[0],ans_calc)
|
|
505
|
-
node.activity.nodes.append(ans_calc)
|
|
506
|
-
if cond_exp != '':
|
|
507
|
-
if hasattr(node, 'expression_reference') and node.expression_reference is not None:
|
|
508
|
-
cond_exp = MC_AND_EXP.format(node.expression_reference, cond_exp)
|
|
509
|
-
cond_exp = cond_exp if ans_calc is None else MC_AND_EXP.format(cond_exp,"${{{}}}>0")
|
|
510
|
-
if not isinstance(cond_exp,str):
|
|
511
|
-
logger.warning("wrong type")
|
|
512
|
-
if hasattr(node, 'reference') and node.reference is not None and len(node.reference)>0:
|
|
513
|
-
reference = [*node.reference, *reference]
|
|
514
|
-
if has_cut_off and ans_calc is not None:
|
|
515
|
-
reference = [*reference,age_node,ans_calc]
|
|
516
|
-
elif ans_calc is not None:
|
|
517
|
-
reference = [*reference,ans_calc]
|
|
518
|
-
if issubclass(node.__class__, TriccNodeCalculateBase) and node.expression_reference is None:
|
|
519
|
-
node.expression_reference = cond_exp
|
|
520
|
-
if reference is None or len(reference) == 0:
|
|
521
|
-
logger.warning('emptsy reference')
|
|
522
|
-
if node.reference is not None and len(node.reference)>0:
|
|
523
|
-
node.reference = [*node.reference, *reference]
|
|
524
|
-
else:
|
|
525
|
-
node.reference = reference
|
|
526
|
-
if ans_calc is not None:
|
|
527
|
-
set_prev_next_node(ans_calc,node)
|
|
528
|
-
else:
|
|
529
|
-
node_calc = TriccNodeCalculate(
|
|
530
|
-
id=generate_id(),
|
|
531
|
-
expression_reference = cond_exp,
|
|
532
|
-
reference=reference ,
|
|
533
|
-
activity = node.activity,
|
|
534
|
-
group = node.activity
|
|
535
|
-
|
|
536
|
-
)
|
|
537
|
-
set_prev_next_node(age_node,node_calc)
|
|
538
|
-
set_prev_next_node(node_calc,node)
|
|
539
|
-
if ans_calc is not None:
|
|
540
|
-
set_prev_next_node(ans_calc,node_calc)
|
|
541
|
-
|
|
542
|
-
node.activity.nodes.append(node_calc)
|