Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions PlantUML/construct_mapping_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,21 @@
for elem in mapping:
# Niveau ressource
if row[1] == row[2]:
if resource not in extracted_data.keys():

Check warning on line 69 in PlantUML/construct_mapping_global.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary "keys()" call.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DDASPEsZhVbr4zW&open=AZ4L_DDASPEsZhVbr4zW&pullRequest=32
extracted_data[resource] = {'profil_id': row[6].split('/')[-1], 'base_fhir': row[1], 'urls': [row[5], row[6]], 'mapping': [], 'links': {}}
extracted_data[resource]['mapping'].append(elem['map'])
# Récupération des références
for row in data:
resource = row[0]
if row[1] != row[2]:
if row[3] is not None and row[4] is not None:
elem_types = json.loads(row[4])
for elem_type in elem_types:
if elem_type['code'] == 'Reference':
for target_profil in elem_type['targetProfile']:
for profil in extracted_data.keys():
if target_profil in extracted_data[profil]['urls']:
if profil not in extracted_data[resource]['links']:
extracted_data[resource]['links'][profil] = str(row[7]) + '..' + str(row[8])
if row[1] != row[2] and row[3] is not None and row[4] is not None:
elem_types = json.loads(row[4])
for elem_type in elem_types:
if elem_type['code'] == 'Reference':
for target_profil in elem_type['targetProfile']:
for profil in extracted_data.keys():
if target_profil in extracted_data[profil]['urls']:
if profil not in extracted_data[resource]['links']:
extracted_data[resource]['links'][profil] = str(row[7]) + '..' + str(row[8])
return extracted_data

# Génération du schéma de mapping global
Expand Down
68 changes: 36 additions & 32 deletions PlantUML/construct_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
class_func = mapping['class']
elements = mapping['elements']
references = mapping['references']
if resource_fhir not in structured_data.keys():

Check warning on line 136 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary "keys()" call.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zR&open=AZ4L_DA2SPEsZhVbr4zR&pullRequest=32
# Un dictionnaire par profil FHIR
structured_data[resource_fhir] = {}
# Pour chaque classe fonctionnelle, on distingue les éléments simples, les éléments complexes, les extensions et les références
Expand All @@ -153,14 +153,14 @@
# Elément de second niveau
if '.' in elem_fhir_sub:
elem_fhir_sub_base, elem_fhir_sub_sub = elem_fhir_sub.split('.', 1)
if elem_fhir_base not in complex_elements.keys():

Check warning on line 156 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary "keys()" call.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zS&open=AZ4L_DA2SPEsZhVbr4zS&pullRequest=32
complex_elements[elem_fhir_base] = {}
if elem_fhir_sub_base not in complex_elements[elem_fhir_base].keys():
complex_elements[elem_fhir_base][elem_fhir_sub_base] = {}
complex_elements[elem_fhir_base][elem_fhir_sub_base][elem_fhir_sub_sub] = elem_func
# Elément de premier niveau
else:
if elem_fhir_base not in complex_elements.keys():

Check warning on line 163 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary "keys()" call.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zT&open=AZ4L_DA2SPEsZhVbr4zT&pullRequest=32
complex_elements[elem_fhir_base] = {}
complex_elements[elem_fhir_base][elem_fhir_sub] = elem_func
else:
Expand All @@ -169,14 +169,14 @@
for ref in references:
elem_fhir = ref['fhir']
elem_fhir = elem_fhir.split('.', 1)[1]
if elem_fhir not in reference_elements.keys():

Check warning on line 172 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary "keys()" call.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zU&open=AZ4L_DA2SPEsZhVbr4zU&pullRequest=32
reference_elements[elem_fhir] = {'resource': ref['target_profile'].split('/')[-1] , 'mapping': [ref['mapping']]}
else:
reference_elements[elem_fhir]['mapping'].append(ref['mapping'])
structured_data[resource_fhir][class_func]['references'] = reference_elements
# Structuration des informations
for fhir_complex, func_complex in complex_elements.items():
if fhir_complex in simple_elements.keys():

Check warning on line 179 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary "keys()" call.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zV&open=AZ4L_DA2SPEsZhVbr4zV&pullRequest=32
structured_data[resource_fhir][class_func]['complex_elements'][fhir_complex] = {'mapping': simple_elements[fhir_complex], 'elements': func_complex}
else:
structured_data[resource_fhir][class_func]['complex_elements'][fhir_complex] = {'mapping': None, 'elements': func_complex}
Expand Down Expand Up @@ -278,6 +278,10 @@
# Génération des schémas
def generate_plantuml(structured_data, output_path, colors):
# Liste contenant les directions possibles pour les flèches
ICON_PLUS = '<&plus> '
MAP_STYLE = ' #back:WhiteSmoke;header:LightGray {'
INDENT = '\n '
ARROW_PLUS = ' => <&plus> '
directions = ['u', 'd', 'l', 'r']
for resource_fhir, class_mapping in structured_data.items():
# Liste des liens entre tableaux
Expand Down Expand Up @@ -305,14 +309,14 @@
complex_elements.append(elem_fhir)
elem_fhir_display = elem_fhir
if elem_fhir.startswith('extension:'):
elem_fhir_display = '<&plus> ' + remove_prefix(elem_fhir, 'extension:')
elem_fhir_display = ICON_PLUS + remove_prefix(elem_fhir, 'extension:')
extension = True
elif ':' in elem_fhir:
elem_fhir_display = '<&layers> ' + elem_fhir
if elem_func is None:
table_title = '\nmap "' + elem_fhir_display + '" as ' + elem_fhir_id + ' #back:WhiteSmoke;header:LightGray {'
table_title = '\nmap "' + elem_fhir_display + '" as ' + elem_fhir_id + MAP_STYLE

Check failure on line 317 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal '" as ' 9 times.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zQ&open=AZ4L_DA2SPEsZhVbr4zQ&pullRequest=32

Check failure on line 317 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal '\nmap "' 8 times.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zP&open=AZ4L_DA2SPEsZhVbr4zP&pullRequest=32
else:
table_title = '\nmap "' + elem_func + ' : ' + elem_fhir_display + '" as ' + elem_func_id + ' #back:WhiteSmoke;header:LightGray {'
table_title = '\nmap "' + elem_func + ' : ' + elem_fhir_display + '" as ' + elem_func_id + MAP_STYLE
tables += table_title
sub_table = None
# Eléments complexes de niveau 2
Expand All @@ -322,30 +326,30 @@
sub_elem_fhir_display = remove_prefix(sub_elem_fhir, 'extension:')
else:
if sub_elem_fhir.startswith('extension:'):
sub_elem_fhir_display = '<&plus> ' + remove_prefix(sub_elem_fhir, 'extension:')
sub_elem_fhir_display = ICON_PLUS + remove_prefix(sub_elem_fhir, 'extension:')
elif ':' in sub_elem_fhir:
sub_elem_fhir_display = '<&layers> ' + sub_elem_fhir
if isinstance(sub_elem_func, str):
tables += '\n ' + replace_non_alnum(sub_elem_func) + ' => ' + sub_elem_fhir_display
tables += INDENT + replace_non_alnum(sub_elem_func) + ' => ' + sub_elem_fhir_display
else:
if 'mapping' in sub_elem_func.keys():
if sub_elem_func['mapping'] is not None:
tables += '\n ' + replace_non_alnum(sub_elem_func) + ' => ' + sub_elem_fhir_display
sub_table = '\nmap "' + replace_non_alnum(sub_elem_func) + ' : ' + sub_elem_fhir_display + '" as ' + keep_alnum(sub_elem_func) + ' #back:WhiteSmoke;header:LightGray {'
tables += INDENT + replace_non_alnum(sub_elem_func) + ' => ' + sub_elem_fhir_display
sub_table = '\nmap "' + replace_non_alnum(sub_elem_func) + ' : ' + sub_elem_fhir_display + '" as ' + keep_alnum(sub_elem_func) + MAP_STYLE
else:
tables += '\n ' + sub_elem_fhir_display + ' *--> ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:'))
sub_table = '\nmap "' + sub_elem_fhir_display + '" as ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + ' #back:WhiteSmoke;header:LightGray {'
tables += INDENT + sub_elem_fhir_display + ' *--> ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:'))

Check failure on line 340 in PlantUML/construct_mappings.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal ' *--> ' 3 times.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4L_DA2SPEsZhVbr4zO&open=AZ4L_DA2SPEsZhVbr4zO&pullRequest=32
sub_table = '\nmap "' + sub_elem_fhir_display + '" as ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + MAP_STYLE
for sub_sub_elem_fhir, sub_sub_elem_func in sub_elem_func['elements'].items():
sub_table += '\n ' + replace_non_alnum(sub_sub_elem_func) + ' => ' + sub_sub_elem_fhir
sub_table += INDENT + replace_non_alnum(sub_sub_elem_func) + ' => ' + sub_sub_elem_fhir
sub_table += '\n}\n'
# Eléments complexes de niveau 3
else:
tables += '\n ' + sub_elem_fhir_display + ' *--> ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:'))
sub_table = '\nmap "' + sub_elem_fhir_display + '" as ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + ' #back:WhiteSmoke;header:LightGray {'
tables += INDENT + sub_elem_fhir_display + ' *--> ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:'))
sub_table = '\nmap "' + sub_elem_fhir_display + '" as ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + MAP_STYLE
for sub_sub_elem_fhir, sub_sub_elem_func in sub_elem_func.items():
if sub_sub_elem_fhir.startswith('extension:'):
sub_sub_elem_fhir = '<&plus> ' + remove_prefix(sub_sub_elem_fhir, 'extension:')
sub_table += '\n ' + replace_non_alnum(sub_sub_elem_func) + ' => ' + sub_sub_elem_fhir
sub_sub_elem_fhir = ICON_PLUS + remove_prefix(sub_sub_elem_fhir, 'extension:')
sub_table += INDENT + replace_non_alnum(sub_sub_elem_func) + ' => ' + sub_sub_elem_fhir
sub_table += '\n}\n'

tables += '\n}\n'
Expand All @@ -362,7 +366,7 @@
f.write('\nobject "**' + resource + '**" as ' + resource + color + ' {')
# Classes fonctionnelles sur la ressource
for sub_elem in sub_elements['mapping']:
f.write('\n ' + sub_elem)
f.write(INDENT + sub_elem)
f.write('\n}\n')
# Extensions (sous-tableaux pour 2 niveaux max)
main_table_extensions = ""
Expand All @@ -373,39 +377,39 @@
mapping_extension_global = extension_details['mapping']
if extension_details['type'] == 'complex':
if mapping_extension_global is not None:
main_table_extensions += '\n ' + replace_non_alnum(mapping_extension_global) + ' => <&plus> ' + extension
main_table_extensions += INDENT + replace_non_alnum(mapping_extension_global) + ARROW_PLUS + extension
links += class_func + '::' + replace_non_alnum(mapping_extension_global) + ' -' + directions[cpt_direction%4] + '-> ' + extension_id + '\n'
cpt_direction += 1
if extension not in complex_elements:
table_extensions += '\nmap "' + mapping_extension_global + ' : <&plus> ' + extension + '" as ' + extension_id + ' #back:WhiteSmoke;header:LightGray {'
table_extensions += '\nmap "' + mapping_extension_global + ' : ' + ICON_PLUS + extension + '" as ' + extension_id + MAP_STYLE
else:
main_table_extensions += '\n ' + extension + ' *-> ' + extension_id
main_table_extensions += INDENT + extension + ' *-> ' + extension_id
if extension not in complex_elements:
table_extensions += '\nmap "<&plus> ' + extension + '" as ' + extension_id + ' #back:WhiteSmoke;header:LightGray {'
table_extensions += '\nmap "' + ICON_PLUS + extension + '" as ' + extension_id + MAP_STYLE
if extension not in complex_elements:
complex_elements.append(extension)
for sub_elem_fhir, sub_elem_func in extension_details['elements'].items():
sub_elem_fhir_display = sub_elem_fhir
if isinstance(sub_elem_func, str):
if sub_elem_fhir.startswith('extension:'):
sub_elem_fhir_display = '<&plus> ' + remove_prefix(sub_elem_fhir, 'extension:')
table_extensions += '\n ' + replace_non_alnum(sub_elem_func) + ' => ' + sub_elem_fhir_display
sub_elem_fhir_display = ICON_PLUS + remove_prefix(sub_elem_fhir, 'extension:')
table_extensions += INDENT + replace_non_alnum(sub_elem_func) + ' => ' + sub_elem_fhir_display
else:
mapping_sub_extension_global = sub_elem_func['mapping']
if mapping_sub_extension_global is not None:
table_extensions += '\n ' + replace_non_alnum(mapping_sub_extension_global) + ' => <&plus> ' + sub_elem_fhir_display
table_sub_extensions = '\nmap "' + replace_non_alnum(mapping_sub_extension_global) + ' : <&plus> ' + sub_elem_fhir_display + '" as ' + keep_alnum(mapping_sub_extension_global) + ' #back:WhiteSmoke;header:LightGray {'
table_extensions += INDENT + replace_non_alnum(mapping_sub_extension_global) + ARROW_PLUS + sub_elem_fhir_display
table_sub_extensions = '\nmap "' + replace_non_alnum(mapping_sub_extension_global) + ' : ' + ICON_PLUS + sub_elem_fhir_display + '" as ' + keep_alnum(mapping_sub_extension_global) + MAP_STYLE
links += extension_id + '::' + replace_non_alnum(mapping_sub_extension_global) + ' -' + directions[cpt_direction%4] + '-> ' + keep_alnum(mapping_sub_extension_global) + '\n'
else:
table_extensions += '\n <&plus>' + sub_elem_fhir_display + ' *--> ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:'))
table_sub_extensions = '\nmap <&plus>"' + sub_elem_fhir_display + '" as ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + ' #back:WhiteSmoke;header:LightGray {'
table_extensions += INDENT + '<&plus>' + sub_elem_fhir_display + ' *--> ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:'))
table_sub_extensions = '\nmap <&plus>"' + sub_elem_fhir_display + '" as ' + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + MAP_STYLE
for sub_sub_elem_fhir, sub_sub_elem_func in sub_elem_func['elements'].items():
table_sub_extensions += '\n ' + replace_non_alnum(sub_sub_elem_func) + ' => ' + sub_sub_elem_fhir
table_sub_extensions += INDENT + replace_non_alnum(sub_sub_elem_func) + ' => ' + sub_sub_elem_fhir
table_sub_extensions += '\n}\n'
table_extensions += '\n}\n'
else:
if mapping_extension_global is not None:
main_table_extensions += '\n ' + replace_non_alnum(mapping_extension_global) + ' => <&plus> ' + extension
main_table_extensions += INDENT + replace_non_alnum(mapping_extension_global) + ARROW_PLUS + extension
f.write(table_sub_extensions)
f.write(table_extensions)
# Tableaux principal (un par classe fonctionnelle mappée sur la ressource)
Expand All @@ -417,23 +421,23 @@
for elem_fhir, elem_func in elements['simple_elements'].items():
elem_fhir_display = elem_fhir
if elem_fhir.startswith('extension:'):
elem_fhir_display = '<&plus> ' + remove_prefix(elem_fhir, 'extension:')
elem_fhir_display = ICON_PLUS + remove_prefix(elem_fhir, 'extension:')
elif ':' in elem_fhir:
elem_fhir_display = '<&layers> ' + elem_fhir
f.write('\n ' + replace_non_alnum(elem_func) + ' => ' + elem_fhir_display)
f.write(INDENT + replace_non_alnum(elem_func) + ' => ' + elem_fhir_display)
# Eléments complexes
for elem_fhir, sub_elements in elements['complex_elements'].items():
elem_fhir_display = elem_fhir
elem_fhir_id = keep_alnum(elem_fhir)
elem_func = sub_elements['mapping']
if elem_fhir.startswith('extension:'):
elem_fhir_display = '<&plus> ' + remove_prefix(elem_fhir, 'extension:')
elem_fhir_display = ICON_PLUS + remove_prefix(elem_fhir, 'extension:')
elif ':' in elem_fhir:
elem_fhir_display = '<&layers> ' + elem_fhir
if elem_func is None:
f.write('\n ' + elem_fhir_display + ' *-> ' + elem_fhir_id)
f.write(INDENT + elem_fhir_display + ' *-> ' + elem_fhir_id)
else:
f.write('\n ' + replace_non_alnum(elem_func) + ' => ' + elem_fhir_display)
f.write(INDENT + replace_non_alnum(elem_func) + ' => ' + elem_fhir_display)
f.write(main_table_extensions)
f.write('\n}\n')
# Liens des références
Expand Down