protected BaseImageLevelUpdateCommand(string name)
     : base("ImageLevelUpdateCommand", true)
 {
     UpdateEntry = new ImageLevelUpdateEntry();
     CommandName = name;
     Description = "Update Dicom Tag";
 }
Пример #2
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));
                    }
                }
            }
        }
Пример #3
0
        protected static DicomAttribute FindAttribute(DicomAttributeCollection collection, ImageLevelUpdateEntry entry)
        {
            if (collection == null)
            {
                return(null);
            }

            if (entry.TagPath.Parents != null)
            {
                foreach (DicomTag tag in entry.TagPath.Parents)
                {
                    DicomAttribute sq = collection[tag] as DicomAttributeSQ;
                    if (sq == null)
                    {
                        throw new Exception(String.Format("Invalid tag value: {0}({1}) is not a SQ VR", tag, tag.Name));
                    }
                    if (sq.IsEmpty)
                    {
                        DicomSequenceItem item = new DicomSequenceItem();
                        sq.AddSequenceItem(item);
                    }

                    DicomSequenceItem[] items = sq.Values as DicomSequenceItem[];
                    Platform.CheckForNullReference(items, "items");
                    collection = items[0];
                }
            }

            return(collection[entry.TagPath.Tag]);
        }
 protected BaseImageLevelUpdateCommand()
     : base("ImageLevelUpdateCommand", true)
 {
     UpdateEntry = new ImageLevelUpdateEntry();
 }
Пример #5
0
        private void Initialize()
        {
            _backupDir = ProcessorContext.BackupDirectory;

            _oldStudyPath        = _oldStudyLocation.GetStudyPath();
            _oldStudyInstanceUid = _oldStudyLocation.StudyInstanceUid;
            _oldStudyFolder      = _oldStudyLocation.StudyFolder;
            _newStudyInstanceUid = _oldStudyInstanceUid;

            _study          = _oldStudyLocation.LoadStudy(ServerExecutionContext.Current.ReadContext);
            _totalSopCount  = _study.NumberOfStudyRelatedInstances;
            _curPatient     = _study.LoadPatient(ServerExecutionContext.Current.ReadContext);
            _oldPatientInfo = new PatientInfo
            {
                PatientsName      = _curPatient.PatientsName,
                PatientId         = _curPatient.PatientId,
                IssuerOfPatientId = _curPatient.IssuerOfPatientId
            };

            _newPatientInfo = new PatientInfo(_oldPatientInfo);
            Debug.Assert(_newPatientInfo.Equals(_oldPatientInfo));

            foreach (BaseImageLevelUpdateCommand command in _commands)
            {
                ImageLevelUpdateEntry imageLevelUpdate = command.UpdateEntry;
                if (imageLevelUpdate == null)
                {
                    continue;
                }

                if (imageLevelUpdate.TagPath.Tag.TagValue == DicomTags.StudyInstanceUid)
                {
                    _newStudyInstanceUid = imageLevelUpdate.GetStringValue();
                }
                else if (imageLevelUpdate.TagPath.Tag.TagValue == DicomTags.PatientId)
                {
                    _newPatientInfo.PatientId = imageLevelUpdate.GetStringValue();
                }
                else if (imageLevelUpdate.TagPath.Tag.TagValue == DicomTags.IssuerOfPatientId)
                {
                    _newPatientInfo.IssuerOfPatientId = imageLevelUpdate.GetStringValue();
                }
                else if (imageLevelUpdate.TagPath.Tag.TagValue == DicomTags.PatientsName)
                {
                    _newPatientInfo.PatientsName = imageLevelUpdate.GetStringValue();
                }
            }

            Platform.CheckForNullReference(_newStudyInstanceUid, "_newStudyInstanceUid");

            NewStudyPath = Path.Combine(_oldStudyLocation.FilesystemPath, _partition.PartitionFolder);
            NewStudyPath = Path.Combine(NewStudyPath, _oldStudyFolder);
            NewStudyPath = Path.Combine(NewStudyPath, _newStudyInstanceUid);

            _newPatient         = FindPatient(_newPatientInfo, ServerExecutionContext.Current.ReadContext);
            _patientInfoChanged = !_newPatientInfo.AreSame(_oldPatientInfo, false);

            Statistics.InstanceCount = _study.NumberOfStudyRelatedInstances;
            Statistics.StudySize     = (ulong)_oldStudyLocation.LoadStudyXml().GetStudySize();

            // The study path will be changed. We will need to delete the original folder at the end.
            // May be too simple to test if two paths are the same. But let's assume it is good enough for 99% of the time.
            _deleteOriginalFolder = NewStudyPath != _oldStudyPath;
            _initialized          = true;
        }