Skip to content

Commit 01f7d08

Browse files
committed
adding optional params to search and retrieve functions
1 parent 99aa011 commit 01f7d08

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

src/dicomweb_client/web.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,8 @@ def search_for_studies(
16281628
offset: Optional[int] = None,
16291629
fields: Optional[Sequence[str]] = None,
16301630
search_filters: Optional[Dict[str, Any]] = None,
1631-
get_remaining: bool = False
1631+
get_remaining: bool = False,
1632+
additional_params: Optional[Dict[str, Any]] = None
16321633
) -> List[Dict[str, dict]]:
16331634
"""Search for studies.
16341635
@@ -1649,19 +1650,23 @@ def search_for_studies(
16491650
get_remaining: bool, optional
16501651
Whether remaining results should be included (this may repeatedly
16511652
query the server for remaining results)
1653+
additional_params: Union[Dict[str, Any], None], optional
1654+
Additional HTTP GET query parameters to include in the request.
16521655
16531656
Returns
16541657
-------
16551658
List[Dict[str, dict]]
16561659
Study representations
16571660
(see `Study Result Attributes <http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_6.7.html#table_6.7.1-2>`_)
16581661
1659-
Note
1662+
Notes
16601663
----
1661-
The server may only return a subset of search results. In this case,
1664+
- The server may only return a subset of search results. In this case,
16621665
a warning will notify the client that there are remaining results.
16631666
Remaining results can be requested via repeated calls using the
16641667
`offset` parameter.
1668+
- If `additional_params` is provided, it will be merged into the standard query parameters,
1669+
with its values overwriting any existing keys if duplicates are present.
16651670
16661671
""" # noqa: E501: E501
16671672
logger.info('search for studies')
@@ -1673,6 +1678,8 @@ def search_for_studies(
16731678
fields=fields,
16741679
search_filters=search_filters
16751680
)
1681+
if additional_params:
1682+
params.update(additional_params)
16761683
return self._http_get_application_json(
16771684
url,
16781685
params=params,
@@ -1918,7 +1925,8 @@ def _get_study(
19181925
self,
19191926
study_instance_uid: str,
19201927
media_types: Optional[Tuple[Union[str, Tuple[str, str]], ...]] = None,
1921-
stream: bool = False
1928+
stream: bool = False,
1929+
params: Optional[Dict[str, Any]] = None
19221930
) -> Iterator[pydicom.dataset.Dataset]:
19231931
"""Get all instances of a study.
19241932
@@ -1932,6 +1940,8 @@ def _get_study(
19321940
stream: bool, optional
19331941
Whether data should be streamed (i.e., requested using chunked
19341942
transfer encoding)
1943+
params: Union[Dict[str, Any], None], optional
1944+
Additional HTTP GET query parameters
19351945
19361946
Returns
19371947
-------
@@ -1947,6 +1957,7 @@ def _get_study(
19471957
if media_types is None:
19481958
return self._http_get_multipart_application_dicom(
19491959
url,
1960+
params=params,
19501961
stream=stream
19511962
)
19521963
common_media_types = self._get_common_media_types(media_types)
@@ -1964,6 +1975,7 @@ def _get_study(
19641975
return self._http_get_multipart_application_dicom(
19651976
url,
19661977
media_types=media_types,
1978+
params=params,
19671979
stream=stream
19681980
)
19691981

@@ -2129,7 +2141,8 @@ def search_for_series(
21292141
offset: Optional[int] = None,
21302142
fields: Optional[Sequence[str]] = None,
21312143
search_filters: Optional[Dict[str, Any]] = None,
2132-
get_remaining: bool = False
2144+
get_remaining: bool = False,
2145+
additional_params: Optional[Dict[str, Any]] = None
21332146
) -> List[Dict[str, dict]]:
21342147
"""Search for series.
21352148
@@ -2152,19 +2165,23 @@ def search_for_series(
21522165
get_remaining: bool, optional
21532166
Whether remaining results should be included (this may repeatedly
21542167
query the server for remaining results)
2168+
additional_params: Union[Dict[str, Any], None], optional
2169+
Additional HTTP GET query parameters to include in the request.
21552170
21562171
Returns
21572172
-------
21582173
List[Dict[str, dict]]
21592174
Series representations
21602175
(see `Series Result Attributes <http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_6.7.html#table_6.7.1-2a>`_)
21612176
2162-
Note
2177+
Notes
21632178
----
2164-
The server may only return a subset of search results. In this case,
2179+
- The server may only return a subset of search results. In this case,
21652180
a warning will notify the client that there are remaining results.
21662181
Remaining results can be requested via repeated calls using the
21672182
`offset` parameter.
2183+
- If `additional_params` is provided, it will be merged into the standard query parameters,
2184+
with its values overwriting any existing keys if duplicates are present.
21682185
21692186
""" # noqa: E501
21702187
if study_instance_uid is not None:
@@ -2180,6 +2197,8 @@ def search_for_series(
21802197
fields=fields,
21812198
search_filters=search_filters
21822199
)
2200+
if additional_params:
2201+
params.update(additional_params)
21832202
return self._http_get_application_json(
21842203
url,
21852204
params=params,
@@ -2191,7 +2210,8 @@ def _get_series(
21912210
study_instance_uid: str,
21922211
series_instance_uid: str,
21932212
media_types: Optional[Tuple[Union[str, Tuple[str, str]], ...]] = None,
2194-
stream: bool = False
2213+
stream: bool = False,
2214+
params: Optional[Dict[str, Any]] = None
21952215
) -> Iterator[pydicom.dataset.Dataset]:
21962216
"""Get instances of a series.
21972217
@@ -2207,6 +2227,8 @@ def _get_series(
22072227
stream: bool, optional
22082228
Whether data should be streamed (i.e., requested using chunked
22092229
transfer encoding)
2230+
params: Union[Dict[str, Any], None], optional
2231+
Additional HTTP GET query parameters
22102232
22112233
Returns
22122234
-------
@@ -2236,6 +2258,7 @@ def _get_series(
22362258
if media_types is None:
22372259
return self._http_get_multipart_application_dicom(
22382260
url,
2261+
params=params,
22392262
stream=stream
22402263
)
22412264
common_media_types = self._get_common_media_types(media_types)
@@ -2253,6 +2276,7 @@ def _get_series(
22532276
return self._http_get_multipart_application_dicom(
22542277
url,
22552278
media_types=media_types,
2279+
params=params,
22562280
stream=stream
22572281
)
22582282

@@ -2514,7 +2538,8 @@ def search_for_instances(
25142538
offset: Optional[int] = None,
25152539
fields: Optional[Sequence[str]] = None,
25162540
search_filters: Optional[Dict[str, Any]] = None,
2517-
get_remaining: bool = False
2541+
get_remaining: bool = False,
2542+
additional_params: Optional[Dict[str, Any]] = None
25182543
) -> List[Dict[str, dict]]:
25192544
"""Search for instances.
25202545
@@ -2539,6 +2564,8 @@ def search_for_instances(
25392564
get_remaining: bool, optional
25402565
Whether remaining results should be included (this may repeatedly
25412566
query the server for remaining results)
2567+
additional_params: Union[Dict[str, Any], None], optional
2568+
Additional HTTP GET query parameters to include in the request.
25422569
25432570
Returns
25442571
-------
@@ -2548,10 +2575,12 @@ def search_for_instances(
25482575
25492576
Note
25502577
----
2551-
The server may only return a subset of search results. In this case,
2578+
- The server may only return a subset of search results. In this case,
25522579
a warning will notify the client that there are remaining results.
25532580
Remaining results can be requested via repeated calls using the
25542581
`offset` parameter.
2582+
- If `additional_params` is provided, it will be merged into the standard query parameters,
2583+
with its values overwriting any existing keys if duplicates are present.
25552584
25562585
""" # noqa: E501
25572586
message = 'search for instances'
@@ -2585,6 +2614,7 @@ def retrieve_instance(
25852614
series_instance_uid: str,
25862615
sop_instance_uid: str,
25872616
media_types: Optional[Tuple[Union[str, Tuple[str, str]], ...]] = None,
2617+
params: Optional[Dict[str, Any]] = None
25882618
) -> pydicom.dataset.Dataset:
25892619
"""Retrieve an individual instance.
25902620
@@ -2599,6 +2629,8 @@ def retrieve_instance(
25992629
media_types: Union[Tuple[Union[str, Tuple[str, str]], ...], None], optional
26002630
Acceptable media types and optionally the UIDs of the
26012631
acceptable transfer syntaxes
2632+
params: Union[Dict[str, Any], None], optional
2633+
Additional HTTP GET query parameters
26022634
26032635
Returns
26042636
-------
@@ -2657,7 +2689,11 @@ def retrieve_instance(
26572689
f'Media type "{common_media_type}" is not supported for '
26582690
'retrieval of an instance. It must be "application/dicom".'
26592691
)
2660-
iterator = self._http_get_multipart_application_dicom(url, media_types)
2692+
iterator = self._http_get_multipart_application_dicom(
2693+
url,
2694+
media_types=media_types,
2695+
params=params
2696+
)
26612697
instances = list(iterator)
26622698
if len(instances) > 1:
26632699
# This should not occur, but safety first.

0 commit comments

Comments
 (0)