示例#1
0
 private StudyData GetAnonymizedStudyData(StudyData original)
 {
     if (_anonymizeStudyDataDelegate != null)
     {
         return(_anonymizeStudyDataDelegate(original.Clone()));
     }
     else
     {
         return(StudyDataPrototype.Clone());
     }
 }
示例#2
0
        private StudyData GetAnonymizedStudyData()
        {
            StudyData originalData = new StudyData();

            originalData.LoadFrom(_currentFile);

            _oldStudyDate = originalData.StudyDate;

            if (string.IsNullOrEmpty(originalData.StudyInstanceUid))
            {
                throw new DicomAnonymizerException("The StudyInstanceUid in the source file cannot be empty.");
            }

            StudyData anonymizedData;

            if (_anonymizedStudyDataMap.ContainsKey(originalData.StudyInstanceUid))
            {
                anonymizedData = _anonymizedStudyDataMap[originalData.StudyInstanceUid];
            }
            else
            {
                anonymizedData = GetAnonymizedStudyData(originalData);

                // generate the new study uid if it hasn't already been remapped
                if (_uidMap.ContainsKey(originalData.StudyInstanceUid))
                {
                    anonymizedData.StudyInstanceUid = _uidMap[originalData.StudyInstanceUid];
                }
                else
                {
                    anonymizedData.StudyInstanceUid = _uidMap[originalData.StudyInstanceUid] = DicomUid.GenerateUid().UID;
                }

                if (String.IsNullOrEmpty(anonymizedData.StudyInstanceUid) || anonymizedData.StudyInstanceUid == originalData.StudyInstanceUid)
                {
                    throw new DicomAnonymizerException("An error occurred while generating a new Uid.");
                }

                ReadOnlyCollection <ValidationFailureDescription> failures = _validationStrategy.GetValidationFailures(originalData, anonymizedData);
                if (failures.Count > 0)
                {
                    throw new DicomAnonymizerValidationException("At least one validation failure has occurred.", failures);
                }

                _uidMap[originalData.StudyInstanceUid] = anonymizedData.StudyInstanceUid;

                //store the anonymized data.
                _anonymizedStudyDataMap[originalData.StudyInstanceUid] = anonymizedData;
            }

            _newStudyDate = anonymizedData.StudyDate;

            return(anonymizedData);
        }
示例#3
0
        public virtual void Anonymize(DicomFile dicomFile)
        {
            if (dicomFile == null)
            {
                throw new ArgumentNullException("dicomFile", "The input DicomFile cannot be null.");
            }

            if (dicomFile.DataSet.IsEmpty())
            {
                dicomFile.Load();
            }

            _currentFile = dicomFile;

            try
            {
                StudyData  anonymizedStudyData  = GetAnonymizedStudyData();
                SeriesData anonymizedSeriesData = GetAnonymizedSeriesData();

                //massage attributes.
                Anonymize();

                anonymizedSeriesData.SaveTo(_currentFile);
                anonymizedStudyData.SaveTo(_currentFile);
            }
            catch (DicomAnonymizerException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new DicomAnonymizerException("An unexpected error has occurred.", e);
            }
            finally
            {
                _currentFile         = null;
                _newStudyDate        = null;
                _oldStudyDate        = null;
                _studyDateDifference = null;
            }
        }
示例#4
0
            public ReadOnlyCollection <ValidationFailureDescription> GetValidationFailures(StudyData originalData, StudyData anonymizedData)
            {
                _failures = new List <ValidationFailureDescription>();

                ValidatePatientNamesNotEqual(originalData.PatientsName, anonymizedData.PatientsName);
                ValidateNotEqual(originalData.PatientId, anonymizedData.PatientId, "PatientId");
                ValidateNotEqual(originalData.AccessionNumber, anonymizedData.AccessionNumber, "AccessionNumber");
                ValidateNotEqual(originalData.StudyId, anonymizedData.StudyId, "StudyId");

                if (!IsOptionSet(_options, ValidationOptions.AllowEqualBirthDate))
                {
                    ValidateNotEqual(originalData.PatientsBirthDateRaw, anonymizedData.PatientsBirthDateRaw, "PatientsBirthDate");
                }
                if (!IsOptionSet(_options, ValidationOptions.AllowEmptyPatientId))
                {
                    ValidateNotEmpty(anonymizedData.PatientId, "PatientId");
                }
                if (!IsOptionSet(_options, ValidationOptions.AllowEmptyPatientName))
                {
                    ValidateNotEmpty(anonymizedData.PatientsNameRaw, "PatientsName");
                }

                ReadOnlyCollection <ValidationFailureDescription> failures = _failures.AsReadOnly();

                _failures = null;
                return(failures);
            }