/// <summary>
        /// Query the Information Model using the given Query Dataset.
        /// </summary>
        /// <param name="queryDataset">Query Dataset.</param>
        /// <returns>A collection of zero or more query reponse datasets.</returns>
        public override DataSetCollection QueryInformationModel(DataSet queryDataset)
        {
            DataSetCollection queryResponses = null;

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

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

            // query at the STUDY level
            if (queryRetrieveLevel == "STUDY")
            {
                TagTypeList queryTagTypeList  = new TagTypeList();
                TagTypeList returnTagTypeList = new TagTypeList();
                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                {
                    if (attribute.Length != 0)
                    {
                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                    }
                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                }


                foreach (StudyInformationEntity studyInformationEntity in Root)
                {
                    if (studyInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                    {
                        // STUDY level matches
                        DataSet queryResponse = new DataSet();
                        studyInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                        queryResponses.Add(queryResponse);
                    }
                }
            }
            else
            {
                // find the matching STUDY
                StudyInformationEntity studyInformationEntity = null;
                foreach (StudyInformationEntity lStudyInformationEntity in Root)
                {
                    if (lStudyInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        studyInformationEntity = lStudyInformationEntity;
                        break;
                    }
                }

                if (studyInformationEntity != null)
                {
                    // query at the SERIES level
                    if (queryRetrieveLevel == "SERIES")
                    {
                        TagTypeList queryTagTypeList  = new TagTypeList();
                        TagTypeList returnTagTypeList = new TagTypeList();
                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                        {
                            // do not add higher level tags
                            if (attribute.Tag == Tag.STUDY_INSTANCE_UID)
                            {
                                continue;
                            }

                            if (attribute.Length != 0)
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                        }

                        foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                        {
                            if (seriesInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                            {
                                // SERIES level matches
                                DataSet queryResponse = new DataSet();
                                studyInformationEntity.CopyUniqueTagTo(queryResponse);
                                seriesInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                queryResponses.Add(queryResponse);
                            }
                        }
                    }
                    else
                    {
                        // find the matching SERIES
                        SeriesInformationEntity seriesInformationEntity = null;
                        foreach (SeriesInformationEntity lSeriesInformationEntity in studyInformationEntity.Children)
                        {
                            if (lSeriesInformationEntity.IsUniqueTagFoundIn(queryDataset))
                            {
                                seriesInformationEntity = lSeriesInformationEntity;
                                break;
                            }
                        }

                        if (seriesInformationEntity != null)
                        {
                            // query at the IMAGE level
                            if (queryRetrieveLevel == "IMAGE")
                            {
                                TagTypeList queryTagTypeList  = new TagTypeList();
                                TagTypeList returnTagTypeList = new TagTypeList();
                                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                {
                                    // do not add higher level tags
                                    if ((attribute.Tag == Tag.STUDY_INSTANCE_UID) ||
                                        (attribute.Tag == Tag.SERIES_INSTANCE_UID))
                                    {
                                        continue;
                                    }

                                    if (attribute.Length != 0)
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                }

                                foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                {
                                    if (instanceInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                    {
                                        // IMAGE level matches
                                        DataSet queryResponse = new DataSet();
                                        studyInformationEntity.CopyUniqueTagTo(queryResponse);
                                        seriesInformationEntity.CopyUniqueTagTo(queryResponse);
                                        instanceInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                        queryResponses.Add(queryResponse);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(queryResponses);
        }
Beispiel #2
0
        /// <summary>
        /// Query the Information Model using the given Query Dataset.
        /// </summary>
        /// <param name="queryDataset">Query Dataset.</param>
        /// <returns>A collection of zero or more query reponse datasets.</returns>
        public override DataSetCollection QueryInformationModel(DataSet queryDataset)
        {
            DataSetCollection queryResponses = new DataSetCollection();;

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

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

            // query at the STUDY level
            if (queryRetrieveLevel == "STUDY")
            {
                TagTypeList queryTagTypeList  = new TagTypeList();
                TagTypeList returnTagTypeList = new TagTypeList();
                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                {
                    if (attribute.ValueRepresentation == VR.SQ)
                    {
                        foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                        {
                            if (IsSequenceHavingValue(s))
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                        }
                    }

                    else if ((attribute.Length != 0) &&
                             (attribute.Tag.ElementNumber != 0x0000))
                    {
                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                    }
                    if (attribute.Tag != Tag.SPECIFIC_CHARACTER_SET)
                    {
                        returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                    }
                }

                foreach (PatientStudyInformationEntity patientStudyInformationEntity in Root)
                {
                    if (patientStudyInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                    {
                        // STUDY level matches
                        DataSet queryResponse = new DataSet();

                        // if the specific character set attribute has been stored in the patient/study IE - return it in the query response
                        DvtkData.Dimse.Attribute specificCharacterSetAttribute = patientStudyInformationEntity.GetSpecificCharacterSet();
                        if (specificCharacterSetAttribute != null)
                        {
                            queryResponse.Add(specificCharacterSetAttribute);
                        }

                        patientStudyInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                        queryResponses.Add(queryResponse);
                    }
                }
            }
            else
            {
                // find the matching STUDY
                PatientStudyInformationEntity patientStudyInformationEntity = null;
                foreach (PatientStudyInformationEntity lPatientStudyInformationEntity in Root)
                {
                    if (lPatientStudyInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        patientStudyInformationEntity = lPatientStudyInformationEntity;
                        break;
                    }
                }

                if (patientStudyInformationEntity != null)
                {
                    // query at the SERIES level
                    if (queryRetrieveLevel == "SERIES")
                    {
                        TagTypeList queryTagTypeList  = new TagTypeList();
                        TagTypeList returnTagTypeList = new TagTypeList();
                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                        {
                            // do not add higher level tags
                            if (attribute.Tag == Tag.STUDY_INSTANCE_UID)
                            {
                                continue;
                            }

                            if (attribute.ValueRepresentation == VR.SQ)
                            {
                                foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                {
                                    if (IsSequenceHavingValue(s))
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                }
                            }

                            else if ((attribute.Length != 0) &&
                                     (attribute.Tag.ElementNumber != 0x0000))
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                        }

                        foreach (SeriesInformationEntity seriesInformationEntity in patientStudyInformationEntity.Children)
                        {
                            if (seriesInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                            {
                                // SERIES level matches
                                DataSet queryResponse = new DataSet();

                                // if the specific character set attribute has been stored in the series IE - return it in the query response
                                DvtkData.Dimse.Attribute specificCharacterSetAttribute = seriesInformationEntity.GetSpecificCharacterSet();
                                if (specificCharacterSetAttribute != null)
                                {
                                    queryResponse.Add(specificCharacterSetAttribute);
                                }

                                patientStudyInformationEntity.CopyUniqueTagTo(queryResponse);
                                seriesInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                queryResponses.Add(queryResponse);
                            }
                        }
                    }
                    else
                    {
                        // find the matching SERIES
                        SeriesInformationEntity seriesInformationEntity = null;
                        foreach (SeriesInformationEntity lSeriesInformationEntity in patientStudyInformationEntity.Children)
                        {
                            if (lSeriesInformationEntity.IsUniqueTagFoundIn(queryDataset))
                            {
                                seriesInformationEntity = lSeriesInformationEntity;
                                break;
                            }
                        }

                        if (seriesInformationEntity != null)
                        {
                            // query at the IMAGE level
                            if (queryRetrieveLevel == "IMAGE")
                            {
                                TagTypeList queryTagTypeList  = new TagTypeList();
                                TagTypeList returnTagTypeList = new TagTypeList();
                                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                {
                                    // do not add higher level tags
                                    if ((attribute.Tag == Tag.STUDY_INSTANCE_UID) ||
                                        (attribute.Tag == Tag.SERIES_INSTANCE_UID))
                                    {
                                        continue;
                                    }

                                    if (attribute.ValueRepresentation == VR.SQ)
                                    {
                                        foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                        {
                                            if (IsSequenceHavingValue(s))
                                            {
                                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                            }
                                        }
                                    }
                                    else if ((attribute.Length != 0) &&
                                             (attribute.Tag.ElementNumber != 0x0000))
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                }

                                foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                {
                                    if (instanceInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                    {
                                        // IMAGE level matches
                                        DataSet queryResponse = new DataSet();

                                        // if the specific character set attribute has been stored in the instance IE - return it in the query response
                                        DvtkData.Dimse.Attribute specificCharacterSetAttribute = instanceInformationEntity.GetSpecificCharacterSet();
                                        if (specificCharacterSetAttribute != null)
                                        {
                                            queryResponse.Add(specificCharacterSetAttribute);
                                        }

                                        patientStudyInformationEntity.CopyUniqueTagTo(queryResponse);
                                        seriesInformationEntity.CopyUniqueTagTo(queryResponse);
                                        instanceInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                        queryResponses.Add(queryResponse);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(queryResponses);
        }