private GetSeriesEntriesResult GetSeriesEntries(GetSeriesEntriesRequest request) { using (var context = new DataAccessContext()) { var entries = context.GetStudyStoreQuery().GetSeriesEntries(request.Criteria); var criteria = (request.Criteria ?? new SeriesEntry()).Series ?? new SeriesIdentifier(); AuditHelper.LogQueryIssued(null, null, EventSource.CurrentUser, EventResult.Success, SopClass.StudyRootQueryRetrieveInformationModelFindUid, criteria.ToDicomAttributeCollection()); return new GetSeriesEntriesResult { SeriesEntries = entries }; } }
public GetSeriesEntriesResult GetSeriesEntries(GetSeriesEntriesRequest request) { Platform.CheckForNullReference(request, "request"); if (request.Criteria == null) request.Criteria = new SeriesEntry(); if (request.Criteria.Series == null) request.Criteria.Series = new SeriesIdentifier(); return new GetSeriesEntriesResult { SeriesEntries = _studyRootQuery.SeriesQuery(request.Criteria.Series) .Select(identifier => new SeriesEntry { Series = identifier }).ToList() }; }
private GetSeriesEntriesResult GetSeriesEntries(GetSeriesEntriesRequest request) { using (var context = new DataAccessContext()) { var entries = context.GetStudyStoreQuery().GetSeriesEntries(request.Criteria); var criteria = (request.Criteria ?? new SeriesEntry()).Series ?? new SeriesIdentifier(); AuditHelper.LogQueryIssued(null, null, EventSource.CurrentUser, EventResult.Success, SopClass.StudyRootQueryRetrieveInformationModelFindUid, criteria.ToDicomAttributeCollection()); return(new GetSeriesEntriesResult { SeriesEntries = entries }); } }
public GetSeriesEntriesResult GetSeriesEntries(GetSeriesEntriesRequest request) { throw new NotImplementedException(); }
public abstract GetSeriesEntriesResult GetSeriesEntries(GetSeriesEntriesRequest request);
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(); } } }
GetSeriesEntriesResult IStudyStoreQuery.GetSeriesEntries(GetSeriesEntriesRequest request) { return ServiceProxyHelper.Call(GetSeriesEntries, request); }
GetSeriesEntriesResult IStudyStoreQuery.GetSeriesEntries(GetSeriesEntriesRequest request) { return(ServiceProxyHelper.Call(GetSeriesEntries, request)); }
// 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); }
// 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(); } }