private DicomProcessingResult HandleDuplicate(string sopInstanceUid, StudyStorageLocation studyLocation, ServerCommandProcessor commandProcessor, DicomFile file) { Study study = studyLocation.Study ?? studyLocation.LoadStudy(ServerExecutionContext.Current.PersistenceContext); if (study != null) { Platform.Log(LogLevel.Info, "Received duplicate SOP {0} (A#:{1} StudyUid:{2} Patient: {3} ID:{4})", sopInstanceUid, study.AccessionNumber, study.StudyInstanceUid, study.PatientsName, study.PatientId); } else { Platform.Log(LogLevel.Info, "Received duplicate SOP {0} (StudyUid:{1}). Existing files haven't been processed.", sopInstanceUid, studyLocation.StudyInstanceUid); } SopProcessingContext sopProcessingContext = new SopProcessingContext(commandProcessor, studyLocation, _context.ContextID); DicomProcessingResult result = DuplicateSopProcessorHelper.Process(sopProcessingContext, file); return(result); }
/// <summary> /// Schedules a reconciliation for the specified <see cref="DicomFile"/> /// </summary> /// <param name="context"></param> /// <param name="file"></param> /// <param name="uid"></param> private static void ScheduleReconcile(SopProcessingContext context, DicomFile file, WorkQueueUid uid) { ImageReconciler reconciler = new ImageReconciler(context); reconciler.ScheduleReconcile(file, StudyIntegrityReasonEnum.InconsistentData, uid); }
/// <summary> /// Process a specific DICOM file related to a <see cref="WorkQueue"/> request. /// </summary> /// <remarks> /// <para> /// On success and if <see cref="uid"/> is set, the <see cref="WorkQueueUid"/> field is deleted. /// </para> /// </remarks> /// <param name="stream">The <see cref="StudyXml"/> file to update with information from the file.</param> /// <param name="group">A group the sop is associated with.</param> /// <param name="file">The file to process.</param> /// <param name="compare">Flag to compare the demographics of <see cref="file"/> with the demographics in the database</param> /// <param name="retry">Flag telling if the item should be retried on failure. Note that if the item is a duplicate, the WorkQueueUid item is not failed. </param> /// <param name="uid">An optional WorkQueueUid associated with the entry, that will be deleted upon success or failed on failure.</param> /// <param name="deleteFile">An option file to delete as part of the process</param> /// <exception cref="Exception"/> /// <exception cref="DicomDataException"/> public ProcessingResult ProcessFile(string group, DicomFile file, StudyXml stream, bool compare, bool retry, WorkQueueUid uid, string deleteFile) { Platform.CheckForNullReference(file, "file"); try { CheckDataLength(file); _instanceStats.ProcessTime.Start(); ProcessingResult result = new ProcessingResult { Status = ProcessingStatus.Success }; using (ServerCommandProcessor processor = new ServerCommandProcessor("Process File")) { SopProcessingContext processingContext = new SopProcessingContext(processor, _context.StorageLocation, group); if (EnforceNameRules) { _patientNameRules.Apply(file); } if (compare && ShouldReconcile(_context.StorageLocation, file)) { ScheduleReconcile(processingContext, file, uid); result.Status = ProcessingStatus.Reconciled; } else { InsertInstance(file, stream, uid, deleteFile); result.Status = ProcessingStatus.Success; } } _instanceStats.ProcessTime.End(); if (_context.SopProcessedRulesEngine.Statistics.LoadTime.IsSet) { _instanceStats.SopRulesLoadTime.Add(_context.SopProcessedRulesEngine.Statistics.LoadTime); } if (_context.SopProcessedRulesEngine.Statistics.ExecutionTime.IsSet) { _instanceStats.SopEngineExecutionTime.Add(_context.SopProcessedRulesEngine.Statistics.ExecutionTime); } _context.SopProcessedRulesEngine.Statistics.Reset(); //TODO: Should throw exception if result is failed? return(result); } catch (Exception e) { // If its a duplicate, ignore the exception, and just throw it if (deleteFile != null && (e is InstanceAlreadyExistsException || e.InnerException != null && e.InnerException is InstanceAlreadyExistsException)) { throw; } if (uid != null) { FailUid(uid, retry); } throw; } }
/// <summary> /// Creates an instance of <see cref="ImageReconciler"/> /// </summary> /// <param name="context"></param> public ImageReconciler(SopProcessingContext context) { _context = context; }