Leadtools.Dicom.Common Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
DicomKeyAttribute Class
See Also  Members  
Leadtools.Dicom.Common.Linq.BasicDirectory Namespace : DicomKeyAttribute Class



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

Object Model

DicomKeyAttribute Class

Syntax

Visual Basic (Declaration) 
Public Class DicomKeyAttribute 
   Inherits System.Attribute
   Implements _Attribute 
Visual Basic (Usage)Copy Code
Dim instance As DicomKeyAttribute
C# 
public class DicomKeyAttribute : System.Attribute, _Attribute  
C++/CLI 
public ref class DicomKeyAttribute : public System.Attribute, _Attribute  

Example

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

Visual BasicCopy Code
<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
C#Copy Code
[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);
        }
    }
}

Inheritance Hierarchy

System.Object
   System.Attribute
      Leadtools.Dicom.Common.Linq.BasicDirectory.DicomKeyAttribute

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

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