@@ -49,24 +49,35 @@ class DICOMSeriesSelectorOperator(Operator):
49
49
}
50
50
"""
51
51
52
- def __init__ (self , rules : Text = None , * args , ** kwargs ):
52
+ def __init__ (self , rules : Text = None , all_matched : bool = False , * args , ** kwargs ) -> None :
53
53
super ().__init__ (* args , ** kwargs )
54
+ """Instantiate an instance.
55
+
56
+ Args:
57
+ rules (Text): Selection rules in JSON string.
58
+ all_matched (bool): Gets all matched series in a study. Defaults to False for first one only.
59
+ """
54
60
55
61
# Delay loading the rules as json string till compute time.
56
62
self ._rules_json_str = rules if rules else None
63
+ self ._all_matched = all_matched
57
64
58
65
def compute (self , op_input : InputContext , op_output : OutputContext , context : ExecutionContext ):
59
66
"""Performs computation for this operator."""
60
67
try :
61
68
dicom_study_list = op_input .get ("dicom_study_list" )
62
69
selection_rules = self ._load_rules () if self ._rules_json_str else None
63
- dicom_series_list , study_selected_series = self .filter (selection_rules , dicom_study_list )
70
+ dicom_series_list , study_selected_series = self .filter (selection_rules , dicom_study_list , self . _all_matched )
64
71
op_output .set (dicom_series_list , "dicom_series" )
65
- op_output .set (study_selected_series , )
72
+ op_output .set (
73
+ study_selected_series ,
74
+ )
66
75
except ItemNotExistsError :
67
76
pass
68
77
69
- def filter (self , selection_rules , dicom_study_list ) -> Tuple [List [SelectedSeries ], List [StudySelectedSeries ]]:
78
+ def filter (
79
+ self , selection_rules , dicom_study_list , all_matched : bool = False
80
+ ) -> Tuple [List [SelectedSeries ], List [StudySelectedSeries ]]:
70
81
"""Selects the series with the given matching rules.
71
82
72
83
If rules object is None, all series will be returned with series instance UID
@@ -78,7 +89,9 @@ def filter(self, selection_rules, dicom_study_list) -> Tuple[List[SelectedSeries
78
89
String array matches as subset, case insensitive
79
90
80
91
Args:
81
- rules_json (object): JSON object containing the matching rules
92
+ selection_rules (object): JSON object containing the matching rules.
93
+ dicom_study_list (list): A list of DICOMStudiy objects.
94
+ all_matched (bool): Gets all matched series in a study. Defaults to False for first one only.
82
95
83
96
Returns:
84
97
list: A list of all selected series of type SelectedSeries.
@@ -114,7 +127,7 @@ def filter(self, selection_rules, dicom_study_list) -> Tuple[List[SelectedSeries
114
127
continue
115
128
116
129
# Select only the first series that matches the conditions, list of one
117
- series_list = self ._select_series (conditions , study , False )
130
+ series_list = self ._select_series (conditions , study , all_matched )
118
131
if series_list and len (series_list ) > 0 :
119
132
selected_series_list .extend (x for x in series_list ) # Add each single one
120
133
for series in series_list :
@@ -152,15 +165,15 @@ def _select_all_series(self, dicom_study_list: List[DICOMStudy]):
152
165
study_selected_series_list .append (study_selected_series )
153
166
return series_list , study_selected_series_list
154
167
155
- def _select_series (self , attributes : dict , study : DICOMStudy , find_all = False ):
168
+ def _select_series (self , attributes : dict , study : DICOMStudy , all_matched = False ):
156
169
"""Finds series whose attributes match the given attributes.
157
170
158
171
Args:
159
172
attributes (dict): Dictionary of attributes for matching
160
- find_all (bool): Find all series that match; default is False
173
+ all_matched (bool): Gets all matched series in a study. Defaults to False for first one only.
161
174
162
175
Returns:
163
- List of DICOMSeries. At most 1 if find_all is False.
176
+ List of DICOMSeries. At most one element if all_matched is False.
164
177
"""
165
178
assert isinstance (attributes , dict ), '"attributes" must be a dict.'
166
179
@@ -215,7 +228,7 @@ def _select_series(self, attributes: dict, study: DICOMStudy, find_all=False):
215
228
logging .info (f"Selected Series, UID: { series .SeriesInstanceUID } " )
216
229
found_series .append (series )
217
230
218
- if not find_all :
231
+ if not all_matched :
219
232
return found_series
220
233
221
234
return found_series
@@ -230,6 +243,7 @@ def _get_instance_properties(obj: object) -> Dict:
230
243
prop_dict [attribute ] = getattr (obj , attribute , None )
231
244
return prop_dict
232
245
246
+
233
247
# Module functions
234
248
def _print_instance_properties (obj : object , pre_fix : str = None , print_val = True ):
235
249
print (f"{ pre_fix } Instance of { type (obj )} " )
0 commit comments