Esempio n. 1
0
        /// <summary>
        /// Performs a SERIES query for the given Study Instance Uid.
        /// </summary>
        public IList <SeriesIdentifier> SeriesQuery(string studyInstanceUid)
        {
            Platform.CheckForEmptyString(studyInstanceUid, "studyInstanceUid");

            SeriesIdentifier criteria = new SeriesIdentifier();

            criteria.StudyInstanceUid = studyInstanceUid;
            return(SeriesQuery(criteria));
        }
Esempio n. 2
0
        /// <summary>
        /// Performs a SERIES level query.
        /// </summary>
        /// <exception cref="FaultException{DataValidationFault}">Thrown when some part of the data in the request is poorly formatted.</exception>
        /// <exception cref="FaultException{QueryFailedFault}">Thrown when the query fails.</exception>
        public IList<SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
        {
            var results = _real.SeriesQuery(queryCriteria);

            AuditHelper.LogQueryIssued(_remoteServer.AETitle, _remoteServer.ScpParameters.HostName, EventSource.CurrentUser,
                           EventResult.Success, SopClass.StudyRootQueryRetrieveInformationModelFindUid,
                           queryCriteria.ToDicomAttributeCollection());

            return results;
        }
Esempio n. 3
0
        /// <summary>
        /// Performs a SERIES level query.
        /// </summary>
        /// <exception cref="FaultException{DataValidationFault}">Thrown when some part of the data in the request is poorly formatted.</exception>
        /// <exception cref="FaultException{QueryFailedFault}">Thrown when the query fails.</exception>
        public IList <SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
        {
            IList <SeriesIdentifier> results = _client.SeriesQuery(queryCriteria);

            if (_seriesComparer != null)
            {
                results = CollectionUtils.Sort(results, _seriesComparer.Compare);
            }

            return(results);
        }
		public IList<SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
		{
			var request = new SeriesQueryRequest
			{
				Criteria = queryCriteria,
				LocalApplicationEntity = _localAE,
				RemoteApplicationEntity = new ApplicationEntity(_remoteAE)
			};

			var query = new DicomStudyRootQueryApplication();
			var result = query.SeriesQuery(request);
			return result.Results;
		}
Esempio n. 5
0
        public IList <SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
        {
            var request = new SeriesQueryRequest
            {
                Criteria = queryCriteria,
                LocalApplicationEntity  = _localAE,
                RemoteApplicationEntity = new ApplicationEntity(_remoteAE)
            };

            var query  = new DicomStudyRootQueryApplication();
            var result = query.SeriesQuery(request);

            return(result.Results);
        }
Esempio n. 6
0
 private IEnumerable<Series> GetSeries(SeriesIdentifier criteria)
 {
     return GetSeries(new SeriesEntry { Series = criteria });
 }
Esempio n. 7
0
 public IList<SeriesIdentifier> SeriesQuery(SeriesIdentifier criteria)
 {
     var entries = GetSeries(criteria);
     return entries.Select(e => e.ToStoreEntry().Series).ToList();
 }
Esempio n. 8
0
		public IList<SeriesIdentifier> LocateSeriesByStudy(string studyInstanceUid, out LocateFailureInfo[] failures)
		{
			Platform.CheckForEmptyString(studyInstanceUid, "studyInstanceUid");

			var criteria = new SeriesIdentifier {StudyInstanceUid = studyInstanceUid};
			var result = LocateSeries(new LocateSeriesRequest {Criteria = criteria});
			failures = result.Failures.ToArray();
			return result.Series;
		}
 public System.Collections.Generic.IList<SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
 {
     var criteria = new SeriesEntry {Series = queryCriteria};
     var result = Real.GetSeriesEntries(new GetSeriesEntriesRequest { Criteria = criteria });
     return result.SeriesEntries.Select(e => e.Series).ToList();
 }
Esempio n. 10
0
 public IList <SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
 {
     return(Query <SeriesIdentifier, StudyRootFindScu>(queryCriteria));
 }
Esempio n. 11
0
 /// <summary>
 /// Performs a SERIES level query.
 /// </summary>
 /// <exception cref="FaultException{DataValidationFault}">Thrown when some part of the data in the request is poorly formatted.</exception>
 /// <exception cref="FaultException{QueryFailedFault}">Thrown when the query fails.</exception>
 public IList <SeriesIdentifier> SeriesQuery(SeriesIdentifier queryCriteria)
 {
     return(base.Channel.SeriesQuery(queryCriteria));
 }
        // Loads annotations from local storage
        private List<IAimDocumentInstance> LoadLocalAimDocumentsForStudy(string studyInstanceUid)
        {
            var seriesIdentifier = new SeriesIdentifier { StudyInstanceUid = studyInstanceUid, Modality = AimManager.AimModality };
            var seriesEntryRequest = new GetSeriesEntriesRequest { Criteria = new SeriesEntry { Series = seriesIdentifier } };

            IList<SeriesEntry> entries = null;
            Platform.GetService<IStudyStoreQuery>(s => entries = s.GetSeriesEntries(seriesEntryRequest).SeriesEntries);

            var instanceToAimFileInfoMap = new Dictionary<string, AimFileInfo>();

            // Get all unique AE Titles for the study. Can study have more than one?
            // We only need to query each AETitle once, or there will be duplicates/errors.
            var studyAes = (from seriesEntry in entries where seriesEntry != null select seriesEntry.Series.RetrieveAE).GroupBy(ae => ae.AETitle).Select(ae1 => ae1.First()).OfType<IDicomServiceNode>().ToList();
            if (!studyAes.Any())
            {
                Platform.Log(LogLevel.Debug, "Study ({0}} has no SR (AIM Annotations) objects", studyInstanceUid);
                return null;
            }
            foreach (var studyAe in studyAes)
            {

                IStudyLoader studyLoader;
                try
                {
                    studyLoader = studyAe.GetService<IStudyLoader>();
                }
                catch (Exception ex)
                {
                    throw new AimManagerException("Cannot get study loader", ex);
                }

                int numberOfSops = studyLoader.Start(new StudyLoaderArgs(studyInstanceUid, null, new StudyLoaderOptions(true)));
                for (int i = 0; i < numberOfSops; i++)
                {
                    using (var sop = studyLoader.LoadNextSop())
                    {
                        if (sop != null && sop.Modality == AimManager.AimModality)
                        {
                            var localSopDataSource = sop.DataSource as ILocalSopDataSource;
                            if (localSopDataSource != null)
                            {
                                var filePathName = localSopDataSource.Filename;
                                switch (AimManager.GetAimVersionFromSop(sop))
                                {
                                    case AimVersion.AimVersion3:
                                        instanceToAimFileInfoMap.Add(filePathName,
                                                                     new AimFileInfo(AimVersion.AimVersion3, sop.StudyInstanceUid, sop.SeriesInstanceUid, sop.SopInstanceUid));
                                        break;
                                    case AimVersion.AimVersion4:
                                        instanceToAimFileInfoMap.Add(filePathName,
                                                                     new AimFileInfo(AimVersion.AimVersion4, sop.StudyInstanceUid, sop.SeriesInstanceUid, sop.SopInstanceUid));
                                        break;
                                }
                            }
                        }
                    }
                }
            }

            if (instanceToAimFileInfoMap.Any())
            {
                var aimDocumentInstances = new List<IAimDocumentInstance>();
                var aim4Instances = instanceToAimFileInfoMap.Where(instance => instance.Value.AimVersion == AimVersion.AimVersion4).ToList();
                if (aim4Instances.Any())
                {
                    using (var dcmHelper = new Aim4.Aim4NativeDcmHelper())
                    {
                        foreach (var instanceInfo in aim4Instances)
                        {
                            var aimDocumentInstance = ReadAimDocumentFromDicomFile(dcmHelper,
                                                                            instanceInfo.Key, instanceInfo.Value.StudyInstanceUid,
                                                                            instanceInfo.Value.SeriesInstanceUid, instanceInfo.Value.SopInstanceUid);
                            if (aimDocumentInstance != null)
                                aimDocumentInstances.Add(aimDocumentInstance);
                        }
                    }
                }

                return aimDocumentInstances.Any() ? aimDocumentInstances : null;
            }

            return null;
        }
        private void LoadNewSeries(List<string> changedStudyInstanceUids)
        {
            const string segmentationModality = "SEG";

            foreach (string studyInstanceUid in changedStudyInstanceUids)
            {
                Study loadedStudy = ImageViewer.StudyTree.GetStudy(studyInstanceUid);
                if (loadedStudy == null)
                    continue; // the given study is not loaded in this ImageViewer

                // Query for new segmentation SOP Instances for the given study
                var seriesIdentifier = new SeriesIdentifier
                                           {
                                               StudyInstanceUid = studyInstanceUid,
                                               Modality = segmentationModality
                                           };
                var seriesEntryRequest = new GetSeriesEntriesRequest
                                             {Criteria = new SeriesEntry {Series = seriesIdentifier}};

                List<SeriesEntry> entries = null;
                Platform.GetService<IStudyStoreQuery>(
                    s =>
                    entries =
                    s.GetSeriesEntries(seriesEntryRequest)
                        .SeriesEntries.Where(
                            entry =>
                            loadedStudy.Series.All(series => series.SeriesInstanceUid != entry.Series.SeriesInstanceUid))
                        .ToList());

                // Get all unique AE Titles for the study. Can study have more than one?
                // We only need to query each AETitle once, or there will be duplicates/errors.
                List<IDicomServiceNode> studyAes =
                    (from seriesEntry in entries where seriesEntry != null select seriesEntry.Series.RetrieveAE).GroupBy
                        (
                            ae => ae.AETitle).Select(ae1 => ae1.First()).OfType<IDicomServiceNode>().ToList();

                if (!studyAes.Any())
                    continue;

                var reallyUpdatedStudies = new HashSet<string>();
                foreach (IDicomServiceNode studyAe in studyAes)
                {
                    IStudyLoader studyLoader;
                    try
                    {
                        studyLoader = studyAe.GetService<IStudyLoader>();
                    }
                    catch (Exception ex)
                    {
                        //Platform.Log(LogLevel.Error, ex, "Cannot get study loader", studyAe);
                        throw new Exception("Cannot get study loader", ex);
                    }

                    int numberOfSops =
                        studyLoader.Start(new StudyLoaderArgs(studyInstanceUid, null, new StudyLoaderOptions(true)));

                    // Load new segmentation SOP Instances
                    if (numberOfSops > 0)
                    {
                        for (int i = 0; i < numberOfSops; i++)
                        {
                            Sop sop = studyLoader.LoadNextSop();
                            if (sop != null && sop.Modality == segmentationModality)
                            {
                                try
                                {
                                    if (ImageViewer.StudyTree.AddSop(sop))
                                    {
                                        SegmentationDocument segmentationDocument =
                                            new SegmentationDeserializer(sop).DeserializeSegmenationDocument();
                                        if (segmentationDocument != null)
                                        {
                                            foreach (Seg seg in segmentationDocument.Segs)
                                            {
                                                IPresentationImage segPresentationImage = null;
                                                if (seg.ImageSeriesUid == null)
                                                {
                                                    if (seg.SegmentImageData != null &&
                                                        seg.SegmentImageData.SegmentFrameData != null &&
                                                        seg.SegmentImageData.SegmentFrameData.Count > 0)
                                                    {
                                                        foreach (
                                                            IImageBox imageBox in
                                                                ImageViewer.PhysicalWorkspace.ImageBoxes.Where(
                                                                    imageBox => imageBox != null))
                                                        {
                                                            if (imageBox.DisplaySet != null)
                                                            {
                                                                segPresentationImage = SegmentationGraphicsHelpers.
                                                                    PresentationImageFromPositionOrientation(
                                                                        seg.SegmentImageData.SegmentFrameData[0].
                                                                            ImagePositionPatient,
                                                                        seg.SegmentImageData.SegmentFrameData[0].
                                                                            ImageOrientationPatient,
                                                                        imageBox.DisplaySet,
                                                                        seg.SegmentImageData.FrameOfReferenceUid);
                                                            }
                                                            if (segPresentationImage != null)
                                                                break;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    segPresentationImage =
                                                        GetFirstPresentationImageForSeries(sop.StudyInstanceUid,
                                                                                           seg.ImageSeriesUid);
                                                }
                                                if (segPresentationImage == null)
                                                {
                                                    Platform.Log(LogLevel.Info,
                                                                 "Failed to find a series and image to display a segmentation frame on (SOP Instance UID={0}, Label = {1}) (New)",
                                                                 segmentationDocument.SopInstanceUid, seg.Label);
                                                }
                                                else
                                                {
                                                    SegmentationGraphicsHelpers.CreateSeriesGraphicsForSeg(
                                                        segPresentationImage, seg, segmentationDocument,
                                                        sop.DataSource as IDicomMessageSopDataSource);
                                                    reallyUpdatedStudies.Add(studyInstanceUid);
                                                }

                                                var sopProvider = segPresentationImage as ISopProvider;
                                                if (sopProvider != null)
                                                    AddSegmentationMenuInfo(segmentationDocument, seg, sopProvider.Sop);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        sop.Dispose();
                                    }
                                }
                                catch (SopValidationException ex)
                                {
                                    Platform.Log(LogLevel.Error, ex,
                                                 "Failed to add newly loaded Segmentation SOP  to the StudyTree (studyInstanceUid={0}; SOPInstaceUID={1})",
                                                 sop.StudyInstanceUid, sop.SopInstanceUid);
                                    sop.Dispose();
                                }
                            }
                            else
                            {
                                sop.Dispose();
                            }
                        }
                    }
                }

                // Update component, if present
                if (reallyUpdatedStudies.Count > 0)
                    UpdateSegmentationTreeInComponent();
            }
        }