←Select platform

InsertDataSet Method

Summary
Adds a DICOM Data Set to the DICOM Directory.
Syntax
C#
Objective-C
C++/CLI
public void InsertDataSet( 
   DicomDataSet dataSet, 
   string fileName 
) 
- (BOOL)insertDataSet:(LTDicomDataSet *)dataSet fileName:(nullable NSString *)fileName error:(NSError **)error; 
public: 
void InsertDataSet(  
   DicomDataSet^ dataSet, 
   String^ fileName 
)  

Parameters

dataSet
A DicomDataSet object that holds the Data Set to be added to the DICOM Directory.

fileName
The name of the DICOM file referenced by the passed DicomDataSet object.

Remarks

If the name of a DICOM file is to be specified, then before using this method, a destination folder must have been specified, either at the construction time or by the method Reset. Otherwise, the method will fail. The DICOM filename must refer to an existing file that resides in the destination folder or in a subfolder of the destination folder. Otherwise, the method will fail and the Data Set will not be added to the DICOM directory. Please notice that the filename passed to the method must specify the absolute path of the file, not the relative one.

If fileName is set to a null reference (Nothing in VB), a Data Set can still be added, even if no destination folder is specified. (That is, if fileName is set to a null reference and the destination folder has not been set, a Data Set can still be added.) In this case, no DICOM file will be referenced for this Data Set (i.e., the corresponding Referenced File ID (0004,1500) will have an empty value).

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
public class MyDicomDir : DicomDir 
{ 
   public MyDicomDir(string destinationFolder, string path) : base(destinationFolder, path) { } 
   public override DicomDirInsertFileCommand OnInsertFile(string fileName, DicomDataSet ds, DicomDirInsertFileStatus status, DicomExceptionCode code) 
   { 
      if (status == DicomDirInsertFileStatus.PreAdd) 
      { 
         string msg = string.Format("About to add the file '{0}'{1}{1}Proceed?", fileName, Environment.NewLine); 
         Console.WriteLine($"{msg}"); 
         return DicomDirInsertFileCommand.Continue; 
 
      } 
      else if (status == DicomDirInsertFileStatus.Success) 
      { 
         string msg = string.Format("The file '{0}' has been added successfully.", fileName); 
         Console.WriteLine(msg); 
      } 
      return DicomDirInsertFileCommand.Continue; 
   } 
}; 
 
public void CreateDicomDirectory() 
{ 
   //Make sure to initialize the DICOM engine, this needs to be done only once  
   //In the whole application 
   DicomEngine.Startup(); 
   using (MyDicomDir dicomDir = new MyDicomDir(null, null)) 
   { 
      bool autoSearch = true; 
      // Set the destination folder 
      dicomDir.Reset(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT")); 
      // Set the File-set Identifier 
      dicomDir.SetFileSetId("SOME_ID"); 
      // Set some options 
      DicomDirOptions options = dicomDir.Options; 
      dicomDir.ResetOptions(); 
      options.IncludeSubfolders = true; 
      options.InsertIconImageSequence = false; 
      options.RejectInvalidFileId = true; 
      dicomDir.Options = options; 
 
      // Set the File-set descriptor file 
      string path = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "README"); 
      dicomDir.SetDescriptorFile(path, null); 
 
      if (autoSearch) 
      { 
         try 
         { 
            dicomDir.InsertFile(null); 
         } 
         catch (Exception ex) 
         { 
            Console.WriteLine($"{ex.GetType().ToString()} {ex.Message}"); 
         } 
      } 
      else 
      { 
         // Load a Data Set and add it to the Directory 
         using (DicomDataSet ds = new DicomDataSet()) 
         { 
            ds.Load(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_001"), DicomDataSetLoadFlags.None); 
            dicomDir.InsertDataSet(ds, Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_001")); 
         } 
 
         // Add some DICOM files to the Directory 
         dicomDir.InsertFile(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_002")); 
         dicomDir.InsertFile(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "HeadCBCT", "CT", "CT_003")); 
      } 
 
      // Test the DataSet 
      DicomElement first = dicomDir.DataSet.FindFirstElement(null, DicomTag.PatientID, false); 
      Console.WriteLine(first.Length.ToString()); 
 
      // Save the DICOMDIR File 
      dicomDir.Save(); 
      //We can now call something like this to call the DICOMDIR back 
      //dicomDir.Load(LeadtoolsExamples.Common.ImagesPath.Path + @"TEMP\DCMTEST\PATIENT1\DICOMDIR",DicomDataSetLoadFlags.LoadAndClose); 
   } 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.8.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.