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; }
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; }