LEADTOOLS Medical (Leadtools.Dicom assembly)
LEAD Technologies, Inc

InsertElementAndSetValue(DicomElement,Boolean,Int64,Object) Method

Example 







An item in the data set.
true to evaluate the Data Set as a tree; false to evaluate the Data Set as a list.
Tag of the item to find or insert.
value to insert
Finds or inserts (if not found) an element in the data set and sets the value of the element .NET support WinRT support Silverlight support
Syntax
public DicomDataSet InsertElementAndSetValue( 
   DicomElement element,
   bool tree,
   long tag,
   object value
)
'Declaration
 
Public Overloads Function InsertElementAndSetValue( _
   ByVal element As DicomElement, _
   ByVal tree As Boolean, _
   ByVal tag As Long, _
   ByVal value As Object _
) As DicomDataSet
'Usage
 
Dim instance As DicomDataSet
Dim element As DicomElement
Dim tree As Boolean
Dim tag As Long
Dim value As Object
Dim value As DicomDataSet
 
value = instance.InsertElementAndSetValue(element, tree, tag, value)
public DicomDataSet InsertElementAndSetValue( 
   DicomElement element,
   bool tree,
   long tag,
   object value
)
ObjectiveC Syntax
 function Leadtools.Dicom.DicomDataSet.InsertElementAndSetValue(DicomElement,Boolean,Int64,Object)( 
   element ,
   tree ,
   tag ,
   value 
)
public:
DicomDataSet^ InsertElementAndSetValue( 
   DicomElement^ element,
   bool tree,
   int64 tag,
   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.
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. 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 indiciates the success of the method. For an example of how this can be used efficiently to create a DICOM sequence, see BeginEditSequence(DicomElement,Boolean,Int64)

Example
Copy CodeCopy Code  
''' 
   Private Sub DicomDataSet_InsertElementAndSetValueExample()
      Dim ds As DicomDataSet = New DicomDataSet()

      ' Set a string
      ds.InsertElementAndSetValue(Nothing, 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
      MessageBox.Show(ds.InsertElementAndSetValueResult.ToString())

      ' Set an array of strings
      Dim names As String() = {"One", "Two", "Three"}
      ds.InsertElementAndSetValue(DicomTag.OtherPatientNames, names)

      ' Another way to do an array of strings
      Dim it As List(Of String) = New List(Of String)()
      it.Add("ORIGINAL")
      it.Add("PRIMARY")
      ds.InsertElementAndSetValue(DicomTag.ImageType, it.ToArray())

      ' Set an array of integers, that will be converted to strings
      Dim namesInt As Integer() = {1, 2, 3}
      ds.InsertElementAndSetValue(DicomTag.PhysicianOfRecord, namesInt)

      ' Set a DicomDateValue
      Dim dicomDate As DicomDateValue = New DicomDateValue(1961, 6, 5)
      ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, dicomDate)

      ' Set a DateTime
      Dim dateTime As DateTime = New DateTime(2003, 5, 16)
      ds.InsertElementAndSetValue(DicomTag.InstanceCreationDate, dateTime)

      ' Set an array of DateTime
      Dim dateTimeArray As DateTime() = {New DateTime(2000, 3, 8), New DateTime(2003, 5, 16)}
      ds.InsertElementAndSetValue(DicomTag.DateOfLastCalibration, dateTimeArray)

      ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "test.dcm"), DicomDataSetSaveFlags.None)
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
/// 
   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
      MessageBox.Show(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);

      ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "test.dcm"), DicomDataSetSaveFlags.None);
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
/// 
private async Task DicomDataSet_InsertElementAndSetValueExample()
{
   DicomDataSet ds = new DicomDataSet();

   // Set a string
   ds.InsertElementAndSetValue(null, false, DicomTagConstants.PatientName, "Patient^Joe^MiddleName");

   // Or use an overload
   ds.InsertElementAndSetValue(DicomTagConstants.PatientName, "Patient^Joe^MiddleName");

   // This is how you check to see if the element got added -- for simplicity, we only check the first time
   Debug.WriteLine(ds.InsertElementAndSetValueResult.ToString());

   // Set an array of strings
   string[] names = { "One", "Two", "Three" };
   ds.InsertElementAndSetValue(DicomTagConstants.OtherPatientNames, names);

   // Another way to do an array of strings
   List<string> it = new List<string>();
   it.Add("ORIGINAL");
   it.Add("PRIMARY");
   ds.InsertElementAndSetValue(DicomTagConstants.ImageType, it.ToArray());

   // Set an array of integers, that will be converted to strings
   int[] namesInt = { 1, 2, 3 };
   ds.InsertElementAndSetValue(DicomTagConstants.PhysicianOfRecord, namesInt);

   // Set a DicomDateValue
   DicomDateValue dicomDate = DicomDateValueHelper.Create(1961, 6, 5);
   ds.InsertElementAndSetValue(DicomTagConstants.PatientBirthDate, dicomDate);

   // Set a DateTime
   DateTime dateTime = new DateTime(2003, 5, 16);
   ds.InsertElementAndSetValue(DicomTagConstants.InstanceCreationDate, dateTime);

   // Set an array of DateTime
   DateTime[] dateTimeArray = { new DateTime(2000, 3, 8), new DateTime(2003, 5, 16) };
   ds.InsertElementAndSetValue(DicomTagConstants.DateOfLastCalibration, dateTimeArray);

   string dicomFileNameOutput = "test.dcm";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(dicomFileNameOutput);
   ILeadStream streamOutput = LeadStreamFactory.Create(saveFile);
   using (IDisposable disposableOUT = streamOutput as IDisposable)
   {
      await ds.SaveAsync(streamOutput, DicomDataSetSaveFlags.None);
   }
}
private void DicomDataSet_InsertElementAndSetValueExample(Stream outputStream)
{
   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
   Debug.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);

   ds.Save(outputStream, DicomDataSetSaveFlags.None);
}
Private Sub DicomDataSet_InsertElementAndSetValueExample(ByVal outputStream As Stream)
   Dim ds As DicomDataSet = New DicomDataSet()
   ' Set a string
   ds.InsertElementAndSetValue(Nothing, 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
   Debug.WriteLine(ds.InsertElementAndSetValueResult.ToString())

   ' Set an array of strings
   Dim names As String() = {"One", "Two", "Three"}
   ds.InsertElementAndSetValue(DicomTag.OtherPatientNames, names)

   ' Another way to do an array of strings
   Dim it As List(Of String) = New List(Of String)()
   it.Add("ORIGINAL")
   it.Add("PRIMARY")
   ds.InsertElementAndSetValue(DicomTag.ImageType, it.ToArray())

   ' Set an array of integers, that will be converted to strings
   Dim namesInt As Integer() = {1, 2, 3}
   ds.InsertElementAndSetValue(DicomTag.PhysicianOfRecord, namesInt)

   ' Set a DicomDateValue
   Dim dicomDate As DicomDateValue = New DicomDateValue(1961, 6, 5)
   ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, dicomDate)

   ' Set a DateTime
   Dim dateTime As DateTime = New DateTime(2003, 5, 16)
   ds.InsertElementAndSetValue(DicomTag.InstanceCreationDate, dateTime)

   ' Set an array of DateTime
   Dim dateTimeArray As DateTime() = {New DateTime(2000, 3, 8), New DateTime(2003, 5, 16)}
   ds.InsertElementAndSetValue(DicomTag.DateOfLastCalibration, dateTimeArray)

   ds.Save(outputStream, DicomDataSetSaveFlags.None)
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DicomDataSet Class
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

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Dicom requires a Medical toolkit server license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features