private void InitializeImporter() { if (_importer == null) { SopInstanceImporterContext context = new SopInstanceImporterContext( String.Format("{0}_{1}", _parms.PartitionAE, _startTimeStamp.ToString("yyyyMMddhhmmss")), _parms.PartitionAE, _parms.PartitionAE); _importer = new SopInstanceImporter(context); } }
public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { try { SopInstanceImporterContext context = new SopInstanceImporterContext( String.Format("{0}_{1}", association.CallingAE, association.TimeStamp.ToString("yyyyMMddhhmmss")), association.CallingAE, Partition.AeTitle); DicomProcessingResult result = new DicomProcessingResult(); ISopInstanceImporter importer = IoC.Get <ISopInstanceImporter>(); if (importer != null) { importer.Context = context; result = importer.Import(message); } if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) { Log.Logger.Info("Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.AccessionNumber, result.StudyInstanceUid); } else { Log.Logger.Info("Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.StudyInstanceUid); } } else { Log.Logger.Warn("Failure importing sop: {0}", result.ErrorMessage); } server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return(true); } catch (DicomDataException ex) { Log.Logger.Error(ex, "Error when import {0}", message.AffectedSopInstanceUid); return(false); // caller will abort the association } catch (Exception ex) { Log.Logger.Error(ex, "Error when import {0}", message.AffectedSopInstanceUid); return(false); // caller will abort the association } }
public StorageFilestreamHandler(DicomScpContext context, ServerAssociationParameters assoc) { _context = context; //_remoteDevice = remoteDevice; _importContext = new SopInstanceImporterContext( String.Format("{0}_{1}", assoc.CallingAE, assoc.TimeStamp.ToString("yyyyMMddhhmmss")), assoc.CallingAE, assoc.CalledAE); //if (_remoteDevice != null && _remoteDevice.DeviceTypeEnum.Equals(DeviceTypeEnum.PrimaryPacs)) //{ // _importContext.DuplicateProcessing = DuplicateProcessingEnum.OverwriteSopAndUpdateDatabase; //} }
public ImportSopResponse ImportSop(ImportSopRequest request) { try { var theFile = new DicomFile(string.Format("{0}{1}", request.SopInstanceUid, ServerPlatform.DicomFileExtension)); using (var stream = new LargeMemoryStream(request.SopInstance)) { theFile.Load(stream); } var partition = ServerPartitionMonitor.Instance.GetPartition(request.CalledAETitle); string aeTitle = theFile.SourceApplicationEntityTitle; if (_importerContext == null) { _importerContext = new SopInstanceImporterContext( String.Format("{0}_{1}", aeTitle, DateTime.Now.ToString("yyyyMMddhhmmss")), partition.AeTitle, partition); } var utility = new SopInstanceImporter(_importerContext); var importResult = utility.Import(theFile); if (!importResult.Successful) { Platform.Log(LogLevel.Error, "Failure importing file file from Web Service: {0}, SOP Instance UID: {1}", importResult.ErrorMessage, request.SopInstanceUid); } else { Platform.Log(LogLevel.Info, "Processed import for SOP through Web Service: {0}.", request.SopInstanceUid); } var result = new ImportSopResponse { DicomStatusCode = importResult.DicomStatus.Code, FailureMessage = importResult.ErrorMessage, Successful = importResult.Successful }; return(result); } catch (Exception ex) { var message = string.Format("Failed to import files: {0}, SOP Instance UID: {1}", ex.Message, request.SopInstanceUid); Platform.Log(LogLevel.Error, message); throw new FaultException(message); } }
public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { try { var context = new SopInstanceImporterContext( String.Format("{0}_{1}", association.CallingAE, association.TimeStamp.ToString("yyyyMMddhhmmss")), association.CallingAE, association.CalledAE); if (Device != null && Device.DeviceTypeEnum.Equals(DeviceTypeEnum.PrimaryPacs)) { context.DuplicateProcessing = DuplicateProcessingEnum.OverwriteSopAndUpdateDatabase; } var importer = new SopInstanceImporter(context); DicomProcessingResult result = importer.Import(message); 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); } } else { Platform.Log(LogLevel.Warn, "Failure importing sop: {0}", result.ErrorMessage); } server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return(true); } catch (DicomDataException ex) { Platform.Log(LogLevel.Error, ex); return(false); // caller will abort the association } catch (Exception ex) { Platform.Log(LogLevel.Error, ex); return(false); // caller will abort the association } }
public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { Platform.Log(LogLevel.Info, "Received request,the message is {0}!!!", message.CommandField); //The following part is added for some devices won't contain the SpecificCharacterSet DicomTag. //The may introduce troubles when decoding the characters. //If there's SpecificCharacterSet DicomTag in the image, do nothing //If there's no SpecificCharacterSet DicomTag in the image, the configured DefaultSCS for the device will be added. //If there's no SpecificCharacterSet DicomTag in the image and no configured DefaultSCS, ISO_IR 100 will be used. if (string.IsNullOrEmpty(message.DataSet.SpecificCharacterSet)) { if (string.IsNullOrEmpty(Device.DefaultSCS)) { sDefaultSCS = "ISO_IR 100"; } else { sDefaultSCS = Device.DefaultSCS; } message.DataSet[DicomTags.SpecificCharacterSet].SetStringValue(sDefaultSCS); message.DataSet.SpecificCharacterSet = sDefaultSCS; } try { var context = new SopInstanceImporterContext( String.Format("{0}_{1}", association.CallingAE, association.TimeStamp.ToString("yyyyMMddhhmmss")), association.CallingAE, association.CalledAE); if (Device != null && Device.DeviceTypeEnum.Equals(DeviceTypeEnum.PrimaryPacs)) { context.DuplicateProcessing = DuplicateProcessingEnum.OverwriteSopAndUpdateDatabase; } var importer = new SopInstanceImporter(context); DicomProcessingResult result = importer.Import(message); if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) { ///if the accession number is fresh, write the accession number to RIS DB. This is for Dalian Yiwei if (strAcsNbr != result.AccessionNumber) { strAcsNbr = result.AccessionNumber; /// Platform.Log(LogLevel.Info, "The AccessionNumber of this received SOP Instance is:{0}", result.AccessionNumber); // RIS4PACS.RISInterface ri = new RIS4PACS.RISInterface(); // ri.SetImageArrive(result.AccessionNumber); try { Thread thread = new Thread(new ParameterizedThreadStart(UpdateRIS)); thread.Start((object)strAcsNbr); // RIS4PACS.RISInterface ri = new RIS4PACS.RISInterface(); // ri.SetImageArrive(result.AccessionNumber); } catch { Platform.Log(LogLevel.Info, "RIS4PACS database update failure."); } } 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); } } else { Platform.Log(LogLevel.Warn, "Failure importing sop: {0}", result.ErrorMessage); } server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return(true); } catch (DicomDataException ex) { Platform.Log(LogLevel.Error, ex); return(false); // caller will abort the association } catch (Exception ex) { Platform.Log(LogLevel.Error, ex); return(false); // caller will abort the association } }