←Select platform

FindFirstElement Method

Summary
Returns the first item in the Data Set with the specified Tag.
Syntax
C#
Objective-C
C++/CLI
Java
public DicomElement FindFirstElement( 
   DicomElement element, 
   long tag, 
   bool tree 
) 
- (nullable LTDicomElement *)findFirstElement:(nullable LTDicomElement *)element tag:(LTDicomTagCode)tag tree:(BOOL)tree; 
public DicomElement findFirstElement(DicomElement element, long tag, boolean tree) 
public: 
DicomElement^ FindFirstElement(  
   DicomElement^ element, 
   int64 tag, 
   bool tree 
)  

Parameters

element
An item in the Data Set.

tag
Tag of the item to find.

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

Return Value

The first item in the Data Set with the specified Tag, or a null reference (Nothing in VB) if an item with the specified Tag was not found.

Remarks

For the sake of the following illustrations, the order of siblings is top to bottom. Therefore first is evaluated top to bottom. If the Data Set is evaluated as a tree structure, this method returns the first item on the same level as element with the same parent as element, that has Tag tag.

Please note that the numbering of the items of interest in this first illustration is arbitrary and does not imply order.

fndfttr.gif
If the passed object points to: The method returns an object pointing to:
Item 1 The first sibling (same level, same parent) of Item 1 that has Tag tag, if such an item exists. If such an item does not exist, the method returns null.
Item 2 The first sibling (same level, same parent) of Item 2 that has Tag tag, if such an item exists. If such an item does not exist, the method returns null.
Item 3 The first sibling (same level, same parent) of Item 3 that has Tag tag, if such an item exists. If such an item does not exist, the method returns null.

If the Data Set is evaluated as a list, this method returns the first item in the entire list that has Tag tag. The search begins at the top of the list.

Please note that the numbering of the items in the following illustration does indicate the order of the items when the Data Set is evaluated as a list.

fndftlst.gif
If the passed object points to: The method returns an object pointing to:
Item 1 The first item in the list that has Tag tag, if such an item exists. Searching begins at the top of the list. If an item with Tag tag is not found, null is returned.
Item 14 The first item in the list that has Tag tag, if such an item exists. Searching begins at the top of the list. If an item with Tag tag is not found, null is returned.
Item 22 The first item in the list that has Tag tag, if such an item exists. Searching begins at the top of the list. If an item with Tag tag is not found, null is returned.

The following methods will also help you find elements in the Data Set with a specific Tag:

FindLastElement

FindPreviousElement

FindNextElement

The following methods will help you find specific modules in the Data Set:

FindModule

FindModuleByIndex

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
public void LoadEnumerateSample() 
{ 
   string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image3.dcm"); 
   //Make sure to initialize the DICOM engine, this needs to be done only once  
   //In the whole application 
   DicomEngine.Startup(); 
   using (DicomDataSet ds = new DicomDataSet()) 
   { 
      //Load DICOM File 
      ds.Load(dicomFileName, DicomDataSetLoadFlags.None); 
      //Insert patient name element, if it doesn't already exist 
      DicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, false); 
      if (element == null) 
      { 
         element = ds.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); 
      } 
      //The dataset should include the patient name element or an error occurred 
      element = ds.FindLastElement(null, DicomTag.PatientName, false); 
      Debug.Assert(element != null); 
      //There can be only one patient element in the root level 
      element = ds.FindPreviousElement(null, false); 
      Debug.Assert(element == null); 
      element = ds.FindNextElement(null, false); 
      Debug.Assert(element == null); 
 
      element = ds.FindFirstElement(null, DicomTag.PatientName, false); 
      //Since the patient name element is in the root level, 
      //GetRootElement will return the same element. 
      DicomElement element1 = ds.GetRootElement(element); 
      Debug.Assert((element1.Tag == element.Tag), "GetRootElement should return same element"); 
 
      //Since the patient name element has no parent then GetParentElement will return null 
      element1 = ds.GetParentElement(element); 
      Debug.Assert(element1 == null, "GetParentElement should return null"); 
 
      //Since the patient name element has no children then GetChildElement will return null 
      element1 = ds.GetChildElement(element, false); 
      Debug.Assert(element1 == null, "GetChildElement should return null"); 
 
      element1 = ds.GetFirstElement(element, false, false); 
      Debug.Assert(element1 != null, "GetFirstElement Can't return null in this case"); 
 
      element1 = ds.GetLastElement(element, false, false); 
      Debug.Assert(element1 != null, "GetLastElement Can't return null in this case"); 
 
      element1 = ds.GetPreviousElement(element, false, true); 
      DicomElement element2 = ds.GetNextElement(element, false, true); 
 
      Debug.Assert(ds.GetElementLevel(element) == 0); 
 
      Debug.Assert(ds.ExistsElement(element)); 
      Debug.Assert(ds.IsVolatileElement(element) == false); 
 
      //Patient Name is not the only element in this level 
      Debug.Assert((element1 != null) && (element2 != null)); 
      //Delete the patient name element 
      ds.DeleteElement(element); 
   } 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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