IndexError from qrscu

Issue #711 resolved
David Platten created an issue

When running a CT query of PACS with the -toshiba option I receive an IndexError when querying for certain dates.

Celery log extract:

[2018-12-20 08:40:58,055: ERROR/MainProcess] Task remapp.netdicom.qrscu.qrscu[38dbf6b1-7b9e-4854-bbf8-b7e95a5b553d] raised unexpected: IndexError('list index out of range',)
Traceback (most recent call last):
  File "d:\server_apps\python27\lib\site-packages\celery\app\trace.py", line 368, in trace_task
    R = retval = fun(*args, **kwargs)
  File "d:\server_apps\python27\lib\site-packages\celery\app\trace.py", line 623, in __protected_call__
    return self.run(*args, **kwargs)
  File "D:\Server_Apps\python27\Lib\site-packages\openrem\remapp\netdicom\qrscu.py", line 953, in qrscu
    assoc, query, all_mods, filters, get_toshiba_images)
  File "D:\Server_Apps\python27\Lib\site-packages\openrem\remapp\netdicom\qrscu.py", line 269, in _prune_series_responses
    _get_toshiba_dose_images(series, assoc, query_id)
  File "D:\Server_Apps\python27\Lib\site-packages\openrem\remapp\netdicom\qrscu.py", line 338, in _get_toshiba_dose_images
    if images[0].sop_class_uid != '1.2.840.10008.5.1.4.1.1.7':
  File "d:\server_apps\python27\lib\site-packages\django\db\models\query.py", line 201, in __getitem__
    return list(qs)[0]
IndexError: list index out of range

I'm investigating this now.

Comments (7)

  1. Ed McDonagh

    Is an empty series not catered for? Or have the instances been deleted but not the series somehow?

    When you say certain dates, presumably that is because it is happening with certain studies?

    I wonder if there are no studies, and it is carrying on regardless? With the new logging, it becomes very evident that the routine doesn't stop when there are no returns or they have all been rejected as unsuitable.

  2. David Platten reporter

    I'm re-running the query in debug mode now with the date that is causing the problem.

  3. David Platten reporter

    The problem is caused when a series has zero images. Below is an extract from qrscu.py and my celery log. The series has no images in it. The zero image count causes the "Toshiba option..." message, but the code then continues and tries to access image[0] which causes the IndexError because there is no image[0].

            if images.count() == 0:
                logger.debug("{0} Toshiba option: No images in series, deleting series.".format(query_id))
                series.delete()
            logger.info("Trying to print image info")
            logger.info("images is: {0}".format(images))
            logger.info("images[0] is: {0}".format(images[0]))
            if images[0].sop_class_uid != '1.2.840.10008.5.1.4.1.1.7':
                logger.debug("{0}: Toshiba option: Image series, SOPClassUID {1}, "
                             " delete all but first image.".format(query_id, images[0].sop_class_uid))
                images.exclude(sop_instance_uid__exact=images[0].sop_instance_uid).delete()
                logger.debug("{0}: Toshiba option: Deleted other images, now {1} remaining (should be 1)".format(
                    query_id, images.count()))
                series.image_level_move = True
                series.save()
            else:
                logger.debug("{0}: Toshiba option: Secondary capture series, keep the {1} images in this series.".format(
                    query_id, images.count()))
    
    [20/Dec/2018 09:33:40] DEBUG [remapp.netdicom.qrscu:336] f3d4f731-dc2d-4b56-ad28-3f2322416fc7 Toshiba option: No images in series, deleting series.
    [20/Dec/2018 09:33:40] INFO [remapp.netdicom.qrscu:338] Trying to print image info
    [20/Dec/2018 09:33:40] INFO [remapp.netdicom.qrscu:339] images is: []
    
  4. David Platten reporter

    I've fixed this by using an else after the first if statement:

            if images.count() == 0:
                logger.debug("{0} Toshiba option: No images in series, deleting series.".format(query_id))
                series.delete()
            else:
                logger.info("Trying to print image info")
                logger.info("images is: {0}".format(images))
                logger.info("images[0] is: {0}".format(images[0]))
                if images[0].sop_class_uid != '1.2.840.10008.5.1.4.1.1.7':
                    logger.debug("{0}: Toshiba option: Image series, SOPClassUID {1}, "
                                 " delete all but first image.".format(query_id, images[0].sop_class_uid))
                    images.exclude(sop_instance_uid__exact=images[0].sop_instance_uid).delete()
                    logger.debug("{0}: Toshiba option: Deleted other images, now {1} remaining (should be 1)".format(
                        query_id, images.count()))
                    series.image_level_move = True
                    series.save()
                else:
                    logger.debug("{0}: Toshiba option: Secondary capture series, keep the {1} images in this series.".format(
                        query_id, images.count()))
    
  5. Log in to comment