Imports Leadtools
Imports Leadtools.Dicom.Scu
Imports Leadtools.Dicom.Scu.Common
Imports Leadtools.Dicom
Imports Leadtools.Dicom.Common.DataTypes
Public Sub MoveInstance()
DicomEngine.Startup()
DicomNet.Startup()
Dim retrieveInstance As QueryRetrieveScu = New QueryRetrieveScu()
Dim query As FindQuery = New FindQuery()
Dim scp As DicomScp = New DicomScp()
'
' Change these parameters to reflect the calling AETitle.
'
retrieveInstance.AETitle = "LEAD_CLIENT"
retrieveInstance.HostPort = 1000
retrieveInstance.HostAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(Function(ip) ip.AddressFamily = AddressFamily.InterNetwork)
'
' Change these parameters to reflect the called AETitle (server).
'
scp.AETitle = "MI_SERVER"
scp.Port = 104
scp.Timeout = 60
scp.PeerAddress = IPAddress.Parse("10.1.1.96")
AddHandler retrieveInstance.BeforeCMove, AddressOf retrieveInstance_BeforeCMove
AddHandler retrieveInstance.Moved, AddressOf retrieveInstance_Moved
AddHandler retrieveInstance.AfterCMove, AddressOf retrieveInstance_AfterCMove
retrieveInstance.Move(scp, String.Empty, "1.2.840.114257.3.6.5.41964868", "1.2.840.114257.3.6.5.5.4214471", "1.2.840.114257.3.6.5.5.18900282")
DicomNet.Shutdown()
DicomEngine.Shutdown()
End Sub
Private Sub retrieveInstance_BeforeCMove(ByVal sender As Object, ByVal e As BeforeCMoveEventArgs)
Console.WriteLine("Before CMove")
End Sub
Private Sub PrintReferencedRequestSequence(ByVal rrs As List(Of ReferencedRequestSequence))
If rrs.Count > 0 Then
Console.WriteLine("Referenced Request Sequence")
For Each rr As ReferencedRequestSequence In rrs
Console.WriteLine(Constants.vbTab & "Accession Number: ", rr.AccessionNumber)
Console.WriteLine(Constants.vbTab & "Study Instance UID: " & rr.StudyInstanceUID)
Console.WriteLine(Constants.vbTab & "Requested Procedure ID: " & rr.RequestedProcedureId)
If rr.RequestedProcedureCodeSequence.Count > 0 Then
Console.WriteLine(Constants.vbTab & "Requested Procedure Code Sequence")
For Each rpc As CodeSequence In rr.RequestedProcedureCodeSequence
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Code Meaning: " & rpc.CodeMeaning)
If Not rpc.EnhancedEncoding Is Nothing Then
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Context Identifier: " & rpc.EnhancedEncoding.ContextIdentifier)
End If
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Scheme Designator: " & rpc.CodeSchemeDesignator)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Scheme Version: " & rpc.CodingSchemeVersion)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Value: " & rpc.CodeValue)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "----------------------------------")
Next rpc
End If
Console.WriteLine(Constants.vbTab & "----------------------------------")
Next rr
End If
End Sub
Private Sub PrintConceptCodeNameSequence(ByVal ccs As CodeSequence)
If Not ccs Is Nothing Then
Console.WriteLine("Content Code Name Sequence")
Console.WriteLine(Constants.vbTab & "Code Meaning: " & ccs.CodeMeaning)
If Not ccs.EnhancedEncoding Is Nothing Then
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Context Identifier: " & ccs.EnhancedEncoding.ContextIdentifier)
End If
Console.WriteLine(Constants.vbTab & "Scheme Designator: " & ccs.CodeSchemeDesignator)
Console.WriteLine(Constants.vbTab & "Scheme Version: " & ccs.CodingSchemeVersion)
Console.WriteLine(Constants.vbTab & "Value: " & ccs.CodeValue)
End If
End Sub
Private Sub retrieveInstance_Moved(ByVal sender As Object, ByVal e As MovedEventArgs)
Select Case e.Instance.InstanceType
Case InstanceLevel.EvidenceDocument
Dim ed As EvidenceDocumentInstance = TryCast(e.Instance, EvidenceDocumentInstance)
Console.WriteLine("Content Date: " & ed.ContentDate.ToString())
Console.WriteLine("Content Time: " & ed.ContentTime.ToString())
If Not ed.ContentTemplateSequence Is Nothing Then
Console.WriteLine("Content Template Sequence")
Console.WriteLine(Constants.vbTab & "Template Identifier: " & ed.ContentTemplateSequence.TemplateIdentifer)
End If
PrintReferencedRequestSequence(ed.ReferencedRequestSeqence)
PrintConceptCodeNameSequence(ed.ConceptNameCodeSequence)
Case InstanceLevel.Image
Dim ii As ImageInstance = TryCast(e.Instance, ImageInstance)
Console.WriteLine("Bits Allocated: " & ii.BitsAllocated)
Console.WriteLine("Columns: " & ii.Columns)
Console.WriteLine("Frames: " & ii.Frames)
Console.WriteLine("Rows: " & ii.Rows)
If Not ii.Images Is Nothing Then
Console.WriteLine("Image Size: " & ii.Images.BytesPerLine * ii.Images.Height)
End If
Case InstanceLevel.KeyImageNote
Dim ki As KeyImageInstance = TryCast(e.Instance, KeyImageInstance)
Console.WriteLine("Content Date: " & ki.ContentDate.ToString())
Console.WriteLine("Content Time: " & ki.ContentTime.ToString())
Console.WriteLine("Observation Date/Time: " & ki.ObservationDateTime.ToString())
PrintReferencedRequestSequence(ki.ReferencedRequestSequence)
PrintConceptCodeNameSequence(ki.ConceptNameCodeSequence)
Case InstanceLevel.PresentationState
Dim pi As PresentationStateInstance = TryCast(e.Instance, PresentationStateInstance)
Console.WriteLine("Presentation Label: " & pi.Label)
Console.WriteLine("Creation Date: " & pi.CreateDate.ToString())
Console.WriteLine("Creation Time: " & pi.CreateTime.ToString())
Console.WriteLine("Creators Name: " & pi.CreatorsName)
Console.WriteLine("Description: " & pi.Description)
If pi.ReferencedSeriesSequence.Count > 0 Then
Console.WriteLine("Referenced Series Sequence")
For Each rss As ReferencedSeriesSequence In pi.ReferencedSeriesSequence
Console.WriteLine(Constants.vbTab & "Series Instance UID: " & rss.SeriesInstanceUID)
If rss.ReferencedImageSequence.Count > 0 Then
Console.WriteLine(Constants.vbTab & "Referenced Image Sequence")
For Each ris As ReferencedImageSequence In rss.ReferencedImageSequence
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Referenced SOP Class UID: " & ris.ReferencedSOPClassUID)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Referenced SOP Instance UID: " & ris.ReferencedSOPInstanceUID)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "----------------------------------")
Next ris
End If
Console.WriteLine(Constants.vbTab & "----------------------------------")
Next rss
End If
Case InstanceLevel.StructuredReport
Dim si As SRInstance = TryCast(e.Instance, SRInstance)
Console.WriteLine("Completion Flag: " & si.CompletionFlag)
Console.WriteLine("Verification Flag: " & si.VerificationFlag)
Console.WriteLine("Content Date: " & si.ContentDate.ToString())
Console.WriteLine("Content Time: " & si.ContentTime.ToString())
Console.WriteLine("Observation Date/Time: " & si.ObservationDateTime.ToString())
If si.VerifyingObserverSequence.Count > 0 Then
Console.WriteLine("Verifying Observer Sequence")
For Each vos As VerifyingObserverSequence In si.VerifyingObserverSequence
Console.WriteLine(Constants.vbTab & "Verifying Organization: " & vos.VerifyingOrganization)
Console.WriteLine(Constants.vbTab & "Verification Date/Time: " & vos.VerificationDateTime.ToString())
Console.WriteLine(Constants.vbTab & "Verifying Observer Name: " & vos.VerifyingObserverName)
If vos.VerifyingObserverIdentificationCodeSequence.Count > 0 Then
Console.WriteLine("Verifying Observer Identification Code Sequence")
For Each cs As CodeSequence In vos.VerifyingObserverIdentificationCodeSequence
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Code Meaning: " & cs.CodeMeaning)
If Not cs.EnhancedEncoding Is Nothing Then
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Context Identifier: " & cs.EnhancedEncoding.ContextIdentifier)
End If
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Scheme Designator: " & cs.CodeSchemeDesignator)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Scheme Version: " & cs.CodingSchemeVersion)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "Value: " & cs.CodeValue)
Console.WriteLine(Constants.vbTab + Constants.vbTab & "----------------------------------")
Next cs
End If
Console.WriteLine(Constants.vbTab & "----------------------------------")
Next vos
End If
PrintReferencedRequestSequence(si.ReferencedRequestSequence)
PrintConceptCodeNameSequence(si.ConceptNameCodeSequence)
End Select
End Sub
Private Sub retrieveInstance_AfterCMove(ByVal sender As Object, ByVal e As AfterCMoveEventArgs)
Console.WriteLine("{0} Completed", e.Completed)
Console.WriteLine("{0} Failed", e.Failed)
Console.WriteLine("{0} Warning", e.Warning)
Console.WriteLine("Status: {0}", e.Status)
End Sub
using Leadtools;
using Leadtools.Dicom.Scu;
using Leadtools.Dicom.Scu.Common;
using Leadtools.Dicom;
using Leadtools.Dicom.Common.DataTypes;
public void MoveInstance()
{
DicomEngine.Startup();
DicomNet.Startup();
QueryRetrieveScu retrieveInstance = new QueryRetrieveScu();
FindQuery query = new FindQuery();
DicomScp scp = new DicomScp();
//
// Change these parameters to reflect the calling AETitle.
//
retrieveInstance.AETitle = "LEAD_CLIENT";
retrieveInstance.HostPort = 1000;
retrieveInstance.HostAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
//
// Change these parameters to reflect the called AETitle (server).
//
scp.AETitle = "MI_SERVER";
scp.Port = 104;
scp.Timeout = 60;
scp.PeerAddress = IPAddress.Parse("10.1.1.96");
retrieveInstance.EnableMoveToSelf = true;
retrieveInstance.BeforeCMove += new BeforeCMoveDelegate(retrieveInstance_BeforeCMove);
retrieveInstance.Moved += new MovedDelegate(retrieveInstance_Moved);
retrieveInstance.AfterCMove += new AfterCMoveDelegate(retrieveInstance_AfterCMove);
retrieveInstance.Move(scp, string.Empty, "1.2.840.114257.3.6.5.41964868", "1.2.840.114257.3.6.5.5.4214471",
"1.2.840.114257.3.6.5.5.18900282");
DicomNet.Shutdown();
DicomEngine.Shutdown();
}
void retrieveInstance_BeforeCMove(object sender, BeforeCMoveEventArgs e)
{
Console.WriteLine("Before CMove");
}
void PrintReferencedRequestSequence(List<ReferencedRequestSequence> rrs)
{
if (rrs.Count > 0)
{
Console.WriteLine("Referenced Request Sequence");
foreach (ReferencedRequestSequence rr in rrs)
{
Console.WriteLine("\tAccession Number: ", rr.AccessionNumber);
Console.WriteLine("\tStudy Instance UID: " + rr.StudyInstanceUID);
Console.WriteLine("\tRequested Procedure ID: " + rr.RequestedProcedureId);
if (rr.RequestedProcedureCodeSequence.Count > 0)
{
Console.WriteLine("\tRequested Procedure Code Sequence");
foreach (CodeSequence rpc in rr.RequestedProcedureCodeSequence)
{
Console.WriteLine("\t\tCode Meaning: " + rpc.CodeMeaning);
if(rpc.EnhancedEncoding!=null)
Console.WriteLine("\t\tContext Identifier: " + rpc.EnhancedEncoding.ContextIdentifier);
Console.WriteLine("\t\tScheme Designator: " + rpc.CodeSchemeDesignator);
Console.WriteLine("\t\tScheme Version: " + rpc.CodingSchemeVersion);
Console.WriteLine("\t\tValue: " + rpc.CodeValue);
Console.WriteLine("\t\t----------------------------------");
}
}
Console.WriteLine("\t----------------------------------");
}
}
}
void PrintConceptCodeNameSequence(CodeSequence ccs)
{
if (ccs != null)
{
Console.WriteLine("Content Code Name Sequence");
Console.WriteLine("\tCode Meaning: " + ccs.CodeMeaning);
if (ccs.EnhancedEncoding != null)
Console.WriteLine("\t\tContext Identifier: " + ccs.EnhancedEncoding.ContextIdentifier);
Console.WriteLine("\tScheme Designator: " + ccs.CodeSchemeDesignator);
Console.WriteLine("\tScheme Version: " + ccs.CodingSchemeVersion);
Console.WriteLine("\tValue: " + ccs.CodeValue);
}
}
void retrieveInstance_Moved(object sender, MovedEventArgs e)
{
switch (e.Instance.InstanceType)
{
case InstanceLevel.EvidenceDocument:
EvidenceDocumentInstance ed = e.Instance as EvidenceDocumentInstance;
Console.WriteLine("Content Date: " + ed.ContentDate);
Console.WriteLine("Content Time: " + ed.ContentTime);
if (ed.ContentTemplateSequence != null)
{
Console.WriteLine("Content Template Sequence");
Console.WriteLine("\tTemplate Identifier: " + ed.ContentTemplateSequence.TemplateIdentifer);
}
PrintReferencedRequestSequence(ed.ReferencedRequestSeqence);
PrintConceptCodeNameSequence(ed.ConceptNameCodeSequence);
break;
case InstanceLevel.Image:
ImageInstance ii = e.Instance as ImageInstance;
Console.WriteLine("Bits Allocated: " + ii.BitsAllocated);
Console.WriteLine("Columns: " + ii.Columns);
Console.WriteLine("Frames: " + ii.Frames);
Console.WriteLine("Rows: " + ii.Rows);
if (ii.Images != null)
Console.WriteLine("Image Size: " + ii.Images.BytesPerLine * ii.Images.Height);
break;
case InstanceLevel.KeyImageNote:
KeyImageInstance ki = e.Instance as KeyImageInstance;
Console.WriteLine("Content Date: " + ki.ContentDate);
Console.WriteLine("Content Time: " + ki.ContentTime);
Console.WriteLine("Observation Date/Time: " + ki.ObservationDateTime);
PrintReferencedRequestSequence(ki.ReferencedRequestSequence);
PrintConceptCodeNameSequence(ki.ConceptNameCodeSequence);
break;
case InstanceLevel.PresentationState:
PresentationStateInstance pi = e.Instance as PresentationStateInstance;
Console.WriteLine("Presentation Label: " + pi.Label);
Console.WriteLine("Creation Date: " + pi.CreateDate);
Console.WriteLine("Creation Time: " + pi.CreateTime);
Console.WriteLine("Creators Name: " + pi.CreatorsName);
Console.WriteLine("Description: " + pi.Description);
if (pi.ReferencedSeriesSequence.Count > 0)
{
Console.WriteLine("Referenced Series Sequence");
foreach (ReferencedSeriesSequence rss in pi.ReferencedSeriesSequence)
{
Console.WriteLine("\tSeries Instance UID: " + rss.SeriesInstanceUID);
if (rss.ReferencedImageSequence.Count > 0)
{
Console.WriteLine("\tReferenced Image Sequence");
foreach (ReferencedImageSequence ris in rss.ReferencedImageSequence)
{
Console.WriteLine("\t\tReferenced SOP Class UID: " + ris.ReferencedSOPClassUID);
Console.WriteLine("\t\tReferenced SOP Instance UID: " + ris.ReferencedSOPInstanceUID);
Console.WriteLine("\t\t----------------------------------");
}
}
Console.WriteLine("\t----------------------------------");
}
}
break;
case InstanceLevel.StructuredReport:
SRInstance si = e.Instance as SRInstance;
Console.WriteLine("Completion Flag: " + si.CompletionFlag);
Console.WriteLine("Verification Flag: " + si.VerificationFlag);
Console.WriteLine("Content Date: " + si.ContentDate);
Console.WriteLine("Content Time: " + si.ContentTime);
Console.WriteLine("Observation Date/Time: " + si.ObservationDateTime);
if (si.VerifyingObserverSequence.Count > 0)
{
Console.WriteLine("Verifying Observer Sequence");
foreach (VerifyingObserverSequence vos in si.VerifyingObserverSequence)
{
Console.WriteLine("\tVerifying Organization: " + vos.VerifyingOrganization);
Console.WriteLine("\tVerification Date/Time: " + vos.VerificationDateTime);
Console.WriteLine("\tVerifying Observer Name: " + vos.VerifyingObserverName);
if (vos.VerifyingObserverIdentificationCodeSequence.Count > 0)
{
Console.WriteLine("Verifying Observer Identification Code Sequence");
foreach (CodeSequence cs in vos.VerifyingObserverIdentificationCodeSequence)
{
Console.WriteLine("\t\tCode Meaning: " + cs.CodeMeaning);
if (cs.EnhancedEncoding != null)
Console.WriteLine("\t\tContext Identifier: " + cs.EnhancedEncoding.ContextIdentifier);
Console.WriteLine("\t\tScheme Designator: " + cs.CodeSchemeDesignator);
Console.WriteLine("\t\tScheme Version: " + cs.CodingSchemeVersion);
Console.WriteLine("\t\tValue: " + cs.CodeValue);
Console.WriteLine("\t\t----------------------------------");
}
}
Console.WriteLine("\t----------------------------------");
}
}
PrintReferencedRequestSequence(si.ReferencedRequestSequence);
PrintConceptCodeNameSequence(si.ConceptNameCodeSequence);
break;
}
}
void retrieveInstance_AfterCMove(object sender, AfterCMoveEventArgs e)
{
Console.WriteLine("{0} Completed", e.Completed);
Console.WriteLine("{0} Failed", e.Failed);
Console.WriteLine("{0} Warning", e.Warning);
Console.WriteLine("Status: {0}", e.Status);
}