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();
                }

                SetTagCommand cmd = new SetTagCommand(tag.TagValue, originalValue, value != null ? value.ToString() : null);
                commandList.Add(cmd);
            }
            return(commandList);
        }
Ejemplo n.º 3
0
        private void UpdateEntity(ServerEntity entity)
        {
            EntityDicomMap entityMap = EntityDicomMapManager.Get(entity.GetType());

            foreach (BaseImageLevelUpdateCommand command in _commands)
            {
                ImageLevelUpdateEntry entry = command.UpdateEntry;
                if (!entityMap.ContainsKey(entry.TagPath.Tag))
                {
                    continue;
                }

                string   value = entry.GetStringValue();
                DicomTag tag   = entry.TagPath.Tag;
                if (tag.TagValue == DicomTags.PatientsSex)
                {
                    // Valid Patient's Sex value : "M", "F" or "O"
                    if (!String.IsNullOrEmpty(value) && !value.ToUpper().Equals("M") && !value.ToUpper().Equals("F"))
                    {
                        value = "O";
                    }
                }
                int maxLength = tag.VR.Equals(DicomVr.PNvr) ? 64 : (int)tag.VR.MaximumLength;
                if (value != null && value.Length > maxLength)
                {
                    Platform.Log(LogLevel.Warn, "Truncating value to VR Length: {0}: {1}", tag.VR.Name, value);
                    if (!entityMap.Populate(entity, entry.TagPath.Tag, value.Substring(0, maxLength)))
                    {
                        throw new ApplicationException(String.Format("Unable to update {0}. See log file for details.", entity.Name));
                    }
                }
                else
                {
                    if (!entityMap.Populate(entity, entry.TagPath.Tag, value))
                    {
                        throw new ApplicationException(String.Format("Unable to update {0}. See log file for details.", entity.Name));
                    }
                }
            }
        }
        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);
        }