Exemplo n.º 1
0
        /// <summary>
        /// Convenience method to insert SOP instance-level data nodes into the study builder tree under this study, creating a <see cref="SeriesNode">series</see> node if 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)
        {
            SeriesNode series = new SeriesNode();

            this.Series.Add(series);
            foreach (SopInstanceNode node in sopInstances)
            {
                series.Images.Add(node);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyDescendants"></param>
        private SeriesNode(SeriesNode source, bool copyDescendants)
        {
            _images      = new SopInstanceNodeCollection(this);
            _instanceUid = StudyBuilder.NewUid();
            _description = source._description;
            _dateTime    = source._dateTime;

            if (copyDescendants)
            {
                foreach (SopInstanceNode sop in source._images)
                {
                    _images.Add(sop.Copy());
                }
            }
        }
 /// <summary>
 /// Constructs a collection owned by the specified series.
 /// </summary>
 /// <param name="series"></param>
 internal SopInstanceNodeCollection(SeriesNode series)
 {
     _series = series;
 }
Exemplo n.º 4
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);
        }