skin dose map code throws an error if there are no irradiation events

Issue #642 resolved
David Platten
created an issue
[2018-07-18 15:30:16,742: ERROR/MainProcess] Task remapp.tools.make_skin_map[090f0149-baa9-42aa-8389-2dddf0b6e140] 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\tools\make_skin_map.py", line 91, in make_skin_map
    0].patient_table_relationship_cid.code_meaning.lower()
  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

This is a result of the following code in make_skin_map.py (the first line after the try causes the error):

        try:
            ptr_meaning = study.projectionxrayradiationdose_set.get().irradeventxraydata_set.all()[
                0].patient_table_relationship_cid.code_meaning.lower()
            if ptr_meaning in u"headfirst":
                ptr = u"H"
            elif ptr_meaning in u"feet-first":
                ptr = u"F"
            else:
                logger.info(u"Study PK {0}: Patient table relationship not recognised ({1}). "
                            u"Assuming head first.".format(study_pk, ptr_meaning))
        except AttributeError:
            logger.info(u"Study PK {0}: Patient table relationship not found. Assuming head first.".format(study_pk))

There needs to be an additional except clause for index errors.

Comments (5)

  1. Log in to comment