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
@@ -3,21 +3,32 @@ import hashlib
3
3
 
4
4
  # from bs4 import BeautifulSoup
5
5
  from tricc_oo.converters.tricc_to_xls_form import (
6
- negate_term,
7
- VERSION_SEPARATOR,
8
- INSTANCE_SEPARATOR,
9
- get_export_name,
6
+ get_export_name, BOOLEAN_MAP
10
7
  )
11
- from tricc_oo.converters.utils import clean_name, remove_html
12
8
  from tricc_oo.models.lang import SingletonLangClass
13
- from tricc_oo.models import *
14
- import re
9
+ from tricc_oo.converters.utils import clean_name, remove_html, generate_id
10
+ from tricc_oo.models.base import (
11
+ TriccOperator,
12
+ TriccOperation, TriccStatic, TriccReference, and_join, TriccNodeType
13
+ )
14
+ from tricc_oo.models.calculate import (
15
+ TriccNodeDisplayCalculateBase,
16
+ TriccNodeCalculate
17
+ )
18
+ from tricc_oo.models.tricc import (
19
+ TriccNodeBaseModel, TriccNodeSelectMultiple, TriccNodeSelectOption,
20
+ TriccNodeSelectOne,
21
+ TriccNodeSelect,
22
+ TriccNodeMoreInfo,
23
+ TriccNodeDisplayModel,
24
+ TriccNodeAcceptDiagnostic,
25
+ TriccNodeNote,
26
+ )
27
+ from typing import Dict
15
28
  from tricc_oo.visitors.tricc import (
16
29
  is_ready_to_process,
17
30
  process_reference,
18
31
  add_calculate,
19
- TRICC_TRUE_VALUE,
20
- TRICC_FALSE_VALUE,
21
32
  get_applicability_expression,
22
33
  get_prev_instance_skip_expression,
23
34
  get_process_skip_expression,
@@ -28,14 +39,20 @@ logger = logging.getLogger("default")
28
39
  langs = SingletonLangClass()
29
40
  TRICC_CALC_EXPRESSION = "${{{0}}}>0"
30
41
 
31
- BOOLEAN_MAP = {
32
- str(TRICC_TRUE_VALUE): 1,
33
- str(TRICC_FALSE_VALUE): 0,
34
- }
42
+
43
+ def get_export_group_name(in_node): return f"gcalc_{get_export_name(in_node)}"
35
44
 
36
45
 
37
46
  def start_group(
38
- strategy, cur_group, groups, df_survey, df_calculate, processed_nodes, process, relevance=False, **kwargs
47
+ strategy,
48
+ cur_group,
49
+ groups,
50
+ df_survey,
51
+ df_calculate,
52
+ processed_nodes,
53
+ process,
54
+ relevance=False,
55
+ **kwargs,
39
56
  ):
40
57
  name = get_export_name(cur_group)
41
58
 
@@ -45,35 +62,39 @@ def start_group(
45
62
 
46
63
  else:
47
64
  groups[name] = 0
48
- is_activity = isinstance(cur_group, TriccNodeActivity)
49
- relevance = (
50
- relevance and cur_group.relevance is not None and cur_group.relevance != ""
51
- )
52
-
65
+ relevance = relevance and cur_group.relevance is not None and cur_group.relevance != ""
66
+ past_instances = len(getattr(cur_group.base_instance, "instances", []))
67
+ group_calc_required = relevance is not None and (len(str(relevance)) > 100 or past_instances > 1)
68
+ calc = None
69
+ if group_calc_required and getattr(cur_group.relevance, 'operator', None) != TriccOperator.ISTRUE:
70
+
71
+ calc = TriccNodeCalculate(
72
+ id=generate_id(get_export_group_name(name)),
73
+ group=cur_group,
74
+ activity=cur_group.activity,
75
+ name=get_export_group_name(name),
76
+ expression=cur_group.relevance
77
+ )
78
+ if calc not in cur_group.calculates:
79
+ cur_group.calculates.append(calc)
80
+ processed_nodes.add(calc)
53
81
 
54
- group_calc_required = (
55
- False and relevance and not is_activity and len(relevance) > 100
56
- )
82
+ cur_group.relevance = TriccOperation(
83
+ TriccOperator.ISTRUE,
84
+ [calc]
85
+ )
57
86
 
58
87
  relevance_expression = cur_group.relevance
59
88
  relevance_expression = get_applicability_expression(cur_group, processed_nodes, process, relevance_expression)
60
89
  relevance_expression = get_prev_instance_skip_expression(cur_group, processed_nodes, process, relevance_expression)
61
90
  relevance_expression = get_process_skip_expression(cur_group, processed_nodes, process, relevance_expression)
62
-
91
+
63
92
  if not relevance:
64
- relevance_expression = ""
93
+ relevance_expression_str = ""
65
94
  elif isinstance(relevance_expression, (TriccOperation, TriccStatic)):
66
- relevance_expression = strategy.get_tricc_operation_expression(
67
- relevance_expression
68
- )
95
+ relevance_expression_str = strategy.get_tricc_operation_expression(relevance_expression)
69
96
 
70
-
71
- # elif is_activity:
72
- # relevance_expression = TRICC_CALC_EXPRESSION.format(get_export_name(cur_group.root))
73
- elif group_calc_required:
74
- relevance_expression = TRICC_CALC_EXPRESSION.format("gcalc_" + name)
75
-
76
- ## group
97
+ # group
77
98
  values = []
78
99
  for column in SURVEY_MAP:
79
100
  if column == "type":
@@ -86,34 +107,27 @@ def start_group(
86
107
  if relevance_expression is True:
87
108
  values.append("")
88
109
  else:
89
- values.append(relevance_expression)
110
+ values.append(relevance_expression_str)
90
111
 
91
112
  else:
92
113
  values.append(get_xfrom_trad(strategy, cur_group, column, SURVEY_MAP))
93
114
  df_survey.loc[len(df_survey)] = values
94
115
 
95
- ### calc
96
- if (
97
- group_calc_required
98
- and len(df_calculate[df_calculate["name"] == "gcalc_" + name]) == 0
99
- ):
116
+ # calc
117
+ if calc and len(df_calculate[df_calculate["name"] == get_export_group_name(name)]) == 0:
100
118
  calc_values = []
101
119
  for column in SURVEY_MAP:
102
120
  if column == "type":
103
121
  calc_values.append("calculate")
104
122
  elif column == "name":
105
- value = "gcalc_" + name
123
+ value = get_export_name(calc)
106
124
  calc_values.append(value)
107
125
  elif column == "calculation":
108
- calc_values.append(
109
- get_attr_if_exists(strategy, cur_group, "relevance", SURVEY_MAP)
110
- )
126
+ calc_values.append(f"number({strategy.get_tricc_operation_expression(calc.expression)}")
111
127
  elif column == "relevance":
112
128
  calc_values.append("")
113
129
  else:
114
- calc_values.append(
115
- get_xfrom_trad(strategy, cur_group, column, SURVEY_MAP)
116
- )
130
+ calc_values.append(get_xfrom_trad(strategy, cur_group, column, SURVEY_MAP))
117
131
 
118
132
  df_calculate.loc[len(df_calculate)] = calc_values
119
133
 
@@ -177,7 +191,8 @@ def end_group(strategy, cur_group, groups, df_survey, **kwargs):
177
191
  # if reference not in used_saves
178
192
  # , then create calculate node reference_1 # and save is used_saves 'reference' : 1
179
193
  # else create calculate node reference_(used_saves['reference']+1) # and update used_saves['reference'] += 1
180
- # once done, walkthrough again and remame reference_(used_saves['reference']) to reference and create the other save
194
+ # once done, walkthrough again and remame
195
+ # reference_(used_saves['reference']) to reference and create the other save
181
196
 
182
197
 
183
198
  ODK_TRICC_TYPE_MAP = {
@@ -231,6 +246,7 @@ SURVEY_MAP = {
231
246
  **langs.get_trads_map("required_message"),
232
247
  "read only": "read only",
233
248
  "calculation": "expression",
249
+ "trigger": "trigger",
234
250
  "repeat_count": "repeat_count",
235
251
  "media::image": "image",
236
252
  "choice_filter": "",
@@ -257,13 +273,11 @@ def get_xfrom_trad(strategy, node, column, mapping, clean_html=False):
257
273
  new_column = arr[0] if arr[0] != "media" else "::".join(arr[0:2])
258
274
  trad = arr[-1] if new_column != column else None
259
275
  value = get_attr_if_exists(strategy, node, new_column, mapping)
260
- # the pattern is to look for if that define a string if(test>0, 'strin')
261
- pattern = r"concat\(|[^\}] *, *'[^']"
262
276
  if (
263
277
  issubclass(node.__class__, TriccNodeDisplayCalculateBase)
264
278
  and column == "calculation"
265
279
  and isinstance(value, str)
266
- and not value.startswith("number")
280
+ and not (value.startswith("number") or value.startswith("round"))
267
281
  and getattr(node, "expression", None)
268
282
  and node.expression.get_datatype() in ("number", "boolean")
269
283
  ):
@@ -281,12 +295,7 @@ def get_xfrom_trad(strategy, node, column, mapping, clean_html=False):
281
295
  value = "autocomplete"
282
296
  elif isinstance(node, TriccNodeNote) and "countdown-timer" in node.name:
283
297
  value = "countdown-timer"
284
- elif (
285
- column == "appearance"
286
- and isinstance(node, TriccNodeAcceptDiagnostic)
287
- and node.severity
288
- and not value
289
- ):
298
+ elif column == "appearance" and isinstance(node, TriccNodeAcceptDiagnostic) and node.severity and not value:
290
299
  if node.severity == "severe":
291
300
  value = "severe"
292
301
  elif node.severity == "moderate":
@@ -310,7 +319,6 @@ def generate_choice_filter(strategy, node):
310
319
  if not isinstance(node, (TriccNodeSelectMultiple, TriccNodeSelectOne)):
311
320
  return
312
321
  relevances = {}
313
- option_filter = {}
314
322
  for o in node.options.values():
315
323
  if o.relevance and o.relevance != TriccStatic(True):
316
324
  key = gen_operation_hash(o.relevance)
@@ -320,9 +328,7 @@ def generate_choice_filter(strategy, node):
320
328
  basic = "string-length(choice_filter)=0"
321
329
  # TODO remove when the bug regarding filter + image will be fixed
322
330
  if any(i.image is not None for i in node.options.values()):
323
- basic = TriccOperation(
324
- TriccOperator.AND, ["string-length(choice_filter)=0", node.relevance]
325
- )
331
+ basic = TriccOperation(TriccOperator.AND, ["string-length(choice_filter)=0", node.relevance])
326
332
 
327
333
  choice_filter = TriccOperation(TriccOperator.OR, [basic])
328
334
  for k, op in relevances.items():
@@ -347,10 +353,7 @@ def generate_choice_filter(strategy, node):
347
353
  def get_attr_if_exists(strategy, node, column, map_array):
348
354
  if column in map_array:
349
355
  mapping = map_array[column]
350
- if (
351
- isinstance(mapping, Dict)
352
- and getattr(node, "tricc_type", None) in map_array[column]
353
- ):
356
+ if isinstance(mapping, Dict) and getattr(node, "tricc_type", None) in map_array[column]:
354
357
  tricc_type = map_array[column][node.tricc_type]
355
358
  if tricc_type[:6] == "select":
356
359
  return tricc_type + " " + node.list_name
@@ -375,11 +378,7 @@ def get_attr_if_exists(strategy, node, column, map_array):
375
378
  [
376
379
  node.applicability,
377
380
  value,
378
- (
379
- TriccStatic(False)
380
- if node.applicability.get_datatype() == "boolean"
381
- else TriccStatic("")
382
- ),
381
+ (TriccStatic(False) if node.applicability.get_datatype() == "boolean" else TriccStatic("")),
383
382
  ],
384
383
  )
385
384
  if column == "name":
@@ -393,11 +392,7 @@ def get_attr_if_exists(strategy, node, column, map_array):
393
392
 
394
393
  elif isinstance(value, (TriccOperation, TriccStatic, TriccReference)):
395
394
  expression = strategy.get_tricc_operation_expression(value)
396
- return (
397
- expression.replace("$this", ".")
398
- if isinstance(expression, str)
399
- else expression
400
- )
395
+ return expression
401
396
  elif value is not None:
402
397
  return str(value) if not isinstance(value, dict) else value
403
398
  else:
@@ -420,14 +415,12 @@ def get_more_info_select(strategy, node):
420
415
  if column == "type":
421
416
  values.append("select_one more_info")
422
417
  elif column == "label":
423
- values.append("NO_LABEL")
418
+ values.append(strategy.get_empty_label())
424
419
  elif column == "name":
425
420
  values.append(get_export_name(node) + "_optin")
426
421
  elif column == "hint":
427
422
  print(get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True))
428
- values.append(
429
- get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True)
430
- )
423
+ values.append(get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True))
431
424
  elif column == "relevance":
432
425
  values.append(get_xfrom_trad(strategy, node.parent, column, SURVEY_MAP))
433
426
  else:
@@ -445,9 +438,7 @@ def get_more_info_message(strategy, node):
445
438
  elif column.startswith("hint"):
446
439
  values.append(langs.get_trads("", trad=None))
447
440
  else:
448
- values.append(
449
- get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True)
450
- )
441
+ values.append(get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True))
451
442
  return values
452
443
 
453
444
 
@@ -498,29 +489,18 @@ def generate_xls_form_export(
498
489
  if node in stashed_nodes:
499
490
  stashed_nodes.remove(node)
500
491
  if kwargs.get("warn", True):
501
- logger.debug(
502
- "generate_xls_form_export: unstashing processed node{} ".format(
503
- node.get_name()
504
- )
505
- )
506
- if issubclass(
507
- node.__class__, (TriccNodeDisplayCalculateBase, TriccNodeDisplayModel)
508
- ):
492
+ logger.debug("generate_xls_form_export: unstashing processed node{} ".format(node.get_name()))
493
+ if issubclass(node.__class__, (TriccNodeDisplayCalculateBase, TriccNodeDisplayModel)):
509
494
  if isinstance(node, TriccNodeSelectOption):
510
495
  values = []
511
496
  for column in CHOICE_MAP:
512
- values.append(
513
- get_xfrom_trad(strategy, node, column, CHOICE_MAP, True)
514
- )
497
+ values.append(get_xfrom_trad(strategy, node, column, CHOICE_MAP, True))
515
498
  # add only if not existing
516
499
  if (
517
500
  len(
518
501
  df_choice[
519
502
  (df_choice["list_name"] == node.list_name)
520
- & (
521
- df_choice["value"]
522
- == BOOLEAN_MAP.get(str(node.name), node.name)
523
- )
503
+ & (df_choice["value"] == BOOLEAN_MAP.get(str(node.name), node.name))
524
504
  ]
525
505
  )
526
506
  == 0
@@ -528,34 +508,22 @@ def generate_xls_form_export(
528
508
  df_choice.loc[len(df_choice)] = values
529
509
  elif isinstance(node, TriccNodeMoreInfo):
530
510
  df_survey.loc[len(df_survey)] = get_more_info_select(strategy, node)
531
- df_survey.loc[len(df_survey)] = get_more_info_message(
532
- strategy, node
533
- )
511
+ df_survey.loc[len(df_survey)] = get_more_info_message(strategy, node)
534
512
  if len(df_choice[(df_choice["list_name"] == "more_info")]) == 0:
535
513
  df_choice.loc[len(df_choice)] = get_more_info_choice(strategy)
536
- elif (
537
- node.tricc_type in ODK_TRICC_TYPE_MAP
538
- and ODK_TRICC_TYPE_MAP[node.tricc_type] is not None
539
- ):
514
+ elif node.tricc_type in ODK_TRICC_TYPE_MAP and ODK_TRICC_TYPE_MAP[node.tricc_type] is not None:
540
515
  if ODK_TRICC_TYPE_MAP[node.tricc_type] == "calculate":
541
516
  values = []
542
517
  for column in SURVEY_MAP:
543
518
  value = get_xfrom_trad(strategy, node, column, SURVEY_MAP)
544
519
  if (
545
520
  column == "default"
546
- and issubclass(
547
- node.__class__, TriccNodeDisplayCalculateBase
548
- )
521
+ and issubclass(node.__class__, TriccNodeDisplayCalculateBase)
549
522
  and value == ""
550
523
  ):
551
524
  value = 0
552
525
  values.append(value)
553
- if (
554
- len(
555
- df_calculate[df_calculate.name == get_export_name(node)]
556
- )
557
- == 0
558
- ):
526
+ if len(df_calculate[df_calculate.name == get_export_name(node)]) == 0:
559
527
  df_calculate.loc[len(df_calculate)] = values
560
528
  else:
561
529
  df_calculate.loc[len(df_calculate)] = values
@@ -563,29 +531,19 @@ def generate_xls_form_export(
563
531
  elif ODK_TRICC_TYPE_MAP[node.tricc_type] != "":
564
532
  values = []
565
533
  for column in SURVEY_MAP:
566
- values.append(
567
- get_xfrom_trad(strategy, node, column, SURVEY_MAP)
568
- )
534
+ values.append(get_xfrom_trad(strategy, node, column, SURVEY_MAP))
569
535
  df_survey.loc[len(df_survey)] = values
570
536
  else:
571
- logger.warning(
572
- "node {} have an unmapped type {}".format(
573
- node.get_name(), node.tricc_type
574
- )
575
- )
537
+ logger.warning("node {} have an unmapped type {}".format(node.get_name(), node.tricc_type))
576
538
  else:
577
- logger.warning(
578
- "node {} have an unsupported type {}".format(
579
- node.get_name(), node.tricc_type
580
- )
581
- )
539
+ logger.warning("node {} have an unsupported type {}".format(node.get_name(), node.tricc_type))
582
540
  # continue walk °
583
541
  return True
584
542
  return False
585
543
 
586
544
 
587
545
  def get_input_line(node, replace_dots=True):
588
- label = langs.get_trads(node.label, force_dict=True)
546
+ # label = langs.get_trads(node.label, force_dict=True)
589
547
  empty = langs.get_trads("", force_dict=True)
590
548
  return [
591
549
  "hidden",
@@ -594,23 +552,24 @@ def get_input_line(node, replace_dots=True):
594
552
  *list(empty.values()), # hint
595
553
  *list(empty.values()), # help
596
554
  "", # default
597
- "hidden", #'appearance', clean_name
598
- "", #'constraint',
599
- *list(empty.values()), #'constraint_message'
600
- "", #'relevance'
601
- "", #'disabled'
602
- "", #'required'
603
- *list(empty.values()), #'required message'
604
- "", #'read only'
605
- "", #'expression'
606
- "", #'repeat_count'
607
- "", #'image'
555
+ "hidden", # 'appearance', clean_name
556
+ "", # 'constraint',
557
+ *list(empty.values()), # 'constraint_message'
558
+ "", # 'relevance'
559
+ "", # 'disabled'
560
+ "", # 'required'
561
+ *list(empty.values()), # 'required message'
562
+ "", # 'read only'
563
+ "",
564
+ "", # 'expression'
565
+ "", # 'repeat_count'
566
+ "", # 'image'
608
567
  "",
609
568
  ]
610
569
 
611
570
 
612
571
  def get_input_calc_line(node, replace_dots=True):
613
- label = langs.get_trads(node.label, force_dict=True)
572
+ # label = langs.get_trads(node.label, force_dict=True)
614
573
  empty = langs.get_trads("", force_dict=True)
615
574
  return [
616
575
  "calculate",
@@ -619,19 +578,17 @@ def get_input_calc_line(node, replace_dots=True):
619
578
  *list(empty.values()), # hint
620
579
  *list(empty.values()), # help
621
580
  "", # default
622
- "", #'appearance', clean_name
623
- "", #'constraint',
624
- *list(empty.values()), #'constraint_message'
625
- "", #'relevance'
626
- "", #'disabled'
627
- "", #'required'
628
- *list(empty.values()), #'required message'
629
- "", #'read only'
630
- "../inputs/contact/"
631
- + clean_name(node.name, replace_dots=replace_dots), #'expression'
632
- "", #'repeat_count'
633
- "", #'image'
581
+ "", # 'appearance', clean_name
582
+ "", # 'constraint',
583
+ *list(empty.values()), # 'constraint_message'
584
+ "", # 'relevance'
585
+ "", # 'disabled'
586
+ "", # 'required'
587
+ *list(empty.values()), # 'required message'
588
+ "", # 'read only'
589
+ "../inputs/contact/" + clean_name(node.name, replace_dots=replace_dots), # 'expression'
590
+ "",
591
+ "", # 'repeat_count'
592
+ "", # 'image'
634
593
  "", # choice filter
635
594
  ]
636
-
637
-
@@ -1,19 +1,16 @@
1
1
  import abc
2
2
 
3
- from tricc_oo.models import (
3
+ from tricc_oo.models.tricc import (
4
4
  TriccNodeMainStart,
5
5
  TriccNodeActivity,
6
- TriccEdge,
7
6
  )
8
7
  from tricc_oo.converters.utils import generate_id
9
8
  from tricc_oo.visitors.tricc import (
10
9
  get_activity_wait,
11
- stashed_node_func,
12
10
  set_prev_next_node,
13
11
  export_proposed_diags,
14
- create_determine_diagnosis_activity
12
+ create_determine_diagnosis_activity,
15
13
  )
16
- from itertools import chain
17
14
  import logging
18
15
 
19
16
  logger = logging.getLogger("default")
@@ -27,7 +24,14 @@ class BaseInputStrategy:
27
24
  def execute_linked_process(self, project):
28
25
  # create an overall activity only if not specified
29
26
  if "main" not in project.start_pages:
30
- page_processes = [(p.root.process, p,) for p in list(project.pages.values()) if getattr(p.root, 'process', None)]
27
+ page_processes = [
28
+ (
29
+ p.root.process,
30
+ p,
31
+ )
32
+ for p in list(project.pages.values())
33
+ if getattr(p.root, "process", None)
34
+ ]
31
35
  sorted_pages = {}
32
36
  diags = []
33
37
  for a in project.pages.values():
@@ -38,34 +42,31 @@ class BaseInputStrategy:
38
42
  if diag.name not in seen_diags:
39
43
  unique_diags.append(diag)
40
44
  seen_diags.add(diag.name)
41
- severity_order = { "severe": 3, "moderate": 2, "mild":1, 'light': 0}
42
- unique_diags = sorted(unique_diags, key=lambda x: (-getattr(severity_order, x.severity or 'light', 0), x.label))
45
+ severity_order = {"severe": 3, "moderate": 2, "mild": 1, "light": 0}
46
+ unique_diags = sorted(
47
+ unique_diags,
48
+ key=lambda x: (
49
+ -getattr(severity_order, x.severity or "light", 0),
50
+ x.label,
51
+ ),
52
+ )
43
53
  for process in self.processes:
44
54
  if process in [p[0] for p in page_processes]:
45
- sorted_pages[process] = [
46
- p[1] for p in page_processes if p[0] == process
47
- ]
48
- elif process == 'determine-diagnosis' and diags:
55
+ sorted_pages[process] = [p[1] for p in page_processes if p[0] == process]
56
+ elif process == "determine-diagnosis" and diags:
49
57
  diags_activity = create_determine_diagnosis_activity(unique_diags)
50
- sorted_pages[process] = [
51
- diags_activity
52
- ]
53
- project.start_pages['determine-diagnosis'] = diags_activity
58
+ sorted_pages[process] = [diags_activity]
59
+ project.start_pages["determine-diagnosis"] = diags_activity
54
60
  root_process = sorted_pages[list(sorted_pages.keys())[0]][0].root
55
61
  root = TriccNodeMainStart(
56
- id=generate_id('s-main'),
62
+ id=generate_id("s-main"),
57
63
  form_id=root_process.form_id,
58
64
  label=root_process.label,
59
- process='main'
65
+ process="main",
60
66
  )
61
67
  nodes = {}
62
68
  nodes[root.id] = root
63
- app = TriccNodeActivity(
64
- id=generate_id('a-main'),
65
- name=root_process.name,
66
- root=root,
67
- nodes=nodes
68
- )
69
+ app = TriccNodeActivity(id=generate_id("a-main"), name=root_process.name, root=root, nodes=nodes)
69
70
  root.activity = app
70
71
  # loop back to app to avoid None
71
72
  app.activity = app
@@ -85,20 +86,15 @@ class BaseInputStrategy:
85
86
  )
86
87
  else:
87
88
  for a in nodes:
88
- set_prev_next_node(
89
- prev_bridge,
90
- a,
91
- edge_only=True
92
- )
89
+ set_prev_next_node(prev_bridge, a, edge_only=True)
93
90
  app.nodes[prev_bridge.id] = prev_bridge
94
-
91
+
95
92
  for n in nodes.values():
96
93
  n.activity = app
97
94
  n.group = app
98
95
  app.nodes[n.id] = n
99
96
  prev_process = process
100
97
 
101
-
102
98
  return app
103
99
  else:
104
100
  return project.start_pages["main"]
@@ -106,7 +102,7 @@ class BaseInputStrategy:
106
102
  def __init__(self, input_path):
107
103
  self.input_path = input_path
108
104
 
109
- ### walking function
105
+ # walking function
110
106
  @abc.abstractmethod
111
107
  def execute(in_filepath, media_path):
112
108
  pass