FNNDSC / med2image

Converts medical images to more displayable formats, e.g. NIfTI to jpg.
MIT License
185 stars 56 forks source link

can not assume most of dicom fields are there #2

Open NicolasRannou opened 9 years ago

NicolasRannou commented 9 years ago

It is only safe to assume we have study, series, and sop uids... we should make sure the other ones are available.

chris@chris:/neuro/users/chris/log $>cd /neuro/users/chris/data/MR_SERVICE_PATIENT_ID_1-1545/2015.03.20-055Y-20150320_0642-3021/097_HeadMatrix_H1P_H2P_H3P_H4P_Tra_sn-097_HeadMatrix_H1P_H2P_H3P_H4P_Tra_sn-35027; /net/tautona/neuro/labs/grantlab/users/chris/src/chrisreloaded/lib/med2image/med2image.py -i $(/bin/ls -1 *dcm | head -n 1) -o %inputFile%SeriesDescription%ProtocolName -t jpg -s m
Mon Mar 23 05:58:19 2015 chris med2image.py[11072]: Converting DICOM image.
Mon Mar 23 05:58:19 2015 chris med2image.py[11072]: PatientName:                                SERVICE PATIENT
Traceback (most recent call last):
  File "/net/tautona/neuro/labs/grantlab/users/chris/src/chrisreloaded/lib/med2image/med2image.py", line 568, in <module>
    C_convert.run()
  File "/net/tautona/neuro/labs/grantlab/users/chris/src/chrisreloaded/lib/med2image/med2image.py", line 250, in run
    self._log('PatientAge:                                 %s\n' % self._dcm.PatientAge)
  File "/usr/lib/python2.7/dist-packages/dicom/dataset.py", line 248, in __getattr__
    "'{0:s}'.".format(name))
AttributeError: Dataset does not have attribute 'PatientAge'.
atomass commented 8 years ago

+1

I solved with

        # line 369
        self._log('Converting DICOM image.\n')
        self._log('PatientName:                                %s\n' % self._dcm.PatientName if hasattr(self._dcm, 'PatientName') else "--")
        self._log('PatientAge:                                 %s\n' % self._dcm.PatientAge if hasattr(self._dcm, 'PatientAge') else "--")
        self._log('PatientSex:                                 %s\n' % self._dcm.PatientSex if hasattr(self._dcm, 'PatientSex') else "--")
        self._log('PatientID:                                  %s\n' % self._dcm.PatientID if hasattr(self._dcm, 'PatientID') else "--")
        self._log('SeriesDescription:                          %s\n' % self._dcm.SeriesDescription if hasattr(self._dcm, 'SeriesDescription') else "--")
        self._log('ProtocolName:                               %s\n' % self._dcm.ProtocolName if hasattr(self._dcm, 'ProtocolName') else "--")```