/// <summary>
        /// Add the given Dataset to the Information Model. The data is normalised into the Information Model.
        /// </summary>
        /// <param name="dataset">Dataset to add to Informatio Model.</param>
        public override void AddToInformationModel(DataSet dataset)
        {
            // STUDY level
            PatientStudyInformationEntity patientStudyInformationEntity = null;

            // check if the patient/study IE is already in the studyRootList
            foreach (PatientStudyInformationEntity lPatientStudyInformationEntity in Root)
            {
                if (lPatientStudyInformationEntity.IsFoundIn(dataset))
                {
                    patientStudyInformationEntity = lPatientStudyInformationEntity;
                    break;
                }
            }

            // patient/study IE is not already in the studyRootList
            if (patientStudyInformationEntity == null)
            {
                // create a new patient/study IE from the dataset and add to the studyRootList
                patientStudyInformationEntity = new PatientStudyInformationEntity();
                patientStudyInformationEntity.CopyFrom(dataset);
                Root.Add(patientStudyInformationEntity);
            }

            // SERIES level
            SeriesInformationEntity seriesInformationEntity = null;

            // check if the series IE is already in the patient/study IE children
            foreach (SeriesInformationEntity lSeriesInformationEntity in patientStudyInformationEntity.Children)
            {
                if (lSeriesInformationEntity.IsFoundIn(dataset))
                {
                    seriesInformationEntity = lSeriesInformationEntity;
                    break;
                }
            }

            // series IE is not already in the patient/study IE children
            if (seriesInformationEntity == null)
            {
                // create a new series IE from the dataset and add to the patient/study IE children
                seriesInformationEntity = new SeriesInformationEntity();
                seriesInformationEntity.CopyFrom(dataset);
                patientStudyInformationEntity.AddChild(seriesInformationEntity);
            }

            // IMAGE (Instance) level
            InstanceInformationEntity instanceInformationEntity = null;

            // check if the instance IE is already in the series IE children
            foreach (InstanceInformationEntity lInstanceInformationEntity in seriesInformationEntity.Children)
            {
                if (lInstanceInformationEntity.IsFoundIn(dataset))
                {
                    instanceInformationEntity = lInstanceInformationEntity;
                    break;
                }
            }

            // instance IE is not already in the series IE children
            if (instanceInformationEntity == null)
            {
                // create a new instance IE from the dataset and add to the series IE children
                instanceInformationEntity = new InstanceInformationEntity(dataset.Filename);
                instanceInformationEntity.CopyFrom(dataset);
                seriesInformationEntity.AddChild(instanceInformationEntity);
            }
        }
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);
        }
Beispiel #3
0
        /// <summary>
        /// Add the given dataset present in a Dicom File to the Information Model. The data is normalised into the Information Model.
        /// </summary>
        /// <param name="dicomFile">The dicom File containing the dataset to be added.</param>
        /// <param name="storeFile">Boolean indicating whether the dataset should be stored or not.</param>
        public override void AddToInformationModel(DvtkData.Media.DicomFile dicomFile, bool storeFile)
        {
            // STUDY level
            PatientStudyInformationEntity patientStudyInformationEntity = null;

            this.IsDataStored = storeFile;

            // check if the patient/study IE is already in the studyRootList
            foreach (PatientStudyInformationEntity lPatientStudyInformationEntity in Root)
            {
                if (lPatientStudyInformationEntity.IsUniqueTagFoundIn(dicomFile.DataSet))
                {
                    patientStudyInformationEntity = lPatientStudyInformationEntity;
                    patientStudyInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
                    break;
                }
            }

            // patient/study IE is not already in the studyRootList
            if (patientStudyInformationEntity == null)
            {
                // create a new patient/study IE from the dataset and add to the studyRootList
                patientStudyInformationEntity = new PatientStudyInformationEntity();
                patientStudyInformationEntity.CopyFrom(dicomFile.DataSet);
                Root.Add(patientStudyInformationEntity);
            }

            // SERIES level
            SeriesInformationEntity seriesInformationEntity = null;

            // check if the series IE is already in the study IE children
            foreach (SeriesInformationEntity lSeriesInformationEntity in patientStudyInformationEntity.Children)
            {
                if (lSeriesInformationEntity.IsUniqueTagFoundIn(dicomFile.DataSet))
                {
                    seriesInformationEntity = lSeriesInformationEntity;
                    seriesInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
                    break;
                }
            }

            // series IE is not already in the study IE children
            if (seriesInformationEntity == null)
            {
                // create a new series IE from the dataset and add to the study IE children
                seriesInformationEntity = new SeriesInformationEntity();
                seriesInformationEntity.CopyFrom(dicomFile.DataSet);
                patientStudyInformationEntity.AddChild(seriesInformationEntity);
            }

            // IMAGE (Instance) level
            InstanceInformationEntity instanceInformationEntity = null;

            // check if the instance IE is already in the series IE children
            foreach (InstanceInformationEntity lInstanceInformationEntity in seriesInformationEntity.Children)
            {
                if (lInstanceInformationEntity.IsUniqueTagFoundIn(dicomFile.DataSet))
                {
                    instanceInformationEntity = lInstanceInformationEntity;
                    instanceInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
                    break;
                }
            }

            // instance IE is not already in the series IE children
            if (instanceInformationEntity == null)
            {
                // Store the dicom File as a DCM file if requested.
                if (storeFile == true)
                {
                    StoreDicomFile(dicomFile);
                }

                // create a new instance IE from the dataset and add to the series IE children
                instanceInformationEntity = new InstanceInformationEntity(dicomFile.DataSet.Filename);
                instanceInformationEntity.CopyFrom(dicomFile.DataSet);
                seriesInformationEntity.AddChild(instanceInformationEntity);
            }

            patientStudyInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
            seriesInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
            instanceInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
        }
        /// <summary>
        /// Add the given dataset present in a Dicom File to the Information Model. The data is normalised into the Information Model.
        /// </summary>
        /// <param name="dicomFile">The dicom File containing the dataset to be added.</param>
        /// <param name="storeFile">Boolean indicating whether the dataset should be stored or not.</param>
        public override void AddToInformationModel(DvtkData.Media.DicomFile dicomFile, bool storeFile)
        {
            // STUDY level
            PatientStudyInformationEntity patientStudyInformationEntity = null;

            this.IsDataStored = storeFile;

            // check if the patient/study IE is already in the studyRootList
            foreach (PatientStudyInformationEntity lPatientStudyInformationEntity in Root)
            {
                if (lPatientStudyInformationEntity.IsUniqueTagFoundIn(dicomFile.DataSet))
                {
                    patientStudyInformationEntity = lPatientStudyInformationEntity;
                    patientStudyInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
                    break;
                }
            }

            // patient/study IE is not already in the studyRootList
            if (patientStudyInformationEntity == null)
            {
                // create a new patient/study IE from the dataset and add to the studyRootList
                patientStudyInformationEntity = new PatientStudyInformationEntity();
                patientStudyInformationEntity.CopyFrom(dicomFile.DataSet);
                Root.Add(patientStudyInformationEntity);
            }

            // SERIES level
            SeriesInformationEntity seriesInformationEntity = null;

            // check if the series IE is already in the study IE children
            foreach (SeriesInformationEntity lSeriesInformationEntity in patientStudyInformationEntity.Children)
            {
                if (lSeriesInformationEntity.IsUniqueTagFoundIn(dicomFile.DataSet))
                {
                    seriesInformationEntity = lSeriesInformationEntity;
                    seriesInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
                    break;
                }
            }

            // series IE is not already in the study IE children
            if (seriesInformationEntity == null)
            {
                // create a new series IE from the dataset and add to the study IE children
                seriesInformationEntity = new SeriesInformationEntity();
                seriesInformationEntity.CopyFrom(dicomFile.DataSet);
                patientStudyInformationEntity.AddChild(seriesInformationEntity);
            }

            // IMAGE (Instance) level
            InstanceInformationEntity instanceInformationEntity = null;

            // check if the instance IE is already in the series IE children
            foreach (InstanceInformationEntity lInstanceInformationEntity in seriesInformationEntity.Children)
            {
                if (lInstanceInformationEntity.IsUniqueTagFoundIn(dicomFile.DataSet))
                {
                    instanceInformationEntity = lInstanceInformationEntity;
                    instanceInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
                    break;
                }
            }

            // instance IE is not already in the series IE children
            if (instanceInformationEntity == null)
            {
                // Store the dicom File as a DCM file if requested.
                if (storeFile == true)
                {
                    StoreDicomFile(dicomFile);
                }

                // create a new instance IE from the dataset and add to the series IE children
                instanceInformationEntity = new InstanceInformationEntity(dicomFile.DataSet.Filename);
                instanceInformationEntity.CopyFrom(dicomFile.DataSet);
                seriesInformationEntity.AddChild(instanceInformationEntity);
            }

            patientStudyInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
            seriesInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
            instanceInformationEntity.CheckForSpecialTags(dicomFile.DataSet);
        }