←Select platform

DeleteStudy Method

Summary

Delete the study records that match the given query parameters, with an option to delete orphaned records.

Syntax
C#
C++/CLI

Parameters

matchingEntitiesCollection

A MatchingParameterCollection which includes the matching parameters for a query.

removeOrphanRecords

true to remove orphaned records created by calling this method; false otherwise.

Return Value

A value representing the number of deleted studies.

Remarks

Deleting one or more studies can potentially leave orphaned database records.

For example:

  • Patient1 has three studies (Study1, Study2, Study3)

Deleting Study1 and Study2 leaves no orphaned records. However, deleting Study1, Study2, and Study3 leaves the following orphaned records:

  • Patient1

Pass true for the removeOrphanRecords argument to automatically remove orphaned when calling this method.

Example
C#
using Leadtools.Dicom; 
using Leadtools.DicomDemos; 
using Leadtools.Medical.DataAccessLayer; 
using Leadtools.Medical.DataAccessLayer.Catalog; 
using Leadtools.Medical.Storage.DataAccessLayer; 
using Leadtools.Medical.Storage.DataAccessLayer.Configuration; 
 
 
public static IStorageDataAccessAgent7 GetStorageDataAccessAgent7() 
{ 
   // Before running this sample, follow these steps: 
   // 1. Run CSPacsDatabaseConfigurationDemo.exe to create the databases 
   // 2. Run CSPACSConfigDemo.exe to create the DICOM services 
   // 3. Set 'serviceDirectory' to the DICOM service folder 
   string serviceDirectory = @"d:\LEADTOOLS22\Bin\Dotnet4\x64\L22_PACS_SCP64"; 
   string productName = "StorageServer"; 
   string serviceName = "L22_PACS_SCP64"; 
   System.Configuration.Configuration configuration = DicomDemoSettingsManager.GetGlobalPacsAddinsConfiguration(serviceDirectory); 
 
   StorageDataAccessConfigurationView view = new StorageDataAccessConfigurationView(configuration, productName, serviceName); 
   IStorageDataAccessAgent7 agent = DataAccessFactory.GetInstance(view).CreateDataAccessAgent<IStorageDataAccessAgent7>(); 
   return agent; 
} 
 
public static void InsertDicomFile(IStorageDataAccessAgent7 agent, string filename) 
{ 
   using (DicomDataSet ds = new DicomDataSet()) 
   { 
      ds.Load(filename, DicomDataSetLoadFlags.None); 
      agent.StoreDicom(ds, filename, string.Empty, null, true, true, true, true); 
   } 
} 
 
public static void RemoveInstance(IStorageDataAccessAgent7 agent, string sopInstanceUid, bool removeOrphanedRecords) 
{ 
   ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstanceUid); 
   MatchingParameterCollection mpc = new MatchingParameterCollection(); 
   MatchingParameterList mpl = new MatchingParameterList(); 
   mpl.Add(instanceEntity); 
   mpc.Add(mpl); 
 
   agent.DeleteInstance(mpc, removeOrphanedRecords); 
} 
 
public static void AddDicomImages(IStorageDataAccessAgent7 agent) 
{ 
   // Clear the database 
   agent.EmptyTable(Table.Patient); 
   agent.EmptyTable(Table.Study); 
   agent.EmptyTable(Table.Series); 
   agent.EmptyTable(Table.Instance); 
 
   // Add four DICOM Images, all the same Patient, Study, and Series 
   InsertDicomFile(agent, @"D:\LEADTOOLS22\Resources\Images\DICOM\MG\mg1.dcm"); 
   InsertDicomFile(agent, @"D:\LEADTOOLS22\Resources\Images\DICOM\MG\mg2.dcm"); 
   InsertDicomFile(agent, @"D:\LEADTOOLS22\Resources\Images\DICOM\MG\mg3.dcm"); 
   InsertDicomFile(agent, @"D:\LEADTOOLS22\Resources\Images\DICOM\MG\mg4.dcm"); 
 
   // Add another image that will not have orphans 
   InsertDicomFile(agent, @"D:\LEADTOOLS22\Resources\Images\DICOM\image2.dcm"); 
} 
 
public static void CreatePatientStudySeriesOrphan(IStorageDataAccessAgent7 agent) 
{ 
   AddDicomImages(agent); 
 
   MatchingParameterCollection mc = new MatchingParameterCollection(); 
   DataSet ds = agent.QueryPatients(mc); 
 
   // Remove the four SOPInstanceUID without removing orphans 
   bool removeOrphanedRecords = false; 
   RemoveInstance(agent, "1.2.840.114257.1.9.1245.56421.20124.5464751.12465.120.3", removeOrphanedRecords); 
   RemoveInstance(agent, "1.2.840.114257.1.9.1245.56421.52314.14567.124.2124", removeOrphanedRecords); 
   RemoveInstance(agent, "1.2.840.114257.1.9.1245.56421.52314.5647.124.2124.1", removeOrphanedRecords); 
   RemoveInstance(agent, "1.2.840.114257.1.9.1245.56421.7124.1245.1245.9542.1245", removeOrphanedRecords); 
} 
 
public static void StorageDatAccessOrphanExample() 
{ 
   try 
   { 
      DicomEngine.Startup(); 
 
      IStorageDataAccessAgent7 agent = GetStorageDataAccessAgent7(); 
 
      // This creates orphans: 
      //    1 Patient  orphan 
      //    1 Study    orphan 
      //    1 Series   orphan 
      //    1 Instance orphan 
      CreatePatientStudySeriesOrphan(agent); 
 
      // Test 1 
      // Remove all orphans in the database 
      agent.RemoveOrphanRecords(null, OrphanTables.All); 
 
      // Create the 3 orphans again 
      CreatePatientStudySeriesOrphan(agent); 
 
      // Test 2 
      // This time remove only orphan records for a particular patient 
      MatchingParameterCollection mc = new MatchingParameterCollection(); 
      MatchingParameterList mpl = new MatchingParameterList(); 
 
      string patientId = "656421"; 
      ICatalogEntity patientEntity = RegisteredEntities.GetPatientEntity(patientId); 
      mpl.Add(patientEntity); 
      mc.Add(mpl); 
 
      try 
      { 
         // Set diagnostic level to 1 to see debug messages in an application like DebugView 
         agent.DiagnosticLevel = 1; 
         agent.RemoveOrphanRecords(mc, OrphanTables.Series); 
         agent.RemoveOrphanRecords(mc, OrphanTables.Study); 
         agent.RemoveOrphanRecords(mc, OrphanTables.Patient); 
      } 
      finally 
      { 
         // Set diagnostic level back to 0 to stop showing debug messages 
         agent.DiagnosticLevel = 0; 
      } 
 
      // Test 3 
      // Add DICOM images, and then delete instances, studies, patients while removing orphans 
      AddDicomImages(agent); 
      agent.DeleteInstance(null, true); 
 
      // Test 4 
      // Add DICOM images, delete series removing all orphans. 
      AddDicomImages(agent); 
      agent.DeleteSeries(null, true); 
 
      // Test 5 
      // Add DICOM images. delete study removing all orphans. 
      AddDicomImages(agent); 
      agent.DeleteStudy(null, true); 
   } 
   finally 
   { 
      DicomEngine.Shutdown(); 
   } 
 
   Console.WriteLine("Finished"); 
} 
Requirements

Target Platforms

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

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