in pathology/transformation_pipeline/ingestion_lib/dicom_util/spec/util/lib/dicom_iod_xml_parser.py [0:0]
def read_table_dict(self) -> TableDefType:
"""Reads and returns dictionary of IOD table definitions.
Returns:
Dictionary of IOD table definitions
"""
defined_tables = {}
valid_headers = [
('Attribute Name', 'Tag', 'Type', 'Attribute Description'),
('Attribute Name', 'Tag', 'Attribute Description'),
('Attribute Name', 'Tag', 'Type', 'Description'),
('Attribute Name', 'Tag', 'Description'),
]
for tbl in self._iod_parser.get_tables(
self._iod_parser.xml_root, valid_headers
):
line_block = []
for row_lines in tbl.rows:
tbl_row = self._iod_parser.parse_table_row(row_lines)
parsed_row = tbl_row.parsed_row
if not parsed_row:
continue
obj = None
if tbl_row.starts_with_emphasis:
obj = LinkedObject()
elif len(parsed_row) == 4:
obj = InlineObject(4)
elif len(parsed_row) == 3:
obj = InlineObject(3)
if obj is not None:
for val in parsed_row:
obj.set_val(val)
if obj.is_init():
line_block.append(obj)
elif len(parsed_row) == 2:
if isinstance(parsed_row, str):
first_line = parsed_row
else:
first_line = parsed_row[0]
# Functional groups are referenced in text and not linked by section.
# Test for text reference and add custom linked resource.
if 'Include one or more Functional Group Macros' in first_line: # pytype: disable=attribute-error
prefix_offset = first_line.index('Include') + len('Include')
obj = LinkedObject(
prefix=first_line[:prefix_offset],
linked_resource='table_IODFunctionalGroupMacros',
)
line_block.append(obj)
if line_block:
t_ref = TableRef(tbl.name, tbl.caption, line_block)
defined_tables[t_ref.name] = t_ref
return defined_tables