public UpdateHistorySeriesMappingCommand(StudyHistory studyHistory, StudyStorageLocation destStudy, UidMapper map) : base("Update Study History Series Mapping") { _map = map; _studyHistory = studyHistory; _destStudy = destStudy; }
/// <summary> /// Constructor /// </summary> public SeriesSopUpdateCommand(StudyStorageLocation originalStudy, StudyStorageLocation targetStudy, UidMapper uidMapper) : base("SeriesSopUpdateCommand") { _originalStudy = originalStudy; _targetStudy = targetStudy; _uidMapper = uidMapper; }
protected void CreateOrLoadUidMappings() { // Load the mapping for the study if (_destinationStudyStorage != null) { var xml = new UidMapXml(); xml.Load(_destinationStudyStorage); UidMapper = new UidMapper(xml); } else { UidMapper = new UidMapper(); } UidMapper.SeriesMapUpdated += UidMapper_SeriesMapUpdated; }
protected void LoadUidMappings() { // Load the mapping for the study if (_destinationStudyStorage != null) { string path = Path.Combine(_destinationStudyStorage.GetStudyPath(), "UidMap.xml"); if (File.Exists(path)) { UidMapXml xml = new UidMapXml(); xml.Load(_destinationStudyStorage); UidMapper = new UidMapper(xml); UidMapper.SeriesMapUpdated += UidMapper_SeriesMapUpdated; } } }
public SaveUidMapXmlCommand(StudyStorageLocation studyLocation, UidMapper mapper) : base("SaveUidMap", true) { _studyLocation = studyLocation; _map = mapper; }
private static SeriesSopUpdateCommand GetUidMappingCommand(StudyStorageLocation sourceStudy, StudyStorageLocation targetStudy, UidMapper uidMapper, string originalSopUid, string originalSeriesUid) { SeriesSopUpdateCommand cmd; string newSeriesUid = uidMapper.FindNewSeriesUid(originalSeriesUid); string newSopUid = uidMapper.FindNewSopUid(originalSopUid); if (string.IsNullOrEmpty(newSeriesUid) == false) { // Series was assigned new uid if (string.IsNullOrEmpty(newSopUid)) { // this is new instance newSopUid = DicomUid.GenerateUid().UID; uidMapper.AddSop(originalSopUid, newSopUid); cmd = new SeriesSopUpdateCommand(sourceStudy, targetStudy, uidMapper); } else { Platform.Log(LogLevel.Info, "Map SOP UID {0} to {1}", originalSopUid, newSopUid); // this is duplicate if (File.Exists(targetStudy.GetSopInstancePath(newSeriesUid, newSopUid))) { throw new InstanceAlreadyExistsException("Instance already exists") { SeriesInstanceUid = newSeriesUid, SopInstanceUid = newSopUid }; } cmd = new SeriesSopUpdateCommand(sourceStudy, targetStudy, uidMapper); } } else { // this is new series newSopUid = DicomUid.GenerateUid().UID; uidMapper.AddSeries(sourceStudy.StudyInstanceUid, targetStudy.StudyInstanceUid, originalSeriesUid, newSopUid); cmd = new SeriesSopUpdateCommand(sourceStudy, targetStudy, uidMapper); Platform.Log(LogLevel.Info, "Map SOP UID {0} to {1}", originalSopUid, newSopUid); } return cmd; }
private static void UpdateUidMap(StudyStorageLocation dest, UidMapper uidMapper) { using (ServerCommandProcessor processor = new ServerCommandProcessor("Update UID Mapping Processor")) { processor.AddCommand(new SaveUidMapXmlCommand(dest, uidMapper)); if (!processor.Execute()) { throw new ApplicationException(String.Format("AUTO-RECONCILE Failed: Unable to update uid mapping. Reason: {0}", processor.FailureReason), processor.FailureException); } } }
private AutoReconcilerResult MergeImage(StudyReconcileAction action, DicomFile file, StudyHistory lastHistory) { string originalSeriesUid = file.DataSet[DicomTags.SeriesInstanceUid].ToString(); string originalSopUid = file.DataSet[DicomTags.SopInstanceUid].ToString(); AutoReconcilerResult preProcessingResult = null; StudyStorageLocation destStudy; UidMapper uidMapper = null; if (lastHistory.DestStudyStorageKey != null) { StudyStorage destinationStudy = StudyStorage.Load(lastHistory.DestStudyStorageKey); //Load the destination. An exception will be thrown if any issues are encountered. FilesystemMonitor.Instance.GetWritableStudyStorageLocation(destinationStudy.ServerPartitionKey, destinationStudy.StudyInstanceUid, StudyRestore.True, StudyCache.True, out destStudy); EnsureStudyCanBeUpdated(destStudy); bool belongsToAnotherStudy = !destStudy.Equals(StorageLocation); ImageUpdateCommandBuilder commandBuilder = new ImageUpdateCommandBuilder(); IList<BaseImageLevelUpdateCommand> commands = commandBuilder.BuildCommands<StudyMatchingMap>(destStudy); if (belongsToAnotherStudy) { Platform.Log(LogLevel.Info, "AUTO-RECONCILE: Move SOP {0} to Study {1}, A#: {2}, Patient {3}", originalSopUid, destStudy.StudyInstanceUid, destStudy.Study.AccessionNumber, destStudy.Study.PatientsName); // Load the Uid Map, either from cache or from disk if (!_uidMapCache.TryGetValue(destStudy.Key, out uidMapper)) { UidMapXml mapXml = new UidMapXml(); mapXml.Load(destStudy); uidMapper = new UidMapper(mapXml); _uidMapCache.Add(destStudy.Key, uidMapper); } try { commands.Add(GetUidMappingCommand(StorageLocation, destStudy, uidMapper, originalSopUid, originalSeriesUid)); } catch (InstanceAlreadyExistsException ex) { Platform.Log(LogLevel.Info, "An instance already exists with the SOP Instance Uid {0}", ex.SopInstanceUid); preProcessingResult = new AutoReconcilerResult(StudyReconcileAction.Discard) { DiscardImage = true }; return preProcessingResult; } } preProcessingResult = new AutoReconcilerResult(action) { Changes = GetUpdateList(file, commands) }; UpdateImage(file, commands); // First, must update the map if (uidMapper != null && uidMapper.Dirty) { UpdateUidMap(destStudy, uidMapper); } if (belongsToAnotherStudy) { SopInstanceImporterContext importContext = new SopInstanceImporterContext(_contextID, file.SourceApplicationEntityTitle, destStudy.ServerPartition); SopInstanceImporter importer = new SopInstanceImporter(importContext); DicomProcessingResult result = importer.Import(file); if (!result.Successful) { throw new ApplicationException(result.ErrorMessage); } } } return preProcessingResult; }