Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MWL & MPPS proxy SCP #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Desktop/ProxySCP/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
102 changes: 102 additions & 0 deletions Desktop/ProxySCP/CoreProxySCP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Dicom;
using Dicom.Log;
using Dicom.Network;
using System;
using System.Collections.Generic;
using System.Text;

namespace ProxySCP
{
public abstract class CoreProxySCP : DicomService, IDicomServiceProvider, IDicomCEchoProvider
{
protected static DicomTransferSyntax[] AcceptedTransferSyntaxes = new DicomTransferSyntax[]
{
DicomTransferSyntax
.ExplicitVRLittleEndian,
DicomTransferSyntax
.ExplicitVRBigEndian,
DicomTransferSyntax
.ImplicitVRLittleEndian
};

protected static DicomTransferSyntax[] AcceptedImageTransferSyntaxes = new DicomTransferSyntax[]
{
// Lossless
DicomTransferSyntax
.JPEGLSLossless,
DicomTransferSyntax
.JPEG2000Lossless,
DicomTransferSyntax
.JPEGProcess14SV1,
DicomTransferSyntax
.JPEGProcess14,
DicomTransferSyntax
.RLELossless,

// Lossy
DicomTransferSyntax
.JPEGLSNearLossless,
DicomTransferSyntax
.JPEG2000Lossy,
DicomTransferSyntax
.JPEGProcess1,
DicomTransferSyntax
.JPEGProcess2_4,

// Uncompressed
DicomTransferSyntax
.ExplicitVRLittleEndian,
DicomTransferSyntax
.ExplicitVRBigEndian,
DicomTransferSyntax
.ImplicitVRLittleEndian
};

protected abstract IList<DicomUID> GetSupportedFeatures();

protected CoreProxySCP(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log)
{
}

public virtual DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request)
{
return new DicomCEchoResponse(request, DicomStatus.Success);
}

public virtual void OnConnectionClosed(Exception exception)
{
}

public virtual void OnReceiveAbort(DicomAbortSource source, DicomAbortReason reason)
{
}

public virtual void OnReceiveAssociationReleaseRequest()
{
SendAssociationReleaseResponse();
}

public virtual void OnReceiveAssociationRequest(DicomAssociation association)
{
//if (association.CalledAE != "STORESCP")
//{
// SendAssociationReject(
// DicomRejectResult.Permanent,
// DicomRejectSource.ServiceUser,
// DicomRejectReason.CalledAENotRecognized);
// return;
//}

var supportedFeatures = this.GetSupportedFeatures();

foreach (var pc in association.PresentationContexts)
{
if (supportedFeatures.Contains(pc.AbstractSyntax)) pc.AcceptTransferSyntaxes(AcceptedTransferSyntaxes);
else if (pc.AbstractSyntax.StorageCategory != DicomStorageCategory.None) pc.AcceptTransferSyntaxes(AcceptedImageTransferSyntaxes);
}

SendAssociationAccept(association);
}

}
}
108 changes: 108 additions & 0 deletions Desktop/ProxySCP/MPPSProxySCP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using Dicom;
using Dicom.Log;
using Dicom.Network;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ProxySCP
{
public class MPPSProxySCP : CoreProxySCP, IDicomNServiceProvider
{
public MPPSProxySCP(INetworkStream stream, Encoding fallbackEncoding, Logger log) : base(stream, fallbackEncoding, log)
{
}
protected override IList<DicomUID> GetSupportedFeatures()
{
return new List<DicomUID>() {
DicomUID.ModalityPerformedProcedureStepSOPClass
};
}

public DicomNActionResponse OnNActionRequest(DicomNActionRequest request)
{

throw new System.NotImplementedException();
}

public DicomNCreateResponse OnNCreateRequest(DicomNCreateRequest request)
{
var signal = new ManualResetEventSlim(false);
DicomNCreateResponse result = null;

var client = new DicomClient();
client.NegotiateAsyncOps();

var newRequest = CloneNCreateRequest(request);
newRequest.OnResponseReceived += (req, response) =>
{
result = new DicomNCreateResponse(request, response.Status)
{
Dataset = response.Dataset
};

signal.Set();
};
client.AddRequest(newRequest);
client.Send("localhost", 108, false, "scu", "scp");

signal.Wait();
return result;
}
public DicomNSetResponse OnNSetRequest(DicomNSetRequest request)
{
var signal = new ManualResetEventSlim(false);
DicomNSetResponse result = null;

var client = new DicomClient();
client.NegotiateAsyncOps();

var newRequest = CloneOnNSetRequest(request);
newRequest.OnResponseReceived += (req, response) =>
{
result = new DicomNSetResponse(request, response.Status);
result.Dataset = response.Dataset;

signal.Set();
};
client.AddRequest(newRequest);
client.Send("localhost", 108, false, "scu", "scp");

signal.Wait();
return result;
}

public DicomNDeleteResponse OnNDeleteRequest(DicomNDeleteRequest request)
{
throw new System.NotImplementedException();
}

public DicomNEventReportResponse OnNEventReportRequest(DicomNEventReportRequest request)
{
throw new System.NotImplementedException();
}

public DicomNGetResponse OnNGetRequest(DicomNGetRequest request)
{
throw new System.NotImplementedException();
}

private DicomNCreateRequest CloneNCreateRequest(DicomNCreateRequest req)
{
var request = new DicomNCreateRequest(req.Command);
request.Dataset = req.Dataset;

return request;
}

private DicomNSetRequest CloneOnNSetRequest(DicomNSetRequest req)
{
var request = new DicomNSetRequest(req.Command)
{
Dataset = req.Dataset
};

return request;
}
}
}
64 changes: 64 additions & 0 deletions Desktop/ProxySCP/MWLProxySCP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Dicom;
using Dicom.Log;
using Dicom.Network;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ProxySCP
{
public class MWLProxySCP : CoreProxySCP, IDicomCFindProvider
{
public MWLProxySCP(INetworkStream stream, Encoding fallbackEncoding, Logger log)
: base(stream, fallbackEncoding, log)
{
}

protected override IList<DicomUID> GetSupportedFeatures()
{
return new List<DicomUID>() {
DicomUID.ModalityWorklistInformationModelFIND
};
}

IEnumerable<DicomCFindResponse> IDicomCFindProvider.OnCFindRequest(DicomCFindRequest request)
{
var signal = new ManualResetEventSlim(false);

var worklist = new List<DicomCFindResponse>();

var client = new DicomClient();
client.NegotiateAsyncOps();

var newRequest = CloneRequest(request);
newRequest.OnResponseReceived += (req, response) =>
{
var result = new DicomCFindResponse(request, response.Status)
{
Dataset = response.Dataset
};
worklist.Add(result);

if (response.Status != DicomStatus.Pending)
{
signal.Set();
}
};
client.AddRequest(newRequest);
client.Send("localhost", 107, false, "scu", "scp");

signal.Wait();
return worklist;
}

private DicomCFindRequest CloneRequest(DicomCFindRequest req)
{
var request = new DicomCFindRequest(req.Command)
{
Dataset = req.Dataset
};

return request;
}
}
}
25 changes: 25 additions & 0 deletions Desktop/ProxySCP/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Dicom;
using Dicom.Network;
using System;

namespace ProxySCP
{
class Program
{
static void Main(string[] args)
{
// preload dictionary to prevent timeouts
var dict = DicomDictionary.Default;


// start DICOM server
var serverMWL = DicomServer.Create<MWLProxySCP>(9107); // host on 9107, forward request to 107
var serverMPPS = DicomServer.Create<MPPSProxySCP>(9108); // host on 9108, forward request to 108
Console.WriteLine("MWL & MPPS Proxy started.");

// end process
Console.WriteLine("Press <return> to end...");
Console.ReadLine();
}
}
}
18 changes: 18 additions & 0 deletions Desktop/ProxySCP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ProxySCP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7143700b-2391-4643-9ccc-b19f24e2ca2d")]
Loading