From 8217b28eddf79cf8bd2bcd25996845c8788c5f63 Mon Sep 17 00:00:00 2001 From: hackermd Date: Tue, 20 Mar 2018 14:48:06 -0400 Subject: [PATCH 1/2] Add URL of Github repo to setup.py --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index ffbe8c1..531a3ca 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import os import io -import sys import re import setuptools @@ -17,7 +15,7 @@ description='Client for DICOMweb RESTful services.', author='Markus D. Herrmann', maintainer='Markus D. Herrmann', - website='https://github.com/clindatsci/dicomweb-python-client', + url='https://github.com/clindatsci/dicomweb-client', license='MIT', platforms=['Linux', 'MacOS', 'Windows'], classifiers=[ From e04b6565156d5d4b565ec360285cc99bf32ed80a Mon Sep 17 00:00:00 2001 From: hackermd Date: Wed, 21 Mar 2018 21:43:57 -0400 Subject: [PATCH 2/2] Fix parsing of nested DICOM JSON values --- src/dicomweb_client/api.py | 64 +++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/dicomweb_client/api.py b/src/dicomweb_client/api.py index 25e71ed..22813ac 100644 --- a/src/dicomweb_client/api.py +++ b/src/dicomweb_client/api.py @@ -57,31 +57,34 @@ def _create_dataelement(tag, vr, value): '"Value" of data element "{}" must be an array.'.format(tag) ) if vr == 'SQ': - value = value[0] - ds = _init_dataset() - if value is not None: - for key, val in value.items(): - if 'vr' not in val: - raise DICOMJSONError( - 'Data element "{}" must have key "vr".'.format(tag) - ) - supported_value_keys = {'Value', 'BulkDataURI', 'InlineBinary'} - val_key = None - for k in supported_value_keys: - if k in val: - val_key = k - break - if val_key is None: - logger.warn( - 'data element has neither key "{}".'.format( - '" nor "'.join(supported_value_keys) + elem_value = [] + for value_item in value: + ds = _init_dataset() + if value_item is not None: + for key, val in value_item.items(): + if 'vr' not in val: + raise DICOMJSONError( + 'Data element "{}" must have key "vr".'.format(tag) ) - ) - e = pydicom.dataelem.DataElement(tag=tag, value=None, VR=vr) - else: - e = _create_dataelement(key, val['vr'], val[val_key]) - ds.add(e) - elem_value = [ds] + supported_keys = {'Value', 'BulkDataURI', 'InlineBinary'} + val_key = None + for k in supported_keys: + if k in val: + val_key = k + break + if val_key is None: + logger.warn( + 'data element has neither key "{}".'.format( + '" nor "'.join(supported_keys) + ) + ) + e = pydicom.dataelem.DataElement( + tag=tag, value=None, VR=vr + ) + else: + e = _create_dataelement(key, val['vr'], val[val_key]) + ds.add(e) + elem_value.append(ds) elif vr == 'PN': # Special case, see DICOM Part 18 Annex F2.2 # http://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_F.2.2 @@ -234,9 +237,12 @@ def __init__(self, url, username=None, password=None, ca_bundle=None): '(?::(?P\d+))?(?:(?P/\w+))?' ) match = re.match(pattern, self.base_url) - self.protocol = match.group('scheme') - self.host = match.group('host') - self.port = match.group('port') + try: + self.protocol = match.group('scheme') + self.host = match.group('host') + self.port = match.group('port') + except AttributeError: + raise ValueError('Malformed URL: {}'.format(self.base_url)) if self.port is not None: self.port = int(self.port) else: @@ -577,7 +583,7 @@ def _http_post_multipart_application_dicom(self, url, datasets): 'boundary="boundary"' ) encoded_datasets = list() - # TODO: can we do this more memory efficient? + # TODO: can we do this more memory efficient? Concatenations? for ds in datasets: with BytesIO() as b: pydicom.dcmwrite(b, ds) @@ -927,7 +933,7 @@ def retrieve_instance_frames_rendered(self, study_instance_uid, url = self._get_instances_url( study_instance_uid, series_instance_uid, sop_instance_uid ) - params = {'quality': 100} # TODO: viewport, window + params = {'quality': 95} # TODO: viewport, window frame_list = ','.join([str(n) for n in frame_numbers]) url += '/frames/{frame_list}/rendered'.format(frame_list=frame_list) pixeldata = self._http_get_multipart_image(url, compression, **params)