Exemple #1
0
        public void GivenLongExtendedQueryTagFilter_WhenIELevelStudy_ValidateExtendedQueryTagFilter()
        {
            var stringBuilder = new IndentedStringBuilder(new StringBuilder());
            var includeField  = new QueryIncludeField(new List <DicomTag>());
            var queryTag      = new QueryTag(DicomTag.NumberOfAssessmentObservations.BuildExtendedQueryTagStoreEntry(level: QueryTagLevel.Study));
            var filter        = new LongSingleValueMatchCondition(queryTag, 123);

            filter.QueryTag = queryTag;
            var filters = new List <QueryFilterCondition>()
            {
                filter,
            };
            var query = new QueryExpression(QueryResource.AllStudies, includeField, false, 0, 0, filters, Array.Empty <string>());

            SqlParameterCollection sqlParameterCollection = CreateSqlParameterCollection();
            var parm = new SqlQueryParameterManager(sqlParameterCollection);

            new SqlQueryGenerator(stringBuilder, query, parm, SqlServer.Features.Schema.SchemaVersion.V4, DefaultPartition.Key);

            string expectedExtendedQueryTagTableFilter = @"INNER JOIN dbo.ExtendedQueryTagLong ctl1
ON ctl1.PartitionKey = st.PartitionKey
AND ctl1.StudyKey = st.StudyKey
WHERE";

            string expectedFilters = @"AND ctl1.TagKey=@p0
AND ctl1.TagValue=@p1";

            string builtString = stringBuilder.ToString();

            Assert.Equal(queryTag.ExtendedQueryTagStoreEntry.Key.ToString(), sqlParameterCollection[0].Value.ToString());
            Assert.Equal(filter.Value.ToString(), sqlParameterCollection[1].Value.ToString());
            Assert.Contains(expectedExtendedQueryTagTableFilter, builtString);
            Assert.Contains(expectedFilters, builtString);
        }
        public override void Visit(LongSingleValueMatchCondition longSingleValueMatchCondition)
        {
            var queryTag         = longSingleValueMatchCondition.QueryTag;
            var dicomTagSqlEntry = DicomTagSqlEntry.GetDicomTagSqlEntry(queryTag);
            var tableAlias       = GetTableAlias(dicomTagSqlEntry, queryTag.IsExtendedQueryTag ? queryTag.ExtendedQueryTagStoreEntry.Key : null);

            _stringBuilder
            .Append("AND ");

            AppendExtendedQueryTagKeyFilter(dicomTagSqlEntry, tableAlias, longSingleValueMatchCondition);

            _stringBuilder
            .Append(dicomTagSqlEntry.SqlColumn, tableAlias)
            .Append("=")
            .Append(_parameters.AddParameter(dicomTagSqlEntry.SqlColumn, longSingleValueMatchCondition.Value))
            .AppendLine();
        }
Exemple #3
0
        public void GivenMultipleExtendedQueryTagFiltersOnDifferentLevels_WhenIELevelInstance_ValidateExtendedQueryTagFilter()
        {
            var stringBuilder = new IndentedStringBuilder(new StringBuilder());
            var includeField  = new QueryIncludeField(new List <DicomTag>());
            var queryTag1     = new QueryTag(DicomTag.ModelGroupUID.BuildExtendedQueryTagStoreEntry(key: 1, level: QueryTagLevel.Instance));
            var filter1       = new StringSingleValueMatchCondition(queryTag1, "abc");

            filter1.QueryTag = queryTag1;

            var queryTag2 = new QueryTag(DicomTag.ContainerDescription.BuildExtendedQueryTagStoreEntry(key: 2, level: QueryTagLevel.Series));
            var filter2   = new StringSingleValueMatchCondition(queryTag2, "description");

            filter2.QueryTag = queryTag2;

            var queryTag3 = new QueryTag(DicomTag.NumberOfAssessmentObservations.BuildExtendedQueryTagStoreEntry(key: 4, level: QueryTagLevel.Study));
            var filter3   = new LongSingleValueMatchCondition(queryTag3, 123);

            filter3.QueryTag = queryTag3;
            var filters = new List <QueryFilterCondition>()
            {
                filter1,
                filter2,
                filter3,
            };
            var query = new QueryExpression(QueryResource.AllInstances, includeField, false, 0, 0, filters, Array.Empty <string>());

            SqlParameterCollection sqlParameterCollection = CreateSqlParameterCollection();
            var parm = new SqlQueryParameterManager(sqlParameterCollection);

            new SqlQueryGenerator(stringBuilder, query, parm, SqlServer.Features.Schema.SchemaVersion.V4, DefaultPartition.Key);

            // cts1 is associated with filter1 which is at the instance level. This means the join should be on all three keys.
            // cts2 is associated with filter2 which is at the series level. This means the join should be on only study and series keys.
            // ctl4 is associated with filter3 which is at the study level. This means the join should be on only the study key.
            string expectedExtendedQueryTagTableFilter = @"INNER JOIN dbo.ExtendedQueryTagString cts1
ON cts1.PartitionKey = st.PartitionKey
AND cts1.StudyKey = st.StudyKey
AND cts1.SeriesKey = se.SeriesKey
AND cts1.InstanceKey = i.InstanceKey
INNER JOIN dbo.ExtendedQueryTagString cts2
ON cts2.PartitionKey = st.PartitionKey
AND cts2.StudyKey = st.StudyKey
AND cts2.SeriesKey = se.SeriesKey
INNER JOIN dbo.ExtendedQueryTagLong ctl4
ON ctl4.PartitionKey = st.PartitionKey
AND ctl4.StudyKey = st.StudyKey
WHERE";

            string expectedFilters = @"AND cts1.TagKey=@p0
AND cts1.TagValue=@p1
AND cts2.TagKey=@p2
AND cts2.TagValue=@p3
AND ctl4.TagKey=@p4
AND ctl4.TagValue=@p5";

            string builtString = stringBuilder.ToString();

            Assert.Equal(queryTag1.ExtendedQueryTagStoreEntry.Key.ToString(), sqlParameterCollection[0].Value.ToString());
            Assert.Equal(filter1.Value.ToString(), sqlParameterCollection[1].Value.ToString());
            Assert.Equal(queryTag2.ExtendedQueryTagStoreEntry.Key.ToString(), sqlParameterCollection[2].Value.ToString());
            Assert.Equal(filter2.Value.ToString(), sqlParameterCollection[3].Value.ToString());
            Assert.Equal(queryTag3.ExtendedQueryTagStoreEntry.Key.ToString(), sqlParameterCollection[4].Value.ToString());
            Assert.Equal(filter3.Value.ToString(), sqlParameterCollection[5].Value.ToString());
            Assert.Contains(expectedExtendedQueryTagTableFilter, builtString);
            Assert.Contains(expectedFilters, builtString);
        }
Exemple #4
0
 public abstract void Visit(LongSingleValueMatchCondition longSingleValueMatchCondition);