←Select platform

InsertElementAndSetValue(DicomElement,bool,long,DicomVRType,object) Method

Summary

Finds or inserts (if not found) an element in the data set and sets the value of the element.

Syntax

C#
C++/CLI
public DicomDataSet InsertElementAndSetValue( 
   DicomElement element, 
   bool tree, 
   long tag, 
   DicomVRType vrType, 
   object value 
) 
public:  
   DicomDataSet^ InsertElementAndSetValue( 
      DicomElement^ element, 
      bool tree, 
      Int64 tag, 
      DicomVRType^ vrType, 
      Object^ value 
   ) 

Parameters

element
An item in the data set.

tree
true to evaluate the Data Set as a tree; false to evaluate the Data Set as a list.

tag
Tag of the item to find or insert.

vrType value representation or format type (character string, integer, person name, etc.) of the element to be inserted.

value
value to insert.

Return Value

A reference to the DicomDataSet class (a 'this' pointer).

Remarks

This method is used to set the value of an existing DICOM data set element, or if the existing element does not already exist, to insert the element and then set its value.

If the element is being inserted (does not already exist), then this overload allows you to specify the value representation DicomVRType of the element to be inserted.

For example, DicomTag.CurveData can have a value representation of either DicomVRType.OB or DicomVRType.OW, so this overload allows you to specify the DicomVRType:

The value parameter can be any supported DICOM value. For details on the value parameter, see SetValue.

This method returns a reference to the DicomDataSet class so that it can be used as part of a fluent interface. After calling this method, the InsertElementAndSetValueResult property contains a value that indicates the success of the method. For an example of how this can be used efficiently to create a DICOM sequence, see BeginEditSequence.

Example

C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
///  
 
private void DicomDataSet_InsertElementAndSetValueExample() 
{ 
   DicomDataSet ds = new DicomDataSet(); 
 
   // Set a string 
   ds.InsertElementAndSetValue(null, false, DicomTag.PatientName, "Patient^Joe^MiddleName"); 
 
   // Or use an overload 
   ds.InsertElementAndSetValue(DicomTag.PatientName, "Patient^Joe^MiddleName"); 
 
   // This is how you check to see if the element got added -- for simplicity, we only check the first time 
   Console.WriteLine(ds.InsertElementAndSetValueResult.ToString()); 
 
   // Set an array of strings 
   string[] names = { "One", "Two", "Three" }; 
   ds.InsertElementAndSetValue(DicomTag.OtherPatientNames, names); 
 
   // Another way to do an array of strings 
   List<string> it = new List<string>(); 
   it.Add("ORIGINAL"); 
   it.Add("PRIMARY"); 
   ds.InsertElementAndSetValue(DicomTag.ImageType, it.ToArray()); 
 
   // Set an array of integers, that will be converted to strings 
   int[] namesInt = { 1, 2, 3 }; 
   ds.InsertElementAndSetValue(DicomTag.PhysicianOfRecord, namesInt); 
 
   // Set a DicomDateValue 
   DicomDateValue dicomDate = new DicomDateValue(1961, 6, 5); 
   ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, dicomDate); 
 
   // Set a DateTime 
   DateTime dateTime = new DateTime(2003, 5, 16); 
   ds.InsertElementAndSetValue(DicomTag.InstanceCreationDate, dateTime); 
 
   // Set an array of DateTime 
   DateTime[] dateTimeArray = { new DateTime(2000, 3, 8), new DateTime(2003, 5, 16) }; 
   ds.InsertElementAndSetValue(DicomTag.DateOfLastCalibration, dateTimeArray); 
 
   // Insert a DicomTag and specify the Value Represention 
   // This is useful when a DICOM tag can have more than one value representation. 
   // For example, (5000,3000) CurveData can have a value representation of either OB or OW 
   int[] curveData = {1897, 1908, 1912, 1912, 1909 }; 
   ds.InsertElementAndSetValue(null, false, DicomTag.CurveData, DicomVRType.OW, curveData); 
 
   ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "test.dcm"), DicomDataSetSaveFlags.None); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

DicomDataSet Class

DicomDataSet Members

Leadtools.Dicom Namespace

DicomDataSet Members

Overload List

SetValue Method

InsertElementAndSetValue(Int64,Object) Method

InsertElementAndSetValue(DicomElement,Boolean,Int64,Object) Method

InsertElementAndSetValueResult Property

BeginEditSequence(DicomElement,Boolean,Int64) Method

EndEditSequence Method

BeginEditItem(Int32) Method

EndEditItem Method

Help Version 23.0.2024.2.29
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.