Skip to content

Commit 1f40962

Browse files
author
hackermd
committed
Fix lookup of element tag given attribute keyword
1 parent c3f8e00 commit 1f40962

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/dicomweb_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.9.3'
1+
__version__ = '0.9.4'
22

33
from dicomweb_client.api import DICOMwebClient

src/dicomweb_client/api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import requests
1616
import pydicom
1717

18-
from dicomweb_client.error import DICOMJSONError
18+
from dicomweb_client.error import DICOMJSONError, HTTPError
1919

2020

2121
logger = logging.getLogger(__name__)
@@ -152,7 +152,7 @@ def load_json_dataset(dataset):
152152
try:
153153
value = mapping['Value']
154154
except KeyError:
155-
logger.warn(
155+
logger.debug(
156156
'mapping for data element "{}" has no "Value" key'.format(tag)
157157
)
158158
value = [None]
@@ -412,7 +412,12 @@ def _http_get(self, url, params, headers):
412412
url += self._build_query_string(params)
413413
logger.debug('GET: {}'.format(url))
414414
response = self._session.get(url=url, headers=headers)
415-
response.raise_for_status()
415+
try:
416+
response.raise_for_status()
417+
except requests.exceptions.HTTPError as error:
418+
raise HTTPError(error)
419+
if response.status_code == 204:
420+
logger.warn('empty response')
416421
# The server may not return all results, but rather include a warning
417422
# header to notify that client that there are remaining results.
418423
# (see DICOM Part 3.18 Section 6.7.1.2)
@@ -1147,4 +1152,4 @@ def lookup_tag(keyword):
11471152
'''
11481153
tag = pydicom.datadict.tag_for_keyword(keyword)
11491154
tag = pydicom.tag.Tag(tag)
1150-
return '{0:04x}{1:04x}'.format(tag.group, tag.element)
1155+
return '{0:04x}{1:04x}'.format(tag.group, tag.element).upper()

src/dicomweb_client/error.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'''Custom error classes'''
2+
import requests
23

34

45
class DICOMJSONError(ValueError):
56
'''Exception class for malformatted DICOM JSON.'''
67
pass
8+
9+
10+
class HTTPError(requests.exceptions.HTTPError):
11+
'''Exception class for HTTP requests with failure status codes.'''
12+
pass

src/dicomweb_client/tests/test_api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
import pydicom
77

88

9+
def test_lookup_tag(httpserver, client):
10+
assert client.lookup_tag('StudyInstanceUID') == '0020000D'
11+
assert client.lookup_tag('SeriesInstanceUID') == '0020000E'
12+
assert client.lookup_tag('SOPInstanceUID') == '00080018'
13+
assert client.lookup_tag('PixelData') == '7FE00010'
14+
15+
16+
def test_lookup_keyword(httpserver, client):
17+
assert client.lookup_keyword('0020000D') == 'StudyInstanceUID'
18+
assert client.lookup_keyword('0020000E') == 'SeriesInstanceUID'
19+
assert client.lookup_keyword('00080018') == 'SOPInstanceUID'
20+
assert client.lookup_keyword('7FE00010') == 'PixelData'
21+
22+
923
def test_search_for_studies(httpserver, client, cache_dir):
1024
cache_filename = os.path.join(cache_dir, 'search_for_studies.json')
1125
with open(cache_filename, 'r') as f:

0 commit comments

Comments
 (0)