←Select platform

DicomKeyAttribute Class

Summary

Specifies what DICOMDIR key this class/property is associated with.

Syntax

C#
VB
C++
public class DicomKeyAttribute : Attribute 
Public Class DicomKeyAttribute  
   Inherits System.Attribute 
   Implements System.Runtime.InteropServices._Attribute  
public ref class DicomKeyAttribute : public System.Attribute, System.Runtime.InteropServices._Attribute   

Example

This example will show how to perform several different types of LINQ based queries on a DICOM basic directory.

C#
VB
using Leadtools.Dicom; 
using Leadtools.Dicom.Common; 
using Leadtools.Dicom.Common.Extensions; 
using Leadtools; 
using Leadtools.Dicom.Common.Linq.BasicDirectory; 
using Leadtools.Dicom.Common.DataTypes; 
 
 
[DicomKey(DicomDirKeyType.Patient)] 
public class PatientEntity 
{ 
   [Element(DicomTag.PatientID)] 
   public string Id 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.PatientName)] 
   public string Name 
   { 
      get; 
      set; 
   } 
} 
 
[DicomKey(DicomDirKeyType.Study)] 
public class StudyEntity 
{ 
   [Element(DicomTag.PatientID)] 
   [DicomKey(DicomDirKeyType.Patient)] 
   public string PatientId 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.StudyDate)] 
   public DateTime? Date 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.StudyTime)] 
   public DateTime? Time 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.StudyDescription)] 
   public string Description 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.StudyInstanceUID)] 
   public string InstanceUID 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.StudyID)] 
   public string Id 
   { 
      get; 
      set; 
   } 
 
   [Element(DicomTag.AccessionNumber)] 
   public string AccessionNumber 
   { 
      get; 
      set; 
   } 
} 
 
public void TestDicomLinq() 
{ 
   DicomEngine.Startup(); 
 
   using (DicomDataSet ds = new DicomDataSet()) 
   { 
      ds.Load(_DicomDirFile, DicomDataSetLoadFlags.None); 
      FindPatients(ds); 
      FindStudies(ds); 
      FindPatientStudy(ds); 
   } 
 
   DicomEngine.Shutdown(); 
} 
 
private void FindPatients(DicomDataSet ds) 
{ 
   var patients = from patient in ds.DirectoryRecord<PatientEntity>() 
                  select new { Name = patient.Name, Id = patient.Id }; 
 
   foreach (var patient in patients) 
   { 
      Console.WriteLine("Id: " + patient.Id); 
      Console.WriteLine("Name: " + patient.Name); 
   } 
} 
 
private void FindStudies(DicomDataSet ds) 
{ 
   var studies = from study in ds.DirectoryRecord<StudyEntity>() 
                 select study; 
 
   foreach (var study in studies) 
   { 
      Console.WriteLine("Patient Id: " + study.PatientId); 
      Console.WriteLine("Accession #: " + study.AccessionNumber); 
      Console.WriteLine("Study Id: " + study.Id); 
   } 
} 
 
private void FindPatientStudy(DicomDataSet ds) 
{ 
   var query = from patient in ds.DirectoryRecord<PatientEntity>() 
               select new 
               { 
                  patient, 
                  Studies = from study in ds.DirectoryRecord<StudyEntity>() 
                            where study.PatientId == patient.Id 
                            select study 
               }; 
 
   foreach (var item in query) 
   { 
      Console.WriteLine("Patient: " + item.patient.Id); 
      foreach (StudyEntity study in item.Studies) 
      { 
         Console.WriteLine("    Instance UID: " + study.InstanceUID); 
      } 
   } 
} 
Imports Leadtools.Dicom 
Imports Leadtools.Dicom.Common 
Imports Leadtools.Dicom.Common.Extensions 
Imports Leadtools.Dicom.Common.Linq 
Imports Leadtools.Dicom.Common.Linq.BasicDirectory 
Imports Leadtools 
Imports Leadtools.Dicom.Common.DataTypes 
 
 
<DicomKey(DicomDirKeyType.Patient)> 
Public Class PatientEntity 
   <Element(DicomTag.PatientID)> 
   Public Property Id() As String 
      Get 
         Return m_Id 
      End Get 
      Set(ByVal value As String) 
         m_Id = value 
      End Set 
   End Property 
   Private m_Id As String 
 
   <Element(DicomTag.PatientName)> 
   Public Property Name() As String 
      Get 
         Return m_Name 
      End Get 
      Set(ByVal value As String) 
         m_Name = value 
      End Set 
   End Property 
   Private m_Name As String 
End Class 
 
<DicomKey(DicomDirKeyType.Study)> 
Public Class StudyEntity 
   <Element(DicomTag.PatientID)> 
   <DicomKey(DicomDirKeyType.Patient)> 
   Public Property PatientId() As String 
      Get 
         Return m_PatientId 
      End Get 
      Set(ByVal value As String) 
         m_PatientId = value 
      End Set 
   End Property 
   Private m_PatientId As String 
 
   <Element(DicomTag.StudyDate)> 
   Public Property [Date]() As System.Nullable(Of DateTime) 
      Get 
         Return m_Date 
      End Get 
      Set(ByVal value As System.Nullable(Of DateTime)) 
         m_Date = value 
      End Set 
   End Property 
   Private m_Date As System.Nullable(Of DateTime) 
 
   <Element(DicomTag.StudyTime)> 
   Public Property Time() As System.Nullable(Of DateTime) 
      Get 
         Return m_Time 
      End Get 
      Set(ByVal value As System.Nullable(Of DateTime)) 
         m_Time = value 
      End Set 
   End Property 
   Private m_Time As System.Nullable(Of DateTime) 
 
   <Element(DicomTag.StudyDescription)> 
   Public Property Description() As String 
      Get 
         Return m_Description 
      End Get 
      Set(ByVal value As String) 
         m_Description = value 
      End Set 
   End Property 
   Private m_Description As String 
 
   <Element(DicomTag.StudyInstanceUID)> 
   Public Property InstanceUID() As String 
      Get 
         Return m_InstanceUID 
      End Get 
      Set(ByVal value As String) 
         m_InstanceUID = value 
      End Set 
   End Property 
   Private m_InstanceUID As String 
 
   <Element(DicomTag.StudyID)> 
   Public Property Id() As String 
      Get 
         Return m_Id 
      End Get 
      Set(ByVal value As String) 
         m_Id = value 
      End Set 
   End Property 
   Private m_Id As String 
 
   <Element(DicomTag.AccessionNumber)> 
   Public Property AccessionNumber() As String 
      Get 
         Return m_AccessionNumber 
      End Get 
      Set(ByVal value As String) 
         m_AccessionNumber = value 
      End Set 
   End Property 
   Private m_AccessionNumber As String 
End Class 
 
Public Sub TestDicomLinq() 
   DicomEngine.Startup() 
 
   Using ds As New DicomDataSet() 
      ds.Load(_DicomDirFile, DicomDataSetLoadFlags.None) 
      FindPatients(ds) 
      FindStudies(ds) 
      FindPatientStudy(ds) 
   End Using 
 
   DicomEngine.Shutdown() 
End Sub 
 
Private Sub FindPatients(ByVal ds As DicomDataSet) 
   Dim patients = From patient In ds.DirectoryRecord(Of PatientEntity)() 
                  Select Name = patient.Name, Id = patient.Id 
 
   For Each patient In patients 
      Console.WriteLine("Id: " & Convert.ToString(patient.Id)) 
      Console.WriteLine("Name: " & Convert.ToString(patient.Name)) 
   Next 
End Sub 
 
Private Sub FindStudies(ByVal ds As DicomDataSet) 
   Dim studies = From study In ds.DirectoryRecord(Of StudyEntity)() 
                 Select study 
 
   For Each study In studies 
      Console.WriteLine("Patient Id: " & Convert.ToString(study.PatientId)) 
      Console.WriteLine("Accession #: " & Convert.ToString(study.AccessionNumber)) 
      Console.WriteLine("Study Id: " & Convert.ToString(study.Id)) 
   Next 
End Sub 
 
Private Sub FindPatientStudy(ByVal ds As DicomDataSet) 
   Dim query = From patient In ds.DirectoryRecord(Of PatientEntity)() 
               Select 
    patient, 
    Studies = From study In ds.DirectoryRecord(Of StudyEntity)() Where study.PatientId = patient.Id 
              Select study 
 
   For Each item In query 
      Console.WriteLine("Patient: " & Convert.ToString(item.patient.Id)) 
      For Each study As StudyEntity In item.Studies 
         Console.WriteLine("    Instance UID: " + study.InstanceUID) 
      Next 
   Next 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom.Common Assembly