-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathextract_attributes.py
29 lines (23 loc) · 1.04 KB
/
extract_attributes.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
'''
Extract the listing of all attributes given in PS3.6 of the DICOM Standard.
'''
from typing import List
import sys
from dicom_standard import parse_lib as pl
from dicom_standard.table_utils import TableDictType, get_table_rows_from_ids
COLUMN_TITLES = ['tag', 'name', 'keyword', 'valueRepresentation', 'valueMultiplicity', 'retired']
TABLE_IDS = ['table_6-1', 'table_7-1', 'table_8-1', 'table_9-1']
# 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:
attr['id'] = pl.create_slug(attr['tag'])
attr['tag'] = attr['tag'].upper()
attr['retired'] = 'Y' if 'RET' in attr['retired'] else 'N'
attributes.append(attr)
return attributes
if __name__ == '__main__':
standard = pl.parse_html_file(sys.argv[1])
table = get_table_rows_from_ids(standard, TABLE_IDS, COLUMN_TITLES)
parsed_table_data = attribute_table_to_json(table)
pl.write_pretty_json(parsed_table_data)