SeiictyUsui / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 0 forks source link

exception thrown accessing dicom object after modifying PatientSetups[0].FixationDevices[2] #51

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. f=dicom.ReadFile( 'Rt_Ion_Plan.dcm' )
2. f.PatientSetups[0].FixationDevices[2] = '1234567-890'
either of the following throw an exception at this point
3a. print str(f)
3b. dicom.WriteFile( 'CorruptedFileBecauseOfException.dcm', f )

Details:
(1) Unzip attached tar file ModifyFixationDevicesBug.tar.bz2 into temp
directory.
(2) python ModifyingFixationDevicesCorruptsDataStructures.py

What version of the product are you using? On what operating system?
0.9.2 (bug also occurs with 0.9.3)

Please provide any additional information below.
python
import dicom
f=dicom.ReadFile( 'RT_Ion_Plan_pt00000030.dcm' )
print str(f)
<<<SNIP>>>
(300a, 0180)  Patient Setup Sequence   1 item(s) ----
   (0018, 5100) Patient Position                    CS: 'HFS'
   (300a, 0182) Patient Setup Number                IS: '1'
   (300a, 0190)  Fixation Device Sequence   5 item(s) ----
      (300a, 00f9) Accessory Code                      LO: '1008756-001'
      (300a, 0192) Fixation Device Type                CS: 'WHOLE_BODY_POD'
      (300a, 0194) Fixation Device Label               SH: 'MPSS_SHORT_EXT'
      (300a, 0196) Fixation Device Description         ST: 'Table
Extension, Short Head Pod'
      ---------
      (300a, 00f9) Accessory Code                      LO: 'N00000030SP'
      (300a, 0192) Fixation Device Type                CS: 'MOLD'
      (300a, 0194) Fixation Device Label               SH: 'MPSS_SP_LINER'
      (300a, 0196) Fixation Device Description         ST: 'Table Liner,
Short Head Pod'
      ---------
      (300a, 00f9) Accessory Code                      LO: '???'
      (300a, 0192) Fixation Device Type                CS: 'MOLD'
      (300a, 0194) Fixation Device Label               SH: 'MPSS_TRI_SUPP_M'
      (300a, 0196) Fixation Device Description         ST: 'Triangle
Pillow, Medium'
      ---------
      (300a, 00f9) Accessory Code                      LO: '???'
      (300a, 0192) Fixation Device Type                CS: 'BITEBLOCK'
      (300a, 0194) Fixation Device Label               SH: 'MOUTHPIECE'
      (300a, 0196) Fixation Device Description         ST: 'Biteblock
mouthpiece'
      ---------
      (300a, 00f9) Accessory Code                      LO: '1003010-002'
      (300a, 0192) Fixation Device Type                CS: 'HEADFRAME'
      (300a, 0194) Fixation Device Label               SH: 'MPSS_Z_BOX'
      (300a, 0196) Fixation Device Description         ST: 'Z-Box'
      ---------
<<<SNIP>>>
===========================================================================
===========================================================================

f.PatientSetups[0].FixationDevices[2] = '1234567-890'  ###### CORRUPTS FILE

dicom.WriteFile( 'Corrupted_TR_Ion_Plan_pt00000030.dcm', f )

Traceback (most recent call last):
  File "ModifyingFixationDevicesCorruptsDataStructures.py", line 48, in
<module>
    dicom.WriteFile( strFilename, f )   # exception thrown here
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 289, in WriteFile
    WriteDataset(fp, no_group2_dataset)
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 144, in WriteDataset
    WriteDataElement(fp, dataset[tag])
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 116, in WriteDataElement
    writers[VR](fp, data_element) # call the function to write that kind of
item
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 154, in WriteSequence
    WriteSequenceItem(fp, dataset)
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 163, in WriteSequenceItem
    WriteDataset(fp, dataset)
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 144, in WriteDataset
    WriteDataElement(fp, dataset[tag])
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 116, in WriteDataElement
    writers[VR](fp, data_element) # call the function to write that kind of
item
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 154, in WriteSequence
    WriteSequenceItem(fp, dataset)
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 163, in WriteSequenceItem
    WriteDataset(fp, dataset)
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter
.py",
line 141, in WriteDataset
    tags = dataset.keys()
AttributeError: 'str' object has no attribute 'keys'

===========================================================================

print str(f)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/dataset.py
",
line 393, in __str__
    return self._PrettyStr()
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/dataset.py
",
line 334, in _PrettyStr
    strings.append(dataset._PrettyStr(indent+1))
  File
"/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/dataset.py
",
line 334, in _PrettyStr
    strings.append(dataset._PrettyStr(indent+1))
AttributeError: 'str' object has no attribute '_PrettyStr'

Original issue reported on code.google.com by howard.b...@gmail.com on 23 Jun 2009 at 7:24

GoogleCodeExporter commented 9 years ago
This looks like a question of setting the wrong object type -- an item in a 
Sequence 
needs to be a Dataset instance. Probably what is needed here is:
f.PatientSetups[0].FixationDevices[2].AccessoryCode = '1234567-890'

However, the code should test that an item assignment is in fact a Dataset. 
I'll create 
that as an issue for the issue list.

Original comment by darcymason@gmail.com on 23 Jun 2009 at 10:29

GoogleCodeExporter commented 9 years ago
Thank you!
--Bryan

Original comment by howard.b...@gmail.com on 24 Jun 2009 at 3:53