Creates and stores JSON and/or XML metadata for All metadata, Existing metadata only, or Missing metadata only.
public void GenerateMetadata(MetadataOptions options,MetadataScope scope)
public:void GenerateMetadata(MetadataOptions^ options,MetadataScope^ scope)
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.
This method iterates through all instances stored in the Instance database table and takes the following actions:
The scope parameter determines if metadata is generated for a DICOM instance, as follows:
If scope is MetadataScope.All, then XML and/or JSON metadata is generated for all instances in the Instance table.
If scope is MetadataScope.Existing, then XML and/or JSON metadata is generated only for existing metadata instances in the corresponding metadata table.
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:
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 folderstring 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 SOPInstanceUIDpublic 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 callsagent.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 methodMetadataOptions 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 metadataagent.DeleteAllMetadataXml();agent.DeleteAllMetadataJson();// Add two DICOM files, and generate the XML and JSON metadata for eachstring 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 sopInstanceUid2bool 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 instancesint xmlMetadataCount = agent.GetCountMetadataXml(MetadataScope.All);Debug.WriteLine("XML MetadataCount: {0}", xmlMetadataCount);// Get the existing count of XML metadata recordsint xmlMetadataExistingCount = agent.GetCountMetadataXml(MetadataScope.Existing);Debug.WriteLine("XML Existing MetadataCount: {0}", xmlMetadataExistingCount);// Get the missing count of XML metadata recordsint xmlMetadataMissingCount = agent.GetCountMetadataXml(MetadataScope.Missing);Debug.WriteLine("XML Missing MetadataCount: {0}", xmlMetadataMissingCount);// Get the missing count of JSON metadata recordsint jsonMetadataMissingCount = agent.GetCountMetadataJson(MetadataScope.Missing);Debug.WriteLine("JSON Missing MetadataCount: {0}", jsonMetadataMissingCount);// Delete the metadata for sopInstanceUid2 and sopInstanceUid3List<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 sopInstanceUid2exists = agent.ExistsMetadataXml(sopInstanceUid2);Debug.Assert(!exists);exists = agent.ExistsMetadataJson(sopInstanceUid2);Debug.Assert(!exists);// Generate metadata for all records in the databaseagent.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 metadataMetadataOptions 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 generatedif (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);}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
