private static IList <BaseImageLevelUpdateCommand> BuildCommandsFromStudyXml(Type type, StudyXml studyXml, IDicomAttributeProvider originalDicomAttributeProvider) { var commandList = new List <BaseImageLevelUpdateCommand>(); EntityDicomMap fieldMap = EntityDicomMapManager.Get(type); //XmlDocument studyXmlDoc = studyXml.GetMemento(new StudyXmlOutputSettings()); // Get the First InstanceXml of the first image IEnumerator <SeriesXml> seriesEnumerator = studyXml.GetEnumerator(); seriesEnumerator.MoveNext(); SeriesXml seriesXml = seriesEnumerator.Current; IEnumerator <InstanceXml> instanceEnumerator = seriesXml.GetEnumerator(); instanceEnumerator.MoveNext(); InstanceXml instanceXml = instanceEnumerator.Current; foreach (DicomTag tag in fieldMap.Keys) { string originalValue = null; string newValue = null; DicomAttribute attribute; if (originalDicomAttributeProvider != null && originalDicomAttributeProvider.TryGetAttribute(tag, out attribute)) { originalValue = attribute.ToString(); } if (instanceXml != null) { attribute = instanceXml[tag]; } else { attribute = null; } if (attribute != null) { newValue = attribute.ToString(); } SetTagCommand cmd = new SetTagCommand(tag.TagValue, originalValue, newValue); commandList.Add(cmd); } return(commandList); }
private static IList <BaseImageLevelUpdateCommand> BuildCommandsFromEntity(ServerEntity entity, IDicomAttributeProvider originalDicomAttributeProvider) { List <BaseImageLevelUpdateCommand> commandList = new List <BaseImageLevelUpdateCommand>(); EntityDicomMap fieldMap = EntityDicomMapManager.Get(entity.GetType()); foreach (DicomTag tag in fieldMap.Keys) { object value = fieldMap[tag].GetValue(entity, null); string originalValue = null; DicomAttribute attribute; if (originalDicomAttributeProvider.TryGetAttribute(tag, out attribute)) { originalValue = attribute.ToString(); } var cmd = new SetTagCommand(tag.TagValue, originalValue, value != null ? value.ToString() : null); commandList.Add(cmd); } return(commandList); }
public IList <BaseImageLevelUpdateCommand> BuildCommands <TTargetType>(IDicomAttributeProvider targetValueProvider, IEnumerable <IDicomAttributeProvider> originalValueProviders) { var commandList = new List <BaseImageLevelUpdateCommand>(); EntityDicomMap fieldMap = EntityDicomMapManager.Get(typeof(TTargetType)); foreach (DicomTag tag in fieldMap.Keys) { DicomAttribute attribute; string originalValue = null; if (originalValueProviders != null) { foreach (IDicomAttributeProvider provider in originalValueProviders) { if (provider.TryGetAttribute(tag, out attribute)) { originalValue = attribute.ToString(); break; } } } if (targetValueProvider.TryGetAttribute(tag, out attribute)) { var cmd = new SetTagCommand(attribute.Tag.TagValue, originalValue, attribute.ToString()); commandList.Add(cmd); } else { // tag doesn't exist, set to empty var cmd = new SetTagCommand(tag.TagValue, originalValue, String.Empty); commandList.Add(cmd); } } return(commandList); }
/// <summary> /// Compiles an XML specification into a <see cref="SetTagCommand"/> object. /// </summary> /// <param name="reader">Reference to a <see cref="XmlReader"/> to read the Xml node.</param> /// <returns>An instance of <see cref="SetTagCommand"/></returns> /// <remarks> /// The <cref="XmlReader"/> must be positioned at an Xml node named "SetTag". /// </remarks> public BaseImageLevelUpdateCommand Compile(XmlReader reader) { SetTagCommand command = XmlUtils.Deserialize <SetTagCommand>(reader); return(command); }
private bool UpdateNameBasedOnTheStudy(DicomFile file) { bool updated = false; string orginalPatientsNameInFile = file.DataSet[DicomTags.PatientsName].ToString(); if (_theStudy==null) { return false; } StudyComparer comparer = new StudyComparer(); ServerPartition partition = ServerPartitionMonitor.Instance.FindPartition(_theStudy.ServerPartitionKey); DifferenceCollection list = comparer.Compare(file, _theStudy, partition.GetComparisonOptions()); if (list.Count == 1) { ComparisionDifference different = list[0]; if (different.DicomTag.TagValue == DicomTags.PatientsName) { if (DicomNameUtils.LookLikeSameNames(orginalPatientsNameInFile, _theStudy.PatientsName)) { using (ServerCommandProcessor processor = new ServerCommandProcessor("Update Patient's Name")) { SetTagCommand command = new SetTagCommand(file, DicomTags.PatientsName, orginalPatientsNameInFile, _theStudy.PatientsName); processor.AddCommand(command); if (!processor.Execute()) { throw new ApplicationException(String.Format("AUTO-CORRECTION Failed: Unable to correct the patient's name in the image. Reason: {0}", processor.FailureReason), processor.FailureException); } updated = true; } } } } return updated; }