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
tricc_oo/__init__.py CHANGED
@@ -5,9 +5,3 @@ Collect easy.
5
5
  """
6
6
 
7
7
  __version__ = "1.0.2"
8
-
9
- from .models.base import *
10
- from .models.calculate import *
11
- from .models.tricc import *
12
- from .serializers import *
13
-
@@ -1,5 +1,4 @@
1
1
  from typing import Dict, List, Any
2
- import json
3
2
  from fhir.resources.codesystem import CodeSystem
4
3
  from tricc_oo.models.ocl import (
5
4
  OCLConcept,
@@ -7,15 +6,16 @@ from tricc_oo.models.ocl import (
7
6
  OCLDetailedName,
8
7
  OCLDetailedDescription,
9
8
  OclConstants,
10
- get_data_type
11
9
  )
12
10
 
11
+
13
12
  def extract_properties_metadata(fhir_cs: CodeSystem) -> Dict[str, Dict]:
14
13
  """
15
- Extracts property definitions from FHIR CodeSystem and converts them to OCL attribute types
14
+ Extracts property definitions from FHIR CodeSystem and converts them
15
+ to OCL attribute types
16
16
  """
17
17
  property_types = {}
18
- if hasattr(fhir_cs, 'property') and fhir_cs.property:
18
+ if hasattr(fhir_cs, "property") and fhir_cs.property:
19
19
  for prop in fhir_cs.property:
20
20
  # Map FHIR property types to OCL datatypes
21
21
  fhir_type = prop.type
@@ -26,76 +26,85 @@ def extract_properties_metadata(fhir_cs: CodeSystem) -> Dict[str, Dict]:
26
26
  "decimal": "Numeric",
27
27
  "integer": "Numeric",
28
28
  "dateTime": "DateTime",
29
- "string": "Text"
29
+ "string": "Text",
30
30
  }.get(fhir_type, "Text")
31
-
31
+
32
32
  property_types[prop.code] = {
33
33
  "name": prop.code,
34
34
  "datatype": ocl_type,
35
- "description": prop.description if hasattr(prop, 'description') else ""
35
+ "description": prop.description if hasattr(prop, "description") else "",
36
36
  }
37
37
  return property_types
38
38
 
39
+
39
40
  def get_fhir_concept_datatype(concept):
40
-
41
- datatype = extract_concept_properties(concept, ['datatype'])
41
+ datatype = extract_concept_properties(concept, ["datatype"])
42
42
  if datatype:
43
- return datatype['datatype']
43
+ return datatype["datatype"]
44
44
  else:
45
45
  return OclConstants.DATA_TYPE_NONE
46
46
 
47
+
47
48
  def extract_concept_properties(concept, property_types: List) -> List[Dict]:
48
49
  """
49
50
  Extracts properties from a FHIR concept and converts them to OCL attributes
50
51
  """
51
52
  properties = {}
52
- if hasattr(concept, 'property') and concept.property:
53
+ if hasattr(concept, "property") and concept.property:
53
54
  for prop in concept.property:
54
55
  if prop.code in property_types:
55
56
  # Handle different property value types
56
- if getattr(prop, 'valueCode', None):
57
+ if getattr(prop, "valueCode", None):
57
58
  value = prop.valueCode
58
- elif getattr(prop, 'valueCoding', None):
59
+ elif getattr(prop, "valueCoding", None):
59
60
  value = prop.valueCoding.code
60
- elif getattr(prop, 'valueString', None):
61
+ elif getattr(prop, "valueString", None):
61
62
  value = prop.valueString
62
- elif getattr(prop, 'valueBoolean', None):
63
+ elif getattr(prop, "valueBoolean", None):
63
64
  value = prop.valueBoolean
64
- elif getattr(prop, 'valueInteger', None):
65
+ elif getattr(prop, "valueInteger", None):
65
66
  value = prop.valueInteger
66
- elif getattr(prop, 'valueDecimal', None):
67
+ elif getattr(prop, "valueDecimal", None):
67
68
  value = prop.valueDecimal
68
- elif getattr(prop, 'valueDateTime', None):
69
+ elif getattr(prop, "valueDateTime", None):
69
70
  value = prop.valueDateTime
70
71
  else:
71
72
  continue
72
73
  if value:
73
74
  properties[prop.code] = value
74
75
  return properties
75
-
76
-
76
+
77
+
77
78
  def get_attributes_from_concept_properties(concept, property_types: Dict) -> List[Dict]:
78
79
  attributes = []
79
80
  properties = extract_concept_properties(concept, property_types=list(property_types))
80
81
  for code, value in properties.items():
81
- attributes.append({
82
- "type": "Attribute",
83
- "attribute_type": code,
84
- "value": value,
85
- "value_type": property_types[code]["datatype"]
86
- })
82
+ attributes.append(
83
+ {
84
+ "type": "Attribute",
85
+ "attribute_type": code,
86
+ "value": value,
87
+ "value_type": property_types[code]["datatype"],
88
+ }
89
+ )
87
90
  return attributes
88
91
 
89
- def transform_fhir_to_ocl(fhir_codesystem_json: Dict, source_name: str, source_owner: str, source_owner_type: str) -> List[Dict[str, Any]]:
92
+
93
+ def transform_fhir_to_ocl(
94
+ fhir_codesystem_json: Dict,
95
+ source_name: str,
96
+ source_owner: str,
97
+ source_owner_type: str,
98
+ ) -> List[Dict[str, Any]]:
90
99
  """
91
100
  Transforms a FHIR CodeSystem resource into an OCL bulk upload JSON payload.
92
-
101
+
93
102
  Args:
94
103
  fhir_codesystem_json: JSON representation of the FHIR CodeSystem resource
95
104
  source_name: Name of the OCL Source
96
105
  source_owner: Owner of the OCL Source (organization or user)
97
106
  source_owner_type : User or Organization
98
-
107
+
99
108
  Returns:
100
109
  List of dictionaries representing OCL bulk upload format
101
110
  """
@@ -109,8 +118,7 @@ def transform_fhir_to_ocl(fhir_codesystem_json: Dict, source_name: str, source_o
109
118
  ocl_payload = []
110
119
 
111
120
  # Add source metadata
112
-
113
-
121
+ source_extras = {}
114
122
  # Add property definitions to extras
115
123
  if property_types:
116
124
  source_extras["attribute_types"] = list(property_types.values())
@@ -123,16 +131,17 @@ def transform_fhir_to_ocl(fhir_codesystem_json: Dict, source_name: str, source_o
123
131
  owner=source_owner,
124
132
  owner_type=source_owner_type,
125
133
  name=fhir_cs.name or "Unnamed Source",
126
- full_name=fhir_cs.title if hasattr(fhir_cs, 'title') else fhir_cs.name,
134
+ full_name=fhir_cs.title if hasattr(fhir_cs, "title") else fhir_cs.name,
127
135
  description=fhir_cs.description or "",
128
136
  source_type="Dictionary",
129
137
  default_locale="en",
130
138
  supported_locales=["en"],
139
+ extras=source_extras,
131
140
  )
132
- )
141
+ )
133
142
 
134
143
  # Transform concepts
135
- if hasattr(fhir_cs, 'concept') and fhir_cs.concept:
144
+ if hasattr(fhir_cs, "concept") and fhir_cs.concept:
136
145
  for concept in fhir_cs.concept:
137
146
  datatype = get_fhir_concept_datatype(concept)
138
147
  ocl_concept = OCLConcept(
@@ -149,15 +158,17 @@ def transform_fhir_to_ocl(fhir_codesystem_json: Dict, source_name: str, source_o
149
158
  name_type=OclConstants.NAME_TYPE_FULLY_SPECIFIED,
150
159
  )
151
160
  ],
152
- descriptions=[]
161
+ descriptions=[],
153
162
  )
154
163
 
155
164
  # Add definition if present
156
- if hasattr(concept, 'definition') and concept.definition:
157
- ocl_concept.descriptions.append(OCLDetailedDescription(
158
- description=concept.definition,
159
- locale="en",
160
- ))
165
+ if hasattr(concept, "definition") and concept.definition:
166
+ ocl_concept.descriptions.append(
167
+ OCLDetailedDescription(
168
+ description=concept.definition,
169
+ locale="en",
170
+ )
171
+ )
161
172
 
162
173
  # Extract and add properties as attributes
163
174
  attributes = get_attributes_from_concept_properties(concept, property_types)
@@ -1,3 +1,4 @@
1
+ # flake8: noqa
1
2
  # Generated from cql.g4 by ANTLR 4.13.2
2
3
  from antlr4 import *
3
4
  from io import StringIO
@@ -1,3 +1,4 @@
1
+ # flake8: noqa
1
2
  # Generated from cql.g4 by ANTLR 4.13.2
2
3
  from antlr4 import *
3
4
  if "." in __name__:
@@ -1,3 +1,4 @@
1
+ # flake8: noqa
1
2
  # Generated from cql.g4 by ANTLR 4.13.2
2
3
  # encoding: utf-8
3
4
  from antlr4 import *
@@ -1,3 +1,4 @@
1
+ # flake8: noqa
1
2
  # Generated from cql.g4 by ANTLR 4.13.2
2
3
  from antlr4 import *
3
4
  if "." in __name__: