@@ -94,6 +94,46 @@ def process_extra_commands(outdir, command, files, dicom_dir_template,
9494 "\t %s %d sequences%s"
9595 % (str (study_session ), len (sequences ), suf )
9696 )
97+ elif command == 'ls-studysessions' :
98+ ensure_heuristic_arg (heuristic )
99+ heuristic = load_heuristic (heuristic )
100+ # heuristic_ls = getattr(heuristic, 'ls', None)
101+ study_sessions = get_study_sessions (
102+ dicom_dir_template , files , heuristic , outdir ,
103+ session , subjs , grouping = grouping )
104+ for ss , seqinfos in study_sessions .items ():
105+ print (f"{ ss } :" )
106+ # deduce unique attributes
107+ from heudiconv .utils import get_dicts_intersection
108+ seqinfo_dicts = [s ._asdict () for s in seqinfos ]
109+ common_seqinfo = get_dicts_intersection (seqinfo_dicts )
110+
111+ diff_seqinfo = []
112+ for sd in seqinfo_dicts :
113+ diff = {
114+ k : v for k , v in sd .items ()
115+ if (k not in common_seqinfo ) and
116+ (k not in {'total_files_till_now' , 'series_uid' })}
117+ # some transformations might be needed to please pyout
118+ for k , v in diff .items ():
119+ if isinstance (v , tuple ):
120+ diff [k ] = ', ' .join (v )
121+ diff_seqinfo .append (diff )
122+
123+ if diff_seqinfo == [{}]:
124+ print (f" only common: { common_seqinfo } " )
125+ continue
126+ from pyout import Tabular
127+ with Tabular (
128+ columns = ['example_dcm_file' , 'series_files' , 'series_id' , 'protocol_name' , 'series_description' ],
129+ style = {"header_" : dict (bold = True ,),
130+ "example_dcm_file" : dict (bold = True ,),
131+ "image_type" : dict (transform = str )},
132+ mode = 'final'
133+ ) as out :
134+ for diffs , files in zip (diff_seqinfo , seqinfos .values ()):
135+ out (diffs )
136+ # print(f"{path_id} {diffs}")
97137 elif command == 'populate-templates' :
98138 ensure_heuristic_arg (heuristic )
99139 heuristic = load_heuristic (heuristic )
0 commit comments