@@ -122,17 +122,14 @@ def uri_search_params(self) -> Dict[str, Union[str, List[str]]]:
122122 if self .include_fields :
123123 search_params ["includefield" ] = self .include_fields
124124
125- # now collect all other Query() fields that can be search params
125+ # now collect all other Query() fields that can be search params.
126+ # Exclude fields that should not be sent to server
126127 exclude_fields = {
127128 "min_study_date" , # addressed above
128129 "max_study_date" ,
129- "include_fields" ,
130- "StudyInstanceUID" , # potential part of url, not search params
131- "SeriesInstanceUID" ,
132- "SOPClassInstanceUID" ,
133- "query_level" ,
130+ "include_fields" , # addressed above
131+ "query_level" , # encoded in url structure
134132 }
135-
136133 other_search_params = {
137134 key : val
138135 for key , val in self .dict ().items ()
@@ -235,6 +232,44 @@ def uri_base(self) -> str:
235232 f'Should be one of "{ QueryLevels } "'
236233 )
237234
235+ def uri_search_params (self ) -> Dict [str , Union [str , List [str ]]]:
236+ """The search parameter part of the URI as defined in
237+ DICOM PS3.18 section 10.6 table 10.6.1-2
238+
239+ Returns
240+ -------
241+ Dict[str, Union[str, List[str]]]
242+ Output that can be fed directly into a requests post request.
243+ format is param_name:param_value. If param_value is a list, the param
244+ will be included multiple times.
245+ See https://docs.python-requests.org/en/latest/user/quickstart/
246+ #passing-parameters-in-urls
247+
248+ Notes
249+ -----
250+ Will not output any parameters with Null or empty value (bool(value)==False).
251+ This does not affect query functionality but makes output cleaner in strings
252+ """
253+ search_params : Dict [
254+ str , Union [str , List [str ]]
255+ ] = super ().uri_search_params ()
256+
257+ # Depending on query level, some UIDs in Hierarchical queries are part
258+ # of url and should not be part of parameter
259+ exclude_fields = set ()
260+ if self .query_level == QueryLevels .INSTANCE :
261+ exclude_fields = {"StudyInstanceUID" , "SeriesInstanceUID" }
262+ if self .query_level == QueryLevels .SERIES :
263+ exclude_fields = {"StudyInstanceUID" }
264+ if self .query_level == QueryLevels .STUDY :
265+ pass # for series level all uids are part of parameters. Don't exclude
266+
267+ return {
268+ key : val
269+ for key , val in search_params .items ()
270+ if key not in exclude_fields
271+ }
272+
238273
239274# used in RelationalQuery
240275STUDY_VALUE_ERROR_TEXT : str = (
@@ -287,7 +322,7 @@ def uri_base(self) -> str:
287322 if self .query_level == QueryLevels .STUDY :
288323 raise ValueError (STUDY_VALUE_ERROR_TEXT )
289324 elif self .query_level == QueryLevels .SERIES :
290- return "/studies "
325+ return "/series "
291326 elif self .query_level == QueryLevels .INSTANCE :
292327 if self .StudyInstanceUID :
293328 # all instances for this study
@@ -364,10 +399,11 @@ def ensure_query_type(cls, query: Query) -> QidoRSQueryBase:
364399 "to HierarchicalQuery"
365400 )
366401 return HierarchicalQuery .init_from_query (query )
367- except UnSupportedParameterError :
402+ except UnSupportedParameterError as e :
368403 logger .debug (
369404 "Converting to HierarchicalQuery did not work. "
370- "Trying slower but less stringent RelationalQuery"
405+ "Trying slower but less stringent RelationalQuery. Error was: "
406+ f"{ str (e )} "
371407 )
372408 return RelationalQuery .init_from_query (query )
373409 else :
0 commit comments