internal void CalculateBaseCollectionForSeries() { if (_instanceList.Count < 2) { return; } // Optimization: a base collection has already been created, just return. if (_seriesTagsStream != null) { return; } IEnumerator <InstanceXml> iterator = GetEnumerator(); if (false == iterator.MoveNext()) { return; } DicomAttributeCollection collect1 = iterator.Current.Collection; if (false == iterator.MoveNext()) { return; } DicomAttributeCollection collect2 = iterator.Current.Collection; _seriesTagsStream = new BaseInstanceXml(collect1, collect2); }
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); }
internal void SetBaseInstance(BaseInstanceXml baseInstance) { if (_baseInstance != baseInstance) { // force the element to be regenerated when GetMemento() is called _cachedElement = null; } _baseInstance = baseInstance; }
internal void SetMemento(XmlNode theSeriesNode) { _dirty = true; _seriesInstanceUid = theSeriesNode.Attributes["UID"].Value; if (!theSeriesNode.HasChildNodes) { return; } XmlNode childNode = theSeriesNode.FirstChild; while (childNode != null) { // Just search for the first study node, parse it, then break if (childNode.Name.Equals("BaseInstance")) { if (childNode.HasChildNodes) { XmlNode instanceNode = childNode.FirstChild; if (instanceNode.Name.Equals("Instance")) { _seriesTagsStream = new BaseInstanceXml(instanceNode); } } } else if (childNode.Name.Equals("Instance")) { // This assumes the BaseInstance is in the xml ahead of the actual instances, note, however, // that if there is only 1 instance in the series, there will be no base instance value InstanceXml instanceStream; if (_seriesTagsStream == null) { instanceStream = new InstanceXml(childNode, null); } else { instanceStream = new InstanceXml(childNode, _seriesTagsStream.Collection); } _instanceList.Add(instanceStream.SopInstanceUid, instanceStream); } childNode = childNode.NextSibling; } }
internal XmlElement GetMemento(XmlDocument theDocument, StudyXmlOutputSettings settings) { _dirty = false; // Calc the base attributes CalculateBaseCollectionForSeries(); XmlElement series = theDocument.CreateElement("Series"); XmlAttribute seriesInstanceUid = theDocument.CreateAttribute("UID"); seriesInstanceUid.Value = _seriesInstanceUid; series.Attributes.Append(seriesInstanceUid); XmlElement baseElement = theDocument.CreateElement("BaseInstance"); // 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) { XmlElement baseInstance = _seriesTagsStream.GetMemento(theDocument, settings); baseElement.AppendChild(baseInstance); } else { _seriesTagsStream = null; } series.AppendChild(baseElement); foreach (InstanceXml instance in _instanceList.Values) { instance.SetBaseInstance(_seriesTagsStream); XmlElement instanceElement = instance.GetMemento(theDocument, settings); series.AppendChild(instanceElement); } return(series); }