Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue updating ContourImageSequence #1664

Open
NickChng opened this issue Oct 5, 2023 · 2 comments
Open

Issue updating ContourImageSequence #1664

NickChng opened this issue Oct 5, 2023 · 2 comments
Labels

Comments

@NickChng
Copy link

NickChng commented Oct 5, 2023

Describe the bug
Unable to replace ContourImageSequence. This exception is thrown:

System.InvalidOperationException: 'Unable to create DICOM element of type SQ with values of type Dicom.DicomSequence'

To Reproduce

The below attempts to replace the ContourImageSequence with itself (which I assume excludes any errors that may be attributable to user generation of the sequence). To be clear, it fails when I try to AddOrUpdate with a user-generated sequence as well.

// Get Sequence
var contourSequence = SSTemplate.Dataset.GetSequence(DicomTag.ReferencedFrameOfReferenceSequence).Items[0]
.GetSequence(DicomTag.RTReferencedStudySequence).Items[0]
.GetSequence(DicomTag.RTReferencedSeriesSequence).Items[0]
.GetSequence(DicomTag.ContourImageSequence);

// Set Sequence - this fails, even when replacing it with itself!
SSTemplate.Dataset.GetSequence(DicomTag.ReferencedFrameOfReferenceSequence).Items[0]
.GetSequence(DicomTag.RTReferencedStudySequence).Items[0]
.GetSequence(DicomTag.RTReferencedSeriesSequence).Items[0].
AddOrUpdate(DicomTag.ContourImageSequence, contourSequence);

Expected behavior
I expect this to work?

Environment
Fellow Oak DICOM version: 4.0.8
OS: Windows 10 x64
Platform: .NET Framework 4.8

@NickChng NickChng added the new label Oct 5, 2023
@gofal
Copy link
Contributor

gofal commented Oct 6, 2023

The AddOrUpdate method is a facade for the various constructors. If you take a look at the constructor of DicomSequence then you see that it takes a list of DicomDatasets as parameter.
public DicomSequence(DicomTag tag, params DicomDataset[] items)

so you could either call
AddOrUpdate(DicomTag.ContourImageSequence, contourSequence.Items.ToArray());
or - because the variable contourSequence also contains the DicomTag - you can just call
AddOrUpdate(contourSequence);

@gofal gofal added question and removed new labels Oct 6, 2023
@NickChng
Copy link
Author

NickChng commented Oct 6, 2023

Thanks for the help!

In terms of my present issue sending only the contourSequence to the method has resolved the exception. In future I wonder if it might be more user-friendly to adjust the constructor to catch this during compile... DicomSequence presents an IEnumerable<DicomDataset> interface, which is presumably why it's accepted as a DicomDataset[]... it's not super obvious to beginners like me why it should work as a DicomItem but not IEnumerable<DicomDataset>.

At any rate, thanks again and I appreciate the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants