in pathology/transformation_pipeline/ingestion_lib/dicom_util/spec/util/lib/util/dicom_xml_core_parser.py [0:0]
def _get_table_row(self, table_row) -> ParsedTableRow:
"""private method reads a single row of a table.
Call Public method: parse_table_row
Args:
table_row: lines of text defining a tables row
Returns:
ParsedTableRow
"""
namespace = self._namespace
line = []
emphasis_start = False
for td in table_row.findall(f'./{namespace}td'):
line_text = []
linked = []
para_sub_block = td.findall(f'./{namespace}para')
if not para_sub_block:
para_sub_block = [td]
pre_line_length = len(line)
for para in para_sub_block:
emphasis = para.find(f'./{namespace}emphasis')
if emphasis is not None:
if not line:
ref = emphasis.find(f'./{namespace}xref')
if ref is not None:
line.append(emphasis.text.strip())
line.append(ref.attrib['linkend'])
emphasis_start = True
continue
if emphasis.text:
line_text.append(emphasis.text.strip())
if not emphasis_start:
if not line_text:
linkedref = [
xref.attrib['linkend']
for xref in para.findall(f'./{namespace}xref')
if 'linkend' in xref.attrib
]
if linkedref:
linked += linkedref
continue
if para.text:
line_text.append(para.text.strip())
if line_text:
line.append('\n'.join(line_text))
elif linked:
line.append(linked)
elif pre_line_length == len(line): # if nothing was add for column
line.append('') # add padding space
return ParsedTableRow(emphasis_start, line)