Thursday, February 09, 2012
Google Custom Search

ClearCanvas Highlights

Download our Open Source software
Watch some Videos
Get the Source
Check out our Licensing
Join our  Forums
Some Research: OICR IPP-Trials

Our Community

Membership Membership:
Latest New User Latest: she
New Today New Today: 15
New Yesterday New Yesterday: 26
User Count Overall: 20578

People Online People Online:
Visitors Visitors: 15
Members Members: 2
Total Total: 17

Online Now Online Now:
01: werve
02: apw707

ClearCanvas Community Forums

DicomDirectoryWriter bug fix (and more)
Last Post 2008-07-24 06:10 PM by steve. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
dblanchard
Senior Member
Senior Member
Posts:185

--
2008-07-10 01:31 PM  
Hi,

I found a bug in DicomDirectoryWriter.  I guess it's been around for a while. I think changes made in Feb or March to DicomFile() DicomFile constructors broke it:
            _metaInfo[DicomTags.TransferSyntaxUid].SetStringValue(TransferSyntax.ExplicitVrLittleEndian.UidString);

This added something to the _metaInfo so this line of code in DicomDirectoryWriter.Save(string) failed:

                    if (dicomFile.MetaInfo.Count == 0)
                        dicomFile.Load(DicomReadOptions.Default);

So the dicom file was never loaded so dicomFile.DataSet was empty and thus couldn't get patient and study info, etc.

So the above line needs to be changed to:

                    if (dicomFile.DataSet.Count == 0)
                        dicomFile.Load(DicomReadOptions.Default);

I also found another bug with setting a blank MultiValue string VR (LO) - if the value is empty, then this does not work properly:

dataSet[DicomTags.SeriesDescription].Values = new string[ 0 ];

(something like this gets called in DicomDirectoryWriter.AddSequenceItem() method -   dicomSequenceItem[dicomTag].Values = dataSet[dicomTag].Values;
)

Thus, a blank SeriesDescription tag was not getting written the Dicom Directory and eFilm Lite would not read the whole DICOMDIR file. 

I think the problem is in the DicomAttributeMultiValueText class - Values set property is inconsistent with the SetStringValue() method.  In SetStringValue(), when the stringValue to be set is null or empty string, then the Count is set to 1:

            if (stringValue == null || stringValue.Length == 0)
            {
                Count = 1;
                StreamLength = 0;
                _values = new String[0];
                return;
            }

In the Values set property, this happens:

                if (value is string[])
                {
                    _values = (string[])value;
                    Count =_values.Length;
                    StreamLength = (uint)ToString().Length;
                }

however when the value is string[0] (which is empty string), then the Count is set to 0, which is different from the SetStringValue(), which it is set to 1.  I believe the solution is:

                if (value is string[])
                {
                    _values = (string[])value;
                    Count = _values.Length == 0 ? 1 : _values.Length;
                    StreamLength = (uint)ToString().Length;
                }

Also, another bug I found with the SetString() method, to demonstate:

dataSet[DicomTags.SeriesDescription].SetStringValue("");
// the above makes the value string[0]
dataSet[DicomTags.SeriesDescription].SetString(0, "");
// this last one calls AppendString() cos IsNull is true, and then at the end of AppendString() it does this:

          Count++;

which makes the Count = 2, I think the fix is:

         Count = newArray.Length;

Anyway, I guess I could have made a patch but when I started writing this email there was only the first fix but then I found the rest while I was testing the fix!  Plus I wasn't sure the exact logic with Count property.  Instead of having it a local var, for DicomAttributeMultiValueText class why don't you override and return Values.length?  something like:

public override Count
{
    get
    {
  if (_values == null)
      return 0;
  else if (_values.length == 0)
     return 1;
  else
     return _values.Length;
   }
protected set
{
throw new InvalidOperationException("cannot set multivalue count property");
}
}

Dan





steve
Senior Member
Senior Member
Posts:1885

--
2008-07-14 11:36 AM  
Dan,

Thanks for the feedback. We've got a bit of a busy week this week getting ready for a sprint review. I'll take a closer look at your changes next week and put them into the repository. If you'd want to create a patch in the mean time, that would be a help.

Thanks,
Steve


Real-time support available to Clinical Edition and Team Edition customers
dblanchard
Senior Member
Senior Member
Posts:185

--
2008-07-14 12:30 PM  
Hi Steve,

See attached.

I didn't change the Count property to be overridden and just return the length of the values array, would require a lot of changes in each set...

Attachment: 080714_DicomDirWriter+more.patch

steve
Senior Member
Senior Member
Posts:1885

--
2008-07-24 06:10 PM  
Hi Dan,

I took a look at the patch, and I agree with the changes. I've committed them into the repository. They're in rev 6391 of the repository.

Steve


Real-time support available to Clinical Edition and Team Edition customers
You are not authorized to post a reply.

Active Forums 4.1
Copyright 2011 ClearCanvas Inc.