Ejemplo n.º 1
0
        /// <summary>
        /// Populate at the IMAGE level a response message.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="tagList"></param>
        /// <param name="theInstanceStream"></param>
        private void PopulateInstance(DicomAttributeCollection request, DicomMessage response, List<uint> tagList,
                                      InstanceXml theInstanceStream)
        {
            DicomAttributeCollection dataSet = response.DataSet;

            dataSet[DicomTags.RetrieveAeTitle].SetStringValue(Partition.AeTitle);
            dataSet[DicomTags.InstanceAvailability].SetStringValue("ONLINE");

            DicomAttributeCollection sourceDataSet = theInstanceStream.Collection;

            if (false == sourceDataSet.Contains(DicomTags.SpecificCharacterSet))
            {
                dataSet[DicomTags.SpecificCharacterSet].SetStringValue(sourceDataSet[DicomTags.SpecificCharacterSet].ToString());
                dataSet.SpecificCharacterSet = sourceDataSet[DicomTags.SpecificCharacterSet].ToString(); // this will ensure the data is encoded using the specified character set
            }

            foreach (uint tag in tagList)
            {
                try
                {
                    switch (tag)
                    {
                        case DicomTags.PatientId:
                            dataSet[DicomTags.PatientId].SetStringValue(request[DicomTags.PatientId].ToString());
                            break;
                        case DicomTags.StudyInstanceUid:
                            dataSet[DicomTags.StudyInstanceUid].SetStringValue(
                                request[DicomTags.StudyInstanceUid].ToString());
                            break;
                        case DicomTags.SeriesInstanceUid:
                            dataSet[DicomTags.SeriesInstanceUid].SetStringValue(
                                request[DicomTags.SeriesInstanceUid].ToString());
                            break;
                        case DicomTags.QueryRetrieveLevel:
                            dataSet[DicomTags.QueryRetrieveLevel].SetStringValue("IMAGE");
                            break;
                        default:
                            if (sourceDataSet.Contains(tag))
                                dataSet[tag] = sourceDataSet[tag].Copy();
                            else
                                dataSet[tag].SetNullValue();
                            break;
                        // Meta tags that should have not been in the RQ, but we've already set
                        case DicomTags.RetrieveAeTitle:
                        case DicomTags.InstanceAvailability:
                        case DicomTags.SpecificCharacterSet:
                            break;
                    }
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Warn, e, "Unexpected error setting tag {0} in C-FIND-RSP",
                                 dataSet[tag].Tag.ToString());
                    dataSet[tag].SetNullValue();
                }
            }
        }
 protected override void OnExecute(CommandProcessor theProcessor)
 {
     // backup
     if (_studyXml.Contains(_seriesUid))
     {
         Platform.Log(LogLevel.Info, "Removing SOP {0} from StudyXML for study {1}", _sopInstanceUid, _studyInstanceUid);
         _oldInstanceXml = _studyXml[_seriesUid][_sopInstanceUid];
         if (!_studyXml.RemoveInstance(_seriesUid, _sopInstanceUid))
             throw new ApplicationException(String.Format("Could not remove SOP Instance {0} from study {1}", _sopInstanceUid, _studyInstanceUid));
     }
 }
Ejemplo n.º 3
0
        public ImageServerSopDataSource(InstanceXml instanceXml, string path)
            : base(new DicomFile(path, new DicomAttributeCollection(), instanceXml.Collection))
        {
            //These don't get set properly for instance xml.
            DicomFile sourceFile = (DicomFile)SourceMessage;
            sourceFile.TransferSyntaxUid = instanceXml.TransferSyntax.UidString;
            sourceFile.MediaStorageSopInstanceUid = instanceXml.SopInstanceUid;
            sourceFile.MetaInfo[DicomTags.SopClassUid].SetString(0, instanceXml.SopClass.Uid);

            _path = path;
        }
Ejemplo n.º 4
0
		protected XmlSopDataSource(InstanceXml instanceXml)
			: base(new DicomFile("", new DicomAttributeCollection(), instanceXml.Collection))
        {
			//These don't get set properly for instance xml.
			var sourceFile = (DicomFile)SourceMessage;
			sourceFile.TransferSyntaxUid = instanceXml.TransferSyntax.UidString;
			sourceFile.MediaStorageSopInstanceUid = instanceXml.SopInstanceUid;
			sourceFile.MetaInfo[DicomTags.SopClassUid].SetString(0, instanceXml.SopClass == null
																	? instanceXml[DicomTags.SopClassUid].ToString()
																	: instanceXml.SopClass.Uid);
		}
        protected override void OnExecute(CommandProcessor commandProcessor)
        {
            _instanceXml = _studyXml.FindInstanceXml(_seriesInstanceUid, _sopInstanceUid);

            _studyXml.RemoveInstance(_seriesInstanceUid, _sopInstanceUid);

            // flush it into disk
            // Write it back out.  We flush it out with every added image so that if a failure happens,
            // we can recover properly.
            if (!commandProcessor.ExecuteSubCommand(this, new SaveXmlCommand(_studyXml, _studyLocation)))
                throw new ApplicationException(commandProcessor.FailureReason);
        }
Ejemplo n.º 6
0
		public StreamingSopDataSource(InstanceXml instanceXml, string host, string aeTitle, string wadoUriPrefix, int wadoServicePort)
			: base(new DicomFile("", new DicomAttributeCollection(), instanceXml.Collection))
		{
			//These don't get set properly for instance xml.
			DicomFile sourceFile = (DicomFile)SourceMessage;
			sourceFile.TransferSyntaxUid = instanceXml.TransferSyntax.UidString;
			sourceFile.MediaStorageSopInstanceUid = instanceXml.SopInstanceUid;

		    sourceFile.MetaInfo[DicomTags.SopClassUid].SetString(0,
		                                                         instanceXml.SopClass == null
		                                                             ? instanceXml[DicomTags.SopClassUid].ToString()
		                                                             : instanceXml.SopClass.Uid);

		    _host = host;
			_aeTitle = aeTitle;
			_wadoUriPrefix = wadoUriPrefix;
			_wadoServicePort = wadoServicePort;
		}
		public StreamingSopDataSource(InstanceXml instanceXml, IDicomFileLoader loader)
			: base(new DicomFile("", new DicomAttributeCollection(), instanceXml.Collection))
		{
			if (!loader.CanLoadCompleteHeader)
				throw new ArgumentException("Loader must be capable of retrieving the full image header.", "loader");
			if (!loader.CanLoadFramePixelData)
				throw new ArgumentException("Loader must be capable of loading frame pixel data.", "loader");

			_loader = loader;
			//These don't get set properly for instance xml.
			var sourceFile = (DicomFile)SourceMessage;
			sourceFile.TransferSyntaxUid = instanceXml.TransferSyntax.UidString;
			sourceFile.MediaStorageSopInstanceUid = instanceXml.SopInstanceUid;

		    sourceFile.MetaInfo[DicomTags.SopClassUid].SetString(0,
		                                                         instanceXml.SopClass == null
		                                                             ? instanceXml[DicomTags.SopClassUid].ToString()
		                                                             : instanceXml.SopClass.Uid);
		}
Ejemplo n.º 8
0
		internal SopInstance(Series parentSeries, InstanceXml instanceXml)
		{
			_parentSeries = parentSeries;
			_xml = instanceXml;
			_metaInfo = new DicomAttributeCollection();

			if (instanceXml.TransferSyntax != null)
			{
				string transferSyntax = instanceXml.TransferSyntax.UidString;
				if (!String.IsNullOrEmpty(transferSyntax))
					_metaInfo[DicomTags.TransferSyntaxUid].SetString(0, transferSyntax);
			}

			if (instanceXml.SopClass != null)
			{
				string sopClass = instanceXml.SopClass.Uid;
				if (!String.IsNullOrEmpty(sopClass))
					_metaInfo[DicomTags.SopClassUid].SetString(0, sopClass);
			}
		}
Ejemplo n.º 9
0
        /// <summary>
        /// Compare at the IMAGE level if a query matches the data in an <see cref="InstanceXml"/> file.
        /// </summary>
        /// <param name="queryMessage"></param>
        /// <param name="matchTagList"></param>
        /// <param name="instanceStream"></param>
        /// <returns></returns>
        private static bool CompareInstanceMatch(DicomMessageBase queryMessage, IEnumerable<uint> matchTagList,
                                                 InstanceXml instanceStream)
        {
            foreach (uint tag in matchTagList)
            {
                if (!instanceStream.Collection.Contains(tag))
                    continue;

                DicomAttribute sourceAttrib = queryMessage.DataSet[tag];
                DicomAttribute matchAttrib = instanceStream.Collection[tag];

                if (sourceAttrib.Tag.VR.Equals(DicomVr.SQvr))
                    continue; // TODO

                if (sourceAttrib.IsNull)
                    continue;

                string sourceString = sourceAttrib.ToString();
                if (sourceString.Contains("*") || sourceString.Contains("?"))
                {
                    sourceString = sourceString.Replace("*", "[\x21-\x7E]");
                    sourceString = sourceString.Replace("?", ".");
                    if (!Regex.IsMatch(matchAttrib.ToString(), sourceString))
                        return false;
                }
                else if (!sourceAttrib.Equals(matchAttrib))
                    return false;
            }

            return true;
        }
Ejemplo n.º 10
0
        private void buttonMoveScuMove_Click(object sender, EventArgs e)
        {
            if (_moveScu != null)
            {
                if (_moveScu.Status == ScuOperationStatus.Running)
                {
                    _moveScu.Cancel();
                    return;
                }
                buttonMoveScuMove.Text = "Move";
                _moveScu.Dispose();
                _moveScu = null;
            }

            var theDoc = new XmlDocument();

            buttonMoveScuMove.Text = "Cancel";

            try
            {
                theDoc.LoadXml(textBoxMoveMessage.Text);
                var instanceXml = new InstanceXml(theDoc.DocumentElement, null);
                DicomAttributeCollection queryMessage = instanceXml.Collection;

                if (queryMessage == null)
                {
                    Platform.Log(LogLevel.Error, "Unexpected error parsing move message");
                    return;
                }

                

                if (comboBoxMoveScuQueryType.SelectedIndex == 0)
                {
                    _moveScu = new StudyRootMoveScu(textBoxMoveScuLocalAe.Text,textBoxMoveScuRemoteAe.Text,textBoxMoveScuRemoteHost.Text,
                        int.Parse(textBoxMoveScuRemotePort.Text),textBoxMoveScuMoveDestination.Text);
                }
                else
                {
                    _moveScu = new PatientRootMoveScu(textBoxMoveScuLocalAe.Text, textBoxMoveScuRemoteAe.Text,
                                                         textBoxMoveScuRemoteHost.Text,
                                                         int.Parse(textBoxMoveScuRemotePort.Text),
                                                         textBoxMoveScuMoveDestination.Text);
                }
                if (queryMessage.Contains(DicomTags.PatientId))
                {
                    var array = queryMessage[DicomTags.PatientId].Values as string[];
                    if (array != null)
                        foreach(string s in array)
                            _moveScu.AddPatientId(s);
                }
                if (queryMessage.Contains(DicomTags.StudyInstanceUid))
                {
                    var array = queryMessage[DicomTags.StudyInstanceUid].Values as string[];
                    if (array != null)
                        foreach (string s in array)
                            _moveScu.AddStudyInstanceUid(s);
                }
                if (queryMessage.Contains(DicomTags.SeriesInstanceUid))
                {
                    var array = queryMessage[DicomTags.SeriesInstanceUid].Values as string[];
                    if (array != null)
                        foreach (string s in array)
                            _moveScu.AddSeriesInstanceUid(s);
                }
                if (queryMessage.Contains(DicomTags.SopInstanceUid))
                {
                    var array = queryMessage[DicomTags.SopInstanceUid].Values as string[];
                    if (array != null)
                        foreach (string s in array)
                            _moveScu.AddSopInstanceUid(s);
                }

                _moveScu.ImageMoveCompleted += delegate(object o, EventArgs args)
                                                   {
                                                       var eventScu = o as MoveScuBase;
                                                       if (eventScu != null)
                                                       {
                                                           Platform.Log(LogLevel.Info,
                                                                        "Total SubOps: {0}, Remaining SubOps {1}, Success SubOps: {2}, Failure SubOps: {3}, Warning SubOps: {4}, Failure Description: {5}",
                                                                        eventScu.TotalSubOperations,
                                                                        eventScu.RemainingSubOperations,
                                                                        eventScu.SuccessSubOperations,
                                                                        eventScu.FailureSubOperations,
                                                                        eventScu.WarningSubOperations,
                                                                        eventScu.FailureDescription);
                                                       }
                                                   };
                _moveScu.BeginMove(delegate {
                                           Invoke(new Action<string>(delegate { buttonMoveScuMove.Text = "Move"; }), new object[]{"Move"});                                           
                                       }, this );

            }
            catch (Exception x)
            {
                Platform.Log(LogLevel.Error, x, "Unable to perform move");
                buttonMoveScuMove.Text = "Move";
            }		
        }
Ejemplo n.º 11
0
		private void buttonQueryScuSearch_Click(object sender, EventArgs e)
		{
            if (_findScu != null)
            {
                if (_findScu.Status == ScuOperationStatus.Running)
                {
                    return;
                }
                _findScu.Dispose();
                _findScu = null;
            }
		    var theDoc = new XmlDocument();

			try
			{
				theDoc.LoadXml(textBoxQueryMessage.Text);
				var instanceXml = new InstanceXml(theDoc.DocumentElement, null);
				DicomAttributeCollection queryMessage = instanceXml.Collection;

				if (queryMessage == null)
				{
					Platform.Log(LogLevel.Error, "Unexpected error parsing query message");
				}

				int maxResults;
				if (!int.TryParse(textBoxQueryScuMaxResults.Text, out maxResults))
					maxResults = -1;

				IList<DicomAttributeCollection> resultsList;
				if (comboBoxQueryScuQueryType.SelectedIndex == 0)
				{
				    _findScu = new StudyRootFindScu
				                      {
				                          MaxResults = maxResults
				                      };
                    _findScu.BeginFind(textBoxQueryScuLocalAe.Text,
								 textBoxQueryScuRemoteAe.Text,
								 textBoxQueryScuRemoteHost.Text,
								 int.Parse(textBoxQueryScuRemotePort.Text), queryMessage, delegate
								                                                             {
                                                                                                 foreach (DicomAttributeCollection msg in _findScu.Results)
                                                                                                 {
                                                                                                     Platform.Log(LogLevel.Info, msg.DumpString);
                                                                                                 }
								                                                             },this);
				}
				else
				{
                    _findScu = new PatientRootFindScu
				                      {
				                          MaxResults = maxResults
				                      };
                    _findScu.BeginFind(textBoxQueryScuLocalAe.Text,
								 textBoxQueryScuRemoteAe.Text,
								 textBoxQueryScuRemoteHost.Text,
								 int.Parse(textBoxQueryScuRemotePort.Text), queryMessage, delegate
								                                                             {
                                                                                                 foreach (DicomAttributeCollection msg in _findScu.Results)
                                                                                                 {
                                                                                                     Platform.Log(LogLevel.Info, msg.DumpString);
                                                                                                 }
								                                                             },this);
              
				}

			
			}
			catch (Exception x)
			{
				Platform.Log(LogLevel.Error, x, "Unable to perform query");
			}		
		}
		private static PaletteColorLut CreateFromColorPaletteSopInstanceXml(string resourceName)
		{
			try
			{
				var resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly());
				using (var xmlStream = resourceResolver.OpenResource(resourceName))
				{
					var xmlDocument = new XmlDocument();
					xmlDocument.Load(xmlStream);
					var docRootNode = CollectionUtils.FirstElement(xmlDocument.GetElementsByTagName("ClearCanvasColorPaletteDefinition")) as XmlElement;
					if (docRootNode != null)
					{
						var instanceNode = CollectionUtils.FirstElement(docRootNode.GetElementsByTagName("Instance")) as XmlElement;
						if (instanceNode != null)
						{
							var instanceXml = new InstanceXml(instanceNode, null);
							return Create(instanceXml.Collection);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Platform.Log(LogLevel.Debug, ex, "Failed to load embedded standard color palette SOP from resource {0}", resourceName);
			}
			return null;
		}
Ejemplo n.º 13
0
		internal SopInstance(Series parentSeries, InstanceXml instanceXml)
		{
			_parentSeries = parentSeries;
			_xml = instanceXml;
		}
Ejemplo n.º 14
0
		public BasicXmlSopDataSource(InstanceXml instanceXml, string path)
			: this(instanceXml, DicomStreamOpener.Create(path)) {}
Ejemplo n.º 15
0
 public TestInstance(InstanceXml instanceXml, DicomFile real) : base(instanceXml)
 {
     _real = real;
 }
Ejemplo n.º 16
0
		public BasicXmlSopDataSource(InstanceXml instanceXml, DicomStreamOpener streamOpener)
			: base(instanceXml)
		{
			_streamOpener = streamOpener;
		}
Ejemplo n.º 17
0
		private void buttonQueryScuSearch_Click(object sender, EventArgs e)
		{
			XmlDocument theDoc = new XmlDocument();

			try
			{
				theDoc.LoadXml(textBoxQueryMessage.Text);
				InstanceXml instanceXml = new InstanceXml(theDoc.DocumentElement, null);
				DicomAttributeCollection queryMessage = instanceXml.Collection;

				if (queryMessage == null)
				{
					Logger.LogError("Unexpected error parsing query message");
				}

				int maxResults;
				if (!int.TryParse(textBoxQueryScuMaxResults.Text, out maxResults))
					maxResults = -1;

				IList<DicomAttributeCollection> resultsList;
				if (comboBoxQueryScuQueryType.SelectedIndex == 0)
				{
					StudyRootFindScu findScu = new StudyRootFindScu();
					findScu.MaxResults = maxResults;
					resultsList = findScu.Find(textBoxQueryScuLocalAe.Text,
								 textBoxQueryScuRemoteAe.Text,
								 textBoxQueryScuRemoteHost.Text,
								 int.Parse(textBoxQueryScuRemotePort.Text), queryMessage);
					findScu.Dispose();
				}
				else
				{
					PatientRootFindScu findScu = new PatientRootFindScu();
					findScu.MaxResults = maxResults;
					resultsList = findScu.Find(textBoxQueryScuLocalAe.Text,
								 textBoxQueryScuRemoteAe.Text,
								 textBoxQueryScuRemoteHost.Text,
								 int.Parse(textBoxQueryScuRemotePort.Text), queryMessage);
					findScu.Dispose();
				}

				foreach (DicomAttributeCollection msg in resultsList)
				{
					Logger.LogInfo(msg.DumpString);
				}
			}
			catch (Exception x)
			{
				Logger.LogErrorException(x, "Unable to perform query");
				return;
			}		
		}
Ejemplo n.º 18
0
        public void UpdateTags(string xml)
        {
            var theDoc = new XmlDocument();

            try
            {
                theDoc.LoadXml(xml);
                var instanceXml = new InstanceXml(theDoc.DocumentElement, null);
                DicomAttributeCollection queryMessage = instanceXml.Collection;

                if (queryMessage == null)
                {
                    Platform.Log(LogLevel.Error, "Unexpected error parsing move message");
                    return;
                }

                foreach (var attribute in queryMessage)
                {
                    _dicomFile.DataSet[attribute.Tag] = attribute.Copy();
                }

            }
            catch (Exception x)
            {
                Platform.Log(LogLevel.Error, x, "Unable to perform update");
            }		
        }
Ejemplo n.º 19
0
		public StreamingSopDataSource(InstanceXml instanceXml, ISopDicomFileLoader loader)
			: base(instanceXml)
		{
			_loader = loader;
			CheckLoaderCapabilities();
		}