@@ -131,20 +131,110 @@ def dicomweb_retrieve_study(
131
131
dicomweb_path = '{}/datasets/{}/dicomStores/{}/dicomWeb/studies/{}' .format (
132
132
url , dataset_id , dicom_store_id , study_uid )
133
133
134
+ file_name = 'study.dcm'
135
+
136
+ # Make an authenticated API request
137
+ session = get_session (service_account_json )
138
+
139
+ response = session .get (dicomweb_path )
140
+
141
+ response .raise_for_status ()
142
+
143
+ with open (file_name , 'wb' ) as f :
144
+ f .write (response .content )
145
+ print ('Retrieved study and saved to file ' +
146
+ '{} in current directory' .format (file_name ))
147
+
148
+ return response
149
+ # [END healthcare_dicomweb_retrieve_study]
150
+
151
+
152
+ # [START healthcare_dicomweb_retrieve_instance]
153
+ def dicomweb_retrieve_instance (
154
+ service_account_json ,
155
+ base_url ,
156
+ project_id ,
157
+ cloud_region ,
158
+ dataset_id ,
159
+ dicom_store_id ,
160
+ study_uid ,
161
+ series_uid ,
162
+ instance_uid ):
163
+ """Handles the GET requests specified in the DICOMweb standard."""
164
+ url = '{}/projects/{}/locations/{}' .format (base_url ,
165
+ project_id , cloud_region )
166
+
167
+ dicom_store_path = '{}/datasets/{}/dicomStores/{}' .format (
168
+ url , dataset_id , dicom_store_id )
169
+
170
+ dicomweb_path = '{}/dicomWeb/studies/{}/series/{}/instances/{}' .format (
171
+ dicom_store_path , study_uid , series_uid , instance_uid )
172
+
173
+ file_name = 'instance.dcm'
174
+
134
175
# Make an authenticated API request
135
176
session = get_session (service_account_json )
136
177
137
178
headers = {
138
- 'Content-Type ' : 'application/dicom+json; charset=utf-8 '
179
+ 'Accept ' : 'application/dicom; transfer-syntax=* '
139
180
}
140
181
141
182
response = session .get (dicomweb_path , headers = headers )
183
+
142
184
response .raise_for_status ()
143
185
144
- print ('Retrieved study with UID: {}' .format (study_uid ))
186
+ with open (file_name , 'wb' ) as f :
187
+ f .write (response .content )
188
+ print ('Retrieved DICOM instance and saved to file ' +
189
+ '{} in current directory' .format (file_name ))
145
190
146
191
return response
147
- # [END healthcare_dicomweb_retrieve_study]
192
+ # [END healthcare_dicomweb_retrieve_instance]
193
+
194
+
195
+ # [START healthcare_dicomweb_retrieve_rendered]
196
+ def dicomweb_retrieve_rendered (
197
+ service_account_json ,
198
+ base_url ,
199
+ project_id ,
200
+ cloud_region ,
201
+ dataset_id ,
202
+ dicom_store_id ,
203
+ study_uid ,
204
+ series_uid ,
205
+ instance_uid ):
206
+ """Handles the GET requests specified in the DICOMweb standard."""
207
+ url = '{}/projects/{}/locations/{}' .format (base_url ,
208
+ project_id , cloud_region )
209
+
210
+ dicom_store_path = '{}/datasets/{}/dicomStores/{}' .format (
211
+ url , dataset_id , dicom_store_id )
212
+
213
+ instance_path = '{}/dicomWeb/studies/{}/series/{}/instances/{}' .format (
214
+ dicom_store_path , study_uid , series_uid , instance_uid )
215
+
216
+ dicomweb_path = '{}/rendered' .format (instance_path )
217
+
218
+ file_name = 'rendered_image.png'
219
+
220
+ # Make an authenticated API request
221
+ session = get_session (service_account_json )
222
+
223
+ headers = {
224
+ 'Accept' : 'image/png'
225
+ }
226
+
227
+ response = session .get (dicomweb_path , headers = headers )
228
+
229
+ response .raise_for_status ()
230
+
231
+ with open (file_name , 'wb' ) as f :
232
+ f .write (response .content )
233
+ print ('Retrieved rendered image and saved to file ' +
234
+ '{} in current directory' .format (file_name ))
235
+
236
+ return response
237
+ # [END healthcare_dicomweb_retrieve_rendered]
148
238
149
239
150
240
# [START healthcare_dicomweb_delete_study]
@@ -228,6 +318,16 @@ def parse_command_line_args():
228
318
default = None ,
229
319
help = 'Unique identifier for a study.' )
230
320
321
+ parser .add_argument (
322
+ '--series_uid' ,
323
+ default = None ,
324
+ help = 'Unique identifier for a series.' )
325
+
326
+ parser .add_argument (
327
+ '--instance_uid' ,
328
+ default = None ,
329
+ help = 'Unique identifier for an instance.' )
330
+
231
331
command = parser .add_subparsers (dest = 'command' )
232
332
233
333
command .add_parser (
@@ -239,6 +339,12 @@ def parse_command_line_args():
239
339
command .add_parser (
240
340
'dicomweb-retrieve-study' ,
241
341
help = dicomweb_retrieve_study .__doc__ )
342
+ command .add_parser (
343
+ 'dicomweb-retrieve-instance' ,
344
+ help = dicomweb_retrieve_instance .__doc__ )
345
+ command .add_parser (
346
+ 'dicomweb-retrieve-rendered' ,
347
+ help = dicomweb_retrieve_rendered .__doc__ )
242
348
command .add_parser (
243
349
'dicomweb-delete-study' ,
244
350
help = dicomweb_delete_study .__doc__ )
@@ -282,6 +388,30 @@ def run_command(args):
282
388
args .dicom_store_id ,
283
389
args .study_uid )
284
390
391
+ elif args .command == 'dicomweb-retrieve-instance' :
392
+ dicomweb_retrieve_instance (
393
+ args .service_account_json ,
394
+ args .base_url ,
395
+ args .project_id ,
396
+ args .cloud_region ,
397
+ args .dataset_id ,
398
+ args .dicom_store_id ,
399
+ args .study_uid ,
400
+ args .series_uid ,
401
+ args .instance_uid )
402
+
403
+ elif args .command == 'dicomweb-retrieve-rendered' :
404
+ dicomweb_retrieve_rendered (
405
+ args .service_account_json ,
406
+ args .base_url ,
407
+ args .project_id ,
408
+ args .cloud_region ,
409
+ args .dataset_id ,
410
+ args .dicom_store_id ,
411
+ args .study_uid ,
412
+ args .series_uid ,
413
+ args .instance_uid )
414
+
285
415
elif args .command == 'dicomweb-delete-study' :
286
416
dicomweb_delete_study (
287
417
args .service_account_json ,
0 commit comments