/// <summary> /// Load all of the instances in a given <see cref="StudyXml"/> file into the component for sending. /// </summary> /// <param name="location"></param> /// <param name="studyXml">The <see cref="StudyXml"/> file to load from</param> public void LoadStudyFromStudyXml(StudyLocation location, StudyXml studyXml) { foreach (SeriesXml seriesXml in studyXml) { LoadSeriesFromSeriesXml(studyXml, location, seriesXml, studyXml.PatientsName, studyXml.PatientId); } }
public InsertOrUpdateStudyCommand(StudyLocation location, StudyXml xml, UpdateReason reason) : base("Insert or Update Study Command") { _studyInstanceUid = xml.StudyInstanceUid; _studyXml = xml; _reason = reason; _location = location; }
public void Initialize(StudyLocation location) { _location = location; using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var studyBroker = context.GetStudyBroker(); var study = studyBroker.GetStudy(_location.Study.StudyInstanceUid); if (study != null) { _location.Study = study; if (study.NumberOfStudyRelatedInstances.HasValue) NumberOfStudyRelatedInstances = study.NumberOfStudyRelatedInstances.Value; } } }
public InsertStudyXmlCommand(DicomFile file, StudyXml studyXml, StudyLocation storageLocation, bool writeFile) : base("Insert Study Xml", true) { _file = file; _studyXml = studyXml; _studyStorageLocation = storageLocation; _writeFile = writeFile; _settings = new StudyXmlOutputSettings { IncludePrivateValues = StudyXmlTagInclusion.IgnoreTag, IncludeUnknownTags = StudyXmlTagInclusion.IgnoreTag, IncludeLargeTags = StudyXmlTagInclusion.IncludeTagExclusion, MaxTagLength = 2048, IncludeSourceFileName = true }; }
public void Initialize(StudyLocation location, List<string> seriesInstanceUids ) { _location = location; SeriesInstanceUids = seriesInstanceUids; StudyXml = _location.LoadStudyXml(); NumberOfSeriesRelatedInstances = 0; foreach (string seriesInstanceUid in seriesInstanceUids) { foreach (SeriesXml seriesXml in StudyXml) { if (seriesXml.SeriesInstanceUid.Equals(seriesInstanceUid)) { NumberOfSeriesRelatedInstances += seriesXml.NumberOfSeriesRelatedInstances; } } } }
/// <summary> /// Constructor. /// </summary> /// <remarks> /// <para> /// Note that all SOP Instances processed must be from the same study. /// </para> /// </remarks> /// <param name="location">The StudyLocation for the study being processed</param> public ProcessStudyUtility(StudyLocation location) { Platform.CheckForNullReference(location, "location"); StudyLocation = location; }
public SaveStudyXmlCommand(StudyXml studyXml, StudyLocation storageLocation) : base("Save Study Xml", true) { _studyXml = studyXml; _studyStorageLocation = storageLocation; }
/// <summary> /// Load all of the instances in a given <see cref="StudyXml"/> file into the component for sending. /// </summary> /// <param name="location"></param> /// <param name="seriesInstanceUid"></param> /// <param name="studyXml">The <see cref="StudyXml"/> file to load from</param> public void LoadSeriesFromStudyXml(StudyLocation location, StudyXml studyXml, string seriesInstanceUid) { foreach (SeriesXml seriesXml in studyXml) { if (seriesInstanceUid.Equals(seriesXml.SeriesInstanceUid)) { LoadSeriesFromSeriesXml(studyXml, location, seriesXml, studyXml.PatientsName, studyXml.PatientId); break; } } }
/// <summary> /// Load all of the instances in a given <see cref="SeriesXml"/> file into the component for sending. /// </summary> /// <param name="seriesXml"></param> /// <param name="location"></param> /// <param name="patientsName"></param> /// <param name="patientId"></param> /// <param name="studyXml"></param> private void LoadSeriesFromSeriesXml(StudyXml studyXml, StudyLocation location, SeriesXml seriesXml, string patientsName, string patientId) { foreach (InstanceXml instanceXml in seriesXml) { var instance = new StorageInstance(location.GetSopInstancePath(seriesXml.SeriesInstanceUid, instanceXml.SopInstanceUid)); AddStorageInstance(instance); instance.SopClass = instanceXml.SopClass; instance.TransferSyntax = instanceXml.TransferSyntax; instance.SopInstanceUid = instanceXml.SopInstanceUid; instance.PatientId = patientId; instance.PatientsName = patientsName; instance.StudyInstanceUid = studyXml.StudyInstanceUid; } }
private void Process(DicomMessageBase message, FileImportBehaviourEnum fileImportBehaviour, WorkItem workItem, DicomProcessingResult result) { result.Initialize(); // Use the command processor for rollback capabilities. using (var commandProcessor = new ViewerCommandProcessor(String.Format("Processing Sop Instance {0}", result.SopInstanceUid))) { try { var studyLocation = new StudyLocation(result.StudyInstanceUid); String destinationFile = studyLocation.GetSopInstancePath(result.SeriesInstanceUid, result.SopInstanceUid); DicomFile file = ConvertToDicomFile(message, destinationFile, _context.SourceAE); // Create the Study Folder, if need be commandProcessor.AddCommand(new CreateDirectoryCommand(studyLocation.StudyFolder)); bool duplicateFile = false; string dupName = null; if (File.Exists(destinationFile)) { // TODO (CR Jun 2012): Shouldn't the commands themselves make this decision at the time // the file is being saved? Otherwise, what happens if the same SOP were being saved 2x simultaneously. // I know the odds are low, but just pointing it out. duplicateFile = true; dupName = Guid.NewGuid().ToString() + ".dcm"; destinationFile = Path.Combine(Path.GetDirectoryName(destinationFile) ?? string.Empty, dupName); } if (fileImportBehaviour == FileImportBehaviourEnum.Move) { commandProcessor.AddCommand(CommandFactory.CreateRenameFileCommand(file.Filename, destinationFile, true)); } else if (fileImportBehaviour == FileImportBehaviourEnum.Copy) { commandProcessor.AddCommand(CommandFactory.CreateCopyFileCommand(file.Filename, destinationFile, true)); } else if (fileImportBehaviour == FileImportBehaviourEnum.Save) { commandProcessor.AddCommand(CommandFactory.CreateSaveDicomFileCommand(destinationFile, file, true)); } var insertWorkItemCommand = CreateWorkItemCommand(workItem, result, file, duplicateFile, dupName); commandProcessor.AddCommand(insertWorkItemCommand); if (commandProcessor.Execute()) { result.DicomStatus = DicomStatuses.Success; IncrementTotalFiles(insertWorkItemCommand, result.StudyInstanceUid); } else { if (commandProcessor.FailureException is ChangeConflictException || commandProcessor.FailureException is SqlCeLockTimeoutException) result.RetrySuggested = true; // Change conflict or lock timeout may work if we just retry Platform.Log(LogLevel.Warn, "Failure Importing file: {0}", file.Filename); string failureMessage = String.Format( "Failure processing message: {0}. Sending failure status.", commandProcessor.FailureReason); result.SetError(DicomStatuses.ProcessingFailure, failureMessage); // processor already rolled back } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when {0}. Rolling back operation.", commandProcessor.Description); commandProcessor.Rollback(); result.SetError(result.DicomStatus ?? DicomStatuses.ProcessingFailure, e.Message); } } }
private void ProcessStudyFolder(string folder) { try { string studyInstanceUid = Path.GetFileName(folder); var location = new StudyLocation(studyInstanceUid); var reprocessStudyFolder = new ReprocessStudyFolder(location); _threadPool.Enqueue(reprocessStudyFolder, delegate(ReprocessStudyFolder r) { var del = new ThreadPoolStopProxy(r); _threadPool.StartStopStateChangedEvent += del.ProxyDelegate; // TODO (CR Jun 2012): Should check the thread pool state right after // subscribing; otherwise, the folder will process to completion, rather than canceling. r.Process(); lock (_syncLock) EventsHelper.Fire( r.Failed ? _studyFailedEvent : _studyFolderProcessedEvent, this, new StudyEventArgs { StudyInstanceUid = r.Location.Study.StudyInstanceUid, Message = r.FailureMessage }); _threadPool.StartStopStateChangedEvent -= del.ProxyDelegate; }); } catch (Exception x) { // TODO (CR Jun 2012): Shouldn't this cause the work item to fail? Platform.Log(LogLevel.Error, x, "Unexpected exception reindexing folder: {0}", folder); } }
private void ProcessStudiesInDatabase() { foreach (long oid in StudyOidList) { try { using (var context = new DataAccessContext(DataAccessContext.WorkItemMutex)) { var broker = context.GetStudyBroker(); var study = broker.GetStudy(oid); var location = new StudyLocation(study.StudyInstanceUid); if (!Directory.Exists(location.StudyFolder)) { broker.Delete(study); context.Commit(); EventsHelper.Fire(_studyDeletedEvent, this, new StudyEventArgs { StudyInstanceUid = study.StudyInstanceUid }); Platform.Log(LogLevel.Info, "Deleted Study that wasn't on disk, but in the database: {0}", study.StudyInstanceUid); } else EventsHelper.Fire(_studyProcessedEvent, this, new StudyEventArgs { StudyInstanceUid = study.StudyInstanceUid }); } } catch (Exception x) { Platform.Log(LogLevel.Warn, "Unexpected exception attempting to reindex StudyOid {0}: {1}", oid, x.Message); } if (_cancelRequested) return; } }
public ReprocessStudyFolder(StudyLocation location ) { Location = location; StudyStoredInDatabase = CheckIfStudyExists(); }