public static DicomRTFrameOFReference CreateReferencedFrames(IReadOnlyList <DicomIdentifiers> identifiers)
        {
            // Check all identifiers have the same SeriesInstanceUid
            var firstIdentifier = identifiers.First();

            if (identifiers.Any(x => x.Series.SeriesInstanceUid != firstIdentifier.Series.SeriesInstanceUid))
            {
                throw new InvalidOperationException("the list of slices are not for the same series");
            }

            if (identifiers.Any(x => x.Study.StudyInstanceUid != firstIdentifier.Study.StudyInstanceUid))
            {
                throw new InvalidOperationException("the list of slices are not for the same study");
            }

            if (identifiers.Any(x => x.FrameOfReference.FrameOfReferenceUid != firstIdentifier.FrameOfReference.FrameOfReferenceUid))
            {
                throw new InvalidOperationException("the list of slices are not from the same frame of reference");
            }

            var frameOfReference = new DicomRTFrameOFReference(firstIdentifier.FrameOfReference.FrameOfReferenceUid, new List <DicomRTReferencedStudy>()
            {
                new DicomRTReferencedStudy(DicomRTReferencedStudy.StudyComponentManagementSopClass, firstIdentifier.Study.StudyInstanceUid, new List <DicomRTReferencedSeries>()
                {
                    new DicomRTReferencedSeries(firstIdentifier.Series.SeriesInstanceUid, identifiers.Select(x => DicomRTContourImageItem.Reference(x.Image.SopCommon)).ToList())
                })
            });

            return(frameOfReference);
        }
        public static DicomDataset Write(DicomRTFrameOFReference dicomRtFrameOfReference)
        {
            var ds = new DicomDataset();

            ds.Add(DicomTag.FrameOfReferenceUID, dicomRtFrameOfReference.FrameOfRefUID);
            var lisOfStudies = new List <DicomDataset>();

            foreach (var refStudy in dicomRtFrameOfReference.ReferencedStudies)
            {
                var newDS = DicomRTReferencedStudy.Write(refStudy);
                lisOfStudies.Add(newDS);
            }
            if (lisOfStudies.Count > 0)
            {
                ds.Add(new DicomSequence(DicomTag.RTReferencedStudySequence, lisOfStudies.ToArray()));
            }
            return(ds);
        }