diff --git a/dicom_standard/extract_attributes.py b/dicom_standard/extract_attributes.py index 644355d..c7b24a5 100644 --- a/dicom_standard/extract_attributes.py +++ b/dicom_standard/extract_attributes.py @@ -30,6 +30,7 @@ def attribute_table_to_list(table_div: Tag) -> List[List[str]]: for row in pr.table_rows(table_div)] +# TODO: Convert attributes to a TypedDict when we update to use Python3.8 def attribute_table_to_json(table: List[TableDictType]) -> List[TableDictType]: attributes = [] for attr in table: diff --git a/dicom_standard/extract_ciod_module_tables.py b/dicom_standard/extract_ciod_module_tables.py index 8de40a7..f28967d 100644 --- a/dicom_standard/extract_ciod_module_tables.py +++ b/dicom_standard/extract_ciod_module_tables.py @@ -11,6 +11,7 @@ from dicom_standard import parse_lib as pl from dicom_standard import parse_relations as pr +from dicom_standard.macro_utils import MetadataTableType from dicom_standard.table_utils import ( TableListType, TableDictType, @@ -36,7 +37,7 @@ def ciod_table_to_dict(table: TableListType) -> List[TableDictType]: return table_to_dict(table, COLUMN_TITLES) -def get_table_with_metadata(table_with_tdiv: Tuple[List[TableDictType], Tag]) -> pl.MetadataTableType: +def get_table_with_metadata(table_with_tdiv: Tuple[List[TableDictType], Tag]) -> MetadataTableType: table, tdiv = table_with_tdiv clean_name = pl.clean_table_name(pr.table_name(tdiv)) table_description = get_table_description(tdiv) diff --git a/dicom_standard/macro_utils.py b/dicom_standard/macro_utils.py index 18d3701..5708f46 100644 --- a/dicom_standard/macro_utils.py +++ b/dicom_standard/macro_utils.py @@ -9,9 +9,9 @@ from bs4 import BeautifulSoup, Tag from dicom_standard.hierarchy_utils import get_hierarchy_markers -from dicom_standard.parse_lib import MetadataTableType AttributeType = Dict[str, str] +MetadataTableType = Dict[str, Any] MacrosType = Dict[str, MetadataTableType] diff --git a/dicom_standard/parse_lib.py b/dicom_standard/parse_lib.py index 8677b35..182f79b 100644 --- a/dicom_standard/parse_lib.py +++ b/dicom_standard/parse_lib.py @@ -30,8 +30,7 @@ ID_PATTERN = re.compile(r'\b(' + '|'.join(NONSTANDARD_SECTION_IDS) + r').+\b') SHORT_DICOM_URL_PREFIX = "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/" -MetadataTableType = Dict[str, Any] -JsonDataType = Union[List[MetadataTableType], MetadataTableType] +GenericTableType = Union[List[Dict[str, Any]], Dict[str, Any]] def parse_html_file(filepath: str) -> BeautifulSoup: @@ -43,11 +42,11 @@ def write_pretty_json(data: Any) -> None: json.dump(data, sys.stdout, sort_keys=False, indent=4, separators=(',', ':')) -def read_json_data(filepath: str) -> JsonDataType: +def read_json_data(filepath: str) -> GenericTableType: with open(filepath, 'r') as json_file: json_string = json_file.read() - json_dict = json.loads(json_string) - return json_dict + json_data = json.loads(json_string) + return json_data def all_tdivs_in_chapter(standard: BeautifulSoup, chapter_name: str) -> List[Tag]: diff --git a/dicom_standard/preprocess_macros_with_attributes.py b/dicom_standard/preprocess_macros_with_attributes.py index 93b24a3..3c64edc 100644 --- a/dicom_standard/preprocess_macros_with_attributes.py +++ b/dicom_standard/preprocess_macros_with_attributes.py @@ -2,8 +2,8 @@ import sys from dicom_standard import parse_lib as pl - -from preprocess_modules_with_attributes import ( +from dicom_standard.macro_utils import MetadataTableType +from dicom_standard.preprocess_modules_with_attributes import ( key_tables_by_id, expand_all_macros, preprocess_attribute_fields, @@ -12,7 +12,7 @@ if __name__ == '__main__': - module_macro_attr_tables = cast(List[pl.MetadataTableType], pl.read_json_data(sys.argv[1])) + module_macro_attr_tables = cast(List[MetadataTableType], pl.read_json_data(sys.argv[1])) id_to_table = key_tables_by_id(module_macro_attr_tables) macro_attr_tables = [table for table in module_macro_attr_tables if table['isMacro']] expanded_tables = expand_all_macros(macro_attr_tables, id_to_table) diff --git a/dicom_standard/preprocess_modules_with_attributes.py b/dicom_standard/preprocess_modules_with_attributes.py index 2e001d5..5f92ce1 100644 --- a/dicom_standard/preprocess_modules_with_attributes.py +++ b/dicom_standard/preprocess_modules_with_attributes.py @@ -10,11 +10,11 @@ import sys from dicom_standard import parse_lib as pl -from dicom_standard.macro_utils import expand_macro_rows, get_id_from_link +from dicom_standard.macro_utils import MetadataTableType, expand_macro_rows, get_id_from_link from dicom_standard.hierarchy_utils import record_hierarchy_for_module -def key_tables_by_id(table_list: List[pl.MetadataTableType]) -> Dict[str, pl.MetadataTableType]: +def key_tables_by_id(table_list: List[MetadataTableType]) -> Dict[str, MetadataTableType]: dict_of_tables = {} for table in table_list: dict_of_tables[get_id_from_link(table['linkToStandard'])] = table @@ -62,7 +62,7 @@ def expand_hierarchy(tables): if __name__ == '__main__': - module_macro_attr_tables = cast(List[pl.MetadataTableType], pl.read_json_data(sys.argv[1])) + module_macro_attr_tables = cast(List[MetadataTableType], pl.read_json_data(sys.argv[1])) id_to_table = key_tables_by_id(module_macro_attr_tables) module_attr_tables = [table for table in module_macro_attr_tables if not table['isMacro']] expanded_tables = expand_all_macros(module_attr_tables, id_to_table) diff --git a/dicom_standard/process_ciod_func_group_macro_relationship.py b/dicom_standard/process_ciod_func_group_macro_relationship.py index 4935f5c..3e0c496 100644 --- a/dicom_standard/process_ciod_func_group_macro_relationship.py +++ b/dicom_standard/process_ciod_func_group_macro_relationship.py @@ -6,8 +6,7 @@ import sys from dicom_standard import parse_lib as pl - -from process_ciod_module_relationship import expand_conditional_statement +from dicom_standard.process_ciod_module_relationship import expand_conditional_statement # Standard workaround: Remove "Macro" from "Frame VOI LUT With LUT Macro" in Table A.84.3.2-1 diff --git a/dicom_standard/process_macro_attribute_relationship.py b/dicom_standard/process_macro_attribute_relationship.py index 4e8764c..01fb1a7 100644 --- a/dicom_standard/process_macro_attribute_relationship.py +++ b/dicom_standard/process_macro_attribute_relationship.py @@ -1,8 +1,7 @@ import sys from dicom_standard import parse_lib as pl - -from process_module_attribute_relationship import get_standard_link +from dicom_standard.process_module_attribute_relationship import get_standard_link def macro_attr_relationship_table(macro_attr_list): diff --git a/dicom_standard/process_macros.py b/dicom_standard/process_macros.py index 7193737..825fc33 100644 --- a/dicom_standard/process_macros.py +++ b/dicom_standard/process_macros.py @@ -6,7 +6,7 @@ from dicom_standard import parse_lib as pl -from process_modules import modules_from_tables +from dicom_standard.process_modules import modules_from_tables if __name__ == '__main__':