Exemple #1
0
        /// <summary>
        /// Convenience method to insert series-level data nodes into the study builder tree under this patient, creating a <see cref="StudyNode">study</see> node if necessary.
        /// </summary>
        /// <param name="series">An array of <see cref="SeriesNode"/>s to insert into the study builder tree.</param>
        public void InsertSeries(SeriesNode[] series)
        {
            StudyNode study = new StudyNode();

            this.Studies.Add(study);
            foreach (SeriesNode node in series)
            {
                study.Series.Add(node);
            }
        }
Exemple #2
0
        /// <summary>
        /// Convenience method to insert SOP instance-level data nodes into the study builder tree under this patient, creating <see cref="StudyNode">study</see> and <see cref="SeriesNode">series</see> nodes as necessary.
        /// </summary>
        /// <param name="sopInstances">An array of <see cref="SopInstanceNode"/>s to insert into the study builder tree.</param>
        public void InsertSopInstance(SopInstanceNode[] sopInstances)
        {
            StudyNode study = new StudyNode();

            this.Studies.Add(study);
            SeriesNode series = new SeriesNode();

            study.Series.Add(series);
            foreach (SopInstanceNode node in sopInstances)
            {
                series.Images.Add(node);
            }
        }
Exemple #3
0
		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="source"></param>
		/// <param name="copyDescendants"></param>
		public StudyNode(StudyNode source, bool copyDescendants) {
			_series = new SeriesNodeCollection(this);
			_instanceUid = StudyBuilder.NewUid();
			_studyId = source._studyId;
			_description = source._description;
			_dateTime = source._dateTime;
			_accessionNum = source._accessionNum;

			if(copyDescendants)
			{
				foreach (SeriesNode series in source._series)
				{
					_series.Add(series.Copy(true));
				}
			}
		}
Exemple #4
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyDescendants"></param>
        public StudyNode(StudyNode source, bool copyDescendants)
        {
            _series       = new SeriesNodeCollection(this);
            _instanceUid  = StudyBuilder.NewUid();
            _studyId      = source._studyId;
            _description  = source._description;
            _dateTime     = source._dateTime;
            _accessionNum = source._accessionNum;

            if (copyDescendants)
            {
                foreach (SeriesNode series in source._series)
                {
                    _series.Add(series.Copy(true));
                }
            }
        }
Exemple #5
0
        private List <SopInstanceNode> DoBuildTree()
        {
            bool doAnonymize = _anonymize;
            Dictionary <string, string> uidMap = new Dictionary <string, string>();
            List <SopInstanceNode>      sops   = new List <SopInstanceNode>();

            // TODO: perform some performance tests to adjust these weights
            float aweight = doAnonymize ? 0.45f : 0;         // portion of the work to anonymize the instances
            float pweight = (1 - aweight) * 0.75f;           // portion of the work to reassign uids
            float mweight = 1 - pweight - aweight;           // portion of the work to remap related uids
            int   count   = _patients.Count;
            int   now     = 0;

            this.Progress = 0;

            // traverse the tree assign new instance uids
            foreach (PatientNode patient in _patients)
            {
                if (patient.Parent != _rootNode)
                {
                    throw new NullReferenceException("Unsynchronized parent-child relationship");
                }

                now++;

                foreach (StudyNode study in patient.Studies)
                {
                    if (study.Parent != patient)
                    {
                        throw new NullReferenceException("Unsynchronized parent-child relationship");
                    }

                    string studyUid = NewUid();
                    uidMap.Add(study.InstanceUid, studyUid);
                    study.InstanceUid = studyUid;

                    foreach (SeriesNode series in study.Series)
                    {
                        if (series.Parent != study)
                        {
                            throw new NullReferenceException("Unsynchronized parent-child relationship");
                        }

                        string seriesUid = NewUid();
                        uidMap.Add(series.InstanceUid, seriesUid);
                        series.InstanceUid = seriesUid;

                        foreach (SopInstanceNode sop in series.Images)
                        {
                            if (sop.Parent != series)
                            {
                                throw new NullReferenceException("Unsynchronized parent-child relationship");
                            }

                            string sopUid = NewUid();
                            uidMap.Add(sop.InstanceUid, sopUid);
                            sop.InstanceUid = sopUid;

                            patient.Update(sop.DicomData);
                            study.Update(sop.DicomData, true);
                            series.Update(sop.DicomData, true);
                            sop.Update(sop.DicomData, true);

                            sops.Add(sop);
                        }
                    }
                }

                this.Progress = mweight * now / count;
            }

            // map any uids that point to an instance that was just reassigned
            count = sops.Count;
            now   = 0;
            foreach (SopInstanceNode sop in sops)
            {
                MapKnownUids(sop.DicomData, uidMap);

                now++;
                this.Progress = mweight * now / count;
            }

            // run the anonymizer if required
            if (doAnonymize)
            {
                DicomAnonymizer anonymizer = new DicomAnonymizer();
                anonymizer.ValidationOptions = ValidationOptions.RelaxAllChecks;

                count = sops.Count;
                now   = 0;

                foreach (SopInstanceNode sop in sops)
                {
                    anonymizer.Anonymize(sop.DicomFile);

                    SeriesNode  series  = sop.Parent;
                    StudyNode   study   = series.Parent;
                    PatientNode patient = study.Parent;

                    // overwrite the anonymized data with any edited properties
                    // anonymizer writes in new anonymized uids based on the new structure, so don't overwrite them!
                    // instead, get the new uids and put them back into the node
                    patient.Update(sop.DicomData);

                    study.Update(sop.DicomData, false);
                    study.InstanceUid = sop.DicomData[DicomTags.StudyInstanceUid].GetString(0, "");

                    series.Update(sop.DicomData, false);
                    series.InstanceUid = sop.DicomData[DicomTags.SeriesInstanceUid].GetString(0, "");

                    sop.Update(sop.DicomData, false);
                    sop.InstanceUid = sop.DicomData[DicomTags.SopInstanceUid].GetString(0, "");

                    now++;
                    this.Progress = mweight * now / count;
                }
            }

            return(sops);
        }
Exemple #6
0
		/// <summary>
		/// Convenience method to insert study-level data nodes into the study builder tree under this patient.
		/// </summary>
		/// <param name="studies">An array of <see cref="StudyNode"/>s to insert into the study builder tree.</param>
		public void InsertStudy(StudyNode[] studies)
		{
			foreach (StudyNode node in studies)
			{
				this.Studies.Add(node);
			}
		}
Exemple #7
0
		/// <summary>
		/// Convenience method to insert series-level data nodes into the study builder tree under this patient, creating a <see cref="StudyNode">study</see> node if necessary.
		/// </summary>
		/// <param name="series">An array of <see cref="SeriesNode"/>s to insert into the study builder tree.</param>
		public void InsertSeries(SeriesNode[] series)
		{
			StudyNode study = new StudyNode();
			this.Studies.Add(study);
			foreach (SeriesNode node in series)
			{
				study.Series.Add(node);
			}
		}
Exemple #8
0
		/// <summary>
		/// Convenience method to insert SOP instance-level data nodes into the study builder tree under this patient, creating <see cref="StudyNode">study</see> and <see cref="SeriesNode">series</see> nodes as necessary.
		/// </summary>
		/// <param name="sopInstances">An array of <see cref="SopInstanceNode"/>s to insert into the study builder tree.</param>
		public void InsertSopInstance(SopInstanceNode[] sopInstances)
		{
			StudyNode study = new StudyNode();
			this.Studies.Add(study);
			SeriesNode series = new SeriesNode();
			study.Series.Add(series);
			foreach (SopInstanceNode node in sopInstances)
			{
				series.Images.Add(node);
			}
		}
 /// <summary>
 /// Constructs a collection owned by the specified study.
 /// </summary>
 /// <param name="study"></param>
 internal SeriesNodeCollection(StudyNode study)
 {
     _study = study;
 }