←Select platform

GenerateMetadata Method

Summary

Creates and stores JSON and/or XML metadata for All metadata, Existing metadata only, or Missing metadata only.

Syntax
C#
C++/CLI
public void GenerateMetadata( 
   MetadataOptions options, 
   MetadataScope scope 
) 
public:  
   void GenerateMetadata( 
      MetadataOptions^ options, 
      MetadataScope^ scope 
   ) 

Parameters

options

Options that determine the type of metadata saved (XML and/or JSON).

scope

An enumeration that specifies if the count is for existing, missing, or all metadata records.

Remarks

This method iterates through all instances stored in the Instance database table and takes the following actions:

  • Loads the instance into a DicomDataSet
  • Converts the DICOM elements from the DicomDataSet to XML and/or JSON metadata
  • Stores the metadata in the corresponding metadata database table (MetadataXml or MetadataJson)

The scope parameter determines if metadata is generated for a DICOM instance, as follows:

  1. If scope is MetadataScope.All, then XML and/or JSON metadata is generated for all instances in the Instance table.

  2. If scope is MetadataScope.Existing, then XML and/or JSON metadata is generated only for existing metadata instances in the corresponding metadata table.

  3. If scope is MetadataScope.Missing, then XML and/or JSON metadata is generated only for instances in the Instance table that do not have corresponding XML and/or JSON metadata.

This method fires the following events:

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
using Leadtools.Dicom.Common.Extensions; 
using Leadtools.DicomDemos; 
using Leadtools.Medical.DataAccessLayer; 
using Leadtools.Medical.Storage.DataAccessLayer; 
using Leadtools.Medical.Storage.DataAccessLayer.Configuration; 
 
public static IStorageDataAccessAgent4 GetStorageDataAccessAgent4() 
{ 
   // 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 = @"C:\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); 
   IStorageDataAccessAgent4 agent = DataAccessFactory.GetInstance(view).CreateDataAccessAgent<IStorageDataAccessAgent4>(); 
   return agent; 
} 
 
// Stores a DICOM file to the database 
// Stores XML and JSON metadata 
// returns the SOPInstanceUID 
public static string StoreDicomAndMetadataToDatabase(string dicomFileName, IStorageDataAccessAgent4 agent) 
{ 
   DicomDataSet ds = new DicomDataSet(); 
   ds.Load(dicomFileName, DicomDataSetLoadFlags.None); 
   DicomElement element = ds.FindFirstElement(null, DicomTag.SOPInstanceUID, true); 
   string sopInstanceUid = ds.GetStringValue(element, 0); 
   agent.StoreDicom(ds, dicomFileName, "DemoAE", null, true, true, true, true); 
 
   // You can store XML and JSON data with separate calls 
   agent.StoreMetadataXml(ds, sopInstanceUid, DicomDataSetSaveXmlFlags.IgnoreBinaryData, true); 
   agent.StoreMetadataJson(ds, sopInstanceUid, DicomDataSetSaveJsonFlags.IgnoreBinaryData, true); 
 
   // Or you can generate both XML and JSON data with a single method 
   MetadataOptions options = new MetadataOptions(); 
   options.SaveJsonFlags = DicomDataSetSaveJsonFlags.IgnoreBinaryData; 
   options.SaveXmlFlags = DicomDataSetSaveXmlFlags.IgnoreBinaryData; 
   options.StoreJson = true; 
   options.StoreXml = true; 
   agent.StoreMetadata(ds, sopInstanceUid, options, true); 
 
   return sopInstanceUid; 
} 
 
public static void DicomMetadataSample() 
{ 
   IStorageDataAccessAgent4 agent = GetStorageDataAccessAgent4(); 
 
   // Delete all existing metadata 
   agent.DeleteAllMetadataXml(); 
   agent.DeleteAllMetadataJson(); 
 
   // Add two DICOM files, and generate the XML and JSON metadata for each 
   string sopInstanceUid2 = StoreDicomAndMetadataToDatabase(@"C:\LEADTOOLS22\Resources\Images\DICOM\image2.dcm", agent); 
   string sopInstanceUid3 = StoreDicomAndMetadataToDatabase(@"C:\LEADTOOLS22\Resources\Images\DICOM\image3.dcm", agent); 
 
   // Verify the metadata exists for sopInstanceUid2 
   bool exists = agent.ExistsMetadataXml(sopInstanceUid2); 
   Debug.Assert(exists); 
   exists = agent.ExistsMetadataJson(sopInstanceUid2); 
   Debug.Assert(exists); 
 
 
   // Get the total possible XML metadata count -- this is the count of all DICOM instances 
   int xmlMetadataCount = agent.GetCountMetadataXml(MetadataScope.All); 
   Debug.WriteLine("XML MetadataCount: {0}", xmlMetadataCount); 
 
   // Get the existing count of XML metadata records 
   int xmlMetadataExistingCount = agent.GetCountMetadataXml(MetadataScope.Existing); 
   Debug.WriteLine("XML Existing MetadataCount: {0}", xmlMetadataExistingCount); 
 
   // Get the missing count of XML metadata records 
   int xmlMetadataMissingCount = agent.GetCountMetadataXml(MetadataScope.Missing); 
   Debug.WriteLine("XML Missing MetadataCount: {0}", xmlMetadataMissingCount); 
 
   // Get the missing count of JSON metadata records 
   int jsonMetadataMissingCount = agent.GetCountMetadataJson(MetadataScope.Missing); 
   Debug.WriteLine("JSON Missing MetadataCount: {0}", jsonMetadataMissingCount); 
 
   // Delete the metadata for sopInstanceUid2 and sopInstanceUid3 
   List<string> sopList = new List<string>(); 
   sopList.Add(sopInstanceUid2); 
   sopList.Add(sopInstanceUid3); 
 
   agent.DeleteMetadataXml(sopList); 
   agent.DeleteMetadataJson(sopList); 
 
   // Verify the metadata exists no longer exists for sopInstanceUid2 
   exists = agent.ExistsMetadataXml(sopInstanceUid2); 
   Debug.Assert(!exists); 
   exists = agent.ExistsMetadataJson(sopInstanceUid2); 
   Debug.Assert(!exists); 
 
   // Generate metadata for all records in the database 
   agent.GenerateMetadataStarting += Agent_GenerateMetadataStarting; 
   agent.GenerateMetadataUpdate += Agent_GenerateMetadataUpdate; 
   agent.GenerateMetadataCompleted += Agent_GenerateMetadataCompleted; 
   agent.GenerateMetadataXml(DicomDataSetSaveXmlFlags.IgnoreBinaryData, MetadataScope.All); 
   agent.GenerateMetadataJson(DicomDataSetSaveJsonFlags.IgnoreBinaryData, MetadataScope.All); 
 
   // Or you can call a single method to generate all metadata 
   MetadataOptions options = new MetadataOptions(); 
   options.SaveJsonFlags = DicomDataSetSaveJsonFlags.IgnoreBinaryData; 
   options.SaveXmlFlags = DicomDataSetSaveXmlFlags.IgnoreBinaryData; 
   options.StoreJson = true; 
   options.StoreXml = true; 
   agent.GenerateMetadata(options, MetadataScope.All); 
} 
 
private static void Agent_GenerateMetadataCompleted(object sender, GenerateMetadataArgs e) 
{ 
   Debug.WriteLine("GenerateMetadataCompleted {0} of {1}: ", e.CurrentItem + 1, e.TotalCount); 
} 
 
private static void Agent_GenerateMetadataUpdate(object sender, GenerateMetadataArgs e) 
{ 
   // Cancel generating metadata after 5 metadata records have been generated 
   if (e.CurrentItem + 1 == 5) 
   { 
      e.Cancelled = true; 
      Debug.WriteLine("GenerateMetadataUpdate - Cancelled {0} of {1}: ", e.CurrentItem + 1, e.TotalCount); 
   } 
} 
 
private static void Agent_GenerateMetadataStarting(object sender, GenerateMetadataArgs e) 
{ 
   Debug.WriteLine("GenerateMetadataStarting {0} of {1}: ", e.CurrentItem + 1, e.TotalCount); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.