private void OnReceiveMoveImageRequest(ClearCanvas.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 }); } } }
private void OnReceiveMoveStudiesRequest(ClearCanvas.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 }); } } } }
public void OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, ClearCanvas.Dicom.DicomMessage message) { foreach (byte pcid in association.GetPresentationContextIDs()) { DicomPresContext context = association.GetPresentationContext(pcid); if (context.Result == DicomPresContextResult.Accept) { if (context.AbstractSyntax == SopClass.StudyRootQueryRetrieveInformationModelFind) { DicomMessage response = new DicomMessage(); response.DataSet[DicomTags.StudyInstanceUid].SetStringValue("1.2.3"); response.DataSet[DicomTags.PatientId].SetStringValue("1"); response.DataSet[DicomTags.PatientsName].SetStringValue("test"); response.DataSet[DicomTags.StudyId].SetStringValue("1"); response.DataSet[DicomTags.StudyDescription].SetStringValue("dummy"); server.SendCFindResponse(presentationID, message.MessageId, response, DicomStatuses.Pending); DicomMessage finalResponse = new DicomMessage(); server.SendCFindResponse(presentationID, message.MessageId, finalResponse, DicomStatuses.Success); } else if (context.AbstractSyntax == SopClass.VerificationSopClass) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); } } } }
public void OnReceiveAssociateRequest(DicomServer server, ServerAssociationParameters association) { if (_delayAssociationAccept.Checked) Thread.Sleep(TimeSpan.FromSeconds(35)); if (_rejectAssociation.Checked) server.SendAssociateReject(DicomRejectResult.Permanent, DicomRejectSource.ServiceUser, DicomRejectReason.CallingAENotRecognized); else server.SendAssociateAccept(association); }
public SendOperationInfo(WorkItemData reference, ushort messageId, byte presentationId, ClearCanvas.Dicom.Network.DicomServer server) { PresentationId = presentationId; Server = server; WorkItemData = reference; MessageId = messageId; SubOperations = 0; Complete = false; FailedSopInstanceUids = new List <string>(); }
private void OnReceiveMoveSeriesRequest(ClearCanvas.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 }); } } }
public void OnNetworkError(DicomServer server, ServerAssociationParameters association, Exception e) { Assert.Fail("Unexpected network error: " + e.Message); }
/// <summary> /// Method for processing Series level queries. /// </summary> /// <param name="server"></param> /// <param name="presentationId"></param> /// <param name="message"></param> /// <returns></returns> private void OnReceiveSeriesLevelQuery(DicomServer server, byte presentationId, DicomMessage message) { //Read context for the query. using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { var tagList = new List<DicomTag>(); var selectSeries = read.GetBroker<ISeriesEntityBroker>(); var criteria = new SeriesSelectCriteria(); criteria.ServerPartitionKey.EqualTo(Partition.GetKey()); DicomAttributeCollection data = message.DataSet; foreach (DicomAttribute attrib in message.DataSet) { tagList.Add(attrib.Tag); if (!attrib.IsNull) switch (attrib.Tag.TagValue) { case DicomTags.StudyInstanceUid: List<ServerEntityKey> list = LoadStudyKey(read, (string[]) data[DicomTags.StudyInstanceUid].Values); if (list.Count == 0) { server.SendCFindResponse(presentationId, message.MessageId, new DicomMessage(), DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); return; } QueryHelper.SetKeyCondition(criteria.StudyKey, list.ToArray()); break; case DicomTags.SeriesInstanceUid: QueryHelper.SetStringArrayCondition(criteria.SeriesInstanceUid, (string[]) data[DicomTags.SeriesInstanceUid].Values); break; case DicomTags.Modality: QueryHelper.SetStringCondition(criteria.Modality, data[DicomTags.Modality].GetString(0, string.Empty)); break; case DicomTags.SeriesNumber: QueryHelper.SetStringCondition(criteria.SeriesNumber, data[DicomTags.SeriesNumber].GetString(0, string.Empty)); break; case DicomTags.SeriesDescription: QueryHelper.SetStringCondition(criteria.SeriesDescription, data[DicomTags.SeriesDescription].GetString(0, string.Empty)); break; case DicomTags.PerformedProcedureStepStartDate: QueryHelper.SetRangeCondition(criteria.PerformedProcedureStepStartDate, data[DicomTags.PerformedProcedureStepStartDate].GetString(0, string.Empty)); break; case DicomTags.PerformedProcedureStepStartTime: QueryHelper.SetRangeCondition(criteria.PerformedProcedureStepStartTime, data[DicomTags.PerformedProcedureStepStartTime].GetString(0, string.Empty)); break; case DicomTags.RequestAttributesSequence: // todo break; default: foreach (var q in _queryExtensions) q.OnReceiveSeriesLevelQuery(message, attrib.Tag, criteria); break; } } int resultCount = 0; try { // Open a second read context, in case other queries are required. using (IReadContext subRead = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { selectSeries.Find(criteria, delegate(Series row) { if (CancelReceived) throw new DicomException("DICOM C-Cancel Received"); resultCount++; if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulateSeries(subRead, message, response, tagList, row); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses) SendBufferedResponses(server, presentationId, message); }); SendBufferedResponses(server, presentationId, message); } } catch (Exception e) { if (CancelReceived) { var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Cancel); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); } else if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: {0} on query from {1}",resultCount,server.AssociationParams.CallingAE); var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); } else { Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request."); var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.ProcessingFailure); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message); } return; } var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); return; } }
/// <summary> /// Method for processing Patient level queries. /// </summary> /// <param name="server"></param> /// <param name="presentationId"></param> /// <param name="message">The Patient level query message.</param> /// <returns></returns> private void OnReceivePatientQuery(DicomServer server, byte presentationId, DicomMessage message) { var tagList = new List<DicomTag>(); using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { var find = read.GetBroker<IPatientEntityBroker>(); var criteria = new PatientSelectCriteria(); criteria.ServerPartitionKey.EqualTo(Partition.GetKey()); DicomAttributeCollection data = message.DataSet; var studySelect = new StudySelectCriteria(); bool studySubSelect = false; foreach (DicomAttribute attrib in message.DataSet) { tagList.Add(attrib.Tag); if (!attrib.IsNull) switch (attrib.Tag.TagValue) { case DicomTags.PatientsName: QueryHelper.SetStringCondition(criteria.PatientsName, data[DicomTags.PatientsName].GetString(0, string.Empty)); break; case DicomTags.PatientId: QueryHelper.SetStringCondition(criteria.PatientId, data[DicomTags.PatientId].GetString(0, string.Empty)); break; case DicomTags.IssuerOfPatientId: QueryHelper.SetStringCondition(criteria.IssuerOfPatientId, data[DicomTags.IssuerOfPatientId].GetString(0, string.Empty)); break; case DicomTags.PatientsSex: // Specify a subselect on Patients Sex in Study QueryHelper.SetStringArrayCondition(studySelect.PatientsSex, (string[])data[DicomTags.PatientsSex].Values); if (!studySubSelect) { criteria.StudyRelatedEntityCondition.Exists(studySelect); studySubSelect = true; } break; case DicomTags.PatientsBirthDate: // Specify a subselect on Patients Birth Date in Study QueryHelper.SetStringArrayCondition(studySelect.PatientsBirthDate, (string[])data[DicomTags.PatientsBirthDate].Values); if (!studySubSelect) { criteria.StudyRelatedEntityCondition.Exists(studySelect); studySubSelect = true; } break; default: foreach (var q in _queryExtensions) { bool extensionSubSelect; q.OnReceivePatientLevelQuery(message, attrib.Tag, criteria, studySelect, out extensionSubSelect); if (extensionSubSelect && !studySubSelect) { criteria.StudyRelatedEntityCondition.Exists(studySelect); studySubSelect = true; } } break; } } int resultCount = 0; try { find.Find(criteria, delegate(Patient row) { if (CancelReceived) throw new DicomException("DICOM C-Cancel Received"); resultCount++; if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulatePatient(response, tagList, row); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses) SendBufferedResponses(server, presentationId, message); }); SendBufferedResponses(server, presentationId, message); } catch (Exception e) { if (CancelReceived) { var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Cancel); } else if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: {0} on query from {1}", resultCount, server.AssociationParams.CallingAE); var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); } else { Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request."); var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.QueryRetrieveUnableToProcess); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message); } return; } } var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); return; }
/// <summary> /// Extension method called when a new DICOM Request message has been called that the /// extension will process. /// </summary> /// <param name="server"></param> /// <param name="association"></param> /// <param name="presentationId"></param> /// <param name="message"></param> /// <returns></returns> public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty); if (message.CommandField == DicomCommandField.CCancelRequest) { Platform.Log(LogLevel.Info,"Received C-FIND-CANCEL-RQ message."); CancelReceived = true; return true; } CancelReceived = false; if (message.AffectedSopClassUid.Equals(SopClass.StudyRootQueryRetrieveInformationModelFindUid)) { if (level.Equals("STUDY")) { // We use the ThreadPool to process the thread requests. This is so that we return back // to the main message loop, and continue to look for cancel request messages coming // in. There's a small chance this may cause delays in responding to query requests if // the .NET Thread pool fills up. ThreadPool.QueueUserWorkItem(delegate { try { OnReceiveStudyLevelQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceiveStudyLevelQuery."); } }); return true; } if (level.Equals("SERIES")) { ThreadPool.QueueUserWorkItem(delegate { try { OnReceiveSeriesLevelQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceiveSeriesLevelQuery."); } }); return true; } if (level.Equals("IMAGE")) { ThreadPool.QueueUserWorkItem(delegate { try { OnReceiveImageLevelQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceiveImageLevelQuery."); } }); return true; } Platform.Log(LogLevel.Error, "Unexpected Study Root Query/Retrieve level: {0}", level); server.SendCFindResponse(presentationId, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); return true; } if (message.AffectedSopClassUid.Equals(SopClass.PatientRootQueryRetrieveInformationModelFindUid)) { if (level.Equals("PATIENT")) { ThreadPool.QueueUserWorkItem(delegate { try { OnReceivePatientQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceivePatientQuery."); } }); return true; } if (level.Equals("STUDY")) { ThreadPool.QueueUserWorkItem(delegate { try { OnReceiveStudyLevelQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceiveStudyLevelQuery."); } }); return true; } if (level.Equals("SERIES")) { ThreadPool.QueueUserWorkItem(delegate { try { OnReceiveSeriesLevelQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceiveSeriesLevelQuery."); } }); return true; } if (level.Equals("IMAGE")) { ThreadPool.QueueUserWorkItem(delegate { try { OnReceiveImageLevelQuery(server, presentationId, message); } catch (Exception x) { Platform.Log(LogLevel.Error, x, "Unexpected exception in OnReceiveImageLevelQuery."); } }); return true; } Platform.Log(LogLevel.Error, "Unexpected Patient Root Query/Retrieve level: {0}", level); server.SendCFindResponse(presentationId, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); return true; } // Not supported message type, send a failure status. server.SendCFindResponse(presentationId, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); return true; }
public IDicomFilestreamHandler OnStartFilestream(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { throw new NotImplementedException(); }
public override bool OnReceiveRequest(ClearCanvas.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); } }
public void OnReceiveAbort(DicomServer server, ServerAssociationParameters association, DicomAbortSource source, DicomAbortReason reason) { throw new Exception("The method or operation is not implemented."); }
public override bool OnReceiveRequest(ClearCanvas.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) { LoadImportContext(association); } 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); }
public override bool OnReceiveRequest(ClearCanvas.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); }
public void OnReceiveAssociateRequest(DicomServer server, ServerAssociationParameters association) { server.SendAssociateAccept(association); }
public void OnReceiveResponseMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { server.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified); Assert.Fail("Unexpected OnReceiveResponseMessage"); }
public override bool OnReceiveRequest(ClearCanvas.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return(true); }
public bool CompleteStream(DicomServer server, ServerAssociationParameters assoc, byte presentationId, DicomMessage message) { DicomProcessingResult result; try { if (_fileStream != null) { _fileStream.Flush(true); _fileStream.Close(); _fileStream.Dispose(); _fileStream = null; } var importer = new SopInstanceImporter(_importContext); result = importer.ImportFile(message, _sourceFilename); 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, assoc.CallingAE, assoc.CalledAE, result.AccessionNumber, result.StudyInstanceUid); else Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.StudyInstanceUid); } } catch (Exception e) { result = new DicomProcessingResult { DicomStatus = DicomStatuses.ProcessingFailure, ErrorMessage = e.Message }; } if (!result.Successful) { Platform.Log(LogLevel.Warn, "Failure importing sop: {0}", result.ErrorMessage); } CleanupDirectory(); server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return true; }
private bool CheckForUnSupportedOptionalMatchingKey(DicomServer server, byte presentationID, DicomMessage message, bool logFirstUnsupportedAttributeOnly) { DicomAttribute attrib; bool UnsupportedOptionalMatchingDetected = false; string comments = ""; do { // ModalityWorklistIod modalityWorklistIod = new ModalityWorklistIod(message.DataSet); attrib = message.DataSet[DicomTags.ScheduledProcedureStepSequence]; DicomAttributeSQ sequence = attrib as DicomAttributeSQ; DicomSequenceItem sequenceSubItems = sequence[0]; //sequence supposed non empty as // it have to be checked by the function // CheckForMissingRequiredMatchingKey() first. if (!sequenceSubItems[DicomTags.ScheduledProcedureStepDescription].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+= "Scheduled Procedure Step Description\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.ScheduledStationName].IsNull) { UnsupportedOptionalMatchingDetected = true; comments += "Scheduled Station Name\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.ScheduledProcedureStepLocation].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="Scheduled Procedure Step Location\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.ScheduledProtocolCodeSequence].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="Scheduled Protocol Code Sequence\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.PreMedication].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="PreMedication\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.RequestedContrastAgent].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="Requested Contrast Agent\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.RequestedContrastAgent].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="Requested Contrast Agent\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.ScheduledProcedureStepStatus].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="Scheduled Procedure Step Status\n"; if (logFirstUnsupportedAttributeOnly) break; } if (!sequenceSubItems[DicomTags.CommentsOnTheScheduledProcedureStep].IsNull) { UnsupportedOptionalMatchingDetected = true; comments+="Comments On The Scheduled Procedure Step\n"; if (logFirstUnsupportedAttributeOnly) break; } //TODO: verify the rest of the Optional Matching keys against your database existing fields in order // to send appropriate status. } while (false); // send specific error status to the calling AE if (UnsupportedOptionalMatchingDetected) { Platform.Log(LogLevel.Warn, "One or more Optional matching Sent by {0} key are note supported." , server.AssociationParams.CallingAE); Platform.Log(LogLevel.Warn, "Unsupported Optional Matching Key Attributes Details : {0}," + comments); } return UnsupportedOptionalMatchingDetected; }
public void OnReceiveDimseCommand(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomAttributeCollection command) { }
private bool CheckForMissingRequiredMatchingKey(DicomServer server, byte presentationID, DicomMessage message) { DicomAttribute attrib; bool requiredMatchingKeyMissing = false; string comment=""; // will receive a description of the first encountred missing r key. // we don't need to collect all missing keys to speed up processing. do { attrib = message.DataSet[DicomTags.ScheduledProcedureStepSequence]; if (attrib.IsNull) { requiredMatchingKeyMissing = true; comment = "Missing Scheduled Procedure Step Sequence"; break; } DicomAttributeSQ sequence = attrib as DicomAttributeSQ; if (attrib.Count == 0) { requiredMatchingKeyMissing = true; comment = "Scheduled Procedure Step Sequence is empty"; break; } if (attrib.Count > 1) { requiredMatchingKeyMissing = true; comment = "Found Multiple Items in Scheduled Procedure Step Sequence"; break; } DicomSequenceItem sequenceSubItems = sequence[0]; if (sequenceSubItems[DicomTags.ScheduledStationAeTitle].IsNull) { requiredMatchingKeyMissing = true; comment = "Missing Scheduled Station Ae Title"; break; } if (sequenceSubItems[DicomTags.Modality].IsNull) { requiredMatchingKeyMissing = true; comment = "Missing Modality"; break; } if (sequenceSubItems[DicomTags.ScheduledPerformingPhysiciansName].IsNull) { requiredMatchingKeyMissing = true; comment = "Missing Scheduled Performing Physicians Name"; break; } if (sequenceSubItems[DicomTags.ScheduledProcedureStepStartDate].IsNull) { requiredMatchingKeyMissing = true; comment = "Missing ScheduledProcedureStepStartDate"; break; } if (sequenceSubItems[DicomTags.ScheduledProcedureStepStartTime].IsNull) { requiredMatchingKeyMissing = true; comment = "Missing Scheduled Procedure Step Start Time"; break; } } while (false); // send specific error status to the calling AE if (requiredMatchingKeyMissing) { Platform.Log(LogLevel.Error, "Required matching key missing on query from {0},"+ "\n Sending Failure Status Identifier Does Not Match SOPClass.", server.AssociationParams.CallingAE); Platform.Log(LogLevel.Error, "Error Details : {0},"+ comment); DicomMessage errorResponse = new DicomMessage(); server.SendCFindResponse(presentationID, message.MessageId, errorResponse, DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); } return requiredMatchingKeyMissing; }
/// <summary> /// Method for processing Image level queries. /// </summary> /// <param name="server"></param> /// <param name="presentationId"></param> /// <param name="message"></param> /// <returns></returns> private void OnReceiveImageLevelQuery(DicomServer server, byte presentationId, DicomMessage message) { var tagList = new List<DicomTag>(); var matchingTagList = new List<uint>(); DicomAttributeCollection data = message.DataSet; string studyInstanceUid = data[DicomTags.StudyInstanceUid].GetString(0, String.Empty); string seriesInstanceUid = data[DicomTags.SeriesInstanceUid].GetString(0, String.Empty); StudyStorageLocation location; try { FilesystemMonitor.Instance.GetReadableStudyStorageLocation(Partition.Key, studyInstanceUid, StudyRestore.True, StudyCache.True, out location); } catch (Exception e) { Platform.Log(LogLevel.Error, "Unable to load storage location for study {0}: {1}", studyInstanceUid, e.Message); var failureResponse = new DicomMessage(); failureResponse.DataSet[DicomTags.InstanceAvailability].SetStringValue("NEARLINE"); failureResponse.DataSet[DicomTags.QueryRetrieveLevel].SetStringValue("IMAGE"); failureResponse.DataSet[DicomTags.RetrieveAeTitle].SetStringValue(Partition.AeTitle); failureResponse.DataSet[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid); failureResponse.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid); server.SendCFindResponse(presentationId, message.MessageId, failureResponse, DicomStatuses.QueryRetrieveUnableToProcess); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message); return; } try { // Will always return a value, although it may be an empty StudyXml file StudyXml studyXml = LoadStudyXml(location); SeriesXml seriesXml = studyXml[seriesInstanceUid]; if (seriesXml == null) { var failureResponse = new DicomMessage(); failureResponse.DataSet[DicomTags.QueryRetrieveLevel].SetStringValue("IMAGE"); server.SendCFindResponse(presentationId, message.MessageId, failureResponse, DicomStatuses.QueryRetrieveUnableToProcess); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message); return; } foreach (DicomAttribute attrib in message.DataSet) { if (attrib.Tag.TagValue.Equals(DicomTags.SpecificCharacterSet) || attrib.Tag.TagValue.Equals(DicomTags.QueryRetrieveLevel)) continue; tagList.Add(attrib.Tag); if (!attrib.IsNull) matchingTagList.Add(attrib.Tag.TagValue); } int resultCount = 0; foreach (InstanceXml theInstanceStream in seriesXml) { if (CompareInstanceMatch(message, matchingTagList, theInstanceStream)) { if (CancelReceived) { var failureResponse = new DicomMessage(); failureResponse.DataSet[DicomTags.QueryRetrieveLevel].SetStringValue("IMAGE"); server.SendCFindResponse(presentationId, message.MessageId, failureResponse, DicomStatuses.Cancel); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); return; } resultCount++; if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: " + resultCount); break; } var response = new DicomMessage(); PopulateInstance(message, response, tagList, theInstanceStream); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses) SendBufferedResponses(server, presentationId, message); } } SendBufferedResponses(server, presentationId, message); var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexepected exception processing IMAGE level query for study {0}: {1}", studyInstanceUid, e.Message); var failureResponse = new DicomMessage(); failureResponse.DataSet[DicomTags.InstanceAvailability].SetStringValue("ONLINE"); failureResponse.DataSet[DicomTags.QueryRetrieveLevel].SetStringValue("IMAGE"); failureResponse.DataSet[DicomTags.RetrieveAeTitle].SetStringValue(Partition.AeTitle); failureResponse.DataSet[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid); failureResponse.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid); server.SendCFindResponse(presentationId, message.MessageId, failureResponse, DicomStatuses.QueryRetrieveUnableToProcess); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message); } return; }
void IDicomServerHandler.OnReceiveAssociateRequest(DicomServer server, ServerAssociationParameters association) { //_sessionDebug.SetAssociationDumpString(association); server.SendAssociateAccept(association); Platform.Log(LogLevel.Info,string.Format("Accepting association between {0} and {1}.", association.CallingAE, association.CalledAE)); }
private void SendBufferedResponses(DicomServer server, byte presentationId, DicomMessage requestMessage) { while (_responseQueue.Count > 0) { DicomMessage response = _responseQueue.Dequeue(); server.SendCFindResponse(presentationId, requestMessage.MessageId, response, DicomStatuses.Pending); if (CancelReceived) throw new DicomException("DICOM C-Cancel Received"); if (!server.NetworkActive) throw new DicomException("Association is no longer valid."); } }
void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { //_sessionDebug.SetAssociationDumpString(association); //_sessionDebug._request = message.Dump(); #region Cancel request if (message.CommandField == DicomCommandField.CCancelRequest) { Platform.Log(LogLevel.Info,string.Format("Received CANCEL-RQ message from {0}.", association.CallingAE)); _cancelReceived = true; return; } #endregion #region CEcho request if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); Platform.Log(LogLevel.Info,string.Format("Received ECHO-RQ message from {0}.", association.CallingAE)); return; } #endregion #region MWL C-FIND request if (message.CommandField == DicomCommandField.CFindRequest) { Platform.Log(LogLevel.Info,string.Format("Message Dumped :\n" + message.Dump("", DicomDumpOptions.KeepGroupLengthElements))); String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty); _cancelReceived = false; if (message.AffectedSopClassUid.Equals(SopClass.ModalityWorklistInformationModelFindUid)) OnReceiveMWLQuery(server, presentationID, message); else // Not supported message type, send a failure status. server.SendCFindResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); return; } #endregion //ignore all unsupported request server.SendAssociateAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.UnexpectedPDU); Platform.Log(LogLevel.Info,string.Format("Unexpected Command. Send Associate Abort message from server to {0}.", association.CallingAE)); return; }
/// <summary> /// Method for processing Study level queries. /// </summary> /// <param name="server"></param> /// <param name="presentationId"></param> /// <param name="message"></param> /// <returns></returns> private void OnReceiveStudyLevelQuery(DicomServer server, byte presentationId, DicomMessage message) { var tagList = new List<DicomTag>(); using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { var find = read.GetBroker<IStudyEntityBroker>(); var criteria = new StudySelectCriteria(); criteria.ServerPartitionKey.EqualTo(Partition.GetKey()); DicomAttributeCollection data = message.DataSet; foreach (DicomAttribute attrib in message.DataSet) { tagList.Add(attrib.Tag); if (!attrib.IsNull) switch (attrib.Tag.TagValue) { case DicomTags.StudyInstanceUid: QueryHelper.SetStringArrayCondition(criteria.StudyInstanceUid, (string[]) data[DicomTags.StudyInstanceUid].Values); break; case DicomTags.PatientsName: QueryHelper.SetStringCondition(criteria.PatientsName, data[DicomTags.PatientsName].GetString(0, string.Empty)); break; case DicomTags.PatientId: QueryHelper.SetStringCondition(criteria.PatientId, data[DicomTags.PatientId].GetString(0, string.Empty)); break; case DicomTags.PatientsBirthDate: QueryHelper.SetRangeCondition(criteria.PatientsBirthDate, data[DicomTags.PatientsBirthDate].GetString(0, string.Empty)); break; case DicomTags.PatientsSex: QueryHelper.SetStringCondition(criteria.PatientsSex, data[DicomTags.PatientsSex].GetString(0, string.Empty)); break; case DicomTags.StudyDate: QueryHelper.SetRangeCondition(criteria.StudyDate, data[DicomTags.StudyDate].GetString(0, string.Empty)); break; case DicomTags.StudyTime: QueryHelper.SetRangeCondition(criteria.StudyTime, data[DicomTags.StudyTime].GetString(0, string.Empty)); break; case DicomTags.AccessionNumber: QueryHelper.SetStringCondition(criteria.AccessionNumber, data[DicomTags.AccessionNumber].GetString(0, string.Empty)); break; case DicomTags.StudyId: QueryHelper.SetStringCondition(criteria.StudyId, data[DicomTags.StudyId].GetString(0, string.Empty)); break; case DicomTags.StudyDescription: QueryHelper.SetStringCondition(criteria.StudyDescription, data[DicomTags.StudyDescription].GetString(0, string.Empty)); break; case DicomTags.ReferringPhysiciansName: QueryHelper.SetStringCondition(criteria.ReferringPhysiciansName, data[DicomTags.ReferringPhysiciansName].GetString(0, string.Empty)); break; case DicomTags.ModalitiesInStudy: // Specify a subselect on Modality in series var seriesSelect = new SeriesSelectCriteria(); QueryHelper.SetStringArrayCondition(seriesSelect.Modality, (string[]) data[DicomTags.ModalitiesInStudy].Values); criteria.SeriesRelatedEntityCondition.Exists(seriesSelect); break; default: foreach (var q in _queryExtensions) q.OnReceiveStudyLevelQuery(message, attrib.Tag, criteria); break; } } int resultCount = 0; try { // Open another read context, in case additional queries are required. using (IReadContext subRead = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { // First find the Online studies var storageCriteria = new StudyStorageSelectCriteria(); storageCriteria.StudyStatusEnum.NotEqualTo(StudyStatusEnum.Nearline); storageCriteria.QueueStudyStateEnum.NotIn(new[] {QueueStudyStateEnum.DeleteScheduled, QueueStudyStateEnum.WebDeleteScheduled, QueueStudyStateEnum.EditScheduled}); criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria); find.Find(criteria, delegate(Study row) { if (CancelReceived) throw new DicomException("DICOM C-Cancel Received"); resultCount++; if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulateStudy(subRead, response, tagList, row, "ONLINE"); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses) SendBufferedResponses(server, presentationId, message); }); // Now find the Nearline studies storageCriteria = new StudyStorageSelectCriteria(); storageCriteria.StudyStatusEnum.EqualTo(StudyStatusEnum.Nearline); storageCriteria.QueueStudyStateEnum.NotIn(new[] { QueueStudyStateEnum.DeleteScheduled, QueueStudyStateEnum.WebDeleteScheduled, QueueStudyStateEnum.EditScheduled }); criteria.StudyStorageRelatedEntityCondition.Exists(storageCriteria); find.Find(criteria, delegate(Study row) { if (CancelReceived) throw new DicomException("DICOM C-Cancel Received"); resultCount++; if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { SendBufferedResponses(server, presentationId, message); throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount); } var response = new DicomMessage(); PopulateStudy(subRead, response, tagList, row, "NEARLINE"); _responseQueue.Enqueue(response); if (_responseQueue.Count >= DicomSettings.Default.BufferedQueryResponses) SendBufferedResponses(server, presentationId, message); }); SendBufferedResponses(server, presentationId, message); } } catch (Exception e) { if (CancelReceived) { var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Cancel); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); } else if (DicomSettings.Default.MaxQueryResponses != -1 && DicomSettings.Default.MaxQueryResponses < resultCount) { Platform.Log(LogLevel.Warn, "Maximum Configured Query Responses Exceeded: {0} on query from {1}", resultCount, server.AssociationParams.CallingAE); var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); } else { Platform.Log(LogLevel.Error, e, "Unexpected exception when processing FIND request."); var errorResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, errorResponse, DicomStatuses.ProcessingFailure); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.SeriousFailureActionTerminated, message); } return; } } var finalResponse = new DicomMessage(); server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success); AuditLog(server.AssociationParams, EventIdentificationContentsEventOutcomeIndicator.Success, message); return; }
void IDicomServerHandler.OnReceiveResponseMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { Platform.Log(LogLevel.Info,string.Format("Unexpectedly received response mess on server.")); server.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.UnrecognizedPDU); //_sessionDebug.DumpSession(); }
public void OnClientClosed(DicomServer server, ServerAssociationParameters association) { }
void IDicomServerHandler.OnReceiveReleaseRequest(DicomServer server, ServerAssociationParameters association) { Platform.Log(LogLevel.Info,string.Format("Received association release request from {0}.", association.CallingAE)); //_sessionDebug.DumpSession(); }
public void OnDimseTimeout(DicomServer client, ServerAssociationParameters association) { }
void IDicomServerHandler.OnReceiveAbort(DicomServer server, ServerAssociationParameters association, DicomAbortSource source, DicomAbortReason reason) { _cancelReceived = true; Platform.Log(LogLevel.Info,string.Format("Unexpected association abort received.")); //_sessionDebug.DumpSession(); }
public void OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { if (_type == TestTypes.SendMR) { DicomAttributeCollection testSet = new DicomAttributeCollection(); _test.SetupMR(testSet); bool same = testSet.Equals(message.DataSet); string studyId = message.DataSet[DicomTags.StudyId].GetString(0, ""); Assert.AreEqual(studyId, "1933"); DicomUid sopInstanceUid; bool ok = message.DataSet[DicomTags.SopInstanceUid].TryGetUid(0, out sopInstanceUid); if (!ok) { server.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified); return; } server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); } else if (_type == TestTypes.Receive) { DicomUid sopInstanceUid; bool ok = message.DataSet[DicomTags.SopInstanceUid].TryGetUid(0, out sopInstanceUid); if (!ok) { server.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.InvalidPDUParameter); return; } server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); } else { Platform.Log(LogLevel.Error,"Unexpected test type mode"); server.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.InvalidPDUParameter); return; } }
void IDicomServerHandler.OnNetworkError(DicomServer server, ServerAssociationParameters association, Exception e) { Platform.Log(LogLevel.Error,e,string.Format("Unexpected network error over association from {0}.", association.CallingAE)); //_sessionDebug.DumpSession(); }
public void OnReceiveReleaseRequest(DicomServer server, ServerAssociationParameters association) { }
void IDicomServerHandler.OnDimseTimeout(DicomServer server, ServerAssociationParameters association) { Platform.Log(LogLevel.Info,string.Format("Received DIMSE Timeout, continuing listening for messages")); //_sessionDebug.DumpSession(); }
public IDicomServerHandler ServerHandlerCreator(DicomServer server, ServerAssociationParameters assoc) { var handler = new ServerHandler(this, _serverType); _serverHandlerList.Add(handler); return handler; }
public override bool OnReceiveRequest(ClearCanvas.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); }
public IDicomServerHandler ServerHandlerCreator(DicomServer server, ServerAssociationParameters assoc) { return new ServerHandler(this, _serverType); }
public abstract bool OnReceiveRequest(ClearCanvas.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message);