public override bool Apply(DicomFile file, OriginalAttributesSequence originalAttributes) { if (_uidMapper == null) return true; // Nothing to do string oldSeriesUid = file.DataSet[DicomTags.SeriesInstanceUid].GetString(0, String.Empty); string oldSopUid = file.DataSet[DicomTags.SopInstanceUid].GetString(0, String.Empty); string newSeriesUid; if (_uidMapper.ContainsSeries(oldSeriesUid)) newSeriesUid = _uidMapper.FindNewSeriesUid(oldSeriesUid); else { newSeriesUid = DicomUid.GenerateUid().UID; _uidMapper.AddSeries(_originalStudy.StudyInstanceUid, _targetStudy.StudyInstanceUid, oldSeriesUid, newSeriesUid); } string newSopInstanceUid; if (_uidMapper.ContainsSop(oldSopUid)) newSopInstanceUid = _uidMapper.FindNewSopUid(oldSopUid); else { newSopInstanceUid = DicomUid.GenerateUid().UID; _uidMapper.AddSop(oldSopUid, newSopInstanceUid); } file.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(newSeriesUid); file.DataSet[DicomTags.SopInstanceUid].SetStringValue(newSopInstanceUid); file.MediaStorageSopInstanceUid = newSopInstanceUid; // add Source Image Sequence AddSourceImageSequence(file, oldSopUid); return true; }
protected override void OnExecute(CommandProcessor theProcessor) { if (_commands!=null) { var sq = new OriginalAttributesSequence { ModifiedAttributesSequence = new DicomSequenceItem(), ModifyingSystem = ProductInformation.Component, ReasonForTheAttributeModification = "CORRECT", AttributeModificationDatetime = Platform.Time, SourceOfPreviousValues = _file.SourceApplicationEntityTitle }; foreach (BaseImageLevelUpdateCommand command in _commands) { if (!command.Apply(_file, sq)) throw new ApplicationException( String.Format("Unable to update the duplicate sop. Command={0}", command)); } var sqAttrib = _file.DataSet[DicomTags.OriginalAttributesSequence] as DicomAttributeSQ; if (sqAttrib != null) sqAttrib.AddSequenceItem(sq.DicomSequenceItem); } }
private void PreprocessDuplicate(DicomFile duplicateDicomFile, ProcessDuplicateAction action) { _patientNameRules.Apply(duplicateDicomFile); if (action==ProcessDuplicateAction.OverwriteUseExisting) { var sq = new OriginalAttributesSequence { ModifiedAttributesSequence = new DicomSequenceItem(), ModifyingSystem = ProductInformation.Component, ReasonForTheAttributeModification = "COERCE", AttributeModificationDatetime = Platform.Time, SourceOfPreviousValues = duplicateDicomFile.SourceApplicationEntityTitle }; foreach (BaseImageLevelUpdateCommand command in _duplicateUpdateCommands) { if (!command.Apply(duplicateDicomFile, sq)) throw new ApplicationException(String.Format("Unable to update the duplicate sop. Command={0}", command)); } var sqAttrib = duplicateDicomFile.DataSet[DicomTags.OriginalAttributesSequence] as DicomAttributeSQ; if (sqAttrib != null) sqAttrib.AddSequenceItem(sq.DicomSequenceItem); } }
public void AssertTagValueChanged(uint tag, string valueToSet, string originalCharacterSet, string expectedNewCharacterSet) { DicomAttributeCollection dataset = new DicomAttributeCollection(); SetupDataSet(dataset, originalCharacterSet); DicomFile file = new DicomFile("test", CreateMetaInfo(), dataset); Assert.AreEqual(originalCharacterSet, file.DataSet[DicomTags.SpecificCharacterSet].ToString()); SetTagCommand cmd = new SetTagCommand(tag, valueToSet); Assert.AreEqual(cmd.CanSaveInUnicode, UnicodeAllowed, "SetTagCommand.CanSaveInUnicode returns an incorrect value"); var sq = new OriginalAttributesSequence { ModifiedAttributesSequence = new DicomSequenceItem(), ModifyingSystem = ProductInformation.Component, ReasonForTheAttributeModification = "CORRECT", AttributeModificationDatetime = Platform.Time, SourceOfPreviousValues = file.SourceApplicationEntityTitle }; Assert.IsTrue(cmd.Apply(file, sq), "SetTagCommand.Apply failed"); var filename = string.Format("Test-{0}.dcm", DicomTagDictionary.GetDicomTag(tag).Name); Assert.IsTrue(file.Save(filename), "Unable to save dicom file"); file = new DicomFile(filename); file.Load(); if (valueToSet == null) Assert.AreEqual(string.Empty, file.DataSet[tag].ToString()); else Assert.AreEqual(valueToSet, file.DataSet[tag].ToString()); Assert.IsTrue(file.DataSet[DicomTags.SpecificCharacterSet].ToString().Equals(expectedNewCharacterSet)); Delete(filename); }
public void AssertExceptionThrown(uint tag, string valueToSet, string originalCharacterSet) { DicomAttributeCollection dataset = new DicomAttributeCollection(); SetupDataSet(dataset, originalCharacterSet); DicomFile file = new DicomFile("test", CreateMetaInfo(), dataset); Assert.AreEqual(originalCharacterSet, file.DataSet[DicomTags.SpecificCharacterSet].ToString()); var sq = new OriginalAttributesSequence { ModifiedAttributesSequence = new DicomSequenceItem(), ModifyingSystem = ProductInformation.Component, ReasonForTheAttributeModification = "CORRECT", AttributeModificationDatetime = Platform.Time, SourceOfPreviousValues = file.SourceApplicationEntityTitle }; SetTagCommand cmd = new SetTagCommand(tag, valueToSet); try { cmd.Apply(file, sq); Assert.Fail("DicomCharacterSetException is expected"); } catch(DicomCharacterSetException) { // good return; } catch(Exception) { Assert.Fail("DicomCharacterSetException is expected"); } }
private void UpdateDicomFile(DicomFile file) { var originalCS = file.DataSet.SpecificCharacterSet; var sq = new OriginalAttributesSequence { ModifiedAttributesSequence = new DicomSequenceItem(), ModifyingSystem = ProductInformation.Component, ReasonForTheAttributeModification = "CORRECT", AttributeModificationDatetime = Platform.Time, SourceOfPreviousValues = file.SourceApplicationEntityTitle }; foreach (BaseImageLevelUpdateCommand command in _commands) { command.File = file; command.Apply(file, sq); } var sqAttrib = file.DataSet[DicomTags.OriginalAttributesSequence] as DicomAttributeSQ; if (sqAttrib != null) sqAttrib.AddSequenceItem(sq.DicomSequenceItem); var newCS = file.DataSet.SpecificCharacterSet; if (!string.Equals(originalCS, newCS)) { if (Platform.IsLogLevelEnabled(ServerPlatform.InstanceLogLevel)) { Platform.Log(ServerPlatform.InstanceLogLevel, "Specific Character Set for SOP {0} has been updated [{1}->{2}]", file.MediaStorageSopInstanceUid, originalCS, newCS); } if (!Common.Settings.Default.AllowedConvertToUnicodeOnEdit) { Platform.Log(LogLevel.Warn, "File was converted to unicode but AllowedConvertToUnicodeOnEdit is false"); } atLeastOneFileUpdatedToUTF8 = IsUTF8(newCS); } SaveFile(file); }
protected override void OnExecute(CommandProcessor theProcessor) { if (File != null) { var sq = new OriginalAttributesSequence { ModifiedAttributesSequence = new DicomSequenceItem(), ModifyingSystem = ProductInformation.Component, ReasonForTheAttributeModification = "CORRECT", AttributeModificationDatetime = Platform.Time, SourceOfPreviousValues = File.SourceApplicationEntityTitle }; Apply(File, sq); var sqAttrib = File.DataSet[DicomTags.OriginalAttributesSequence] as DicomAttributeSQ; if (sqAttrib != null) sqAttrib.AddSequenceItem(sq.DicomSequenceItem); } }
public abstract bool Apply(DicomFile file, OriginalAttributesSequence originalAttributes);
public override bool Apply(DicomFile file, OriginalAttributesSequence originalAttributes) { if (UpdateEntry != null) { DicomAttribute attr = FindAttribute(file.DataSet, UpdateEntry); if (attr != null) { var copiedAttrib = attr.Copy(); originalAttributes.ModifiedAttributesSequence[copiedAttrib.Tag] = copiedAttrib; UpdateEntry.OriginalValue = attr.ToString(); try { var desiredValue = UpdateEntry.GetStringValue(); attr.SetStringValue(desiredValue); if (!string.IsNullOrEmpty(desiredValue)) { //Make sure the data is not garbled when stored into file EnsureCharacterSetIsGood(file, attr, desiredValue); } } catch(DicomCharacterSetException) { throw; //rethrow } catch (DicomDataException) { //TODO: Why do we ignore it? Platform.Log(LogLevel.Warn, "Unexpected exception when updating tag {0} to value {1}, leaving current value: {2}", UpdateEntry.TagPath, UpdateEntry.GetStringValue(), attr.ToString()); UpdateEntry.Value = attr.ToString(); } } } return true; }