Пример #1
0
        /// <summary>
        /// Get an XML document representing the <see cref="StudyXml"/>.
        /// </summary>
        /// <remarks>
        /// This method can be called multiple times as DICOM SOP Instances are added
        /// to the <see cref="StudyXml"/>.  Note that caching is done of the
        /// XmlDocument to improve performance.  If the collections in the InstanceStreams
        /// are modified, the caching mechanism may cause the updates not to be contained
        /// in the generated XmlDocument.
        /// </remarks>
        /// <returns></returns>
        public StudyXmlMemento GetMemento(StudyXmlOutputSettings settings)
        {
            var memento = new StudyXmlMemento();

            if (_doc == null)
            {
                _doc = new XmlDocument();
            }
            else
            {
                _doc.RemoveAll();
            }
            memento.Document = _doc;

            if (settings.OptimizedMemento)
            {
                memento.RootNode = new StudyXmlMemento.StudyXmlNode
                {
                    ElementName = "ClearCanvasStudyXml",
                };

                var studyElement = new StudyXmlMemento.StudyXmlNode
                {
                    ElementName = "Study",
                };
                studyElement.AddAttribute("UID", _studyInstanceUid);

                memento.RootNode.AddChild(studyElement);

                foreach (SeriesXml series in this)
                {
                    var seriesElement = series.GetMemento(memento, settings);

                    studyElement.AddChild(seriesElement);
                }
            }
            else
            {
                XmlElement clearCanvas = _doc.CreateElement("ClearCanvasStudyXml");

                XmlElement study = _doc.CreateElement("Study");

                XmlAttribute studyInstanceUid = _doc.CreateAttribute("UID");
                studyInstanceUid.Value = _studyInstanceUid;
                study.Attributes.Append(studyInstanceUid);

                foreach (SeriesXml series in this)
                {
                    XmlElement seriesElement = series.GetMemento(_doc, settings);

                    study.AppendChild(seriesElement);
                }

                clearCanvas.AppendChild(study);
                _doc.AppendChild(clearCanvas);
            }

            return(memento);
        }
Пример #2
0
        internal StudyXmlMemento.StudyXmlNode GetMemento(StudyXmlMemento theDocument, StudyXmlOutputSettings settings)
        {
            _dirty = false;
            // Calc the base attributes
            CalculateBaseCollectionForSeries();

            var seriesElement = new StudyXmlMemento.StudyXmlNode {
                ElementName = "Series"
            };

            seriesElement.AddAttribute("UID", _seriesInstanceUid);


            // If there's only 1 total image in the series, leave an empty base instance
            // and just have the entire image be stored.
            if (_instanceList.Count > 1)
            {
                if (!string.IsNullOrEmpty(_seriesTagsStream.XmlFragment))
                {
                    seriesElement.AddChild(new StudyXmlMemento.StudyXmlNode(_seriesTagsStream.XmlFragment));
                }
                else
                {
                    XmlElement baseElement  = theDocument.Document.CreateElement("BaseInstance");
                    XmlElement baseInstance = _seriesTagsStream.GetMemento(theDocument.Document, settings);
                    baseElement.AppendChild(baseInstance);

                    var baseNode = new StudyXmlMemento.StudyXmlNode(baseElement);
                    _seriesTagsStream.XmlFragment = baseNode.XmlElementFragment;
                    seriesElement.AddChild(baseNode);
                }
            }
            else
            {
                _seriesTagsStream = null;
                seriesElement.AddChild(new StudyXmlMemento.StudyXmlNode("<BaseInstance/>"));
            }

            foreach (InstanceXml instance in _instanceList.Values)
            {
                instance.SetBaseInstance(_seriesTagsStream);

                if (!string.IsNullOrEmpty(instance.XmlFragment))
                {
                    seriesElement.AddChild(new StudyXmlMemento.StudyXmlNode(instance.XmlFragment));
                }
                else
                {
                    XmlElement instanceElement = instance.GetMemento(theDocument.Document, settings);

                    var node = new StudyXmlMemento.StudyXmlNode(instanceElement);
                    instance.XmlFragment = node.XmlElementFragment;
                    seriesElement.AddChild(node);
                }
            }

            return(seriesElement);
        }