tricc-oo 1.5.23__py3-none-any.whl → 1.5.25__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 CHANGED
@@ -1,16 +1,17 @@
1
- from tricc_oo.strategies.output.spice import SpiceStrategy
2
- from tricc_oo.strategies.output.xlsform_cht_hf import XLSFormCHTHFStrategy
3
- from tricc_oo.strategies.output.xlsform_cht import XLSFormCHTStrategy
4
- from tricc_oo.strategies.output.xlsform_cdss import XLSFormCDSSStrategy
5
- from tricc_oo.strategies.output.xls_form import XLSFormStrategy
6
- from tricc_oo.strategies.input.drawio import DrawioStrategy
1
+ from tricc_oo.strategies.output.spice import SpiceStrategy # noqa: F401
2
+ from tricc_oo.strategies.output.xlsform_cht_hf import XLSFormCHTHFStrategy # noqa: F401
3
+ from tricc_oo.strategies.output.xlsform_cht import XLSFormCHTStrategy # noqa: F401
4
+ from tricc_oo.strategies.output.xlsform_cdss import XLSFormCDSSStrategy # noqa: F401
5
+ from tricc_oo.strategies.output.xls_form import XLSFormStrategy # noqa: F401
6
+ from tricc_oo.strategies.output.openmrs_form import OpenMRSStrategy # noqa: F401
7
+ from tricc_oo.strategies.output.fhir_form import FHIRStrategy # noqa: F401
8
+ from tricc_oo.strategies.output.html_form import HTMLStrategy # noqa: F401
9
+ from tricc_oo.strategies.input.drawio import DrawioStrategy # noqa: F401
7
10
  import getopt
8
- import gettext
9
11
  import logging
10
12
  import os
11
13
  import sys
12
14
  import gc
13
- import shutil
14
15
  from pathlib import Path
15
16
 
16
17
  # set up logging to file
@@ -39,15 +40,15 @@ def setup_logger(
39
40
  level=logging.INFO,
40
41
  formatting="[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s",
41
42
  ):
42
- l = logging.getLogger(logger_name)
43
+ logger = logging.getLogger(logger_name)
43
44
  formatter = logging.Formatter(formatting)
44
45
  file_handler = logging.FileHandler(log_file, mode="w+")
45
46
  file_handler.setFormatter(formatter)
46
47
  stream_handler = logging.StreamHandler()
47
48
  stream_handler.setFormatter(formatter)
48
49
 
49
- l.setLevel(level)
50
- l.addHandler(file_handler)
50
+ logger.setLevel(level)
51
+ logger.addHandler(file_handler)
51
52
 
52
53
 
53
54
  class ColorFormatter(logging.Formatter):
tests/test_cql.py CHANGED
@@ -53,9 +53,9 @@ class TestCql(unittest.TestCase):
53
53
 
54
54
  def test_case(self):
55
55
  case_cql = """
56
- case AgeInMonths()
57
- when 0 then 'newborn'
58
- when 1 then 'newborn'
56
+ case AgeInMonths()
57
+ when 0 then 'newborn'
58
+ when 1 then 'newborn'
59
59
  else 'child' end
60
60
  """
61
61
  case_operation = transform_cql_to_operation(case_cql)
@@ -72,7 +72,7 @@ class TestCql(unittest.TestCase):
72
72
 
73
73
  def test_ifs(self):
74
74
  case_cql = """
75
- case
75
+ case
76
76
  when AgeInMonths() <= 2 then true
77
77
  when AgeInYears() > 5 then true
78
78
  else false end
@@ -6,9 +6,13 @@ from fhir.resources.codesystem import (
6
6
 
7
7
  from fhir.resources.valueset import ValueSet
8
8
  import logging
9
+ import uuid
9
10
 
10
11
  logger = logging.getLogger("default")
11
12
 
13
+ # Namespace for deterministic UUIDs
14
+ UUID_NAMESPACE = uuid.UUID('12345678-1234-5678-9abc-def012345678')
15
+
12
16
 
13
17
  def lookup_codesystems_code(codesystems, ref):
14
18
  if ref.startswith("final."):
@@ -83,7 +87,8 @@ def check_and_add_concept(code_system: CodeSystem, code: str, display: str, attr
83
87
  new_concept = concept
84
88
  if not new_concept:
85
89
  # Add the new concept if it does not exist
86
- new_concept = CodeSystemConcept.construct(code=code, display=display)
90
+ concept_id = str(uuid.uuid5(UUID_NAMESPACE, display))
91
+ new_concept = CodeSystemConcept.construct(code=code, display=display, id=concept_id)
87
92
  if not hasattr(code_system, "concept"):
88
93
  code_system.concept = []
89
94
  code_system.concept.append(new_concept)
@@ -1,8 +1,9 @@
1
1
  import logging
2
- from tricc_oo.converters.utils import clean_name
3
- from tricc_oo.models.tricc import TriccNodeSelectOption
2
+ from tricc_oo.converters.utils import clean_name, clean_str
3
+ from tricc_oo.models.tricc import TriccNodeSelectOption, TRICC_TRUE_VALUE, TRICC_FALSE_VALUE
4
4
  from tricc_oo.models.calculate import TriccNodeInput
5
- from tricc_oo.models.base import TriccNodeBaseModel
5
+ from tricc_oo.models.base import TriccNodeBaseModel, TriccStatic, TriccReference
6
+
6
7
  # from babel import _
7
8
 
8
9
  # TRICC_SELECT_MULTIPLE_CALC_EXPRESSION = "count-selected(${{{0}}}) - number(selected(${{{0}}},'opt_none'))"
@@ -18,6 +19,10 @@ TRICC_NEGATE = "not({})"
18
19
  # TRICC_AND_EXPRESSION = '{0} and {1}'
19
20
  VERSION_SEPARATOR = "_Vv_"
20
21
  INSTANCE_SEPARATOR = "_Ii_"
22
+ BOOLEAN_MAP = {
23
+ str(TRICC_TRUE_VALUE): 1,
24
+ str(TRICC_FALSE_VALUE): 0,
25
+ }
21
26
 
22
27
 
23
28
  logger = logging.getLogger("default")
@@ -26,9 +31,36 @@ logger = logging.getLogger("default")
26
31
 
27
32
 
28
33
  def get_export_name(node, replace_dots=True):
29
- if isinstance(node, str):
30
- return clean_name(node, replace_dots=replace_dots)
31
- if node.export_name is None:
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)):
42
+ if isinstance(node, TriccNodeSelectOption):
43
+ value = node.name
44
+ elif isinstance(node, TriccStatic):
45
+ value = node.value
46
+ else:
47
+ value = node
48
+ if isinstance(value, bool): # or r.value in ('true', 'false')
49
+ export_name = BOOLEAN_MAP[str(TRICC_TRUE_VALUE)] if value else BOOLEAN_MAP[str(TRICC_FALSE_VALUE)]
50
+ elif value == TRICC_TRUE_VALUE:
51
+ export_name = BOOLEAN_MAP[str(TRICC_TRUE_VALUE)]
52
+ elif value == TRICC_FALSE_VALUE:
53
+ export_name = BOOLEAN_MAP[str(TRICC_FALSE_VALUE)]
54
+ elif isinstance(value, str):
55
+ export_name = f"'{clean_str(value, replace_dots=replace_dots)}'"
56
+ else:
57
+ export_name = str(value)
58
+ if hasattr(node, 'export_name'):
59
+ node.export_name = export_name
60
+ return export_name
61
+ elif not hasattr(node, 'export_name'):
62
+ return node
63
+ else:
32
64
  node.gen_name()
33
65
  if isinstance(node, TriccNodeSelectOption):
34
66
  node.export_name = node.name
@@ -41,8 +73,7 @@ def get_export_name(node, replace_dots=True):
41
73
  node.export_name = clean_name("load." + node.name, replace_dots=replace_dots)
42
74
  else:
43
75
  node.export_name = clean_name(node.name, replace_dots=replace_dots)
44
-
45
- return node.export_name
76
+ return node.export_name
46
77
 
47
78
 
48
79
  def get_list_names(list):
@@ -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:]
tricc_oo/models/tricc.py CHANGED
@@ -15,6 +15,8 @@ import logging
15
15
 
16
16
 
17
17
  logger = logging.getLogger(__name__)
18
+ TRICC_TRUE_VALUE = "true"
19
+ TRICC_FALSE_VALUE = "false"
18
20
 
19
21
 
20
22
  class TriccNodeCalculateBase(TriccNodeBaseModel):
@@ -404,7 +406,7 @@ class TriccNodeSelectYesNo(TriccNodeSelectOne):
404
406
  pass
405
407
 
406
408
 
407
- class TriccNodeAcceptDiagnostic(TriccNodeSelectOne):
409
+ class TriccNodeAcceptDiagnostic(TriccNodeSelectYesNo):
408
410
  severity: Optional[str] = None
409
411
  priority: Union[float, int, None] = None
410
412
 
@@ -3,7 +3,7 @@ import hashlib
3
3
 
4
4
  # from bs4 import BeautifulSoup
5
5
  from tricc_oo.converters.tricc_to_xls_form import (
6
- get_export_name,
6
+ get_export_name, BOOLEAN_MAP
7
7
  )
8
8
  from tricc_oo.models.lang import SingletonLangClass
9
9
  from tricc_oo.converters.utils import clean_name, remove_html
@@ -13,7 +13,6 @@ from tricc_oo.models.base import (
13
13
  )
14
14
  from tricc_oo.models.calculate import (
15
15
  TriccNodeDisplayCalculateBase,
16
-
17
16
  )
18
17
  from tricc_oo.models.tricc import (
19
18
  TriccNodeActivity, TriccNodeBaseModel, TriccNodeSelectMultiple, TriccNodeSelectOption,
@@ -29,8 +28,6 @@ from tricc_oo.visitors.tricc import (
29
28
  is_ready_to_process,
30
29
  process_reference,
31
30
  add_calculate,
32
- TRICC_TRUE_VALUE,
33
- TRICC_FALSE_VALUE,
34
31
  get_applicability_expression,
35
32
  get_prev_instance_skip_expression,
36
33
  get_process_skip_expression,
@@ -41,11 +38,6 @@ logger = logging.getLogger("default")
41
38
  langs = SingletonLangClass()
42
39
  TRICC_CALC_EXPRESSION = "${{{0}}}>0"
43
40
 
44
- BOOLEAN_MAP = {
45
- str(TRICC_TRUE_VALUE): 1,
46
- str(TRICC_FALSE_VALUE): 0,
47
- }
48
-
49
41
 
50
42
  def start_group(
51
43
  strategy,
@@ -3,7 +3,7 @@ import os
3
3
 
4
4
  from tricc_oo.converters.xml_to_tricc import create_activity
5
5
  from tricc_oo.visitors.tricc import (
6
- process_calculate,
6
+ load_calculate,
7
7
  set_prev_next_node,
8
8
  replace_node,
9
9
  stashed_node_func,
@@ -47,7 +47,7 @@ class DrawioStrategy(BaseInputStrategy):
47
47
  # add save nodes and merge nodes
48
48
  stashed_node_func(
49
49
  start_page.root,
50
- process_calculate,
50
+ load_calculate,
51
51
  used_calculates=used_calculates,
52
52
  calculates=calculates,
53
53
  recursive=False,
@@ -83,6 +83,7 @@ class BaseOutPutStrategy:
83
83
  # node function
84
84
  @abc.abstractmethod
85
85
  def generate_calculate(self, node, **kwargs):
86
+ # called to generate the calculates on the project
86
87
  pass
87
88
 
88
89
  @abc.abstractmethod
@@ -91,10 +92,14 @@ class BaseOutPutStrategy:
91
92
 
92
93
  @abc.abstractmethod
93
94
  def generate_relevance(self, node, **kwargs):
95
+ # called to generate the references on the project
96
+
94
97
  pass
95
98
 
96
99
  @abc.abstractmethod
97
100
  def generate_export(self, node, **kwargs):
101
+ # called to the project export
102
+
98
103
  pass
99
104
 
100
105
  @abc.abstractmethod
@@ -102,87 +107,116 @@ class BaseOutPutStrategy:
102
107
  pass
103
108
 
104
109
  def tricc_operation_equal(self, ref_expressions):
110
+ # r[0] = r[1]
105
111
  raise NotImplementedError("This type of opreration is not supported in this strategy")
106
112
 
107
113
  def tricc_operation_not_equal(self, ref_expressions):
114
+ # r[0] != r[1]
108
115
  raise NotImplementedError("This type of opreration is not supported in this strategy")
109
116
 
110
117
  def tricc_operation_not(self, ref_expressions):
118
+ # !r[0]
111
119
  raise NotImplementedError("This type of opreration is not supported in this strategy")
112
120
 
113
121
  def tricc_operation_and(self, ref_expressions):
122
+ # r[0] and r[1] ... and r[n]
114
123
  raise NotImplementedError("This type of opreration is not supported in this strategy")
115
124
 
116
125
  def tricc_operation_or(self, ref_expressions):
126
+ # r[0] or r[1] ... or r[n]
117
127
  raise NotImplementedError("This type of opreration is not supported in this strategy")
118
128
 
119
129
  def tricc_operation_or_and(self, ref_expressions):
130
+ # (r[0] or r[1] ... or r[n-1]) and r[n]
120
131
  raise NotImplementedError("This type of opreration is not supported in this strategy")
121
132
 
122
133
  def tricc_operation_native(self, ref_expressions):
134
+ # r[0](*r[1:])
123
135
  raise NotImplementedError("This type of opreration is not supported in this strategy")
124
136
 
125
137
  def tricc_operation_istrue(self, ref_expressions):
138
+ # r[0] is true
126
139
  raise NotImplementedError("This type of opreration is not supported in this strategy")
127
140
 
128
141
  def tricc_operation_isfalse(self, ref_expressions):
142
+ # r[0] is false
129
143
  raise NotImplementedError("This type of opreration is not supported in this strategy")
130
144
 
131
145
  def tricc_operation_selected(self, ref_expressions):
146
+ # for choice question (single or multiple) it returns true if the second reference is selected
147
+ # r[1] in r[0]
132
148
  raise NotImplementedError("This type of opreration is not supported in this strategy")
133
149
 
134
150
  def tricc_operation_more_or_equal(self, ref_expressions):
151
+ # r[0] >= r[1]
135
152
  raise NotImplementedError("This type of opreration is not supported in this strategy")
136
153
 
137
154
  def tricc_operation_less_or_equal(self, ref_expressions):
155
+ # r[0] <= r[1]
138
156
  raise NotImplementedError("This type of opreration is not supported in this strategy")
139
157
 
140
158
  def tricc_operation_more(self, ref_expressions):
159
+ # r[0] > r[1]
141
160
  raise NotImplementedError("This type of opreration is not supported in this strategy")
142
161
 
143
162
  def tricc_operation_less(self, ref_expressions):
163
+ # r[0] < r[1]
144
164
  raise NotImplementedError("This type of opreration is not supported in this strategy")
145
165
 
146
166
  def tricc_operation_between(self, ref_expressions):
167
+ # r[0] between r[1] and r[2]
147
168
  raise NotImplementedError("This type of opreration is not supported in this strategy")
148
169
 
149
170
  def tricc_operation_case(self, ref_expressions):
171
+ # case r[0] when r[1][0] then r[1][1] ... when r[n-1][0] then r[n-1][1] else (r[n] or None)
150
172
  raise NotImplementedError("This type of opreration is not supported in this strategy")
151
173
 
152
174
  def tricc_operation_if(self, ref_expressions):
175
+ # if r[0][0] then r[0][1] ... elif r[n-1][0] then r[n-1][1] else (r[n] or None)
153
176
  raise NotImplementedError("This type of opreration is not supported in this strategy")
154
177
 
155
178
  def tricc_operation_contains(self, ref_expressions):
179
+ # r[0] contains r[1]
156
180
  raise NotImplementedError("This type of opreration is not supported in this strategy")
157
181
 
158
182
  def tricc_operation_exists(self, ref_expressions):
183
+ # r[0] exists
159
184
  raise NotImplementedError("This type of opreration is not supported in this strategy")
160
185
 
161
186
  def tricc_operation_has_qualifier(self, ref_expressions):
187
+ # r[0] is a class and has r[1] qualifier
162
188
  raise NotImplementedError("This type of opreration is not supported in this strategy")
163
189
 
164
190
  def tricc_operation_zscore(self, ref_expressions):
191
+ # FIXME zscore((gender=r[0], Xfy=r[1], xfY=r[2])
165
192
  raise NotImplementedError("This type of opreration is not supported in this strategy")
166
193
 
167
194
  def tricc_operation_datetime_to_decimal(self, ref_expressions):
195
+ # cast r[0] in decimal
168
196
  raise NotImplementedError("This type of opreration is not supported in this strategy")
169
197
 
170
198
  def tricc_operation_round(self, ref_expressions):
199
+ # round(r[0], r[1])
171
200
  raise NotImplementedError("This type of opreration is not supported in this strategy")
172
201
 
173
202
  def tricc_operation_izscore(self, ref_expressions):
203
+ # FIXME izscore(gender=r[0], Z=r[1], xfY=r[2])
174
204
  raise NotImplementedError("This type of opreration is not supported in this strategy")
175
205
 
176
206
  def tricc_operation_age_day(self, ref_expressions):
207
+ # Patient age in day
177
208
  raise NotImplementedError("This type of opreration is not supported in this strategy")
178
209
 
179
210
  def tricc_operation_age_month(self, ref_expressions):
211
+ # Patient age in Month
180
212
  raise NotImplementedError("This type of opreration is not supported in this strategy")
181
213
 
182
214
  def tricc_operation_age_year(self, ref_expressions):
215
+ # Patient age in Years
183
216
  raise NotImplementedError("This type of opreration is not supported in this strategy")
184
217
 
185
218
  def tricc_operation_concatenate(self, ref_expressions):
219
+ # concatenate(*r)
186
220
  raise NotImplementedError("This type of opreration is not supported in this strategy")
187
221
 
188
222
  # Utils