private void LoadSop(string file) { try { Sop sop = Sop.Create(file); try { _viewer.StudyTree.AddSop(sop); } catch (SopValidationException) { sop.Dispose(); throw; } } catch (Exception e) { // Things that could go wrong in which an exception will be thrown: // 1) file is not a valid DICOM image // 2) file is a valid DICOM image, but its image parameters are invalid // 3) file is a valid DICOM image, but we can't handle this type of DICOM image _failed++; Platform.Log(LogLevel.Error, e); } _total++; }
public void TestGetPixelAspectRatioString() { using (var dataset = CreateMockDataset("CR", SopClass.ComputedRadiographyImageStorage, null, new SizeF(0.6f, 0.5f), "FIDUCIAL", "details", null)) using (var sop = (ImageSop)Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Assert.AreEqual(@"5\6", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.33333331, 0.3333333); Assert.AreEqual(@"1\1", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.7074200013, 0.7074200009); Assert.AreEqual(@"1\1", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.3, 0.4); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.4, 0.3000001); Assert.AreEqual(@"4\3", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.55, 0.4); Assert.AreEqual(@"11\8", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.7777777, 0.3333333); Assert.AreEqual(@"7\3", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } }
///<summary>Inserts one Sop into the database. Provides option to use the existing priKey.</summary> public static long Insert(Sop sop, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { sop.SopNum = ReplicationServers.GetKey("sop", "SopNum"); } string command = "INSERT INTO sop ("; if (useExistingPK || PrefC.RandomKeys) { command += "SopNum,"; } command += "SopCode,Description) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(sop.SopNum) + ","; } command += "'" + POut.String(sop.SopCode) + "'," + "'" + POut.String(sop.Description) + "')"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { sop.SopNum = Db.NonQ(command, true); } return(sop.SopNum); }
///<summary>Updates one Sop in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> public static void Update(Sop sop, Sop oldSop) { string command = ""; if (sop.SopCode != oldSop.SopCode) { if (command != "") { command += ","; } command += "SopCode = '" + POut.String(sop.SopCode) + "'"; } if (sop.Description != oldSop.Description) { if (command != "") { command += ","; } command += "Description = '" + POut.String(sop.Description) + "'"; } if (command == "") { return; } command = "UPDATE sop SET " + command + " WHERE SopNum = " + POut.Long(sop.SopNum); Db.NonQ(command); }
///<summary>Inserts one Sop into the database. Returns the new priKey.</summary> public static long Insert(Sop sop) { if (DataConnection.DBtype == DatabaseType.Oracle) { sop.SopNum = DbHelper.GetNextOracleKey("sop", "SopNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(sop, true)); } catch (Oracle.DataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { sop.SopNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(sop, false)); } }
public void TestAgentCodeSequence() { var agent1 = new CodeSequenceMacro { CodeMeaning = "Contrastinol", CodeValue = "123", CodingSchemeDesignator = "ABC" }; var agent2 = new CodeSequenceMacro { CodeMeaning = "Bolusinate", CodeValue = "456", CodingSchemeDesignator = "DEF" }; var dataset = TestDataSource.CreateImageSopDataSource(); dataset[DicomTags.ContrastBolusAgent].SetStringValue(@"Contrastinol and Bolusinate"); dataset[DicomTags.ContrastBolusAgentSequence].AddSequenceItem(agent1.DicomSequenceItem); using (var sop = (ImageSop)Sop.Create(dataset)) using (var images = new DisposableList <IPresentationImage>(PresentationImageFactory.Create(sop))) { Assert.AreEqual(@"Contrastinol", _annotationItems[_cbAgent].GetAnnotationText(images[0])); dataset[DicomTags.ContrastBolusAgentSequence].AddSequenceItem(agent2.DicomSequenceItem); Assert.AreEqual(@"Contrastinol\Bolusinate", _annotationItems[_cbAgent].GetAnnotationText(images[0])); agent1.CodeMeaning = string.Empty; Assert.AreEqual(@"123 (ABC)\Bolusinate", _annotationItems[_cbAgent].GetAnnotationText(images[0])); agent2.CodeMeaning = string.Empty; Assert.AreEqual(@"Contrastinol and Bolusinate", _annotationItems[_cbAgent].GetAnnotationText(images[0])); dataset[DicomTags.ContrastBolusAgent].SetNullValue(); Assert.AreEqual(@"123 (ABC)\456 (DEF)", _annotationItems[_cbAgent].GetAnnotationText(images[0])); } }
///<summary>Inserts one Sop into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(Sop sop, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO sop ("; if (!useExistingPK && isRandomKeys) { sop.SopNum = ReplicationServers.GetKeyNoCache("sop", "SopNum"); } if (isRandomKeys || useExistingPK) { command += "SopNum,"; } command += "SopCode,Description) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(sop.SopNum) + ","; } command += "'" + POut.String(sop.SopCode) + "'," + "'" + POut.String(sop.Description) + "')"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { sop.SopNum = Db.NonQ(command, true, "SopNum", "sop"); } return(sop.SopNum); }
private static IEnumerable <IComparable> GetCompareValues(Sop sop) { //Group be common study level attributes yield return(sop.StudyInstanceUid); //Group by common series level attributes //This sorts "FOR PRESENTATION" images to the beginning (except in reverse, of course). if (!sop.IsImage) { yield return(1); } else { yield return(((ImageSop)sop).PresentationIntentType == "FOR PRESENTATION" ? 0 : 1); } yield return(sop.SeriesNumber); yield return(sop.SeriesDescription); yield return(sop.SeriesInstanceUid); yield return(sop.InstanceNumber); yield return(sop[DicomTags.AcquisitionNumber].GetInt32(0, 0)); }
public SopDataSourceStudyItem(Sop sop) { if (sop.DataSource is ILocalSopDataSource) { _filename = ((ILocalSopDataSource)sop.DataSource).Filename; _sopReference = sop.CreateTransientReference(); } }
public SopDataSourceStudyItem(ILocalSopDataSource sopDataSource) { _filename = sopDataSource.Filename; using (Sop sop = new Sop(sopDataSource)) { _sopReference = sop.CreateTransientReference(); } }
private DisplayData CreateDisplayDataBy(Sop sop) { var imageSop = sop as ImageSop; Debug.Assert(imageSop != null); return(DataAccessor.CreateImageData(imageSop.DicomSource, imageSop.GetNormalizedPixelData, imageSop.PresentationState)); }
private IEnumerable <IComparable> GetCompareValues(Sop sop) { yield return(DateParser.Parse(sop.StudyDate)); yield return(TimeParser.Parse(sop.StudyTime)); yield return(sop.StudyDescription); }
public SopDataSourceStudyItem(Sop sop) { Platform.CheckTrue(sop.DataSource is ILocalSopDataSource, "Sop must be local"); { _filename = ((ILocalSopDataSource)sop.DataSource).Filename; _sopReference = sop.CreateTransientReference(); } }
protected virtual List <IPresentationImage> CreateImages(KeyImageContentItem item) { List <IPresentationImage> images = new List <IPresentationImage>(); ImageSop imageSop = FindReferencedImageSop(item.ReferencedImageSopInstanceUid, item.Source.GeneralStudy.StudyInstanceUid); if (imageSop != null) { int frameNumber = item.FrameNumber.GetValueOrDefault(-1); if (item.FrameNumber.HasValue) { // FramesCollection is a 1-based index!!! if (frameNumber > 0 && frameNumber <= imageSop.Frames.Count) { images.Add(Create(imageSop.Frames[frameNumber])); } else { Platform.Log(LogLevel.Error, "The referenced key image {0} does not have a frame {1} (referenced in Key Object Selection {2})", item.ReferencedImageSopInstanceUid, frameNumber, item.Source.SopCommon.SopInstanceUid); images.Add(new KeyObjectPlaceholderImage(SR.MessageReferencedKeyImageFrameNotFound)); } } else { foreach (Frame frame in imageSop.Frames) { images.Add(Create(frame)); } } Sop presentationStateSop = FindReferencedSop(item.PresentationStateSopInstanceUid, item.Source.GeneralStudy.StudyInstanceUid); if (presentationStateSop != null) { foreach (IPresentationImage image in images) { if (image is IPresentationStateProvider) { try { IPresentationStateProvider presentationStateProvider = (IPresentationStateProvider)image; presentationStateProvider.PresentationState = DicomSoftcopyPresentationState.Load(presentationStateSop.DataSource); } catch (Exception ex) { Platform.Log(LogLevel.Warn, ex, SR.MessagePresentationStateReadFailure); } } } } } else { Platform.Log(LogLevel.Warn, "The referenced key image {0} is not loaded as part of the current study (referenced in Key Object Selection {1})", item.ReferencedImageSopInstanceUid, item.Source.SopCommon.SopInstanceUid); images.Add(new KeyObjectPlaceholderImage(SR.MessageReferencedKeyImageFromOtherStudy)); } return(images); }
///<summary>Updates one Sop in the database.</summary> public static void Update(Sop sop) { string command = "UPDATE sop SET " + "SopCode = '" + POut.String(sop.SopCode) + "', " + "Description= '" + POut.String(sop.Description) + "' " + "WHERE SopNum = " + POut.Long(sop.SopNum); Db.NonQ(command); }
private async Task DeleteSopRowAsync(Sop item) { using (var conn = new SqlConnection(ConfigurationManager.GetEnvironmentVariable("OalConnectionString"))) //using (var conn = new SqlConnection(ConfigurationManager.GetEnvironmentVariable("ConnectionString"))) using (SqlCommand cmd = new SqlCommand("DELETE FROM dbo.Sop WHERE Id=@Id", conn)) { cmd.Parameters.Add("@id", SqlDbType.Int, 4).Value = item.id; await conn.OpenAsync().ConfigureAwait(false); } }
public void TestNil() { var dataset = TestDataSource.CreateImageSopDataSource(); using (var sop = (ImageSop)Sop.Create(dataset)) using (var images = new DisposableList <IPresentationImage>(PresentationImageFactory.Create(sop))) { Assert.IsEmpty(_annotationItems[_cbAgent].GetAnnotationText(images[0])); } }
private static string GetPresentationIntent(Sop sop) { DicomAttribute attribute; if (sop.DataSource.TryGetAttribute(DicomTags.PresentationIntentType, out attribute)) { return((attribute.ToString() ?? string.Empty).ToUpperInvariant()); } return(string.Empty); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<Sop> TableToList(DataTable table){ List<Sop> retVal=new List<Sop>(); Sop sop; for(int i=0;i<table.Rows.Count;i++) { sop=new Sop(); sop.SopNum = PIn.Long (table.Rows[i]["SopNum"].ToString()); sop.SopCode = PIn.String(table.Rows[i]["SopCode"].ToString()); sop.Description= PIn.String(table.Rows[i]["Description"].ToString()); retVal.Add(sop); } return retVal; }
///<summary>Returns true if Update(Sop,Sop) would make changes to the database. ///Does not make any changes to the database and can be called before remoting role is checked.</summary> public static bool UpdateComparison(Sop sop, Sop oldSop) { if (sop.SopCode != oldSop.SopCode) { return(true); } if (sop.Description != oldSop.Description) { return(true); } return(false); }
public void TestAgentDescriptorOnly() { var dataset = TestDataSource.CreateImageSopDataSource(); dataset[DicomTags.ContrastBolusAgent].SetStringValue(@"Contrastinol and Bolusinate"); using (var sop = (ImageSop)Sop.Create(dataset)) using (var images = new DisposableList <IPresentationImage>(PresentationImageFactory.Create(sop))) { Assert.AreEqual(@"Contrastinol and Bolusinate", _annotationItems[_cbAgent].GetAnnotationText(images[0])); } }
public void WriteCD() { string strBurnPath = System.Windows.Forms.Application.StartupPath + "\\Nero\\"; DirectoryInfo Dir = new DirectoryInfo(strBurnPath); string strImagePath = strBurnPath + "\\Images\\"; string strSoucePath = System.Windows.Forms.Application.StartupPath + @"\DicomFiles\"; Dir = new DirectoryInfo(strImagePath); if (!Dir.Exists) { Dir.Create(); } else { foreach (FileInfo file in Dir.GetFiles()) { file.Delete(); } } foreach (IImageSet imageSet in Context.Viewer.LogicalWorkspace.ImageSets) { foreach (IDisplaySet displaySet in imageSet.DisplaySets) { foreach (IPresentationImage image in displaySet.PresentationImages) { if (image is IImageSopProvider) { Sop sop = ((IImageSopProvider)image).Sop; try { File.Copy(strSoucePath + sop.SopInstanceUid + ".dcm", strImagePath + sop.SopInstanceUid + ".dcm"); } catch (Exception ex) { Platform.Log(LogLevel.Fatal, ex); //strSoucePath = //File.Copy(strSoucePath + sop.SopInstanceUid + ".dcm", strImagePath + sop.SopInstanceUid + ".dcm"); } } } } } string appname = System.Windows.Forms.Application.StartupPath + "\\nero.exe"; try { System.Diagnostics.Process.Start(appname); } catch { } }
public VtkTestPresentationImage() : base(100, 100, 100) { var dcf = new DicomFile(); FillDicomDataSet(dcf.MetaInfo, dcf.DataSet); using (var dataSource = new TestDataSource(dcf)) using (var sop = (ImageSop)Sop.Create(dataSource)) { _frameReference = sop.Frames[1].CreateTransientReference(); } }
public PlaceholderPresentationImage(Sop sop) : base(new GrayscaleImageGraphic(1, 1)) { _sopReference = sop.CreateTransientReference(); var sopClass = SopClass.GetSopClass(sop.SopClassUid); var sopClassDescription = sopClass != null ? sopClass.Name : SR.LabelUnknown; CompositeImageGraphic.Graphics.Add(new ErrorMessageGraphic { Text = string.Format(SR.MessageUnsupportedImageType, sopClassDescription), Color = Color.WhiteSmoke }); Platform.Log(LogLevel.Warn, "Unsupported SOP Class \"{0} ({1})\" (SOP Instance {2})", sopClassDescription, sop.SopClassUid, sop.SopInstanceUid); }
public void Add(Sop sop) { bool result = base.TryAddReference(sop.StudyInstanceUid, sop.SeriesInstanceUid, sop.SopClassUid, sop.SopInstanceUid); if (result && !_seriesInfo.ContainsKey(sop.SeriesInstanceUid)) { SeriesInfo seriesInfo = new SeriesInfo(); seriesInfo.RetrieveAeTitle = sop[DicomTags.RetrieveAeTitle].ToString(); seriesInfo.StorageMediaFileSetId = sop[DicomTags.StorageMediaFileSetId].GetString(0, string.Empty); seriesInfo.StorageMediaFileSetUid = sop[DicomTags.StorageMediaFileSetUid].GetString(0, string.Empty); _seriesInfo.Add(sop.SeriesInstanceUid, seriesInfo); } }
public void LaunchOnePrint() { IPresentationImage currentImage = Context.Viewer.SelectedPresentationImage; IDisplaySet displaySet = currentImage.ParentDisplaySet; string strFiles = ""; if (currentImage is IImageSopProvider) { Sop sop = ((IImageSopProvider)currentImage).Sop; strFiles += sop.SopInstanceUid + ";"; LanchThirdPrint(strFiles); } }
private void ChangeToSyntax(IBackgroundTaskContext context) { var study = (StudyTableItem)context.UserState; try { _tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "ClearCanvas"); _tempPath = System.IO.Path.Combine(_tempPath, "Compression"); _tempPath = System.IO.Path.Combine(_tempPath, Path.GetRandomFileName()); string message = String.Format("Changing transfer syntax to: {0}", _syntax); context.ReportProgress(new BackgroundTaskProgress(0, message)); var loader = study.Server.GetService <IStudyLoader>(); int numberOfSops = loader.Start(new StudyLoaderArgs(study.StudyInstanceUid, null)); if (numberOfSops <= 0) { return; } for (int i = 0; i < numberOfSops; ++i) { Sop sop = loader.LoadNextSop(); if (sop != null) { if (sop.DataSource is ILocalSopDataSource) { string filename = Path.Combine(_tempPath, string.Format("{0}.dcm", i)); DicomFile file = ((ILocalSopDataSource)sop.DataSource).File; file.ChangeTransferSyntax(_syntax); file.Save(filename); } } int progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100); context.ReportProgress(new BackgroundTaskProgress(progressPercent, message)); } //trigger an import of the anonymized files. var client = new DicomFileImportBridge(); client.ImportFileList(new List <string> { _tempPath }, BadFileBehaviourEnum.Move, FileImportBehaviourEnum.Move); context.Complete(); } catch (Exception e) { context.Error(e); } }
public void Launch3D() { IPresentationImage currentImage = Context.Viewer.SelectedPresentationImage; IDisplaySet displaySet = currentImage.ParentDisplaySet; var filteredFrames = new List <Frame>(); string lDicom3DPath = System.Windows.Forms.Application.StartupPath + @"\Third\3ddata\"; DirectoryInfo Dir = new DirectoryInfo(lDicom3DPath); if (!Dir.Exists) { Dir.Create(); } else { foreach (FileInfo file in Dir.GetFiles()) { file.Delete(); } } string strSourceTemp = ""; string strDestTemp = ""; foreach (IPresentationImage image in displaySet.PresentationImages) { if (image is IImageSopProvider) { Sop sop = ((IImageSopProvider)image).Sop; strSourceTemp = System.Windows.Forms.Application.StartupPath + @"\DicomFiles\" + sop.SopInstanceUid + ".dcm"; strDestTemp = lDicom3DPath + sop.SopInstanceUid + ".dcm"; File.Copy(strSourceTemp, strDestTemp); } } // string l3dPrnAppName = System.Windows.Forms.Application.StartupPath + @"\Third\3d.exe"; try { //Call Dicom Print Process System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo(); Info.FileName = l3dPrnAppName; Info.Arguments = "3D"; System.Diagnostics.Process proc = System.Diagnostics.Process.Start(Info); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex.ToString()); } }
/// <summary> /// Creates the presentation images for a given image SOP. /// </summary> /// <param name="sop">The image SOP from which presentation images are to be created.</param> /// <returns>A list of created presentation images.</returns> public virtual List <IPresentationImage> CreateImages(Sop sop) { if (sop.IsImage) { return(CreateImages((ImageSop)sop)); } if (sop.SopClassUid == SopClass.KeyObjectSelectionDocumentStorageUid) { return(CreateImages(new KeyObjectSelectionDocumentIod(sop.DataSource))); } return(new List <IPresentationImage>()); }
public void LaunchPrintAll() { string strFiles = ""; foreach (IPresentationImage image in GetAllVisibleImages()) { if (image is IImageSopProvider) { Sop sop = ((IImageSopProvider)image).Sop; strFiles += sop.SopInstanceUid + ";"; } } LanchThirdPrint(strFiles); }
public override int Compare(Sop x, Sop y) { // this sorts FOR PRESENTATION series to the beginning. // FOR PROCESSING and unspecified series are considered equal for the purposes of sorting by intent. const string forPresentation = "FOR PRESENTATION"; int presentationIntentX = GetPresentationIntent(x) == forPresentation ? 0 : 1; int presentationIntentY = GetPresentationIntent(y) == forPresentation ? 0 : 1; int result = presentationIntentX - presentationIntentY; if (Reverse) { return(-result); } return(result); }
///<summary>Inserts one Sop into the database. Provides option to use the existing priKey.</summary> public static long Insert(Sop sop,bool useExistingPK){ if(!useExistingPK && PrefC.RandomKeys) { sop.SopNum=ReplicationServers.GetKey("sop","SopNum"); } string command="INSERT INTO sop ("; if(useExistingPK || PrefC.RandomKeys) { command+="SopNum,"; } command+="SopCode,Description) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(sop.SopNum)+","; } command+= "'"+POut.String(sop.SopCode)+"'," +"'"+POut.String(sop.Description)+"')"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { sop.SopNum=Db.NonQ(command,true); } return sop.SopNum; }
///<summary>Inserts one Sop into the database. Returns the new priKey.</summary> public static long Insert(Sop sop){ if(DataConnection.DBtype==DatabaseType.Oracle) { sop.SopNum=DbHelper.GetNextOracleKey("sop","SopNum"); int loopcount=0; while(loopcount<100){ try { return Insert(sop,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ sop.SopNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(sop,false); } }
///<summary>Updates one Sop in the database.</summary> public static void Update(Sop sop){ string command="UPDATE sop SET " +"SopCode = '"+POut.String(sop.SopCode)+"', " +"Description= '"+POut.String(sop.Description)+"' " +"WHERE SopNum = "+POut.Long(sop.SopNum); Db.NonQ(command); }
///<summary>Updates one Sop in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> public static void Update(Sop sop,Sop oldSop){ string command=""; if(sop.SopCode != oldSop.SopCode) { if(command!=""){ command+=",";} command+="SopCode = '"+POut.String(sop.SopCode)+"'"; } if(sop.Description != oldSop.Description) { if(command!=""){ command+=",";} command+="Description = '"+POut.String(sop.Description)+"'"; } if(command==""){ return; } command="UPDATE sop SET "+command +" WHERE SopNum = "+POut.Long(sop.SopNum); Db.NonQ(command); }