in pathology/transformation_pipeline/ingestion_lib/dicom_util/spec/util/lib/dicom_tag_xml_parser.py [0:0]
def parse_spec(self) -> DicomStandardTags:
"""Parses Dicom Tags from Dicom Standard XML.
Returns:
DicomStandardTags
"""
logging.info('Parsing DICOM IOD XML Tags')
dicom_tags = []
header_tables = [('Tag', 'Name', 'Keyword', 'VR', 'VM', '')]
table_list = self._part6_parser.get_tables(
self._part6_parser.xml_root, header_tables
)
for table in table_list:
for row in table.rows:
parsed_row = self._part6_parser.parse_table_row(row)
address = self.unicode_check(
DicomTagXmlParser._get_index(parsed_row, 0)
)
# allow unicode in comments.
comment = DicomTagXmlParser._get_index(parsed_row, 1)
keyword = self.unicode_check(
DicomTagXmlParser._get_index(parsed_row, 2)
)
vr = self.unicode_check(DicomTagXmlParser._get_index(parsed_row, 3))
vm = self.unicode_check(DicomTagXmlParser._get_index(parsed_row, 4))
retired = self.unicode_check(
DicomTagXmlParser._get_index(parsed_row, 5)
)
dicom_tags.append(ParsedTag(address, comment, keyword, vr, vm, retired))
header_tables = [
('Tag', 'Message Field', 'Keyword', 'VR', 'VM', 'Description of Field'),
('Tag', 'Message Field', 'Keyword', 'VR', 'VM'),
]
table_list = self._part7_parser.get_tables(
self._part7_parser.xml_root, header_tables
)
for table in table_list:
if table.caption == 'Retired Command Fields':
retired = 'Retired'
else:
retired = ''
for row in table.rows:
parsed_row = self._part7_parser.parse_table_row(row)
address = DicomTagXmlParser._get_index(parsed_row, 0)
commentlst = [
DicomTagXmlParser._get_index(parsed_row, 1).replace('\n', ''),
DicomTagXmlParser._get_index(parsed_row, 5).replace('\n', ''),
]
comment = ' '.join([txt for txt in commentlst if txt])
comment = self.unicode_check(comment)
keyword = self.unicode_check(
DicomTagXmlParser._get_index(parsed_row, 2)
)
vr = self.unicode_check(DicomTagXmlParser._get_index(parsed_row, 3))
vm = self.unicode_check(DicomTagXmlParser._get_index(parsed_row, 4))
dicom_tags.append(ParsedTag(address, comment, keyword, vr, vm, retired))
dicom_tags = sorted(dicom_tags, key=lambda x: x.address)
main_tags = collections.OrderedDict()
mask_tags = collections.OrderedDict()
for tag in dicom_tags:
if tag.is_mask:
mask_tags[tag.address] = tag
else:
main_tags[tag.address] = tag
return DicomStandardTags(main_tags, mask_tags)