/// <summary>
		/// Load the first instance from the first series of the StudyXml file for a study.
		/// </summary>
		/// <param name="location">The storage location of the study.</param>
		/// <returns></returns>
		protected static DicomFile LoadInstance(StudyStorageLocation location)
		{
			string studyXml = Path.Combine(location.GetStudyPath(), location.StudyInstanceUid + ".xml");

			if (!File.Exists(studyXml))
			{
				return null;
			}

			FileStream stream = FileStreamOpener.OpenForRead(studyXml, FileMode.Open);
			var theDoc = new XmlDocument();
			StudyXmlIo.Read(theDoc, stream);
			stream.Close();
			stream.Dispose();
			var xml = new StudyXml();
			xml.SetMemento(theDoc);
            
			IEnumerator<SeriesXml> seriesEnumerator = xml.GetEnumerator();
			if (seriesEnumerator.MoveNext())
			{
				SeriesXml seriesXml = seriesEnumerator.Current;
				IEnumerator<InstanceXml> instanceEnumerator = seriesXml.GetEnumerator();
				if (instanceEnumerator.MoveNext())
				{
					InstanceXml instance = instanceEnumerator.Current;
					var file = new DicomFile("file.dcm",new DicomAttributeCollection(), instance.Collection)
						{TransferSyntax = instance.TransferSyntax};
					return file;
				}
			}

			return null;
		}
        private static IList <BaseImageLevelUpdateCommand> BuildCommandsFromStudyXml(Type type, StudyXml studyXml, IDicomAttributeProvider originalDicomAttributeProvider)
        {
            var            commandList = new List <BaseImageLevelUpdateCommand>();
            EntityDicomMap fieldMap    = EntityDicomMapManager.Get(type);
            //XmlDocument studyXmlDoc = studyXml.GetMemento(new StudyXmlOutputSettings());

            // Get the First InstanceXml of the first image
            IEnumerator <SeriesXml> seriesEnumerator = studyXml.GetEnumerator();

            seriesEnumerator.MoveNext();
            SeriesXml seriesXml = seriesEnumerator.Current;
            IEnumerator <InstanceXml> instanceEnumerator = seriesXml.GetEnumerator();

            instanceEnumerator.MoveNext();
            InstanceXml instanceXml = instanceEnumerator.Current;

            foreach (DicomTag tag in fieldMap.Keys)
            {
                string         originalValue = null;
                string         newValue      = null;
                DicomAttribute attribute;

                if (originalDicomAttributeProvider != null && originalDicomAttributeProvider.TryGetAttribute(tag, out attribute))
                {
                    originalValue = attribute.ToString();
                }

                if (instanceXml != null)
                {
                    attribute = instanceXml[tag];
                }
                else
                {
                    attribute = null;
                }
                if (attribute != null)
                {
                    newValue = attribute.ToString();
                }
                SetTagCommand cmd = new SetTagCommand(tag.TagValue, originalValue, newValue);
                commandList.Add(cmd);
            }
            return(commandList);
        }
Esempio n. 3
0
        /// <summary>
        /// Load the first instance from the first series of the StudyXml file for a study.
        /// </summary>
        /// <param name="location">The storage location of the study.</param>
        /// <returns></returns>
        protected static DicomFile LoadInstance(StudyStorageLocation location)
        {
            string studyXml = Path.Combine(location.GetStudyPath(), location.StudyInstanceUid + ".xml");

            if (!File.Exists(studyXml))
            {
                return(null);
            }

            FileStream stream     = FileStreamOpener.OpenForRead(studyXml, FileMode.Open);
            var        theMemento = new StudyXmlMemento();

            StudyXmlIo.Read(theMemento, stream);
            stream.Close();
            stream.Dispose();
            var xml = new StudyXml();

            xml.SetMemento(theMemento);

            IEnumerator <SeriesXml> seriesEnumerator = xml.GetEnumerator();

            if (seriesEnumerator.MoveNext())
            {
                SeriesXml seriesXml = seriesEnumerator.Current;
                IEnumerator <InstanceXml> instanceEnumerator = seriesXml.GetEnumerator();
                if (instanceEnumerator.MoveNext())
                {
                    InstanceXml instance = instanceEnumerator.Current;
                    var         file     = new DicomFile("file.dcm", new DicomAttributeCollection(), instance.Collection)
                    {
                        TransferSyntax = instance.TransferSyntax
                    };
                    return(file);
                }
            }

            return(null);
        }