Skip to content
Open
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
30 changes: 17 additions & 13 deletions PlantUML/construct_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Chemin du dossier où seront générées les fichiers plantuml
output_path = sys.argv[2]

EXTENSION_EXTENSION_PREFIX = 'Extension.extension:'

# Dictionnaire des couleurs des différents profils
colors = {
'RORHealthcareService': {'back': 'AliceBlue', 'header': 'LightSkyBlue'},
Expand Down Expand Up @@ -106,8 +108,8 @@
extracted_data['resource_extensions'][resource][json.loads(row[5])[0]['profile'][0]] = row[3]
# Récupération du mapping dans les extensions
else:
if row[2].startswith('Extension.extension:'):
if '.' not in remove_prefix(row[2], 'Extension.extension:'):
if row[2].startswith(EXTENSION_EXTENSION_PREFIX):
if '.' not in remove_prefix(row[2], EXTENSION_EXTENSION_PREFIX):
if row[5] is not None:
if row[7] not in extracted_data['complex_extensions'].keys():
extracted_data['complex_extensions'][row[7]] = []
Expand All @@ -133,7 +135,7 @@
class_func = mapping['class']
elements = mapping['elements']
references = mapping['references']
if resource_fhir not in structured_data.keys():

Check warning on line 138 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=AZ4WSE3gCmMGJffqmMwo&open=AZ4WSE3gCmMGJffqmMwo&pullRequest=33
# 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 +155,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 158 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=AZ4WSE3gCmMGJffqmMwp&open=AZ4WSE3gCmMGJffqmMwp&pullRequest=33
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 165 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=AZ4WSE3gCmMGJffqmMwq&open=AZ4WSE3gCmMGJffqmMwq&pullRequest=33
complex_elements[elem_fhir_base] = {}
complex_elements[elem_fhir_base][elem_fhir_sub] = elem_func
else:
Expand All @@ -169,14 +171,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 174 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=AZ4WSE3gCmMGJffqmMwr&open=AZ4WSE3gCmMGJffqmMwr&pullRequest=33
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 181 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=AZ4WSE3gCmMGJffqmMws&open=AZ4WSE3gCmMGJffqmMws&pullRequest=33
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 @@ -228,7 +230,7 @@
mapping_extension_global = mapping_extension['Extension']
for elem_fhir, elem_func in mapping_extension.items():
if elem_fhir != 'Extension':
elem_fhir = remove_prefix(elem_fhir, 'Extension.extension:')
elem_fhir = remove_prefix(elem_fhir, EXTENSION_EXTENSION_PREFIX)
elem_fhir = remove_suffix(elem_fhir, '.value[x]')
mapping_extension_sub_elements[elem_fhir] = elem_func
if extension in extracted_data['complex_extensions'].keys():
Expand All @@ -244,7 +246,7 @@
elem_func = mapping_sub_extension['Extension']
for sub_elem_fhir, sub_elem_func in mapping_sub_extension.items():
if sub_elem_fhir != 'Extension':
sub_elem_fhir = remove_prefix(sub_elem_fhir, 'Extension.extension:')
sub_elem_fhir = remove_prefix(sub_elem_fhir, EXTENSION_EXTENSION_PREFIX)
sub_elem_fhir = remove_suffix(sub_elem_fhir, '.value[x]')
sub_mapping_elements[sub_elem_fhir] = sub_elem_func
if sub_extension in extracted_data['complex_extensions'].keys():
Expand Down Expand Up @@ -276,6 +278,8 @@
return structured_data

# Génération des schémas
PLANTUML_AS = '" as '

def generate_plantuml(structured_data, output_path, colors):
# Liste contenant les directions possibles pour les flèches
directions = ['u', 'd', 'l', 'r']
Expand Down Expand Up @@ -310,9 +314,9 @@
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 + PLANTUML_AS + elem_fhir_id + ' #back:WhiteSmoke;header:LightGray {'

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 "' 7 times.

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

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 ' #back:WhiteSmoke;header:LightGray {' 9 times.

See more on https://sonarcloud.io/project/issues?id=ansforge_IG-workflows&issues=AZ4WSE3gCmMGJffqmMwn&open=AZ4WSE3gCmMGJffqmMwn&pullRequest=33
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 + PLANTUML_AS + elem_func_id + ' #back:WhiteSmoke;header:LightGray {'
tables += table_title
sub_table = None
# Eléments complexes de niveau 2
Expand All @@ -331,17 +335,17 @@
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 {'
sub_table = '\nmap "' + replace_non_alnum(sub_elem_func) + ' : ' + sub_elem_fhir_display + PLANTUML_AS + keep_alnum(sub_elem_func) + ' #back:WhiteSmoke;header:LightGray {'
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 {'
sub_table = '\nmap "' + sub_elem_fhir_display + PLANTUML_AS + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + ' #back:WhiteSmoke;header:LightGray {'
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 += '\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 {'
sub_table = '\nmap "' + sub_elem_fhir_display + PLANTUML_AS + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + ' #back:WhiteSmoke;header:LightGray {'
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:')
Expand Down Expand Up @@ -377,11 +381,11 @@
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 + ' : <&plus> ' + extension + PLANTUML_AS + extension_id + ' #back:WhiteSmoke;header:LightGray {'
else:
main_table_extensions += '\n ' + extension + ' *-> ' + extension_id
if extension not in complex_elements:
table_extensions += '\nmap "<&plus> ' + extension + '" as ' + extension_id + ' #back:WhiteSmoke;header:LightGray {'
table_extensions += '\nmap "<&plus> ' + extension + PLANTUML_AS + extension_id + ' #back:WhiteSmoke;header:LightGray {'
if extension not in complex_elements:
complex_elements.append(extension)
for sub_elem_fhir, sub_elem_func in extension_details['elements'].items():
Expand All @@ -394,11 +398,11 @@
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_sub_extensions = '\nmap "' + replace_non_alnum(mapping_sub_extension_global) + ' : <&plus> ' + sub_elem_fhir_display + PLANTUML_AS + keep_alnum(mapping_sub_extension_global) + ' #back:WhiteSmoke;header:LightGray {'
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_sub_extensions = '\nmap <&plus>"' + sub_elem_fhir_display + PLANTUML_AS + keep_alnum(remove_prefix(sub_elem_fhir, 'extension:')) + ' #back:WhiteSmoke;header:LightGray {'
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 += '\n}\n'
Expand Down