コード例 #1
0
        private void OnReceiveMoveImageRequest(Macro.Dicom.Network.DicomServer server, byte presentationID, DicomMessage message, IDicomServiceNode remoteAEInfo)
        {
            string studyInstanceUid  = message.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty);
            string seriesInstanceUid = message.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty);
            var    sopInstanceUids   = (string[])message.DataSet[DicomTags.SopInstanceUid].Values;

            lock (_syncLock)
            {
                using (var context = new DataAccessContext())
                {
                    var s = context.GetStudyStoreQuery().StudyQuery(new StudyRootStudyIdentifier
                    {
                        StudyInstanceUid = studyInstanceUid
                    });
                    var identifier = CollectionUtils.FirstElement(s);

                    var client = new DicomSendBridge();
                    client.SendSops(remoteAEInfo, identifier, seriesInstanceUid, sopInstanceUids, WorkItemPriorityEnum.High);
                    _sendOperations.Add(new SendOperationInfo(client.WorkItem, message.MessageId, presentationID, server)
                    {
                        SubOperations = sopInstanceUids.Length
                    });
                }
            }
        }
コード例 #2
0
        private void OnReceiveMoveStudiesRequest(Macro.Dicom.Network.DicomServer server, byte presentationID, DicomMessage message, IDicomServiceNode remoteAEInfo)
        {
            IEnumerable <string> studyUids = (string[])message.DataSet[DicomTags.StudyInstanceUid].Values;

            foreach (string studyUid in studyUids)
            {
                lock (_syncLock)
                {
                    int subOperations = 0;
                    using (var context = new DataAccessContext())
                    {
                        var s =
                            context.GetStudyStoreQuery().StudyQuery(new StudyRootStudyIdentifier
                        {
                            StudyInstanceUid = studyUid
                        });
                        var identifier = CollectionUtils.FirstElement(s);
                        if (identifier.NumberOfStudyRelatedInstances.HasValue)
                        {
                            subOperations = identifier.NumberOfStudyRelatedInstances.Value;
                        }

                        var client = new DicomSendBridge();
                        client.SendStudy(remoteAEInfo, identifier, WorkItemPriorityEnum.High);
                        _sendOperations.Add(new SendOperationInfo(client.WorkItem, message.MessageId,
                                                                  presentationID,
                                                                  server)
                        {
                            SubOperations = subOperations
                        });
                    }
                }
            }
        }
コード例 #3
0
 public SendOperationInfo(WorkItemData reference, ushort messageId, byte presentationId, Macro.Dicom.Network.DicomServer server)
 {
     PresentationId        = presentationId;
     Server                = server;
     WorkItemData          = reference;
     MessageId             = messageId;
     SubOperations         = 0;
     Complete              = false;
     FailedSopInstanceUids = new List <string>();
 }
コード例 #4
0
        private void OnReceiveMoveSeriesRequest(Macro.Dicom.Network.DicomServer server, byte presentationID, DicomMessage message, IDicomServiceNode remoteAEInfo)
        {
            string studyInstanceUid = message.DataSet[DicomTags.StudyInstanceUid].GetString(0, "");
            var    seriesUids       = (string[])message.DataSet[DicomTags.SeriesInstanceUid].Values;

            lock (_syncLock)
            {
                int subOperations = 0;
                using (var context = new DataAccessContext())
                {
                    var results = context.GetStudyStoreQuery().SeriesQuery(new SeriesIdentifier
                    {
                        StudyInstanceUid =
                            studyInstanceUid,
                    });
                    foreach (SeriesIdentifier series in results)
                    {
                        foreach (string seriesUid in seriesUids)
                        {
                            if (series.SeriesInstanceUid.Equals(seriesUid) &&
                                series.NumberOfSeriesRelatedInstances.HasValue)
                            {
                                subOperations += series.NumberOfSeriesRelatedInstances.Value;
                                break;
                            }
                        }
                    }

                    var s =
                        context.GetStudyStoreQuery().StudyQuery(new StudyRootStudyIdentifier
                    {
                        StudyInstanceUid = studyInstanceUid
                    });
                    var identifier = CollectionUtils.FirstElement(s);
                    var client     = new DicomSendBridge();

                    client.SendSeries(remoteAEInfo, identifier, seriesUids, WorkItemPriorityEnum.High);
                    _sendOperations.Add(new SendOperationInfo(client.WorkItem, message.MessageId, presentationID,
                                                              server)
                    {
                        SubOperations = subOperations
                    });
                }
            }
        }
コード例 #5
0
        public override bool OnReceiveRequest(Macro.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message)
        {
            String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, "").Trim();

            var extendedConfiguration = Common.DicomServer.DicomServer.GetExtendedConfiguration();
            var queryResponsesInUtf8  = extendedConfiguration.QueryResponsesInUtf8;

            if (message.AffectedSopClassUid.Equals(SopClass.StudyRootQueryRetrieveInformationModelFindUid))
            {
                try
                {
                    using (var context = new DataAccessContext())
                    {
                        IEnumerable <DicomAttributeCollection> results = context.GetStudyStoreQuery().Query(message.DataSet);
                        foreach (DicomAttributeCollection result in results)
                        {
                            const string utf8 = "ISO_IR 192";
                            if (queryResponsesInUtf8)
                            {
                                ChangeCharacterSet(result, utf8);
                            }

                            var response = new DicomMessage(null, result);

                            //Add these to each response.
                            message.DataSet[DicomTags.RetrieveAeTitle].SetStringValue(Context.AETitle);
                            message.DataSet[DicomTags.InstanceAvailability].SetStringValue("ONLINE");

                            response.DataSet[DicomTags.QueryRetrieveLevel].SetStringValue(level);
                            server.SendCFindResponse(presentationID, message.MessageId, response,
                                                     DicomStatuses.Pending);
                        }
                    }
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request.");

                    try
                    {
                        var errorResponse = new DicomMessage();
                        server.SendCFindResponse(presentationID, message.MessageId, errorResponse,
                                                 DicomStatuses.QueryRetrieveUnableToProcess);

                        return(true);
                    }
                    finally
                    {
                        AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.SeriousFailure,
                                                     message.AffectedSopClassUid, message.DataSet);
                    }
                }

                try
                {
                    var finalResponse = new DicomMessage();
                    server.SendCFindResponse(presentationID, message.MessageId, finalResponse, DicomStatuses.Success);

                    AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.Success,
                                                 message.AffectedSopClassUid, message.DataSet);
                    return(true);
                }
                catch
                {
                    AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.SeriousFailure,
                                                 message.AffectedSopClassUid, message.DataSet);
                    throw;
                }
            }

            try
            {
                Platform.Log(LogLevel.Error, "Unexpected Study Root Query/Retrieve level: {0}", level);
                server.SendCFindResponse(presentationID, message.MessageId, new DicomMessage(),
                                         DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass);
                return(true);
            }
            finally
            {
                AuditHelper.LogQueryReceived(association.CallingAE, GetRemoteHostName(association), EventResult.SeriousFailure,
                                             message.AffectedSopClassUid, message.DataSet);
            }
        }
コード例 #6
0
 public override bool OnReceiveRequest(Macro.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message)
 {
     server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success);
     return(true);
 }
コード例 #7
0
 public abstract bool OnReceiveRequest(Macro.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message);
コード例 #8
0
        public override bool OnReceiveRequest(Macro.Dicom.Network.DicomServer server,
                                              ServerAssociationParameters association, byte presentationID, DicomMessage message)
        {
            string   studyInstanceUid;
            string   seriesInstanceUid;
            DicomUid sopInstanceUid;

            bool ok = message.DataSet[DicomTags.SopInstanceUid].TryGetUid(0, out sopInstanceUid);

            if (ok)
            {
                ok = message.DataSet[DicomTags.SeriesInstanceUid].TryGetString(0, out seriesInstanceUid);
            }
            if (ok)
            {
                ok = message.DataSet[DicomTags.StudyInstanceUid].TryGetString(0, out studyInstanceUid);
            }

            if (!ok)
            {
                Platform.Log(LogLevel.Error, "Unable to retrieve UIDs from request message, sending failure status.");

                server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID,
                                          DicomStatuses.ProcessingFailure);

                return(true);
            }

            if (_importContext == null)
            {
                _importContext = new DicomReceiveImportContext(association.CallingAE, GetRemoteHostName(association), StudyStore.GetConfiguration(), EventSource.CurrentProcess);

                // Publish new WorkItems as they're added to the context
                lock (_importContext.StudyWorkItemsSyncLock)
                {
                    _importContext.StudyWorkItems.ItemAdded += delegate(object sender, DictionaryEventArgs <string, WorkItem> args)
                    {
                        Platform.GetService(
                            (IWorkItemActivityMonitorService service) =>
                            service.Publish(new WorkItemPublishRequest
                        {
                            Item =
                                WorkItemDataHelper
                                .FromWorkItem(
                                    args.Item)
                        }));


                        var auditedInstances = new AuditedInstances();
                        var request          =
                            args.Item.Request as DicomReceiveRequest;
                        if (request != null)
                        {
                            auditedInstances.AddInstance(request.Patient.PatientId, request.Patient.PatientsName,
                                                         request.Study.StudyInstanceUid);
                        }

                        AuditHelper.LogReceivedInstances(
                            association.CallingAE, GetRemoteHostName(association),
                            auditedInstances, EventSource.CurrentProcess,
                            EventResult.Success, EventReceiptAction.ActionUnknown);
                    }
                    ;

                    _importContext.StudyWorkItems.ItemChanged += (sender, args) => Platform.GetService(
                        (IWorkItemActivityMonitorService service) =>
                        service.Publish(new WorkItemPublishRequest {
                        Item = WorkItemDataHelper.FromWorkItem(args.Item)
                    }));
                }
            }

            var importer = new ImportFilesUtility(_importContext);

            var result = importer.Import(message, BadFileBehaviourEnum.Ignore, FileImportBehaviourEnum.Save);

            if (result.Successful)
            {
                if (!String.IsNullOrEmpty(result.AccessionNumber))
                {
                    Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})",
                                 result.SopInstanceUid, association.CallingAE, association.CalledAE, result.AccessionNumber,
                                 result.StudyInstanceUid);
                }
                else
                {
                    Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})",
                                 result.SopInstanceUid, association.CallingAE, association.CalledAE,
                                 result.StudyInstanceUid);
                }
                server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus);
            }
            else
            {
                if (result.DicomStatus == DicomStatuses.ProcessingFailure)
                {
                    Platform.Log(LogLevel.Error, "Failure importing sop: {0}", result.ErrorMessage);
                }

                //OnReceiveError(message, result.ErrorMessage, association.CallingAE);
                server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid,
                                          result.DicomStatus, result.ErrorMessage);
            }

            return(true);
        }
コード例 #9
0
        public override bool OnReceiveRequest(Macro.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message)
        {
            //// Check for a Cancel message, and cancel the SCU.
            if (message.CommandField == DicomCommandField.CCancelRequest)
            {
                OnReceiveCancelRequest(message);
                return(true);
            }

            // TODO (CR Jun 2012): Log when there's more than 1.

            var remoteAE = ServerDirectory.GetRemoteServersByAETitle(message.MoveDestination).FirstOrDefault();

            if (remoteAE == null)
            {
                server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                         DicomStatuses.QueryRetrieveMoveDestinationUnknown);
                return(true);
            }

            String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty);

            try
            {
                if (level.Equals("STUDY"))
                {
                    OnReceiveMoveStudiesRequest(server, presentationID, message, remoteAE);
                }
                else if (level.Equals("SERIES"))
                {
                    OnReceiveMoveSeriesRequest(server, presentationID, message, remoteAE);
                }
                else if (level.Equals("IMAGE"))
                {
                    OnReceiveMoveImageRequest(server, presentationID, message, remoteAE);
                }
                else
                {
                    Platform.Log(LogLevel.Error, "Unexpected Study Root Move Query/Retrieve level: {0}", level);

                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass);
                    return(true);
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when processing C-MOVE-RQ");
                try
                {
                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveUnableToProcess, e.Message);
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex,
                                 "Unable to send final C-MOVE-RSP message on association from {0} to {1}",
                                 association.CallingAE, association.CalledAE);
                }
            }

            return(true);
        }