tricc-oo 1.6.25__py3-none-any.whl → 1.7.0.dev1__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.
tricc_oo/models/base.py CHANGED
@@ -217,7 +217,6 @@ class TriccNodeBaseModel(TriccBaseModel):
217
217
  expression_inputs: List[Expression] = []
218
218
  activity: Optional[FwTriccNodeBaseModel] = None
219
219
  ref_def: Optional[Union[int, str]] = None # for medal creator
220
- is_sequence_defined: bool = False
221
220
 
222
221
  class Config:
223
222
  use_enum_values = True # <--
@@ -275,7 +274,7 @@ class TriccNodeBaseModel(TriccBaseModel):
275
274
 
276
275
 
277
276
  class TriccStatic(BaseModel):
278
- value: Union[str, float, int, bool, TriccNodeBaseModel]
277
+ value: Union[str, float, int, bool]
279
278
 
280
279
  def __init__(self, value):
281
280
  super().__init__(value=value)
@@ -378,7 +377,6 @@ class TriccOperator(StrEnum):
378
377
  PARENTHESIS = "parenthesis"
379
378
  CONCATENATE = "concatenate"
380
379
  DATETIME_TO_DECIMAL = "datetime_to_decimal"
381
- DIAGNOSIS_LIST = "diagnosis_list"
382
380
 
383
381
 
384
382
  RETURNS_BOOLEAN = [
@@ -425,8 +423,6 @@ RETURNS_NUMBER = [
425
423
 
426
424
  RETURNS_DATE = [TriccOperator.CAST_DATE]
427
425
 
428
- RETURNS_STRING = [TriccOperator.DIAGNOSIS_LIST]
429
-
430
426
  OPERATION_LIST = {
431
427
  ">=": TriccOperator.MORE_OR_EQUAL,
432
428
  "<=": TriccOperator.LESS_OR_EQUAL,
@@ -484,8 +480,6 @@ class TriccOperation(BaseModel):
484
480
  return "number"
485
481
  elif self.operator in RETURNS_DATE:
486
482
  return "date"
487
- elif self.operator in RETURNS_STRING:
488
- return "string"
489
483
  elif self.operator == TriccOperator.CONCATENATE:
490
484
  return "string"
491
485
  elif self.operator == TriccOperator.PARENTHESIS:
tricc_oo/models/tricc.py CHANGED
@@ -99,7 +99,6 @@ class TriccNodeActivity(TriccNodeBaseModel):
99
99
  # - case definition
100
100
  calculates: List[TriccNodeCalculateBase] = []
101
101
  applicability: Optional[Union[Expression, TriccOperation]] = None
102
- is_sequence_defined: bool = False
103
102
 
104
103
  # redefine
105
104
  def make_instance(self, instance_nb=None, **kwargs):
@@ -295,15 +294,13 @@ class TriccNodeDisplayModel(TriccNodeBaseModel):
295
294
  default: Optional[Union[Expression, TriccOperation, TriccReference, TriccStatic]] = None
296
295
  trigger: Optional[Union[Expression, TriccOperation, TriccReference]] = None
297
296
  priority: Union[float, int, None] = None
298
- concept_type: str = None
299
- datatype: str = None
297
+
300
298
  # to use the enum value of the TriccNodeType
301
299
 
302
300
 
303
301
  class TriccNodeNote(TriccNodeDisplayModel):
304
302
  tricc_type: TriccNodeType = TriccNodeType.note
305
303
  datatype: str = "string"
306
- is_sequence_defined: bool = True
307
304
 
308
305
 
309
306
  class TriccNodeInputModel(TriccNodeDisplayModel):
@@ -311,7 +308,6 @@ class TriccNodeInputModel(TriccNodeDisplayModel):
311
308
  constraint_message: Optional[Union[str, Dict[str, str]]] = None
312
309
  constraint: Optional[Expression] = None
313
310
  save: Optional[str] = None # contribute to another calculate
314
- is_sequence_defined: bool = True
315
311
 
316
312
 
317
313
  class TriccNodeDate(TriccNodeInputModel):
@@ -16,7 +16,7 @@ from tricc_oo.models.calculate import (
16
16
  TriccNodeCalculate
17
17
  )
18
18
  from tricc_oo.models.tricc import (
19
- TriccNodeBaseModel, TriccNodeSelectMultiple, TriccNodeSelectOption,
19
+ TriccNodeActivity, TriccNodeBaseModel, TriccNodeSelectMultiple, TriccNodeSelectOption,
20
20
  TriccNodeSelectOne,
21
21
  TriccNodeSelect,
22
22
  TriccNodeMoreInfo,
@@ -32,7 +32,6 @@ from tricc_oo.visitors.tricc import (
32
32
  get_applicability_expression,
33
33
  get_prev_instance_skip_expression,
34
34
  get_process_skip_expression,
35
- process_operation_reference,
36
35
  )
37
36
 
38
37
  logger = logging.getLogger("default")
@@ -40,10 +39,7 @@ logger = logging.getLogger("default")
40
39
  langs = SingletonLangClass()
41
40
  TRICC_CALC_EXPRESSION = "${{{0}}}>0"
42
41
 
43
-
44
- def get_export_group_name(in_node): return f"gcalc_{get_export_name(in_node)}"
45
-
46
- def get_export_group_required(in_node): return in_node.relevance and in_node.relevance != TriccStatic(True)
42
+ def get_export_group_name(in_node):return f"gcalc_{get_export_name(in_node)}"
47
43
 
48
44
  def start_group(
49
45
  strategy,
@@ -64,60 +60,40 @@ def start_group(
64
60
 
65
61
  else:
66
62
  groups[name] = 0
63
+ is_activity = isinstance(cur_group, TriccNodeActivity)
67
64
  relevance = relevance and cur_group.relevance is not None and cur_group.relevance != ""
68
65
  past_instances = len(getattr(cur_group.base_instance, "instances", []))
69
- group_calc_required = get_export_group_required(cur_group)
66
+ group_calc_required = relevance is not None and (len(str(relevance)) > 100 or past_instances>1)
70
67
  calc = None
71
- if group_calc_required and len(df_calculate[df_calculate["name"] == get_export_group_name(cur_group)]) == 0:
72
-
68
+ if group_calc_required and getattr(cur_group.relevance, 'operator', None) != TriccOperator.ISTRUE:
69
+
73
70
  calc = TriccNodeCalculate(
74
71
  id=generate_id(get_export_group_name(name)),
75
- group=cur_group.group,
72
+ group=cur_group,
76
73
  activity=cur_group.activity,
77
74
  name=get_export_group_name(name),
78
75
  expression=cur_group.relevance
79
76
  )
80
-
81
- if calc not in cur_group.activity.calculates:
82
- process_reference(
83
- calc,
84
- processed_nodes,
85
- calculates=kwargs.get('calculates', None),
86
- used_calculates=kwargs.get('used_calculates', None),
87
- replace_reference=True,
88
- warn=False,
89
- codesystems=kwargs.get('codesystems', None)
90
- )
91
- cur_group.activity.calculates.append(calc)
92
- cur_group.activity.nodes[calc.id] = calc
77
+ if calc not in cur_group.calculates:
78
+ cur_group.calculates.append(calc)
93
79
  processed_nodes.add(calc)
94
-
80
+
95
81
  cur_group.relevance = TriccOperation(
96
82
  TriccOperator.ISTRUE,
97
83
  [calc]
98
84
  )
99
-
85
+
100
86
  relevance_expression = cur_group.relevance
101
87
  relevance_expression = get_applicability_expression(cur_group, processed_nodes, process, relevance_expression)
102
88
  relevance_expression = get_prev_instance_skip_expression(cur_group, processed_nodes, process, relevance_expression)
103
89
  relevance_expression = get_process_skip_expression(cur_group, processed_nodes, process, relevance_expression)
104
90
 
91
+
105
92
  if not relevance:
106
93
  relevance_expression_str = ""
107
94
  elif isinstance(relevance_expression, (TriccOperation, TriccStatic)):
108
- relevance_expression = process_operation_reference(
109
- relevance_expression,
110
- cur_group,
111
- processed_nodes=processed_nodes,
112
- calculates=kwargs.get('calculates', None),
113
- used_calculates=kwargs.get('used_calculates', None),
114
- replace_reference=True,
115
- warn=False,
116
- codesystems=kwargs.get('codesystems', None),
117
- ) or relevance_expression
118
- if relevance_expression:
119
- relevance_expression_str = strategy.get_tricc_operation_expression(relevance_expression)
120
-
95
+ relevance_expression_str = strategy.get_tricc_operation_expression(relevance_expression)
96
+
121
97
  # group
122
98
  values = []
123
99
  for column in SURVEY_MAP:
@@ -138,7 +114,7 @@ def start_group(
138
114
  df_survey.loc[len(df_survey)] = values
139
115
 
140
116
  # calc
141
- if calc and len(df_calculate[df_calculate["name"] == get_export_group_name(name)]) == 0:
117
+ if calc and len(df_calculate[df_calculate["name"] == get_export_group_name(name)]) == 0:
142
118
  calc_values = []
143
119
  for column in SURVEY_MAP:
144
120
  if column == "type":
@@ -147,7 +123,7 @@ def start_group(
147
123
  value = get_export_name(calc)
148
124
  calc_values.append(value)
149
125
  elif column == "calculation":
150
- calc_values.append(f"number({strategy.get_tricc_operation_expression(calc.expression)})")
126
+ calc_values.append(f"number({strategy.get_tricc_operation_expression(calc.expression)}")
151
127
  elif column == "relevance":
152
128
  calc_values.append("")
153
129
  else:
@@ -357,7 +333,8 @@ def generate_choice_filter(strategy, node):
357
333
  choice_filter = TriccOperation(TriccOperator.OR, [basic])
358
334
  for k, op in relevances.items():
359
335
  choice_filter.append(
360
- and_join(
336
+ TriccOperation(
337
+ TriccOperator.AND,
361
338
  [
362
339
  TriccOperation(
363
340
  TriccOperator.EQUAL,
@@ -367,7 +344,7 @@ def generate_choice_filter(strategy, node):
367
344
  ],
368
345
  ),
369
346
  op,
370
- ]
347
+ ],
371
348
  )
372
349
  )
373
350
  return strategy.get_tricc_operation_expression(choice_filter)
@@ -432,7 +409,7 @@ def get_attr_if_exists(strategy, node, column, map_array):
432
409
  return ""
433
410
 
434
411
 
435
- def get_more_info_select(strategy, base_name, relevance):
412
+ def get_more_info_select(strategy, node):
436
413
  values = []
437
414
  for column in SURVEY_MAP:
438
415
  if column == "type":
@@ -440,30 +417,28 @@ def get_more_info_select(strategy, base_name, relevance):
440
417
  elif column == "label":
441
418
  values.append(strategy.get_empty_label())
442
419
  elif column == "name":
443
- values.append(base_name + "_optin")
420
+ values.append(get_export_name(node) + "_optin")
421
+ elif column == "hint":
422
+ print(get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True))
423
+ values.append(get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True))
444
424
  elif column == "relevance":
445
- values.append(relevance)
425
+ values.append(get_xfrom_trad(strategy, node.parent, column, SURVEY_MAP))
446
426
  else:
447
427
  values.append(get_xfrom_trad(strategy, None, column, SURVEY_MAP))
448
428
  return values
449
429
 
450
430
 
451
- def get_more_info_message(strategy, base_name, message):
431
+ def get_more_info_message(strategy, node):
452
432
  values = []
453
433
  for column in SURVEY_MAP:
454
434
  if column == "type":
455
435
  values.append("note")
456
- elif column == "name":
457
- values.append(base_name)
458
436
  elif column == "relevance":
459
- values.append(f"${{{base_name}_optin}} = 1")
460
- elif column.startswith("label"):
461
- arr = column.split("::")
462
- column = arr[0]
463
- trad = arr[1] if len(arr) == 2 else None
464
- values.append(langs.get_trads(message, trad=trad))
437
+ values.append(f"${{{get_export_name(node)}_optin}} = 1")
438
+ elif column.startswith("hint"):
439
+ values.append(langs.get_trads("", trad=None))
465
440
  else:
466
- values.append(get_xfrom_trad(strategy, None, column, SURVEY_MAP, clean_html=True))
441
+ values.append(get_xfrom_trad(strategy, node, column, SURVEY_MAP, clean_html=True))
467
442
  return values
468
443
 
469
444
 
@@ -484,13 +459,6 @@ def get_more_info_choice(strategy):
484
459
  return values
485
460
 
486
461
 
487
- def inject_more_info(strategy, base_name, relevance, message, df_survey, df_choice):
488
- df_survey.loc[len(df_survey)] = get_more_info_select(strategy, base_name, relevance)
489
- df_survey.loc[len(df_survey)] = get_more_info_message(strategy, base_name, message)
490
- if len(df_choice[(df_choice["list_name"] == "more_info")]) == 0:
491
- df_choice.loc[len(df_choice)] = get_more_info_choice(strategy)
492
-
493
-
494
462
  def generate_xls_form_export(
495
463
  strategy,
496
464
  node,
@@ -501,7 +469,6 @@ def generate_xls_form_export(
501
469
  df_calculate,
502
470
  cur_group,
503
471
  calculates,
504
- help_before=False,
505
472
  **kwargs,
506
473
  ):
507
474
  # check that all prev nodes were processed
@@ -513,15 +480,6 @@ def generate_xls_form_export(
513
480
  codesystems=kwargs.get("codesystems", None),
514
481
  ):
515
482
  if node not in processed_nodes:
516
- if help_before and getattr(node, 'help', None):
517
- base_name=f"{get_export_name(node)}_more_info"
518
- inject_more_info(
519
- strategy,
520
- base_name,
521
- get_xfrom_trad(strategy, node, "relevance", SURVEY_MAP),
522
- node.help,
523
- df_survey,
524
- df_choice)
525
483
  add_calculate(calculates, node)
526
484
  if node.group != cur_group and not isinstance(node, TriccNodeSelectOption):
527
485
  return False
@@ -549,14 +507,10 @@ def generate_xls_form_export(
549
507
  ):
550
508
  df_choice.loc[len(df_choice)] = values
551
509
  elif isinstance(node, TriccNodeMoreInfo):
552
- inject_more_info(
553
- strategy,
554
- get_export_name(node),
555
- get_xfrom_trad(strategy, node.parent, "relevance", SURVEY_MAP),
556
- node.label,
557
- df_survey,
558
- df_choice
559
- )
510
+ df_survey.loc[len(df_survey)] = get_more_info_select(strategy, node)
511
+ df_survey.loc[len(df_survey)] = get_more_info_message(strategy, node)
512
+ if len(df_choice[(df_choice["list_name"] == "more_info")]) == 0:
513
+ df_choice.loc[len(df_choice)] = get_more_info_choice(strategy)
560
514
  elif node.tricc_type in ODK_TRICC_TYPE_MAP and ODK_TRICC_TYPE_MAP[node.tricc_type] is not None:
561
515
  if ODK_TRICC_TYPE_MAP[node.tricc_type] == "calculate":
562
516
  values = []
@@ -583,16 +537,6 @@ def generate_xls_form_export(
583
537
  logger.warning("node {} have an unmapped type {}".format(node.get_name(), node.tricc_type))
584
538
  else:
585
539
  logger.warning("node {} have an unsupported type {}".format(node.get_name(), node.tricc_type))
586
- if not help_before and getattr(node, 'help', None):
587
- base_name=f"{get_export_name(node)}_more_info"
588
- inject_more_info(
589
- strategy,
590
- base_name,
591
- get_xfrom_trad(strategy, node, "relevance", SURVEY_MAP),
592
- node.help,
593
- df_survey,
594
- df_choice
595
- )
596
540
  # continue walk °
597
541
  return True
598
542
  return False
@@ -43,9 +43,6 @@ class BaseOutPutStrategy:
43
43
 
44
44
  self.export(self.project.start_pages, version=version)
45
45
 
46
- logger.info("validate the output")
47
- self.validate()
48
-
49
46
  # walking function
50
47
  def process_base(self, start_pages, **kwargs):
51
48
  # for each node, check if condition is required issubclass(TriccNodeDisplayModel)
@@ -109,10 +106,6 @@ class BaseOutPutStrategy:
109
106
  def export(self, **kwargs):
110
107
  pass
111
108
 
112
- @abc.abstractmethod
113
- def validate(self):
114
- pass
115
-
116
109
  def tricc_operation_equal(self, ref_expressions):
117
110
  # r[0] = r[1]
118
111
  raise NotImplementedError("This type of opreration is not supported in this strategy")
@@ -145,16 +145,15 @@ class DHIS2Strategy(BaseOutPutStrategy):
145
145
  raise NotImplementedError(
146
146
  f"This type of operation '{operation.operator}' is not supported in this strategy"
147
147
  )
148
-
149
148
  def get_display(self, node):
150
149
  if hasattr(node, 'label') and node.label:
151
- ret = node.label
150
+ ret = node.label
152
151
  elif hasattr(node, 'name') and node.name:
153
152
  ret = node.name
154
153
  else:
155
154
  ret = str(node.id)
156
- return ret.replace('\u00a0', ' ').strip()
157
-
155
+ return ret.replace('\u00a0', ' ').strip()
156
+
158
157
  def execute(self):
159
158
  version = datetime.datetime.now().strftime("%Y%m%d%H%M")
160
159
  logger.info(f"build version: {version}")
@@ -274,12 +273,13 @@ class DHIS2Strategy(BaseOutPutStrategy):
274
273
  "id": de_id,
275
274
  "name": self.get_export_name(node),
276
275
  "shortName": node.name[:50],
277
- "displayFormName": self.get_display(node),
276
+ "displayFormName":self.get_display(node),
278
277
  "formName": self.get_display(node),
279
278
  "valueType": value_type,
280
279
  "domainType": "TRACKER",
281
280
  "aggregationType": "NONE"
282
281
  }
282
+
283
283
  if issubclass(node.__class__, TriccNodeSelect) and not isinstance(node, TriccNodeSelectYesNo):
284
284
  data_element["optionSetValue"] = True
285
285
 
@@ -736,15 +736,15 @@ class DHIS2Strategy(BaseOutPutStrategy):
736
736
  return f"#{{{node_id}}}"
737
737
  elif issubclass(r.__class__, TriccNodeCalculateBase):
738
738
  # Use variable name from concept_map
739
- node_id = self.get_export_name(r)
739
+ node_id = self.get_export_name(r)
740
740
  return f"#{{{node_id}}}"
741
741
  elif issubclass(r.__class__, TriccNodeInputModel):
742
742
  # Use variable name from concept_map
743
- node_id = self.get_export_name(r)
743
+ node_id = self.get_export_name(r)
744
744
  return f"#{{{node_id}}}"
745
745
  elif issubclass(r.__class__, TriccNodeBaseModel):
746
746
  # Use variable name from concept_map
747
- node_id = self.get_export_name(r)
747
+ node_id = self.get_export_name(r)
748
748
  return f"#{{{node_id}}}"
749
749
  else:
750
750
  raise NotImplementedError(f"This type of node {r.__class__.__name__} is not supported within an operation")
@@ -410,7 +410,7 @@ class OpenMRSStrategy(BaseOutPutStrategy):
410
410
  elif issubclass(r.__class__, TriccNodeInputModel):
411
411
  return self.get_export_name(r)
412
412
  elif issubclass(r.__class__, TriccNodeSelect):
413
- return "(" + self.get_export_name(r) + " ?? [])"
413
+ return "(" + self.get_export_name(r) + " ?? [])"
414
414
  elif issubclass(r.__class__, TriccNodeBaseModel):
415
415
  return self.get_export_name(r)
416
416
  else:
@@ -458,7 +458,7 @@ class OpenMRSStrategy(BaseOutPutStrategy):
458
458
  return f"!({ref_expressions[0]})"
459
459
 
460
460
  def tricc_operation_plus(self, ref_expressions):
461
- return "(" + " + ".join(ref_expressions) + ")"
461
+ return "(" + " + ".join(ref_expressions) +")"
462
462
 
463
463
  def tricc_operation_minus(self, ref_expressions):
464
464
  if len(ref_expressions) > 1: