Ejemplo n.º 1
0
        public async Task OnNCreateRequestAsync_ShouldRespond()
        {
            var port = Ports.GetNext();

            using (DicomServer.Create <AsyncDicomNServiceProvider>(port, logger: _logger.IncludePrefix("DicomServer")))
            {
                var client = new Network.Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP")
                {
                    Logger = _logger.IncludePrefix(typeof(DicomClient).Name)
                };

                DicomNCreateResponse            response = null;
                DicomRequest.OnTimeoutEventArgs timeout  = null;
                var request = new DicomNCreateRequest(
                    DicomUID.BasicFilmSession,
                    new DicomUID("1.2.3", null, DicomUidType.SOPInstance))
                {
                    OnResponseReceived = (req, res) => response = res,
                    OnTimeout          = (sender, args) => timeout = args
                };

                await client.AddRequestAsync(request).ConfigureAwait(false);

                await client.SendAsync().ConfigureAwait(false);

                Assert.NotNull(response);
                Assert.Equal(DicomStatus.Success, response.Status);
                Assert.Null(timeout);
            }
        }
        public async Task AcceptStoreContexts()
        {
            int port = Ports.GetNext();

            using (DicomServer.Create <AcceptOnlyEchoStoreProvider>(port))
            {
                var         echoReq    = new DicomCEchoRequest();
                DicomStatus echoStatus = DicomStatus.Pending;
                echoReq.OnResponseReceived += (req, resp) => echoStatus = resp.Status;

                var         storeReq    = new DicomCStoreRequest(@".\Test Data\CT1_J2KI");
                DicomStatus storeStatus = DicomStatus.Pending;
                storeReq.OnResponseReceived += (req, resp) => storeStatus = resp.Status;

                var         filmSession = new FilmSession(DicomUID.BasicFilmSession, DicomUID.Generate());
                var         printReq    = new DicomNCreateRequest(filmSession.SOPClassUID, filmSession.SOPInstanceUID);
                DicomStatus printStatus = DicomStatus.Pending;
                printReq.OnResponseReceived += (req, resp) => printStatus = resp.Status;

                var client = new Client.DicomClient("127.0.0.1", port, false, "SCU", "ANY-SCP");
                await client.AddRequestsAsync(echoReq, storeReq, printReq);

                await client.SendAsync();

                Assert.Equal(DicomStatus.Success, echoStatus);
                Assert.Equal(DicomStatus.Success, storeStatus);
                Assert.Equal(DicomStatus.SOPClassNotSupported, printStatus);
            }
        }
 public DicomNCreateResponse OnNCreateRequest(DicomNCreateRequest request)
 {
     return(new DicomNCreateResponse(request, DicomStatus.Success)
     {
         Dataset = request.Dataset
     });
 }
Ejemplo n.º 4
0
        public void SOPInstanceUIDGetter_SOPInstanceUIDNotDefinedInConstruction_IsNotDefinedInRequest()
        {
            var command = new DicomDataset();

            command.Add(DicomTag.CommandField, (ushort)DicomCommandField.NCreateRequest);
            command.Add(DicomTag.MessageID, (ushort)1);
            command.Add(DicomTag.RequestedSOPClassUID, "1.2.3");

            var request  = new DicomNCreateRequest(command);
            var expected = request.SOPInstanceUID;

            Assert.Null(expected);
        }
Ejemplo n.º 5
0
        public void Constructor_FromRequestWithoutSopInstanceUid_ShouldNotThrow()
        {
            var request =
                new DicomNCreateRequest(new DicomDataset
            {
                { DicomTag.CommandField, (ushort)DicomCommandField.NCreateRequest },
                { DicomTag.MessageID, (ushort)1 },
                { DicomTag.AffectedSOPClassUID, "1.2.3" }
            });

            DicomNCreateResponse response = null;
            var exception = Record.Exception(() => response = new DicomNCreateResponse(request, DicomStatus.Success));

            Assert.Null(exception);
            Assert.Null(response.SOPInstanceUID);
        }
Ejemplo n.º 6
0
        private DicomNCreateResponse CreateFilmBox(DicomNCreateRequest request)
        {
            if (_filmSession == null)
            {
                this.Logger.Error("A basic film session does not exist for this association {0}", CallingAE);
                SendAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.NotSpecified);
                return new DicomNCreateResponse(request, DicomStatus.NoSuchObjectInstance);

            }


            var filmBox = _filmSession.CreateFilmBox(request.SOPInstanceUID, request.Dataset);

            if (!filmBox.Initialize())
            {
                this.Logger.Error("Failed to initialize requested film box {0}", filmBox.SOPInstanceUID.UID);
                SendAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.NotSpecified);
                return new DicomNCreateResponse(request, DicomStatus.ProcessingFailure);
            }

            this.Logger.Info("Created new film box {0}", filmBox.SOPInstanceUID.UID);

            var response = new DicomNCreateResponse(request, DicomStatus.Success);
            response.Command.Add(DicomTag.AffectedSOPInstanceUID, filmBox.SOPInstanceUID);
            response.Dataset = filmBox;
            return response;
        }
Ejemplo n.º 7
0
        private DicomNCreateResponse CreateFilmSession(DicomNCreateRequest request)
        {
            if (_filmSession != null)
            {
                this.Logger.Error("Attemted to create new basic film session on association with {0}", CallingAE);
                SendAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.NotSpecified);
                return new DicomNCreateResponse(request, DicomStatus.NoSuchObjectInstance);
            }

            var pc = request.PresentationContext;

            bool isColor = pc != null && pc.AbstractSyntax == DicomUID.BasicColorPrintManagementMetaSOPClass;


            _filmSession = new FilmSession(request.SOPClassUID, request.SOPInstanceUID, request.Dataset, isColor);


            this.Logger.Info("Create new film session {0}", _filmSession.SOPInstanceUID.UID);

            var response = new DicomNCreateResponse(request, DicomStatus.Success);
            response.Command.Add(DicomTag.AffectedSOPInstanceUID, _filmSession.SOPInstanceUID);
            return response;
        }
Ejemplo n.º 8
0
 public DicomNCreateResponse OnNCreateRequest(DicomNCreateRequest request)
 {
     lock (_synchRoot)
     {
         if (request.SOPClassUID == DicomUID.BasicFilmSessionSOPClass)
         {
             return CreateFilmSession(request);
         }
         else if (request.SOPClassUID == DicomUID.BasicFilmBoxSOPClass)
         {
             return CreateFilmBox(request);
         }
         else
         {
             return new DicomNCreateResponse(request, DicomStatus.SOPClassNotSupported);
         }
     }
 }
Ejemplo n.º 9
0
        public void Print()
        {
            var dicomClient = new DicomClient();
            dicomClient.AddRequest(new DicomNCreateRequest(FilmSession.SOPClassUID, FilmSession.SOPInstanceUID, 0)
            {
                Dataset = FilmSession
            });


            foreach (var filmbox in FilmSession.BasicFilmBoxes)
            {

                var imageBoxRequests = new List<DicomNSetRequest>();

                var filmBoxRequest = new DicomNCreateRequest(FilmBox.SOPClassUID, filmbox.SOPInstanceUID, 0)
                {
                    Dataset = filmbox
                };
                filmBoxRequest.OnResponseReceived = (request, response) =>
                {
                    if (response.HasDataset)
                    {
                        var seq = response.Dataset.Get<DicomSequence>(DicomTag.ReferencedImageBoxSequence);
                        for (int i = 0; i < seq.Items.Count; i++)
                        {
                            var req = imageBoxRequests[i];
                            var imageBox = req.Dataset;
                            var sopInstanceUid = seq.Items[i].Get<string>(DicomTag.ReferencedSOPInstanceUID);
                            imageBox.Add(DicomTag.SOPInstanceUID, sopInstanceUid);
                            req.Command.Add(DicomTag.RequestedSOPInstanceUID, sopInstanceUid);
                        }
                    }
                };
                dicomClient.AddRequest(filmBoxRequest);



                foreach (var image in filmbox.BasicImageBoxes)
                {
                    var req = new DicomNSetRequest(image.SOPClassUID, image.SOPInstanceUID)
                    {
                        Dataset = image
                    };

                    imageBoxRequests.Add(req);
                    dicomClient.AddRequest(req);
                }
            }

            dicomClient.AddRequest(new DicomNActionRequest(FilmSession.SOPClassUID, FilmSession.SOPInstanceUID, 0x0001));

            dicomClient.Send(RemoteAddress, RemotePort, false, CallingAE, CalledAE);
        }
Ejemplo n.º 10
0
 public Task <DicomNCreateResponse> OnNCreateRequestAsync(DicomNCreateRequest request)
 {
     return(Task.FromResult(new DicomNCreateResponse(request, DicomStatus.Success)));
 }
Ejemplo n.º 11
0
		public DicomNCreateResponse(DicomNCreateRequest request, DicomStatus status) : base(request, status) {
		}
 public Task <DicomNCreateResponse> OnNCreateRequestAsync(DicomNCreateRequest request) => throw new NotImplementedException();
Ejemplo n.º 13
0
        private DicomNCreateResponse CreatePresentationLut(DicomNCreateRequest request)
        {
            if (_filmSession == null)
            {
                Logger.Error("Film Session on association with {0} does not exist", CallingAE);
                SendAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.NotSpecified);
                return new DicomNCreateResponse(request, DicomStatus.NoSuchObjectInstance);
            }

            _filmSession.CreatePresentationLut(request.SOPInstanceUID, request.Dataset);
            var response = new DicomNCreateResponse(request, DicomStatus.Success);
            response.Command.Add(DicomTag.AffectedSOPInstanceUID, _filmSession.SOPInstanceUID);
            return response;
        }
Ejemplo n.º 14
0
 public DicomNCreateResponse(DicomNCreateRequest request, DicomStatus status) : base(request, status)
 {
 }