public StorageFilestreamHandler(IDicomServerContext context, DicomReceiveImportContext importContext)
		{
			_context = context;
			_importContext = importContext;

			if (LocalStorageMonitor.IsMaxUsedSpaceExceeded)
			{
				//The input to this method is a VALID DICOM file, and we know we should have stored it if it weren't for
				//the fact that we're out of disk space. So, we insert the work item UID anyway, knowing that it'll cause
				//the work item to fail. In fact, that's why we're doing it.
				_rejectFile = true;
			}

			if (!File.Exists(_context.StorageConfiguration.FileStoreIncomingFolder))
				Directory.CreateDirectory(_context.StorageConfiguration.FileStoreIncomingFolder);
		}
Exemplo n.º 2
0
		protected void LoadImportContext(ServerAssociationParameters association)
		{
			_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 += (sender, args) =>
				                                           {
					                                           _importContext.PublishWorkItemActivity(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) =>
					_importContext.PublishWorkItemActivity(WorkItemDataHelper.FromWorkItem(args.Item));
			}
		}
Exemplo n.º 3
0
		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;
		}
Exemplo n.º 4
0
		protected void LoadImportContext(ServerAssociationParameters association)
		{
			_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) }));
			}
		}