-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathextract_sops.py
32 lines (24 loc) · 1.11 KB
/
extract_sops.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
30
31
32
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 = ['name', 'id', 'ciod']
TABLE_IDS = ['table_B.5-1', 'table_I.4-1', 'table_GG.3-1']
def generate_ciod_id(name: str) -> str:
cleaned_name = name.split('IOD')[0].strip()
# Standard workaround: Table B.5-1 has a miscapitalized word in an IOD Specification
# https://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_B.5.html#table_B.5-1
if cleaned_name == 'Pseudo-color Softcopy Presentation State':
cleaned_name = 'Pseudo-Color Softcopy Presentation State'
return cleaned_name
def sop_table_to_json(table: List[TableDictType]) -> List[TableDictType]:
sops = []
for sop in table:
sop['ciod'] = generate_ciod_id(sop['ciod'])
sops.append(sop)
return sops
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 = sop_table_to_json(table)
pl.write_pretty_json(parsed_table_data)