예제 #1
0
        /// <summary>
        /// Add a <see cref="DicomFile"/> to the StudyXml.
        /// </summary>
        /// <param name="theFile">The <see cref="DicomFile"/> to add.</param>
        /// <param name="fileSize">The size in bytes of the file being added.</param>
        /// <param name="settings">The settings used when writing out the file.</param>
        /// <returns>true on scuccess.</returns>
        public bool AddFile(DicomFile theFile, long fileSize, StudyXmlOutputSettings settings)
        {
            Platform.CheckForNullReference(settings, "settings");

            // Create a copy of the collection without pixel data
            DicomAttributeCollection data = new InstanceXmlDicomAttributeCollection(theFile.DataSet, true,
                                                                                    settings.IncludePrivateValues !=
                                                                                    StudyXmlTagInclusion.IgnoreTag,
                                                                                    settings.IncludeUnknownTags !=
                                                                                    StudyXmlTagInclusion.IgnoreTag,
                                                                                    DicomTags.PixelData);

            String studyInstanceUid = data[DicomTags.StudyInstanceUid];

            if (String.IsNullOrEmpty(_studyInstanceUid))
            {
                _studyInstanceUid = studyInstanceUid;
            }
            else if (!_studyInstanceUid.Equals(studyInstanceUid))
            {
                Platform.Log(LogLevel.Error,
                             "Attempting to add an instance to the stream where the study instance UIDs don't match for SOP: {0}",
                             theFile.MediaStorageSopInstanceUid);
                return(false);
            }
            String seriesInstanceUid = data[DicomTags.SeriesInstanceUid];

            SeriesXml series = this[seriesInstanceUid];

            if (series == null)
            {
                series = new SeriesXml(seriesInstanceUid);
                this[seriesInstanceUid] = series;
            }

            String sopInstanceUid = data[DicomTags.SopInstanceUid];

            InstanceXml instance = series[sopInstanceUid];

            if (instance != null)
            {
                // Decided to remove this log as part of the Marmot development milestone.  Didn't seem like much value.
                //Platform.Log(LogLevel.Warn,
                //             "Attempting to add a duplicate SOP instance to the stream.  Replacing value: {0}",
                //             theFile.MediaStorageSopInstanceUid);
            }

            instance = new InstanceXml(data, theFile.SopClass, theFile.TransferSyntax);
            instance.SourceAETitle  = theFile.SourceApplicationEntityTitle;
            instance.SourceFileName = theFile.Filename;
            instance.FileSize       = fileSize;
            series[sopInstanceUid]  = instance;

            return(true);
        }
예제 #2
0
        public InstanceXml(XmlNode instanceNode, DicomAttributeCollection baseCollection)
        {
            InstanceXmlDicomAttributeCollection thisCollection = new InstanceXmlDicomAttributeCollection();

            _collection = thisCollection;
            _collection.ValidateVrValues  = false;
            _collection.ValidateVrLengths = false;

            if (baseCollection != null)
            {
                AddExcludedTagsFromBase(baseCollection);

                _baseCollectionEnumerator = baseCollection.GetEnumerator();
                if (!_baseCollectionEnumerator.MoveNext())
                {
                    _baseCollectionEnumerator = null;
                }
            }

            if (!instanceNode.HasChildNodes)
            {
                return;
            }

            _instanceXmlEnumerator = instanceNode.ChildNodes.GetEnumerator();
            if (!_instanceXmlEnumerator.MoveNext())
            {
                _instanceXmlEnumerator = null;
            }

            if (instanceNode.Attributes["UID"] != null)
            {
                _sopInstanceUid = instanceNode.Attributes["UID"].Value;
            }

            if (instanceNode.Attributes["SourceAETitle"] != null)
            {
                _sourceAETitle = XmlUnescapeString(instanceNode.Attributes["SourceAETitle"].Value);
            }

            if (instanceNode.Attributes["SopClassUID"] != null)
            {
                _sopClass = SopClass.GetSopClass(instanceNode.Attributes["SopClassUID"].Value);
            }

            _transferSyntax = instanceNode.Attributes["TransferSyntaxUID"] != null
                                ? TransferSyntax.GetTransferSyntax(instanceNode.Attributes["TransferSyntaxUID"].Value)
                                : TransferSyntax.ExplicitVrLittleEndian;

            if (instanceNode.Attributes["SourceFileName"] != null)
            {
                _sourceFileName = instanceNode.Attributes["SourceFileName"].Value;
            }

            if (instanceNode.Attributes["FileSize"] != null)
            {
                long.TryParse(instanceNode.Attributes["FileSize"].Value, out _fileSize);
            }

            // This should never happen
            if (_sopClass == null)
            {
                _sopClass = SopClass.GetSopClass(Collection[DicomTags.SopClassUid].GetString(0, String.Empty));
            }
        }