コード例 #1
0
ファイル: VoiWindow.cs プロジェクト: ronmark1/ClearCanvas-1
        /// <summary>
        /// Sets the VOI window attributes in the data source with the specified windows.
        /// </summary>
        /// <param name="windows">The list of <see cref="VoiWindow"/>s to be set.</param>
        /// <param name="dataset">A DICOM data source.</param>
        public static void SetWindows(IEnumerable <VoiWindow> windows, IDicomAttributeProvider dataset)
        {
            var voiWindows         = windows.ToList();
            var windowCenters      = DicomStringHelper.GetDicomStringArray(voiWindows.Select(s => s.Center));
            var windowWidths       = DicomStringHelper.GetDicomStringArray(voiWindows.Select(s => s.Width));
            var windowExplanations = voiWindows.Any(s => !string.IsNullOrEmpty(s.Explanation)) ? DicomStringHelper.GetDicomStringArray(voiWindows.Select(s => s.Explanation)) : null;

            if (voiWindows.Count > 0)
            {
                dataset[DicomTags.WindowCenter].SetStringValue(windowCenters);
                dataset[DicomTags.WindowWidth].SetStringValue(windowWidths);
                if (!string.IsNullOrEmpty(windowExplanations))
                {
                    dataset[DicomTags.WindowCenterWidthExplanation].SetStringValue(windowExplanations);
                }
                else
                {
                    dataset[DicomTags.WindowCenterWidthExplanation].SetEmptyValue();
                }
            }
            else
            {
                dataset[DicomTags.WindowCenter].SetEmptyValue();
                dataset[DicomTags.WindowWidth].SetEmptyValue();
                dataset[DicomTags.WindowCenterWidthExplanation].SetEmptyValue();
            }
        }
コード例 #2
0
ファイル: Sop.cs プロジェクト: zhan2016/MacroMedicalSystem
 internal IStudyRootStudyIdentifier GetStudyIdentifier()
 {
     return(new StudyRootStudyIdentifier(this, this, null)
     {
         SpecificCharacterSet = DicomStringHelper.GetDicomStringArray(SpecificCharacterSet),
         RetrieveAE = DataSource.Server,
         InstanceAvailability = "ONLINE"
     });
 }
コード例 #3
0
        /// <summary>
        /// Sets the VOI window attributes in the data source with the specified windows.
        /// </summary>
        /// <param name="windows">The list of <see cref="VoiWindow"/>s to be set.</param>
        /// <param name="dataset">A DICOM data source.</param>
        public static void SetWindows(IEnumerable <VoiWindow> windows, IDicomAttributeProvider dataset)
        {
            var windowCenters      = DicomStringHelper.GetDicomStringArray(windows.Select(s => s.Center));
            var windowWidths       = DicomStringHelper.GetDicomStringArray(windows.Select(s => s.Width));
            var windowExplanations = DicomStringHelper.GetDicomStringArray(windows.Select(s => s.Explanation));

            dataset[DicomTags.WindowCenter].SetStringValue(windowCenters);
            dataset[DicomTags.WindowWidth].SetStringValue(windowWidths);
            dataset[DicomTags.WindowCenterWidthExplanation].SetStringValue(windowExplanations);
        }
コード例 #4
0
 public IList <StudyEntry> QueryByStudyInstanceUid(IEnumerable <string> studyInstanceUids)
 {
     return(Real.GetStudyEntries(
                new GetStudyEntriesRequest
     {
         Criteria = new StudyEntry
         {
             Study = new StudyRootStudyIdentifier
             {
                 StudyInstanceUid = DicomStringHelper.GetDicomStringArray(studyInstanceUids)
             }
         }
     }).StudyEntries);
 }
コード例 #5
0
        /// <summary>
        /// Performs a STUDY query for the given Study Instance Uids.
        /// </summary>
        public IList <StudyRootStudyIdentifier> QueryByStudyInstanceUid(IEnumerable <string> studyInstanceUids)
        {
            foreach (string studyInstanceUid in studyInstanceUids)
            {
                Platform.CheckForEmptyString(studyInstanceUid, "studyInstanceUid");

                if (studyInstanceUid.Contains("*") || studyInstanceUid.Contains("?"))
                {
                    throw new ArgumentException("Study Instance Uid cannot contain wildcard characters.");
                }
            }

            StudyRootStudyIdentifier criteria = new StudyRootStudyIdentifier();

            criteria.StudyInstanceUid = DicomStringHelper.GetDicomStringArray(studyInstanceUids);
            return(StudyQuery(criteria));
        }
コード例 #6
0
        public IList <StudyRootStudyIdentifier> LocateStudyByInstanceUid(IEnumerable <string> studyInstanceUids, out LocateFailureInfo[] failures)
        {
            var instanceUids = studyInstanceUids.ToArray();

            foreach (string studyInstanceUid in instanceUids)
            {
                Platform.CheckForEmptyString(studyInstanceUid, "studyInstanceUid");

                if (studyInstanceUid.Contains("*") || studyInstanceUid.Contains("?"))
                {
                    throw new ArgumentException("Study Instance Uid cannot contain wildcard characters.");
                }
            }

            var criteria = new StudyRootStudyIdentifier {
                StudyInstanceUid = DicomStringHelper.GetDicomStringArray(instanceUids)
            };
            var result = LocateStudies(new LocateStudiesRequest {
                Criteria = criteria
            });

            failures = result.Failures.ToArray();
            return(result.Studies);
        }
コード例 #7
0
 private static string FormatMultiValues(IEnumerable <IDicomAttributeProvider> frames, Func <IDicomAttributeProvider, uint, string, string> formatter, uint dicomTag, string formatString)
 {
     return(DicomStringHelper.GetDicomStringArray(frames.Select(f => formatter(f, dicomTag, formatString))));
 }
コード例 #8
0
        public MRImageAnnotationItemProvider()
            : base("AnnotationItemProviders.Dicom.MRImage", new AnnotationResourceResolver(typeof(MRImageAnnotationItemProvider).Assembly))
        {
            _annotationItems = new List <IAnnotationItem>();

            AnnotationResourceResolver resolver = new AnnotationResourceResolver(this);

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.EchoTime",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                bool tagExists = frame[DicomTags.EffectiveEchoTime].TryGetFloat64(0, out value) || frame[DicomTags.EchoTime].TryGetFloat64(0, out value);
                if (tagExists)
                {
                    return(String.Format(SR.FormatMilliseconds, value.ToString("F2")));
                }

                return("");
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.MagneticFieldStrength",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                bool tagExists = frame[DicomTags.MagneticFieldStrength].TryGetFloat64(0, out value);
                if (tagExists)
                {
                    return(String.Format(SR.FormatTeslas, value.ToString("F1")));
                }

                return("");
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.AcquisitionMatrix",
                    resolver,
                    delegate(Frame frame)
            {
                // the acquisition matrix of an MR image refers to the dimensions of the raw data as acquired by the modality
                // which is encoded in frequency domain, so the two axes are phase and frequency
                // it seems that we simply want the width x height of the raw data here
                // which is basically figuring out whether phase is rows or cols, and formatting the numbers appropriately
                string phaseDirection = frame[DicomTags.InPlanePhaseEncodingDirection].ToString().ToUpperInvariant();

                var acqAttrib = frame[DicomTags.AcquisitionMatrix];
                if (!acqAttrib.IsEmpty && acqAttrib.Count >= 4)
                {
                    // the order of the values in this attribute is: freq-rows \ freq-cols \ phase-rows \ phase-cols
                    // the acquisition matrix tag is used by MR Image module, which uses the code string COL and ROW
                    switch (phaseDirection)
                    {
                    case "COL":
                        const int phaseColumns  = 3;
                        const int frequencyRows = 0;
                        return(String.Format(SR.Format2Dimensions, acqAttrib.GetUInt16(phaseColumns, 0), acqAttrib.GetUInt16(frequencyRows, 0)));

                    case "ROW":
                    default:
                        const int frequencyColumns = 1;
                        const int phaseRows        = 2;
                        return(String.Format(SR.Format2Dimensions, acqAttrib.GetUInt16(frequencyColumns, 0), acqAttrib.GetUInt16(phaseRows, 0)));
                    }
                }
                else
                {
                    int phaseSteps, frequencySteps;
                    if (frame[DicomTags.MrAcquisitionFrequencyEncodingSteps].TryGetInt32(0, out frequencySteps) &&
                        frame[DicomTags.MrAcquisitionPhaseEncodingStepsInPlane].TryGetInt32(0, out phaseSteps))
                    {
                        // in the MR FOV/Geometry functional group, the code strings are COLUMN, ROW and OTHER
                        switch (phaseDirection)
                        {
                        case "COLUMN":
                            return(string.Format(SR.Format2Dimensions, phaseSteps, frequencySteps));

                        case "ROW":
                            return(string.Format(SR.Format2Dimensions, frequencySteps, phaseSteps));
                        }
                    }
                }

                return(string.Empty);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.ReceiveCoilName",
                    resolver,
                    delegate(Frame frame)
            {
                string value;
                value = frame[DicomTags.ReceiveCoilName].GetString(0, null);
                return(value);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.RepetitionTime",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                bool tagExists = frame[DicomTags.RepetitionTime].TryGetFloat64(0, out value);
                if (tagExists)
                {
                    return(String.Format(SR.FormatMilliseconds, value.ToString("F2")));
                }

                return("");
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.EchoTrainLength",
                    resolver,
                    delegate(Frame frame)
            {
                int value;
                bool tagExists = frame[DicomTags.EchoTrainLength].TryGetInt32(0, out value);
                if (tagExists)
                {
                    return(String.Format("{0}", value));
                }

                return("");
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.InversionTime",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                var tagExists = frame[DicomTags.InversionTime].TryGetFloat64(0, out value);
                if (tagExists)
                {
                    return(string.Format(SR.FormatMilliseconds, value.ToString("F2")));
                }

                DicomAttribute dicomAttribute;
                if (((IDicomAttributeProvider)frame).TryGetAttribute(DicomTags.InversionTimes, out dicomAttribute) && !dicomAttribute.IsEmpty && !dicomAttribute.IsNull)
                {
                    var values = dicomAttribute.Values as double[];
                    if (values != null)
                    {
                        return(string.Format(SR.FormatMilliseconds, DicomStringHelper.GetDicomStringArray(values, "F2")));
                    }
                }
                return(string.Empty);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.TriggerTime",
                    resolver,
                    delegate(Frame frame)
            {
                // TODO CR (30 Sep 2013): Update to support enhanced MR - this tag is actually for cardiac MR, and now appears in the cardiac synchronization functional group
                double value;
                var tagExists = frame[DicomTags.TriggerTime].TryGetFloat64(0, out value);
                return(tagExists ? string.Format(SR.FormatMilliseconds, value.ToString("F2")) : string.Empty);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.NumberOfAverages",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                var tagExists = frame[DicomTags.NumberOfAverages].TryGetFloat64(0, out value);
                return(tagExists ? string.Format("{0}", value) : string.Empty);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.PixelBandwidth",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                var tagExists = frame[DicomTags.PixelBandwidth].TryGetFloat64(0, out value);
                return(tagExists ? string.Format(SR.FormatHertzPerPixel, value.ToString("F2")) : string.Empty);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.MRImage.FlipAngle",
                    resolver,
                    delegate(Frame frame)
            {
                double value;
                var tagExists = frame[DicomTags.FlipAngle].TryGetFloat64(0, out value);
                return(tagExists ? string.Format(SR.FormatDegrees, value.ToString("F2")) : string.Empty);
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );
        }
コード例 #9
0
        /// <summary>
        /// Figure out which studies have been deleted and/or updated.
        /// </summary>
        private void ProcessChangedStudiesAsync(out DateTime?queryStartTime, out List <string> deletedStudyUids, out List <StudyEntry> updatedStudies)
        {
            deletedStudyUids = new List <string>();
            updatedStudies   = new List <StudyEntry>();
            queryStartTime   = null;
            DateTime now = DateTime.Now;

            var fiveSeconds         = TimeSpan.FromSeconds(5);
            var rapidChangeInterval = TimeSpan.FromMilliseconds(300);

            lock (_syncLock)
            {
                if (_queryingForUpdates)
                {
                    return; //Already querying.
                }
                //Nothing to query for? Return.
                if (_setChangedStudies.Count == 0 || !_lastStudyChangeTime.HasValue)
                {
                    return;
                }

                bool studiesChanging = now - _lastStudyChangeTime.Value < rapidChangeInterval;
                if (studiesChanging)
                {
                    //Many DIFFERENT studies are changing in very rapid succession. Delay until it settles down, which usually isn't long.
                    Platform.Log(LogLevel.Debug, "Studies are still actively changing - delaying update.");
                    return;
                }

                if (!_hastenUpdateQuery)
                {
                    bool updatedRecently = _lastUpdateQueryEndTime.HasValue && now - _lastUpdateQueryEndTime < fiveSeconds;
                    if (updatedRecently)
                    {
                        //We just finished an update query less than 5 seconds ago.
                        Platform.Log(LogLevel.Debug, "Studies were updated within the last 5 seconds - delaying update.");
                        return;
                    }
                }

                //Reset this before the immediate query.
                _hastenUpdateQuery = false;

                //Add everything to the deleted list.
                deletedStudyUids.AddRange(_setChangedStudies.Keys);
                _setChangedStudies.Clear();

                //We are officially querying for updates.
                _queryingForUpdates = true;
            }

            queryStartTime = now;
            string studyUids = DicomStringHelper.GetDicomStringArray(deletedStudyUids);

            try
            {
                var clock = new CodeClock();
                clock.Start();

                var criteria = new StudyRootStudyIdentifier {
                    StudyInstanceUid = studyUids
                };
                var request = new GetStudyEntriesRequest {
                    Criteria = new StudyEntry {
                        Study = criteria
                    }
                };

                IList <StudyEntry> entries = null;

                //We're doing it this way here because it's local only.
                Platform.GetService <IStudyStoreQuery>(s => entries = s.GetStudyEntries(request).StudyEntries);

                foreach (var entry in entries)
                {
                    //If we got a result back, then it's not deleted.
                    deletedStudyUids.Remove(entry.Study.StudyInstanceUid);
                    updatedStudies.Add(entry);
                }

                clock.Stop();
                Platform.Log(LogLevel.Debug, "Study update query took {0}.", clock);
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
            }
            finally
            {
                lock (_syncLock)
                {
                    //Finished querying for updates.
                    _queryingForUpdates     = false;
                    _lastUpdateQueryEndTime = now;
                }
            }
        }
コード例 #10
0
            private DicomAttributeCollection GetResult(T candidate)
            {
                DicomAttributeCollection result = new DicomAttributeCollection();

                string specificCharacterSet = _getSpecificCharacterSetDelegate(candidate);

                if (!String.IsNullOrEmpty(specificCharacterSet))
                {
                    result.SpecificCharacterSet = specificCharacterSet;
                    result[DicomTags.SpecificCharacterSet].SetStringValue(specificCharacterSet);
                }
                result.ValidateVrLengths = false;
                result.ValidateVrValues  = false;

                foreach (QueryablePropertyInfo property in QueryableProperties <T> .GetProperties())
                {
                    string criteria = _queryCriteria[property.Path];

                    bool includeResult = property.IsUnique || property.IsHigherLevelUnique || criteria != null;
                    if (!includeResult)
                    {
                        continue;
                    }

                    object   propertyValue = property.ReturnProperty.GetValue(candidate, null);
                    string[] testValues    = Convert.ToStringArray(propertyValue, property.ReturnPropertyConverter);

                    if (criteria == null)
                    {
                        criteria = "";
                    }

                    bool isModalitiesInStudy = property.Path.Equals(DicomTags.ModalitiesInStudy);
                    bool containsWildcards   = ContainsWildcardCharacters(criteria);

                    //special case, we post-filter modalities in study when it contains wildcards b/c the hql query won't
                    //always produce exactly the right results.  This will never happen anyway.
                    bool query = !String.IsNullOrEmpty(criteria) && ((!property.IsHigherLevelUnique && property.PostFilterOnly) ||
                                                                     (isModalitiesInStudy && containsWildcards));

                    if (query)
                    {
                        string[] criteriaValues;
                        if (property.AllowListMatching)
                        {
                            criteriaValues = DicomStringHelper.GetStringArray(criteria);
                        }
                        else
                        {
                            criteriaValues = new string[] { criteria }
                        };

                        //When something doesn't match, the candidate is not a match, and the result is filtered out.
                        if (!AnyMatch(property, criteriaValues, testValues))
                        {
                            return(null);
                        }
                    }

                    string resultValue = DicomStringHelper.GetDicomStringArray(testValues);
                    AddValueToResult(property.Path, resultValue, result);
                }

                return(result);
            }
コード例 #11
0
        public void Update(StudyXml studyXml)
        {
            Platform.CheckForNullReference(studyXml, "studyXml");

            var dataSet = studyXml.First().First().Collection;

            DicomAttribute attribute       = dataSet[DicomTags.StudyInstanceUid];
            string         datasetStudyUid = attribute.ToString();

            if (!String.IsNullOrEmpty(StudyInstanceUid) && StudyInstanceUid != datasetStudyUid)
            {
                string message = String.Format("The study uid in the data set does not match this study's uid ({0} != {1}).",
                                               datasetStudyUid, StudyInstanceUid);

                throw new InvalidOperationException(message);
            }

            StudyInstanceUid = attribute.ToString();

            Platform.CheckForEmptyString(StudyInstanceUid, "StudyInstanceUid");

            _studyXml = studyXml;

            attribute = dataSet[DicomTags.PatientId];
            PatientId = attribute.ToString();

            attribute    = dataSet[DicomTags.PatientsName];
            PatientsName = new PersonName(attribute.ToString());

            attribute = dataSet[DicomTags.ReferringPhysiciansName];
            ReferringPhysiciansName = new PersonName(attribute.ToString());

            attribute   = dataSet[DicomTags.PatientsSex];
            PatientsSex = attribute.ToString();

            attribute            = dataSet[DicomTags.PatientsBirthDate];
            PatientsBirthDateRaw = attribute.ToString();
            PatientsBirthDate    = DateParser.Parse(PatientsBirthDateRaw);

            attribute            = dataSet[DicomTags.PatientsBirthTime];
            PatientsBirthTimeRaw = attribute.ToString();
            var time = TimeParser.Parse(PatientsBirthTimeRaw);

            if (time.HasValue)
            {
                PatientsBirthTimeTicks = time.Value.TimeOfDay.Ticks;
            }
            else
            {
                PatientsBirthTimeTicks = null;
            }

            attribute = dataSet[DicomTags.StudyId];
            StudyId   = attribute.ToString();

            attribute       = dataSet[DicomTags.AccessionNumber];
            AccessionNumber = attribute.ToString();

            attribute        = dataSet[DicomTags.StudyDescription];
            StudyDescription = attribute.ToString();

            attribute    = dataSet[DicomTags.StudyDate];
            StudyDateRaw = attribute.ToString();
            StudyDate    = DateParser.Parse(StudyDateRaw);

            attribute    = dataSet[DicomTags.StudyTime];
            StudyTimeRaw = attribute.ToString();
            time         = TimeParser.Parse(StudyTimeRaw);
            if (time.HasValue)
            {
                StudyTimeTicks = time.Value.TimeOfDay.Ticks;
            }
            else
            {
                StudyTimeTicks = null;
            }

            if (dataSet.Contains(DicomTags.ProcedureCodeSequence))
            {
                attribute = dataSet[DicomTags.ProcedureCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    ProcedureCodeSequenceCodeValue = sequence[DicomTags.CodeValue].ToString();
                    ProcedureCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                }
            }

            attribute = dataSet[DicomTags.PatientSpeciesDescription];
            PatientSpeciesDescription = attribute.ToString();

            if (dataSet.Contains(DicomTags.PatientSpeciesCodeSequence))
            {
                attribute = dataSet[DicomTags.PatientSpeciesCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    PatientSpeciesCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                    PatientSpeciesCodeSequenceCodeValue   = sequence[DicomTags.CodeValue].ToString();
                    PatientSpeciesCodeSequenceCodeMeaning = sequence[DicomTags.CodeMeaning].ToString();
                }
            }

            attribute = dataSet[DicomTags.PatientBreedDescription];
            PatientBreedDescription = attribute.ToString();

            if (dataSet.Contains(DicomTags.PatientBreedCodeSequence))
            {
                attribute = dataSet[DicomTags.PatientBreedCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    PatientBreedCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                    PatientBreedCodeSequenceCodeValue   = sequence[DicomTags.CodeValue].ToString();
                    PatientBreedCodeSequenceCodeMeaning = sequence[DicomTags.CodeMeaning].ToString();
                }
            }

            attribute         = dataSet[DicomTags.ResponsiblePerson];
            ResponsiblePerson = new PersonName(attribute.ToString());

            attribute             = dataSet[DicomTags.ResponsiblePersonRole];
            ResponsiblePersonRole = attribute.ToString();

            attribute = dataSet[DicomTags.ResponsibleOrganization];
            ResponsibleOrganization = attribute.ToString();

            attribute            = dataSet[DicomTags.SpecificCharacterSet];
            SpecificCharacterSet = attribute.ToString();

            var modalities = _studyXml
                             .Select(s => s.First()[DicomTags.Modality].GetString(0, null))
                             .Where(value => !String.IsNullOrEmpty(value)).Distinct();

            ModalitiesInStudy = DicomStringHelper.GetDicomStringArray(modalities);

            var stationNames = _studyXml
                               .Select(s => s.First()[DicomTags.StationName].GetString(0, null))
                               .Where(value => !String.IsNullOrEmpty(value)).Distinct();

            StationNamesInStudy = DicomStringHelper.GetDicomStringArray(stationNames);

            var institutionNames = _studyXml
                                   .Select(s => s.First()[DicomTags.InstitutionName].GetString(0, null))
                                   .Where(value => !String.IsNullOrEmpty(value)).Distinct();

            InstitutionNamesInStudy = DicomStringHelper.GetDicomStringArray(institutionNames);

            var sopClasses = (from series in _studyXml
                              from instance in series
                              where instance.SopClass != null
                              select instance.SopClass.Uid).Distinct();

            SopClassesInStudy = DicomStringHelper.GetDicomStringArray(sopClasses);

            #region Meta Info

            var sourceAEs = (from series in _studyXml
                             from instance in series
                             where !String.IsNullOrEmpty(instance.SourceAETitle)
                             select instance.SourceAETitle).Distinct();
            SourceAETitlesInStudy = DicomStringHelper.GetDicomStringArray(sourceAEs);

            #endregion

            //these have to be here, rather than in Initialize b/c they are
            // computed from the series, which are parsed from the xml.
            NumberOfStudyRelatedSeries    = _studyXml.NumberOfStudyRelatedSeries;
            NumberOfStudyRelatedInstances = _studyXml.NumberOfStudyRelatedInstances;
        }
コード例 #12
0
        public PatientAnnotationItemProvider()
            : base("AnnotationItemProviders.Dicom.Patient", new AnnotationResourceResolver(typeof(PatientAnnotationItemProvider).Assembly))
        {
            _annotationItems = new List <IAnnotationItem>();

            AnnotationResourceResolver resolver = new AnnotationResourceResolver(this);

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.EthnicGroup",
                    resolver,
                    FrameDataRetrieverFactory.GetStringRetriever(DicomTags.EthnicGroup),
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.PatientComments",
                    resolver,
                    FrameDataRetrieverFactory.GetStringRetriever(DicomTags.PatientComments),
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.PatientId",
                    resolver,
                    delegate(Frame frame) { return(frame.ParentImageSop.PatientId); },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.OtherPatientIds",
                    resolver,
                    delegate(Frame frame)
            {
                var patientIds = new List <string>();
                DicomAttribute attribute;
                if (frame.ParentImageSop.TryGetAttribute(DicomTags.OtherPatientIds, out attribute))
                {
                    patientIds.AddRange(DicomStringHelper.GetStringArray(attribute));
                }

                if (frame.ParentImageSop.TryGetAttribute(DicomTags.OtherPatientIdsSequence, out attribute) && !attribute.IsEmpty && !attribute.IsNull)
                {
                    var sqAttr = (DicomAttributeSQ)attribute;
                    for (var i = 0; i < sqAttr.Count; i++)
                    {
                        var attr = sqAttr[i][DicomTags.PatientId];
                        if (attr != null && !string.IsNullOrEmpty(attr))
                        {
                            patientIds.Add(attr);
                        }
                    }
                }

                return(DicomStringHelper.GetDicomStringArray(patientIds.Distinct()));
            },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.PatientsBirthDate",
                    resolver,
                    delegate(Frame frame) { return(frame.ParentImageSop.PatientsBirthDate); },
                    DicomDataFormatHelper.DateFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.PatientsBirthTime",
                    resolver,
                    FrameDataRetrieverFactory.GetStringRetriever(DicomTags.PatientsBirthTime),
                    DicomDataFormatHelper.TimeFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <PersonName>
                (
                    "Dicom.Patient.PatientsName",
                    resolver,
                    delegate(Frame frame) { return(frame.ParentImageSop.PatientsName); },
                    DicomDataFormatHelper.PersonNameFormatter
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.PatientsSex",
                    resolver,
                    delegate(Frame frame) { return(frame.ParentImageSop.PatientsSex); },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <PersonName>
                (
                    "Dicom.Patient.ResponsiblePerson",
                    resolver,
                    delegate(Frame frame) { return(frame.ParentImageSop.ResponsiblePerson); },
                    DicomDataFormatHelper.PersonNameFormatter
                )
            );

            _annotationItems.Add
            (
                new DicomAnnotationItem <string>
                (
                    "Dicom.Patient.ResponsibleOrganization",
                    resolver,
                    delegate(Frame frame) { return(frame.ParentImageSop.ResponsibleOrganization); },
                    DicomDataFormatHelper.RawStringFormat
                )
            );

            _annotationItems.Add
            (
                new CodeSequenceAnnotationItem
                (
                    "Dicom.Patient.PatientSpecies",
                    resolver,
                    DicomTags.PatientSpeciesCodeSequence,
                    DicomTags.PatientSpeciesDescription
                )
            );

            _annotationItems.Add
            (
                new CodeSequenceAnnotationItem
                (
                    "Dicom.Patient.PatientBreed",
                    resolver,
                    DicomTags.PatientBreedCodeSequence,
                    DicomTags.PatientBreedDescription
                )
            );
        }
コード例 #13
0
        internal void Initialize(DicomFile file)
        {
            DicomAttributeCollection sopInstanceDataset = file.DataSet;

            DicomAttribute attribute       = sopInstanceDataset[DicomTags.StudyInstanceUid];
            string         datasetStudyUid = attribute.ToString();

            if (!String.IsNullOrEmpty(StudyInstanceUid) && StudyInstanceUid != datasetStudyUid)
            {
                string message = String.Format("The study uid in the data set does not match this study's uid ({0} != {1}).",
                                               datasetStudyUid, StudyInstanceUid);

                throw new InvalidOperationException(message);
            }
            else
            {
                StudyInstanceUid = attribute.ToString();
            }

            Platform.CheckForEmptyString(StudyInstanceUid, "StudyInstanceUid");

            attribute = sopInstanceDataset[DicomTags.PatientId];
            PatientId = attribute.ToString();

            attribute       = sopInstanceDataset[DicomTags.PatientsName];
            PatientsName    = new PersonName(attribute.ToString());
            PatientsNameRaw = DicomImplementation.CharacterParser.EncodeAsIsomorphicString(PatientsName, sopInstanceDataset.SpecificCharacterSet);

            attribute = sopInstanceDataset[DicomTags.ReferringPhysiciansName];
            ReferringPhysiciansName    = new PersonName(attribute.ToString());
            ReferringPhysiciansNameRaw = DicomImplementation.CharacterParser.EncodeAsIsomorphicString(ReferringPhysiciansName, sopInstanceDataset.SpecificCharacterSet);

            attribute   = sopInstanceDataset[DicomTags.PatientsSex];
            PatientsSex = attribute.ToString();

            attribute            = sopInstanceDataset[DicomTags.PatientsBirthDate];
            PatientsBirthDateRaw = attribute.ToString();

            attribute = sopInstanceDataset[DicomTags.StudyId];
            StudyId   = attribute.ToString();

            attribute       = sopInstanceDataset[DicomTags.AccessionNumber];
            AccessionNumber = attribute.ToString();

            attribute        = sopInstanceDataset[DicomTags.StudyDescription];
            StudyDescription = attribute.ToString();

            attribute    = sopInstanceDataset[DicomTags.StudyDate];
            StudyDateRaw = attribute.ToString();
            StudyDate    = DateParser.Parse(StudyDateRaw);

            attribute    = sopInstanceDataset[DicomTags.StudyTime];
            StudyTimeRaw = attribute.ToString();

            if (sopInstanceDataset.Contains(DicomTags.ProcedureCodeSequence))
            {
                attribute = sopInstanceDataset[DicomTags.ProcedureCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    ProcedureCodeSequenceCodeValue = sequence[DicomTags.CodeValue].ToString();
                    ProcedureCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                }
            }

            attribute            = sopInstanceDataset[DicomTags.SpecificCharacterSet];
            SpecificCharacterSet = attribute.ToString();

            string[] modalitiesInStudy = DicomStringHelper.GetStringArray(ModalitiesInStudy ?? "");
            ModalitiesInStudy = DicomStringHelper.GetDicomStringArray(
                ComputeModalitiesInStudy(modalitiesInStudy, sopInstanceDataset[DicomTags.Modality].GetString(0, "")));
        }