protected override InstancePreProcessingResult PreProcessFile(Model.WorkQueueUid uid, DicomFile file) { // Return a result indicating the file has been reconciled. InstancePreProcessingResult result = new InstancePreProcessingResult { AutoReconciled = true }; return(result); }
/// <summary> /// Apply changes to the file prior to processing it. /// </summary> /// <param name="uid"></param> /// <param name="file"></param> protected virtual InstancePreProcessingResult PreProcessFile(WorkQueueUid uid, DicomFile file) { String contextID = uid.GroupID ?? String.Format("{0}_{1}", String.IsNullOrEmpty(file.SourceApplicationEntityTitle) ? ServerPartition.AeTitle : file.SourceApplicationEntityTitle, WorkQueueItem.InsertTime.ToString("yyyyMMddHHmmss")); var result = new InstancePreProcessingResult(); var patientNameRules = new PatientNameRules(Study); UpdateItem updateItem = patientNameRules.Apply(file); result.Modified = updateItem != null; var autoBaseReconciler = new AutoReconciler(contextID, StorageLocation); InstancePreProcessingResult reconcileResult = autoBaseReconciler.Process(file); result.AutoReconciled = reconcileResult != null; result.Modified |= reconcileResult != null; if (reconcileResult != null && reconcileResult.DiscardImage) { result.DiscardImage = true; } // if the studyuid is modified, the file will be deleted by the caller. if (file.DataSet[DicomTags.StudyInstanceUid].ToString().Equals(StorageLocation.StudyInstanceUid)) { if (result.Modified) { file.Save(); } } return(result); }
/// <summary> /// Process a specified <see cref="WorkQueueUid"/> /// </summary> /// <param name="item">The <see cref="WorkQueue"/> item being processed</param> /// <param name="sop">The <see cref="WorkQueueUid"/> being processed</param> /// <param name="studyXml">The <see cref="StudyXml"/> object for the study being processed</param> /// <returns>true if the <see cref="WorkQueueUid"/> is successfully processed. false otherwise</returns> protected virtual bool ProcessWorkQueueUid(Model.WorkQueue item, WorkQueueUid sop, StudyXml studyXml) { Platform.CheckForNullReference(item, "item"); Platform.CheckForNullReference(sop, "sop"); Platform.CheckForNullReference(studyXml, "studyXml"); OnProcessUidBegin(item, sop); string path = null; try { if (sop.Duplicate && sop.Extension != null) { path = ServerPlatform.GetDuplicateUidPath(StorageLocation, sop); var file = new DicomFile(path); file.Load(); InstancePreProcessingResult result = PreProcessFile(sop, file); if (false == file.DataSet[DicomTags.StudyInstanceUid].ToString().Equals(StorageLocation.StudyInstanceUid) || result.DiscardImage) { RemoveWorkQueueUid(sop, null); } else { var duplicateResult = ProcessDuplicate(file, sop, studyXml); if (duplicateResult.ActionTaken == DuplicateProcessResultAction.Delete || duplicateResult.ActionTaken == DuplicateProcessResultAction.Accept) { // make sure the folder is also deleted if it's empty string folder = Path.GetDirectoryName(path); String reconcileRootFolder = ServerPlatform.GetDuplicateFolderRootPath(StorageLocation); DirectoryUtility.DeleteIfEmpty(folder, reconcileRootFolder); } } } else { try { path = StorageLocation.GetSopInstancePath(sop.SeriesInstanceUid, sop.SopInstanceUid); var file = new DicomFile(path); file.Load(); InstancePreProcessingResult result = PreProcessFile(sop, file); if (false == file.DataSet[DicomTags.StudyInstanceUid].ToString().Equals(StorageLocation.StudyInstanceUid) || result.DiscardImage) { RemoveWorkQueueUid(sop, path); } else { ProcessFile(sop, file, studyXml, !result.AutoReconciled); } } catch (DicomException ex) { // bad file. Remove it from the filesystem and the queue RemoveBadDicomFile(path, ex.Message); DeleteWorkQueueUid(sop); return(false); } } return(true); } catch (StudyIsNearlineException) { // handled by caller throw; } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when processing file: {0} SOP Instance: {1}", path, sop.SopInstanceUid); item.FailureDescription = e.InnerException != null? String.Format("{0}:{1}", e.GetType().Name, e.InnerException.Message) : String.Format("{0}:{1}", e.GetType().Name, e.Message); //No longer needed. Update was moved into the SopInstanceProcessor //sop.FailureCount++; //UpdateWorkQueueUid(sop); return(false); } finally { OnProcessUidEnd(item, sop); } }