Skip to content

Commit

Permalink
Fix lookup of element tag given attribute keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
hackermd committed Nov 15, 2018
1 parent c3f8e00 commit 1f40962
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/dicomweb_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.9.3'
__version__ = '0.9.4'

from dicomweb_client.api import DICOMwebClient
13 changes: 9 additions & 4 deletions src/dicomweb_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import requests
import pydicom

from dicomweb_client.error import DICOMJSONError
from dicomweb_client.error import DICOMJSONError, HTTPError


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -152,7 +152,7 @@ def load_json_dataset(dataset):
try:
value = mapping['Value']
except KeyError:
logger.warn(
logger.debug(
'mapping for data element "{}" has no "Value" key'.format(tag)
)
value = [None]
Expand Down Expand Up @@ -412,7 +412,12 @@ def _http_get(self, url, params, headers):
url += self._build_query_string(params)
logger.debug('GET: {}'.format(url))
response = self._session.get(url=url, headers=headers)
response.raise_for_status()
try:
response.raise_for_status()
except requests.exceptions.HTTPError as error:
raise HTTPError(error)
if response.status_code == 204:
logger.warn('empty response')
# The server may not return all results, but rather include a warning
# header to notify that client that there are remaining results.
# (see DICOM Part 3.18 Section 6.7.1.2)
Expand Down Expand Up @@ -1147,4 +1152,4 @@ def lookup_tag(keyword):
'''
tag = pydicom.datadict.tag_for_keyword(keyword)
tag = pydicom.tag.Tag(tag)
return '{0:04x}{1:04x}'.format(tag.group, tag.element)
return '{0:04x}{1:04x}'.format(tag.group, tag.element).upper()
6 changes: 6 additions & 0 deletions src/dicomweb_client/error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'''Custom error classes'''
import requests


class DICOMJSONError(ValueError):
'''Exception class for malformatted DICOM JSON.'''
pass


class HTTPError(requests.exceptions.HTTPError):
'''Exception class for HTTP requests with failure status codes.'''
pass
14 changes: 14 additions & 0 deletions src/dicomweb_client/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
import pydicom


def test_lookup_tag(httpserver, client):
assert client.lookup_tag('StudyInstanceUID') == '0020000D'
assert client.lookup_tag('SeriesInstanceUID') == '0020000E'
assert client.lookup_tag('SOPInstanceUID') == '00080018'
assert client.lookup_tag('PixelData') == '7FE00010'


def test_lookup_keyword(httpserver, client):
assert client.lookup_keyword('0020000D') == 'StudyInstanceUID'
assert client.lookup_keyword('0020000E') == 'SeriesInstanceUID'
assert client.lookup_keyword('00080018') == 'SOPInstanceUID'
assert client.lookup_keyword('7FE00010') == 'PixelData'


def test_search_for_studies(httpserver, client, cache_dir):
cache_filename = os.path.join(cache_dir, 'search_for_studies.json')
with open(cache_filename, 'r') as f:
Expand Down

0 comments on commit 1f40962

Please sign in to comment.