Ejemplo n.º 1
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="source"></param>
        /// <param name="copyDescendants"></param>
        private PatientNode(PatientNode source, bool copyDescendants)
        {
            _studies   = new StudyNodeCollection(this);
            _patientId = source._patientId;
            _name      = source._name;
            _birthdate = source._birthdate;
            _sex       = source._sex;

            if (copyDescendants)
            {
                foreach (StudyNode study in source._studies)
                {
                    _studies.Add(study.Copy(true));
                }
            }
        }
 /// <summary>
 /// Constructs a collection owned by the specified patient.
 /// </summary>
 /// <param name="patient">The patient node that owns the collection.</param>
 internal StudyNodeCollection(PatientNode patient)
 {
     _patient = patient;
 }
Ejemplo n.º 3
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);
        }