using Leadtools;
using Leadtools.Dicom.Scu;
using Leadtools.Dicom.Scu.Common;
using Leadtools.Dicom;
using Leadtools.Dicom.Common.DataTypes;
using Leadtools.Dicom.Common.DataTypes.Status;
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.HostReady += RetrieveInstance_HostReady;
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();
}
private void RetrieveInstance_HostReady(object sender, HostReadyEventArgs e)
{
if (e.ScpHost != null)
{
Console.WriteLine("HostReady: Host AETitle:{0} Host Port:{1}", e.ScpHost.AETitle, e.ScpHost.HostPort);
}
}
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);
if (e.Status != DicomCommandStatusType.Success)
{
string statusAllString = e.StatusAll.ToString(StatusFormatFlags.IgnoreStatus, "\n", "\t");
Console.WriteLine(statusAllString);
}
}