static string GetValues(DvtkData.Collections.StringCollection collections)
        {
            string retstring = "";

            foreach (object v in collections)
            {
                retstring = retstring + "\\" + v.ToString();
            }
            return(retstring.Remove(0, 1));
        }
Example #2
0
        /// <summary>
        /// Includes the non-dataset attributes in the information model.
        /// Handled attributes are,
        /// MODALITIES_IN_STUDY
        /// NUMBER_OF_PATIENT_RELATED_STUDIES
        /// NUMBER_OF_PATIENT_RELATED_SERIES
        /// NUMBER_OF_PATIENT_RELATED_INSTANCES
        /// NUMBER_OF_STUDY_RELATED_SERIES
        /// NUMBER_OF_STUDY_RELATED_INSTANCES.
        /// NUMBER_OF_SERIES_RELATED_INSTANCES
        /// </summary>
        /// <param name="sourceDataset"></param>
        public void CheckForSpecialTags(AttributeSet sourceDataset)
        {
            if (_tagTypeList != null&&sourceDataset!=null)
            {
                foreach (TagType tagType in _tagTypeList)
                {
                    if (tagType.Tag == Tag.MODALITIES_IN_STUDY)
                    {
                        DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag);
                        if (sourceAttribute != null)
                        {
                            // if an entry already exists - remove it
                            DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
                            if (destinationAttribute != null)
                            {
                                _dataset.Remove(destinationAttribute);
                            }
                            if (destinationAttribute != null && destinationAttribute.Tag == Tag.MODALITIES_IN_STUDY && destinationAttribute.ValueRepresentation == VR.CS)
                            {
                                StringCollection values = ((CodeString)destinationAttribute.DicomValue).Values;
                                string actualModality = ((CodeString)sourceDataset.GetAttribute(Tag.MODALITY).DicomValue).Values[0];

                                if (actualModality != null && !values.Contains(actualModality.Trim()))
                                {
                                    values.Add(actualModality.Trim());
                                }
                                CodeString cs = new CodeString();
                                cs.Values = values;
                                sourceAttribute.DicomValue = cs;
                                System.UInt32 length = 0;
                                foreach (String data in cs.Values)
                                {
                                    length += (System.UInt32)data.Length;
                                }
                                sourceAttribute.Length = length + (System.UInt32)cs.Values.Count - 1;
                            }
                            _dataset.Add(sourceAttribute);
                        }
                        else if (tagType.Tag == Tag.MODALITIES_IN_STUDY)
                        {
                            sourceAttribute = new DvtkData.Dimse.Attribute();
                            sourceAttribute.Tag = Tag.MODALITIES_IN_STUDY;
                            sourceAttribute.Name = "Modalities in study";
                            DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
                            string actualModality = ((CodeString)sourceDataset.GetAttribute(Tag.MODALITY).DicomValue).Values[0];
                            StringCollection values = null;
                            if (destinationAttribute != null && destinationAttribute.ValueRepresentation == VR.CS)
                            {
                                _dataset.Remove(destinationAttribute);
                                values = ((CodeString)destinationAttribute.DicomValue).Values;
                            }
                            if (values == null)
                                values = new StringCollection();
                            if (actualModality != null && !values.Contains(actualModality.Trim()))
                            {
                                values.Add(actualModality.Trim());
                            }
                            CodeString cs = new CodeString();
                            cs.Values = values;
                            sourceAttribute.DicomValue = cs;
                            System.UInt32 length = 0;
                            foreach (String data in cs.Values)
                            {
                                length += (System.UInt32)data.Length;
                            }
                            sourceAttribute.Length = length + (System.UInt32)cs.Values.Count - 1;
                            _dataset.Add(sourceAttribute);
                        }
                    }
                    else if (tagType.Tag == Tag.NUMBER_OF_PATIENT_RELATED_STUDIES&&_level=="PATIENT")
                    {
                        HandlePatientRelatedStudies(tagType, sourceDataset);
                    }
                    else if (tagType.Tag == Tag.NUMBER_OF_PATIENT_RELATED_SERIES&& _level=="PATIENT")
                    {
                        HandlePatientRelatedSeries(tagType, sourceDataset);
                    }
                    else if (tagType.Tag == Tag.NUMBER_OF_PATIENT_RELATED_INSTANCES&&_level=="PATIENT")
                    {
                        HandlePatientRelatedInstances(tagType, sourceDataset);
                    }
                    else if (tagType.Tag == Tag.NUMBER_OF_STUDY_RELATED_SERIES&&_level=="STUDY")
                    {
                        HandleStudyRelatedSeries(tagType, sourceDataset);
                    }
                    else if (tagType.Tag == Tag.NUMBER_OF_STUDY_RELATED_INSTANCES&&_level=="STUDY")
                    {
                        HandleStudyRelatedInstances(tagType, sourceDataset);
                    }
                    else if (tagType.Tag == Tag.NUMBER_OF_SERIES_RELATED_INSTANCES&&_level=="SERIES")
                    {
                        HandleSeriesRelatedInstances(tagType, sourceDataset);
                    }
                }

            }
        }
Example #3
0
 void HandleStudyRelatedSeries(TagType tagType, AttributeSet sourceDataset)
 {
     DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag);
     if (sourceAttribute == null)
     {
         sourceAttribute = new DvtkData.Dimse.Attribute();
         sourceAttribute.Tag = Tag.NUMBER_OF_STUDY_RELATED_SERIES;
         sourceAttribute.Name = "Number of Study related Series";
     }
     DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
     if (destinationAttribute != null)
     {
         _dataset.Remove(destinationAttribute);
     }
     IntegerString str = new IntegerString();
     StringCollection colle = new StringCollection();
     colle.Add(Children.Count.ToString());
     str.Values = colle;
     System.UInt32 length = 0;
     foreach (String data in str.Values)
     {
         length += (System.UInt32)data.Length;
     }
     sourceAttribute.DicomValue = str;
     sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1;
     _dataset.Add(sourceAttribute);
 }
Example #4
0
        void HandlePatientRelatedSeries(TagType tagType, AttributeSet sourceDataset)
        {
            DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag);
            if (sourceAttribute == null)
            {
                sourceAttribute = new DvtkData.Dimse.Attribute();
                sourceAttribute.Tag = Tag.NUMBER_OF_PATIENT_RELATED_SERIES;
                sourceAttribute.Name = "Number of Patient related series";
            }
            DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
            if (destinationAttribute != null)
            {
                _dataset.Remove(destinationAttribute);
            }
            IntegerString str = new IntegerString();
            StringCollection colle = new StringCollection();
            int noOfSeries = 0;
            for (int i = 0; i < Children.Count; i++)
            {
                noOfSeries = noOfSeries + Children[i].Children.Count;
            }
            colle.Add(noOfSeries.ToString());
            str.Values = colle;
            System.UInt32 length = 0;
            foreach (String data in str.Values)
            {
                length += (System.UInt32)data.Length;
            }
            sourceAttribute.DicomValue = str;
            sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1;
            _dataset.Add(sourceAttribute);

            //DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag);
            //if (sourceAttribute != null)
            //{
            //    // if an entry already exists - remove it
            //    DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
            //    if (destinationAttribute != null)
            //    {
            //        _dataset.Remove(destinationAttribute);
            //    }
            //    if (destinationAttribute != null && destinationAttribute.Tag == Tag.NUMBER_OF_PATIENT_RELATED_STUDIES)
            //    {
            //        IntegerString str = new IntegerString();
            //        StringCollection colle = new StringCollection();
            //        int noOfSeries = 0;
            //        for (int i = 0; i < Children.Count; i++)
            //        {
            //            noOfSeries = noOfSeries + Children[i].Children.Count;
            //        }

            //        colle.Add(noOfSeries.ToString());
            //        str.Values = colle;
            //        System.UInt32 length = 0;
            //        foreach (String data in str.Values)
            //        {
            //            length += (System.UInt32)data.Length;
            //        }
            //        sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1;
            //    }
            //    _dataset.Add(sourceAttribute);
            //}
            //else
            //{
            //    sourceAttribute = new DvtkData.Dimse.Attribute();
            //    sourceAttribute.Tag = Tag.NUMBER_OF_PATIENT_RELATED_STUDIES;
            //    sourceAttribute.Name = "Number of Patient related series";
            //    DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
            //    StringCollection values = null;
            //    if (destinationAttribute != null)
            //    {
            //        _dataset.Remove(destinationAttribute);
            //    }
            //    values = new StringCollection();
            //    int noOfSeries = 0;
            //    for (int i = 0; i < Children.Count; i++)
            //    {
            //        noOfSeries = noOfSeries + Children[i].Children.Count;
            //    }
            //    values.Add(noOfSeries.ToString());

            //    IntegerString IS = new IntegerString();
            //    IS.Values = values;
            //    sourceAttribute.DicomValue = IS;
            //    System.UInt32 length = 0;
            //    foreach (String data in IS.Values)
            //    {
            //        length += (System.UInt32)data.Length;
            //    }
            //    sourceAttribute.Length = length + (System.UInt32)IS.Values.Count - 1;
            //    _dataset.Add(sourceAttribute);
            //}
        }
Example #5
0
 void HandlePatientRelatedInstances(TagType tagType, AttributeSet sourceDataset)
 {
     DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag);
     if (sourceAttribute == null)
     {
         sourceAttribute = new DvtkData.Dimse.Attribute();
         sourceAttribute.Tag = Tag.NUMBER_OF_PATIENT_RELATED_INSTANCES;
         sourceAttribute.Name = "Number of Patient related instances";
     }
     DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag);
     if (destinationAttribute != null)
     {
         _dataset.Remove(destinationAttribute);
     }
     IntegerString str = new IntegerString();
     StringCollection colle = new StringCollection();
     int noOfInstances = 0;
     for (int i = 0; i < Children.Count; i++)
     {
         for (int j = 0; j < Children[i].Children.Count; j++)
         {
             noOfInstances = noOfInstances + Children[i].Children[j].Children.Count;
         }
     }
     colle.Add(noOfInstances.ToString());
     str.Values = colle;
     System.UInt32 length = 0;
     foreach (String data in str.Values)
     {
         length += (System.UInt32)data.Length;
     }
     sourceAttribute.DicomValue = str;
     sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1;
     _dataset.Add(sourceAttribute);
 }
Example #6
0
        /// <summary>
        /// Retrieve a list of filenames from the Information Model. The filenames match the
        /// individual instances matching the retrieve dataset attributes.
        /// </summary>
        /// <param name="retrieveDataset">Retrive dataset.</param>
        /// <returns>File list - containing the filenames of all instances matching the retrieve dataset attributes.</returns>
        public DvtkData.Collections.StringCollection RetrieveInformationModel(DataSet retrieveDataset)
        {
            DvtkData.Collections.StringCollection fileList = new DvtkData.Collections.StringCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";

            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = retrieveDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // Find the matching PATIENT.
            PatientInformationEntity patientInformationEntity = null;

            foreach (PatientInformationEntity lPatientInformationEntity in Root)
            {
                if (lPatientInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                {
                    patientInformationEntity = lPatientInformationEntity;
                    break;
                }
            }

            if (patientInformationEntity != null)
            {
                // retrieve at the PATIENT level
                if (queryRetrieveLevel == "PATIENT")
                {
                    fileList = patientInformationEntity.FileNames;
                }
                else
                {
                    // Find the matching STUDIES.
                    BaseInformationEntityList studyInformationEntities = patientInformationEntity.ChildrenWithUniqueTagFoundIn(retrieveDataset);

                    if (studyInformationEntities.Count > 0)
                    {
                        // Retrieve at the STUDY level
                        if (queryRetrieveLevel == "STUDY")
                        {
                            foreach (StudyInformationEntity studyInformationEntity in studyInformationEntities)
                            {
                                foreach (String fileName in studyInformationEntity.FileNames)
                                {
                                    fileList.Add(fileName);
                                }
                            }
                        }
                        else
                        {
                            // Find the matching SERIES.
                            BaseInformationEntityList seriesInformationEntities = studyInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                            if (seriesInformationEntities.Count > 0)
                            {
                                // retrieve at the SERIES level
                                if (queryRetrieveLevel == "SERIES")
                                {
                                    foreach (SeriesInformationEntity seriesInformationEntity in seriesInformationEntities)
                                    {
                                        foreach (String fileName in seriesInformationEntity.FileNames)
                                        {
                                            fileList.Add(fileName);
                                        }
                                    }
                                }
                                else
                                {
                                    // Find the matching IMAGE
                                    BaseInformationEntityList instanceInformationEntities = seriesInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                                    // retrieve at the IMAGE level
                                    if ((instanceInformationEntities.Count > 0) &&
                                        (queryRetrieveLevel == "IMAGE"))
                                    {
                                        foreach (InstanceInformationEntity instanceInformationEntity in instanceInformationEntities)
                                        {
                                            if (instanceInformationEntity.Filename != null)
                                            {
                                                fileList.Add(instanceInformationEntity.Filename);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(fileList);
        }
        /// <summary>
        /// Retrieve a list of filenames from the Information Model. The filenames match the
        /// individual instances matching the retrieve dataset attributes.
        /// </summary>
        /// <param name="retrieveDataset">Retrive dataset.</param>
        /// <returns>File list - containing the filenames of all instances matching the retrieve dataset attributes.</returns>
        public DvtkData.Collections.StringCollection RetrieveInformationModel(DataSet retrieveDataset)
        {
            DvtkData.Collections.StringCollection fileList = new DvtkData.Collections.StringCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";
            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = retrieveDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // Find the matching PATIENT.
            PatientInformationEntity patientInformationEntity = null;
            foreach (PatientInformationEntity lPatientInformationEntity in Root)
            {
                if (lPatientInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                {
                    patientInformationEntity = lPatientInformationEntity;
                    break;
                }
            }

            if (patientInformationEntity != null)
            {
                // retrieve at the PATIENT level
                if (queryRetrieveLevel == "PATIENT")
                {
                    fileList = patientInformationEntity.FileNames;
                }
                else
                {
                    // Find the matching STUDIES.
                    BaseInformationEntityList studyInformationEntities = patientInformationEntity.ChildrenWithUniqueTagFoundIn(retrieveDataset);

                    if (studyInformationEntities.Count > 0)
                    {
                        // Retrieve at the STUDY level
                        if (queryRetrieveLevel == "STUDY")
                        {
                            foreach (StudyInformationEntity studyInformationEntity in studyInformationEntities)
                            {
                                foreach (String fileName in studyInformationEntity.FileNames)
                                {
                                    fileList.Add(fileName);
                                }
                            }
                        }
                        else
                        {
                            // Find the matching SERIES.
                            BaseInformationEntityList seriesInformationEntities = studyInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                            if (seriesInformationEntities.Count > 0)
                            {
                                // retrieve at the SERIES level
                                if (queryRetrieveLevel == "SERIES")
                                {
                                    foreach (SeriesInformationEntity seriesInformationEntity in seriesInformationEntities)
                                    {
                                        foreach (String fileName in seriesInformationEntity.FileNames)
                                        {
                                            fileList.Add(fileName);
                                        }
                                    }
                                }
                                else
                                {
                                    // Find the matching IMAGE
                                    BaseInformationEntityList instanceInformationEntities = seriesInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                                    // retrieve at the IMAGE level
                                    if ((instanceInformationEntities.Count > 0) &&
                                        (queryRetrieveLevel == "IMAGE"))
                                    {
                                        foreach (InstanceInformationEntity instanceInformationEntity in instanceInformationEntities)
                                        {
                                            if (instanceInformationEntity.Filename != null)
                                                fileList.Add(instanceInformationEntity.Filename);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return fileList;
        }