-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathprocess_ciod_func_group_macro_relationship.py
43 lines (34 loc) · 1.59 KB
/
process_ciod_func_group_macro_relationship.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
Takes the extracted CIOD-Functional Group Macro table information to build a list of all
CIOD-Functional Group Macro relationships defined in the DICOM Standard.
'''
import re
import sys
from dicom_standard import parse_lib as pl
from dicom_standard.process_ciod_module_relationship import expand_conditional_statement
# Standard workaround: Remove "Macro Attributes" from "Photoacoustic Reconstruction Algorithm Macro Attributes" in Table A.89.4-1
# https://dicom.nema.org/medical/dicom/2023c/output/html/part03.html#table_A.89.4-1
def clean_macro_name(text):
return re.sub(' Macro Attributes', '', text).strip()
def define_all_relationships(ciod_macro_list):
all_relationships = []
for table in ciod_macro_list:
ciod = table['name']
macros = table['macros']
module_type = table['moduleType']
all_relationships.extend([define_ciod_macro_relationship(ciod, macro, module_type)
for macro in macros])
return all_relationships
def define_ciod_macro_relationship(ciod, macro, module_type):
usage, conditional_statement = expand_conditional_statement(macro['usage'])
return {
"ciodId": pl.create_slug(ciod),
"macroId": pl.create_slug(clean_macro_name(pl.text_from_html_string(macro['macro']))),
"usage": usage,
"conditionalStatement": conditional_statement,
"moduleType": module_type,
}
if __name__ == '__main__':
ciod_macro_list = pl.read_json_data(sys.argv[1])
ciod_macro_relationships = define_all_relationships(ciod_macro_list)
pl.write_pretty_json(ciod_macro_relationships)