3

After upgrading to fo-dicom 4.0, I started to get a DicomDataException: 'DicomTag doesn't support values' when trying to obtain a DicomDataset from a DICOMDIR file.

Code is as follows:

var dicomDirectory = await DicomDirectory.OpenAsync(dicomdirPath);
foreach (var patientRecord in dicomDirectory.RootDirectoryRecordCollection)
{
    foreach (var studyRecord in patientRecord.LowerLevelDirectoryRecordCollection)
    {
        foreach (var seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection)
        {
            foreach (var imageRecord in seriesRecord.LowerLevelDirectoryRecordCollection)
            {
                //this is the problematic line
                var dicomDataset = imageRecord.GetValue<DicomSequence>(DicomTag.IconImageSequence, 0).Items.First();
                //more stuff
            }
        }
    }
}

With the previous version (3.?) I was doing var dicomImage = imageRecord.Get<DicomSequence>(DicomTag.IconImageSequence).Items.First(); and it worked just fine, but after the upgrade I was getting an Obsolete warning so I changed it to the recommended method, which was GetValue.

How can I get the dataset using the current version of fo-dicom?

Pona
  • 167
  • 1
  • 17
  • 3
    From this change, it appears that `Get` should become a `GetSequence` call, not a `GetValue`: https://github.com/fo-dicom/fo-dicom/commit/e43fdb33703af7b0ecab60c32c9b8800b13912ab – Ben Voigt Oct 21 '18 at 06:01
  • @BenVoigt Yeah, after some more digging I got around the problem by using GetSequence; I guess I got stuck because the Exception message wasn't clear enough (at least for me). I was going to write it as an answer but, given you beat me to it, you could promote your comment to Answer so that I can mark it as such. Thanks – Pona Oct 21 '18 at 23:20
  • 1
    nah, you did the work of writing the code and testing it, so you should have credit. Besides, I know nothing about `fo-dicom`, found that diff by searching – Ben Voigt Oct 22 '18 at 00:07

1 Answers1

4

Finally, after digging through fo-dicom's Gitter and GitHub issues (and as @BenVoight mentioned in the comments as well), I found that in 4.0 we should use GetSequence(DicomTag.IconImageSequence) instead of GetValue<DicomSequence>(DicomTag.IconImageSequence): when retrieving Sequences, using GetValue will throw. Several other Get methods have been added, such as GetValueOrDefault, GetValues<T> instead of GetValue<T[]>, and more, as can be seen in the project's Dataset test.

Also, as a corollary, I also found another API incompatibility in 4.0 regarding the previous version (I'll post it here in case someone upgraded and got lost in the changes): when dealing with DicomImage, we shouldn't access its .Dataset to retrieve values, because it's been deprecated as well. Instead, we should store a reference to the Dataset from which the DicomImage was created in order to retrieve tag values.

Pona
  • 167
  • 1
  • 17