Skip to content

Commit

Permalink
Be more strict about DICOMweb query
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Sep 18, 2023
1 parent 095e24f commit d1b22e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Top

- Currently when images are received by the DICOMweb API they are temporarily downloaded to the file system before then send back to the requester. Try to pass the dataset directly.
- Update documentation
- Fix some stuff and use our fork then of DICOMwebClient
-- <https://github.com/ImagingDataCommons/dicomweb-client/issues/88>
Expand All @@ -13,9 +14,9 @@
- Locked info for other apps like batch_transfer_locked.html
- Hint when app is locked for admin user
- Encrypt data between swarm containers
-- <https://docs.docker.com/network/drivers/overlay/#encrypt-traffic-on-an-overlay-network>
-- <https://forums.docker.com/t/configuring-encryption-for-swarm-overlay-network-in-compose/29469/2>
-- We can also make the network attachable to do the "exec" stuff in tasks.py using one off containers using "run"
-- <https://docs.docker.com/network/drivers/overlay/#encrypt-traffic-on-an-overlay-network>
-- <https://forums.docker.com/t/configuring-encryption-for-swarm-overlay-network-in-compose/29469/2>
-- We can also make the network attachable to do the "exec" stuff in tasks.py using one off containers using "run"

## High Priority

Expand Down
11 changes: 3 additions & 8 deletions adit/core/utils/dicom_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def from_dict(cls, query: dict[str, str], **additional_attributes) -> "QueryData
ds = Dataset()

for k, v in query.items():
_set_dataset_value(ds, k, v, ignore_invalid_tags=True, ignore_invalid_values=True)
_set_dataset_value(ds, k, v)

for k, v in additional_attributes.items():
_set_dataset_value(ds, k, v)
Expand Down Expand Up @@ -238,13 +238,9 @@ def __contains__(self, keyword: str) -> bool:
return keyword in self._ds


def _set_dataset_value(
ds: Dataset, k: str, v: Any, ignore_invalid_tags=False, ignore_invalid_values=False
) -> None:
def _set_dataset_value(ds: Dataset, k: str, v: Any) -> None:
t = datadict.tag_for_keyword(k)
if t is None:
if ignore_invalid_tags:
return
raise ValueError(f"Unknown DICOM tag with keyword: {k}")

vr = datadict.dictionary_VR(t)
Expand All @@ -265,5 +261,4 @@ def _set_dataset_value(
elem = DataElement(t, vr, v, validation_mode=config.RAISE)
ds.add(elem)
except ValueError as err:
if not ignore_invalid_values:
raise ValueError(f"Invalid value for DICOM tag {t} ({vr}): {v}") from err
raise ValueError(f"Invalid value for DICOM tag '{k}' (VR {vr}): {v} ({str(err)})") from err
14 changes: 12 additions & 2 deletions adit/dicom_web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ async def get(
query[key] = value

source_server = await self._fetch_dicom_server(request, ae_title, "source")
results = await qido_find(source_server, query, self.level)

try:
results = await qido_find(source_server, query, self.level)
except ValueError as err:
logger.warn(f"Invalid DICOMweb study query - {err}")
raise ValidationError(str(err)) from err

return Response([result.dataset.to_json_dict() for result in results])

Expand Down Expand Up @@ -90,7 +95,12 @@ async def get(

query["StudyInstanceUID"] = study_uid
source_server = await self._fetch_dicom_server(request, ae_title, "source")
results = await qido_find(source_server, query, self.level)

try:
results = await qido_find(source_server, query, self.level)
except ValueError as err:
logger.warn(f"Invalid DICOMweb series query - {err}")
raise ValidationError(str(err)) from err

return Response([result.dataset.to_json_dict() for result in results])

Expand Down

0 comments on commit d1b22e2

Please sign in to comment.