sjoerdk / dicomtrolley

Retrieve medical images via WADO, MINT, RAD69 and DICOM-QR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

STUDY-level querying with "StudyDate" DICOM-tag

wardhendrix opened this issue · comments

  • dicomtrolley version: 2.1.6
  • Python version: 3.8
  • Operating System: Ubuntu

Description

We would like to query our PACS on STUDY-level by using "StudyDate" as key (DICOM-QR protocol).

What I Did

DicomTrolley returns the following error when querying with "PatientID" and "StudyDate" as keys (STUDY-level):

ValueError: "DICOMQuery" object has no field "StudyDate"

Below follows a snippet of our script:

dicom_tags_criteria = {'PatientID': '1234', 'StudyDate': '20230101'}
query = DICOMQuery(
    include_fields=['PatientID', 'AccessionNumber', 'StudyInstanceUID', 'StudyDate'],
    query_level=QueryLevels.STUDY
)
for key, value in dicom_tags_criteria.items():
    setattr(query, key, value)
results = self.trolley.find_studies(query)

Thanks for the problem description! Sorry for the long wait.

The main issue is this:

  • For date queries, dicomtrolley uses min_study_date and max_study_date parameters with python datetime values. See Finding studies. This abstracts away from the different ways in which date queries are implemented in different backends like Mint and DICOM-QR.

In addition I would suggest two optimizations:

  • Use the generic Query class instead of the more specific DICOMQuery. The generic Query class can be used with any dicomtrolley.Searcher implementation, while DICOMQuery will only work for DICOM-QR. There are no DICOM-QR specific settings you need here.
  • Try to avoid setattr unless you really need to. Especially on a pydantic object. Setattr is a low level operation that bypasses any init logic the object might have. Here you could use **your_dict in the init instead.

The full working updated snippet is then this:

dicom_tags_criteria = {'PatientID': '1234567',
                       'min_study_date': datetime(year=2023, month=1, day=1),
                       'max_study_date': datetime(year=2023, month=1, day=1)}
query = Query(
    **dicom_tags_criteria,
    include_fields=['PatientID', 'AccessionNumber', 'StudyInstanceUID', 'StudyDate'],
    query_level=QueryLevels.STUDY
)
results = trolley.find_studies(query)

Hi Sjoerd, thank you for your detailed answer! I will update our software with your proposed optimizations.