From 0f09dd60858787ca7068c3dba86bdcf8ec9de862 Mon Sep 17 00:00:00 2001 From: Esma <69813504+esmadau@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:04:36 -0800 Subject: [PATCH] Reapply "track total content length and files indexed (#3318)" (#3346) (#3349) * Reapply "track total content length and files indexed (#3318)" (#3346) This reverts commit 8a0247d9e0eeaf17850fa01325d1dcdbd5ec5de4. * add FunctionsPreservedDependencies so openTelemetry can be used / DiagnosticSource loaded as needed by functions host --- .../Features/Common/IndexedFileProperties.cs | 38 + .../Features/Store/IIndexDataStore.cs | 7 + .../Telemetry/MetricPointExtensions.cs | 51 + .../Microsoft.Health.Dicom.Core.csproj | 1 + ...icrosoft.Health.Dicom.Functions.App.csproj | 23 + .../host.json | 3 + .../local.settings.json | 1 + .../IndexMetricsCollectionFunctionTests.cs | 56 + .../IndexMetricsCollectionFunction.cs | 70 + .../IndexMetricsCollectionOptions.cs | 26 + .../ServiceCollectionExtensions.cs | 2 + .../Features/Schema/Migrations/57.diff.sql | 31 + .../Features/Schema/Migrations/57.sql | 3674 +++++++++++++++++ .../Features/Schema/Model/V56.Generated.cs | 2956 +++++++++++++ .../Schema/Model/VLatest.Generated.cs | 15 + .../Features/Schema/SchemaVersion.cs | 1 + .../Features/Schema/SchemaVersionConstants.cs | 4 +- .../Sql/Sprocs/GetIndexedFileMetrics.sql | 19 + .../Schema/Sql/Tables/FileProperty.sql | 6 + .../Features/Store/SqlIndexDataStore.cs | 6 + .../Features/Store/SqlIndexDataStoreV1.cs | 5 + .../Features/Store/SqlIndexDataStoreV57.cs | 55 + .../Microsoft.Health.Dicom.SqlServer.csproj | 2 +- .../DicomSqlServerRegistrationExtensions.cs | 1 + .../IndexedFilePropertiesCollection.cs | 13 + .../Persistence/IndexedFilePropertiesTests.cs | 101 + .../Persistence/SqlDataStoreTestsFixture.cs | 1 + 27 files changed, 7165 insertions(+), 3 deletions(-) create mode 100644 src/Microsoft.Health.Dicom.Core/Features/Common/IndexedFileProperties.cs create mode 100644 src/Microsoft.Health.Dicom.Core/Features/Telemetry/MetricPointExtensions.cs create mode 100644 src/Microsoft.Health.Dicom.Functions.UnitTests/IndexMetricsCollection/IndexMetricsCollectionFunctionTests.cs create mode 100644 src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionFunction.cs create mode 100644 src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionOptions.cs create mode 100644 src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.diff.sql create mode 100644 src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.sql create mode 100644 src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V56.Generated.cs create mode 100644 src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/GetIndexedFileMetrics.sql create mode 100644 src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV57.cs create mode 100644 test/Microsoft.Health.Dicom.Tests.Integration/IndexedFilePropertiesCollection.cs create mode 100644 test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IndexedFilePropertiesTests.cs diff --git a/src/Microsoft.Health.Dicom.Core/Features/Common/IndexedFileProperties.cs b/src/Microsoft.Health.Dicom.Core/Features/Common/IndexedFileProperties.cs new file mode 100644 index 0000000000..62de77dbcf --- /dev/null +++ b/src/Microsoft.Health.Dicom.Core/Features/Common/IndexedFileProperties.cs @@ -0,0 +1,38 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System; + +namespace Microsoft.Health.Dicom.Core.Features.Common; + +/// +/// Metadata on FileProperty table in database +/// +public readonly struct IndexedFileProperties : IEquatable +{ + /// + /// Total indexed FileProperty in database + /// + public long TotalIndexed { get; init; } + + /// + /// Total sum of all ContentLength rows in FileProperty table + /// + public long TotalSum { get; init; } + + public override bool Equals(object obj) => obj is IndexedFileProperties other && Equals(other); + + public bool Equals(IndexedFileProperties other) + => TotalIndexed == other.TotalIndexed && TotalSum == other.TotalSum; + + public override int GetHashCode() + => HashCode.Combine(TotalIndexed, TotalSum); + + public static bool operator ==(IndexedFileProperties left, IndexedFileProperties right) + => left.Equals(right); + + public static bool operator !=(IndexedFileProperties left, IndexedFileProperties right) + => !(left == right); +} diff --git a/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs b/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs index 7c82c3b2c8..db41dc92db 100644 --- a/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs +++ b/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs @@ -185,4 +185,11 @@ public interface IIndexDataStore /// The cancellation token. /// A task that with list of instance metadata with new watermark. Task UpdateFilePropertiesContentLengthAsync(IReadOnlyDictionary filePropertiesByWatermark, CancellationToken cancellationToken = default); + + /// + /// Retrieves total count in FileProperty table and summation of all content length values across FileProperty table. + /// + /// The cancellation token. + /// A task that gets the count + Task GetIndexedFileMetricsAsync(CancellationToken cancellationToken = default); } diff --git a/src/Microsoft.Health.Dicom.Core/Features/Telemetry/MetricPointExtensions.cs b/src/Microsoft.Health.Dicom.Core/Features/Telemetry/MetricPointExtensions.cs new file mode 100644 index 0000000000..e91e76b0eb --- /dev/null +++ b/src/Microsoft.Health.Dicom.Core/Features/Telemetry/MetricPointExtensions.cs @@ -0,0 +1,51 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using OpenTelemetry.Metrics; + +namespace Microsoft.Health.Dicom.Core.Features.Telemetry; + +/// +/// Since only enumerators are exposed publicly for working with tags or getting the collection of +/// metrics, these extension facilitate getting both. +/// +public static class MetricPointExtensions +{ + /// + /// Get tags key value pairs from metric point. + /// + public static Dictionary GetTags(this MetricPoint metricPoint) + { + var tags = new Dictionary(); + foreach (var pair in metricPoint.Tags) + { + tags.Add(pair.Key, pair.Value); + } + + return tags; + } + + /// + /// Get all metrics emitted after flushing. + /// + [SuppressMessage("Performance", "CA1859: Use concrete types when possible for improved performance", Justification = "Result should be read-only.")] + public static IReadOnlyList GetMetricPoints(this ICollection exportedItems, string metricName) + { + MetricPointsAccessor accessor = exportedItems + .Single(item => item.Name.Equals(metricName, StringComparison.Ordinal)) + .GetMetricPoints(); + var metrics = new List(); + foreach (MetricPoint metricPoint in accessor) + { + metrics.Add(metricPoint); + } + + return metrics; + } +} \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.Core/Microsoft.Health.Dicom.Core.csproj b/src/Microsoft.Health.Dicom.Core/Microsoft.Health.Dicom.Core.csproj index 2253d421a3..94d8cd6521 100644 --- a/src/Microsoft.Health.Dicom.Core/Microsoft.Health.Dicom.Core.csproj +++ b/src/Microsoft.Health.Dicom.Core/Microsoft.Health.Dicom.Core.csproj @@ -32,6 +32,7 @@ + diff --git a/src/Microsoft.Health.Dicom.Functions.App/Microsoft.Health.Dicom.Functions.App.csproj b/src/Microsoft.Health.Dicom.Functions.App/Microsoft.Health.Dicom.Functions.App.csproj index 519a9de8d2..8fa12f72da 100644 --- a/src/Microsoft.Health.Dicom.Functions.App/Microsoft.Health.Dicom.Functions.App.csproj +++ b/src/Microsoft.Health.Dicom.Functions.App/Microsoft.Health.Dicom.Functions.App.csproj @@ -26,6 +26,29 @@ + + + + + + + + + + + + + + + + PreserveNewest diff --git a/src/Microsoft.Health.Dicom.Functions.App/host.json b/src/Microsoft.Health.Dicom.Functions.App/host.json index 6b29e19089..7a944f785c 100644 --- a/src/Microsoft.Health.Dicom.Functions.App/host.json +++ b/src/Microsoft.Health.Dicom.Functions.App/host.json @@ -75,6 +75,9 @@ "FirstRetryInterval": "00:01:00", "MaxNumberOfAttempts": 4 } + }, + "IndexMetricsCollection": { + "Frequency": "0 0 * * *" } }, "Extensions": { diff --git a/src/Microsoft.Health.Dicom.Functions.App/local.settings.json b/src/Microsoft.Health.Dicom.Functions.App/local.settings.json index ae75e97fed..9d909c57f7 100644 --- a/src/Microsoft.Health.Dicom.Functions.App/local.settings.json +++ b/src/Microsoft.Health.Dicom.Functions.App/local.settings.json @@ -2,6 +2,7 @@ "IsEncrypted": false, "Values": { "AzureFunctionsJobHost__DicomFunctions__Indexing__MaxParallelBatches": "1", + "AzureFunctionsJobHost__DicomFunctions__IndexMetricsCollection__Frequency": "0 0 * * *", "AzureFunctionsJobHost__Logging__Console__IsEnabled": "true", "AzureFunctionsJobHost__SqlServer__ConnectionString": "server=(local);Initial Catalog=Dicom;Integrated Security=true;TrustServerCertificate=true", "AzureFunctionsJobHost__BlobStore__ConnectionString": "UseDevelopmentStorage=true", diff --git a/src/Microsoft.Health.Dicom.Functions.UnitTests/IndexMetricsCollection/IndexMetricsCollectionFunctionTests.cs b/src/Microsoft.Health.Dicom.Functions.UnitTests/IndexMetricsCollection/IndexMetricsCollectionFunctionTests.cs new file mode 100644 index 0000000000..17000b6c62 --- /dev/null +++ b/src/Microsoft.Health.Dicom.Functions.UnitTests/IndexMetricsCollection/IndexMetricsCollectionFunctionTests.cs @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System.Threading.Tasks; +using Microsoft.Azure.WebJobs; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Microsoft.Health.Dicom.Core.Configs; +using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.Store; +using Microsoft.Health.Dicom.Functions.MetricsCollection; +using NSubstitute; +using Xunit; + +namespace Microsoft.Health.Dicom.Functions.UnitTests.IndexMetricsCollection; + +public class IndexMetricsCollectionFunctionTests +{ + private readonly IndexMetricsCollectionFunction _collectionFunction; + private readonly IIndexDataStore _indexStore; + private readonly TimerInfo _timer; + + public IndexMetricsCollectionFunctionTests() + { + _indexStore = Substitute.For(); + _collectionFunction = new IndexMetricsCollectionFunction( + _indexStore, + Options.Create(new FeatureConfiguration { EnableExternalStore = true, })); + _timer = Substitute.For(default, default, default); + } + + [Fact] + public async Task GivenIndexMetricsCollectionFunction_WhenRun_CollectionExecutedWhenExternalStoreEnabled() + { + _indexStore.GetIndexedFileMetricsAsync().ReturnsForAnyArgs(new IndexedFileProperties()); + + await _collectionFunction.Run(_timer, NullLogger.Instance); + + await _indexStore.ReceivedWithAnyArgs(1).GetIndexedFileMetricsAsync(); + } + + [Fact] + public async Task GivenIndexMetricsCollectionFunction_WhenRun_CollectionNotExecutedWhenExternalStoreNotEnabled() + { + _indexStore.GetIndexedFileMetricsAsync().ReturnsForAnyArgs(new IndexedFileProperties()); + var collectionFunctionWihtoutExternalStore = new IndexMetricsCollectionFunction( + _indexStore, + Options.Create(new FeatureConfiguration { EnableExternalStore = false, })); + + await collectionFunctionWihtoutExternalStore.Run(_timer, NullLogger.Instance); + + await _indexStore.DidNotReceiveWithAnyArgs().GetIndexedFileMetricsAsync(); + } +} diff --git a/src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionFunction.cs b/src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionFunction.cs new file mode 100644 index 0000000000..888ff508b9 --- /dev/null +++ b/src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionFunction.cs @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System.Threading.Tasks; +using EnsureThat; +using Microsoft.Azure.WebJobs; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Health.Dicom.Core.Configs; +using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.Store; +using Microsoft.Health.Functions.Extensions; + +namespace Microsoft.Health.Dicom.Functions.MetricsCollection; + +/// +/// A function for collecting index metrics +/// +public class IndexMetricsCollectionFunction +{ + private readonly IIndexDataStore _indexDataStore; + private readonly bool _externalStoreEnabled; + private readonly bool _enableDataPartitions; + private const string RunFrequencyVariable = $"%{AzureFunctionsJobHost.RootSectionName}:DicomFunctions:{IndexMetricsCollectionOptions.SectionName}:{nameof(IndexMetricsCollectionOptions.Frequency)}%"; + + public IndexMetricsCollectionFunction( + IIndexDataStore indexDataStore, + IOptions featureConfiguration) + { + EnsureArg.IsNotNull(featureConfiguration, nameof(featureConfiguration)); + _indexDataStore = EnsureArg.IsNotNull(indexDataStore, nameof(indexDataStore)); + _externalStoreEnabled = featureConfiguration.Value.EnableExternalStore; + _enableDataPartitions = featureConfiguration.Value.EnableDataPartitions; + } + + /// + /// Asynchronously collects index metrics. + /// + /// The timer which tracks the invocation schedule. + /// A diagnostic logger. + /// A task that represents the asynchronous metrics collection operation. + [FunctionName(nameof(IndexMetricsCollectionFunction))] + public async Task Run( + [TimerTrigger(RunFrequencyVariable)] TimerInfo invocationTimer, + ILogger log) + { + EnsureArg.IsNotNull(invocationTimer, nameof(invocationTimer)); + EnsureArg.IsNotNull(log, nameof(log)); + if (!_externalStoreEnabled) + { + log.LogInformation("External store is not enabled. Skipping index metrics collection."); + return; + } + + if (invocationTimer.IsPastDue) + { + log.LogWarning("Current function invocation is running late."); + } + IndexedFileProperties indexedFileProperties = await _indexDataStore.GetIndexedFileMetricsAsync(); + + log.LogInformation( + "DICOM telemetry - TotalFilesIndexed: {TotalFilesIndexed} , TotalByesIndexed: {TotalContentLengthIndexed} , with ExternalStoreEnabled: {ExternalStoreEnabled} and DataPartitionsEnabled: {PartitionsEnabled}", + indexedFileProperties.TotalIndexed, + indexedFileProperties.TotalSum, + _externalStoreEnabled, + _enableDataPartitions); + } +} \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionOptions.cs b/src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionOptions.cs new file mode 100644 index 0000000000..8eaeef4032 --- /dev/null +++ b/src/Microsoft.Health.Dicom.Functions/MetricsCollection/IndexMetricsCollectionOptions.cs @@ -0,0 +1,26 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System.ComponentModel.DataAnnotations; + +namespace Microsoft.Health.Dicom.Functions.MetricsCollection; + +/// +/// Options on collecting indexing metrics +/// +public class IndexMetricsCollectionOptions +{ + /// + /// The default section name for in a configuration. + /// + public const string SectionName = "IndexMetricsCollection"; + + /// + /// Gets or sets the cron expression that indicates how frequently to run the index metrics collection function. + /// + /// A value cron expression + [Required] + public string Frequency { get; set; } +} diff --git a/src/Microsoft.Health.Dicom.Functions/Registration/ServiceCollectionExtensions.cs b/src/Microsoft.Health.Dicom.Functions/Registration/ServiceCollectionExtensions.cs index efb42dfcf8..d3754fa944 100644 --- a/src/Microsoft.Health.Dicom.Functions/Registration/ServiceCollectionExtensions.cs +++ b/src/Microsoft.Health.Dicom.Functions/Registration/ServiceCollectionExtensions.cs @@ -24,6 +24,7 @@ using Microsoft.Health.Dicom.Functions.DataCleanup; using Microsoft.Health.Dicom.Functions.Export; using Microsoft.Health.Dicom.Functions.Indexing; +using Microsoft.Health.Dicom.Functions.MetricsCollection; using Microsoft.Health.Dicom.Functions.Update; using Microsoft.Health.Dicom.SqlServer.Registration; using Microsoft.Health.Extensions.DependencyInjection; @@ -67,6 +68,7 @@ public static IDicomFunctionsBuilder ConfigureFunctions( .AddFunctionsOptions(configuration, PurgeHistoryOptions.SectionName, isDicomFunction: false) .AddFunctionsOptions(configuration, "DicomServer:Features", isDicomFunction: false) .AddFunctionsOptions(configuration, UpdateOptions.SectionName) + .AddFunctionsOptions(configuration, IndexMetricsCollectionOptions.SectionName) .ConfigureDurableFunctionSerialization() .AddJsonSerializerOptions(o => o.ConfigureDefaultDicomSettings()) .AddSingleton() diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.diff.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.diff.sql new file mode 100644 index 0000000000..81eb7abd2b --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.diff.sql @@ -0,0 +1,31 @@ +SET XACT_ABORT ON + +BEGIN TRANSACTION +GO +CREATE OR ALTER PROCEDURE dbo.GetIndexedFileMetrics + AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; +SELECT TotalIndexedFileCount=COUNT_BIG(*), + TotalIndexedBytes=SUM(ContentLength) +FROM dbo.FileProperty; +END +GO + +COMMIT TRANSACTION + +IF NOT EXISTS +( + SELECT * + FROM sys.indexes + WHERE NAME = 'IXC_FileProperty_ContentLength' + AND Object_id = OBJECT_ID('dbo.FileProperty') +) +BEGIN + CREATE NONCLUSTERED INDEX IXC_FileProperty_ContentLength ON dbo.FileProperty + ( + ContentLength + ) WITH (DATA_COMPRESSION = PAGE, ONLINE = ON) +END +GO \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.sql new file mode 100644 index 0000000000..b99df7063b --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/57.sql @@ -0,0 +1,3674 @@ + +/************************************************************************************************* + Auto-Generated from Sql build task. Do not manually edit it. +**************************************************************************************************/ +SET XACT_ABORT ON +BEGIN TRAN +IF EXISTS (SELECT * + FROM sys.tables + WHERE name = 'Instance') + BEGIN + ROLLBACK; + RETURN; + END + +CREATE SEQUENCE dbo.WatermarkSequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.StudyKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.SeriesKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.InstanceKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.TagKeySequence + AS INT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE SEQUENCE dbo.PartitionKeySequence + AS INT + START WITH 2 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE SEQUENCE dbo.WorkitemKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE SEQUENCE dbo.WorkitemWatermarkSequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE TABLE dbo.ChangeFeed ( + Sequence BIGINT IDENTITY (1, 1) NOT NULL, + Timestamp DATETIMEOFFSET (7) DEFAULT SYSDATETIMEOFFSET() NOT NULL, + Action TINYINT NOT NULL, + StudyInstanceUid VARCHAR (64) NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + SopInstanceUid VARCHAR (64) NOT NULL, + OriginalWatermark BIGINT NOT NULL, + CurrentWatermark BIGINT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + FilePath NVARCHAR (4000) NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ChangeFeed + ON dbo.ChangeFeed(Timestamp, Sequence); + +CREATE NONCLUSTERED INDEX IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.ChangeFeed(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ChangeFeed_Sequence + ON dbo.ChangeFeed(Sequence) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.DeletedInstance ( + StudyInstanceUid VARCHAR (64) NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + SopInstanceUid VARCHAR (64) NOT NULL, + Watermark BIGINT NOT NULL, + DeletedDateTime DATETIMEOFFSET (0) NOT NULL, + RetryCount INT NOT NULL, + CleanupAfter DATETIMEOFFSET (0) NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + OriginalWatermark BIGINT NULL, + FilePath NVARCHAR (4000) NULL, + ETag NVARCHAR (4000) NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_DeletedInstance + ON dbo.DeletedInstance(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark); + +CREATE NONCLUSTERED INDEX IX_DeletedInstance_RetryCount_CleanupAfter + ON dbo.DeletedInstance(RetryCount, CleanupAfter) + INCLUDE(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, OriginalWatermark, FilePath, ETag) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTag ( + TagKey INT NOT NULL, + TagPath VARCHAR (64) NOT NULL, + TagVR VARCHAR (2) NOT NULL, + TagPrivateCreator NVARCHAR (64) NULL, + TagLevel TINYINT NOT NULL, + TagStatus TINYINT NOT NULL, + QueryStatus TINYINT DEFAULT 1 NOT NULL, + ErrorCount INT DEFAULT 0 NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTag + ON dbo.ExtendedQueryTag(TagKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTag_TagPath + ON dbo.ExtendedQueryTag(TagPath); + +CREATE TABLE dbo.ExtendedQueryTagDateTime ( + TagKey INT NOT NULL, + TagValue DATETIME2 (7) NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + TagValueUtc DATETIME2 (7) NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagDateTime + ON dbo.ExtendedQueryTagDateTime(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDateTime_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDateTime(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDateTime_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDateTime(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagDouble ( + TagKey INT NOT NULL, + TagValue FLOAT (53) NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagDouble + ON dbo.ExtendedQueryTagDouble(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDouble_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDouble(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDouble_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDouble(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagError ( + TagKey INT NOT NULL, + ErrorCode SMALLINT NOT NULL, + Watermark BIGINT NOT NULL, + CreatedTime DATETIME2 (7) NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagError + ON dbo.ExtendedQueryTagError(TagKey, Watermark); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagError_CreatedTime_Watermark_TagKey + ON dbo.ExtendedQueryTagError(CreatedTime, Watermark, TagKey) + INCLUDE(ErrorCode); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagError_Watermark + ON dbo.ExtendedQueryTagError(Watermark); + +CREATE TABLE dbo.ExtendedQueryTagLong ( + TagKey INT NOT NULL, + TagValue BIGINT NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagLong + ON dbo.ExtendedQueryTagLong(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagLong_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagLong(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagLong_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagLong(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagOperation ( + TagKey INT NOT NULL, + OperationId UNIQUEIDENTIFIER NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagOperation + ON dbo.ExtendedQueryTagOperation(TagKey); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagOperation_OperationId + ON dbo.ExtendedQueryTagOperation(OperationId) + INCLUDE(TagKey); + +CREATE TABLE dbo.ExtendedQueryTagPersonName ( + TagKey INT NOT NULL, + TagValue NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + WatermarkAndTagKey AS CONCAT(TagKey, '.', Watermark), + TagValueWords AS REPLACE(REPLACE(TagValue, '^', ' '), '=', ' ') PERSISTED, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagPersonName + ON dbo.ExtendedQueryTagPersonName(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagPersonName(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagPersonName_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagPersonName(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey + ON dbo.ExtendedQueryTagPersonName(WatermarkAndTagKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagString ( + TagKey INT NOT NULL, + TagValue NVARCHAR (64) NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagString + ON dbo.ExtendedQueryTagString(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagString_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagString(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagString_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagString(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.FileProperty ( + InstanceKey BIGINT NOT NULL, + Watermark BIGINT NOT NULL, + FilePath NVARCHAR (4000) NOT NULL, + ETag NVARCHAR (4000) NOT NULL, + ContentLength BIGINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_FileProperty + ON dbo.FileProperty(InstanceKey, Watermark) WITH (DATA_COMPRESSION = PAGE, ONLINE = ON); + +CREATE NONCLUSTERED INDEX IXC_FileProperty_InstanceKey_Watermark_ContentLength + ON dbo.FileProperty(InstanceKey, Watermark, ContentLength) WITH (DATA_COMPRESSION = PAGE, ONLINE = ON); + +CREATE NONCLUSTERED INDEX IXC_FileProperty_ContentLength + ON dbo.FileProperty(ContentLength) WITH (DATA_COMPRESSION = PAGE, ONLINE = ON); + +CREATE TABLE dbo.Instance ( + InstanceKey BIGINT NOT NULL, + SeriesKey BIGINT NOT NULL, + StudyKey BIGINT NOT NULL, + StudyInstanceUid VARCHAR (64) NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + SopInstanceUid VARCHAR (64) NOT NULL, + Watermark BIGINT NOT NULL, + Status TINYINT NOT NULL, + LastStatusUpdatedDate DATETIME2 (7) NOT NULL, + CreatedDate DATETIME2 (7) NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + TransferSyntaxUid VARCHAR (64) NULL, + HasFrameMetadata BIT DEFAULT 0 NOT NULL, + OriginalWatermark BIGINT NULL, + NewWatermark BIGINT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Instance + ON dbo.Instance(PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.Instance(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) + INCLUDE(Status, Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.Instance(PartitionKey, Status, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) + INCLUDE(Watermark, TransferSyntaxUid, HasFrameMetadata) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_Watermark_Status + ON dbo.Instance(Watermark, Status) + INCLUDE(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_PartitionKey_SopInstanceUid + ON dbo.Instance(PartitionKey, SopInstanceUid) + INCLUDE(SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyKey_Watermark + ON dbo.Instance(PartitionKey, Status, StudyKey, Watermark) + INCLUDE(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyKey_SeriesKey_Watermark + ON dbo.Instance(PartitionKey, Status, StudyKey, SeriesKey, Watermark) + INCLUDE(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Watermark + ON dbo.Instance(PartitionKey, Watermark) + INCLUDE(StudyKey, SeriesKey, StudyInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyInstanceUid_NewWatermark + ON dbo.Instance(PartitionKey, Status, StudyInstanceUid, NewWatermark) + INCLUDE(SeriesInstanceUid, SopInstanceUid, Watermark, OriginalWatermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_Watermark_Status_CreatedDate + ON dbo.Instance(Watermark, Status, CreatedDate) + INCLUDE(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.Partition ( + PartitionKey INT NOT NULL, + PartitionName VARCHAR (64) NOT NULL, + CreatedDate DATETIME2 (7) NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_Partition + ON dbo.Partition(PartitionKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Partition_PartitionName + ON dbo.Partition(PartitionName) + INCLUDE(PartitionKey); + +INSERT INTO dbo.Partition (PartitionKey, PartitionName, CreatedDate) +VALUES (1, 'Microsoft.Default', SYSUTCDATETIME()); + +CREATE TABLE dbo.Series ( + SeriesKey BIGINT NOT NULL, + StudyKey BIGINT NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + Modality NVARCHAR (16) NULL, + PerformedProcedureStepStartDate DATE NULL, + ManufacturerModelName NVARCHAR (64) NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Series + ON dbo.Series(PartitionKey, StudyKey, SeriesKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Series_PartitionKey_StudyKey_SeriesInstanceUid + ON dbo.Series(PartitionKey, StudyKey, SeriesInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_SeriesInstanceUid + ON dbo.Series(PartitionKey, SeriesInstanceUid) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_Modality + ON dbo.Series(PartitionKey, Modality) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_PerformedProcedureStepStartDate + ON dbo.Series(PartitionKey, PerformedProcedureStepStartDate) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_ManufacturerModelName + ON dbo.Series(PartitionKey, ManufacturerModelName) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.Study ( + StudyKey BIGINT NOT NULL, + StudyInstanceUid VARCHAR (64) NOT NULL, + PatientId NVARCHAR (64) NOT NULL, + PatientName NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI NULL, + ReferringPhysicianName NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI NULL, + StudyDate DATE NULL, + StudyDescription NVARCHAR (64) NULL, + AccessionNumber NVARCHAR (16) NULL, + PatientNameWords AS REPLACE(REPLACE(PatientName, '^', ' '), '=', ' ') PERSISTED, + ReferringPhysicianNameWords AS REPLACE(REPLACE(ReferringPhysicianName, '^', ' '), '=', ' ') PERSISTED, + PatientBirthDate DATE NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Study + ON dbo.Study(PartitionKey, StudyKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Study_StudyKey + ON dbo.Study(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Study_PartitionKey_StudyInstanceUid + ON dbo.Study(PartitionKey, StudyInstanceUid) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_PatientId + ON dbo.Study(PartitionKey, PatientId) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_PatientName + ON dbo.Study(PartitionKey, PatientName) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_ReferringPhysicianName + ON dbo.Study(PartitionKey, ReferringPhysicianName) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_StudyDate + ON dbo.Study(PartitionKey, StudyDate) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_StudyDescription + ON dbo.Study(PartitionKey, StudyDescription) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_AccessionNumber + ON dbo.Study(PartitionKey, AccessionNumber) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_PatientBirthDate + ON dbo.Study(PartitionKey, PatientBirthDate) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.Workitem ( + WorkitemKey BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + WorkitemUid VARCHAR (64) NOT NULL, + TransactionUid VARCHAR (64) NULL, + Status TINYINT NOT NULL, + CreatedDate DATETIME2 (7) NOT NULL, + LastStatusUpdatedDate DATETIME2 (7) NOT NULL, + Watermark BIGINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Workitem + ON dbo.Workitem(PartitionKey, WorkitemKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Workitem_PartitionKey_WorkitemUid + ON dbo.Workitem(PartitionKey, WorkitemUid) + INCLUDE(Watermark, WorkitemKey, Status, TransactionUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Workitem_WorkitemKey_Watermark + ON dbo.Workitem(WorkitemKey, Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.WorkitemQueryTag ( + TagKey INT NOT NULL, + TagPath VARCHAR (64) NOT NULL, + TagVR VARCHAR (2) NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_WorkitemQueryTag + ON dbo.WorkitemQueryTag(TagKey); + +CREATE UNIQUE NONCLUSTERED INDEX IXC_WorkitemQueryTag_TagPath + ON dbo.WorkitemQueryTag(TagPath) WITH (DATA_COMPRESSION = PAGE); + +CREATE TYPE dbo.AddExtendedQueryTagsInputTableType_1 AS TABLE ( + TagPath VARCHAR (64) , + TagVR VARCHAR (2) , + TagPrivateCreator NVARCHAR (64), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertStringExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue NVARCHAR (64), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertDoubleExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue FLOAT (53), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertLongExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue BIGINT , + TagLevel TINYINT); + +CREATE TYPE dbo.InsertDateTimeExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue DATETIME2 (7), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertDateTimeExtendedQueryTagTableType_2 AS TABLE ( + TagKey INT , + TagValue DATETIME2 (7), + TagValueUtc DATETIME2 (7) NULL, + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertPersonNameExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI, + TagLevel TINYINT ); + +CREATE TYPE dbo.ExtendedQueryTagKeyTableType_1 AS TABLE ( + TagKey INT); + +CREATE TYPE dbo.WatermarkTableType AS TABLE ( + Watermark BIGINT); + +CREATE TYPE dbo.FilePropertyTableType AS TABLE ( + Watermark BIGINT NOT NULL INDEX IXC_FilePropertyTableType CLUSTERED, + FilePath NVARCHAR (4000) NOT NULL, + ETag NVARCHAR (4000) NOT NULL); + +CREATE TYPE dbo.FilePropertyTableType_2 AS TABLE ( + Watermark BIGINT NOT NULL INDEX IXC_FilePropertyTableType_2 CLUSTERED, + FilePath NVARCHAR (4000) NOT NULL, + ETag NVARCHAR (4000) NOT NULL, + ContentLength BIGINT NOT NULL); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00100010', 'PN'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00100020', 'LO'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '0040A370.00080050', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '0040A370.00401001', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404005', 'DT'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404025.00080100', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404026.00080100', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00741000', 'CS'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404027.00080100', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '0020000D', 'UI'); + +COMMIT +GO +IF ((SELECT is_read_committed_snapshot_on + FROM sys.databases + WHERE database_id = DB_ID()) = 0) + BEGIN + ALTER DATABASE CURRENT + SET READ_COMMITTED_SNAPSHOT ON; + END + +IF ((SELECT is_auto_update_stats_async_on + FROM sys.databases + WHERE database_id = DB_ID()) = 0) + BEGIN + ALTER DATABASE CURRENT + SET AUTO_UPDATE_STATISTICS_ASYNC ON; + END + +IF ((SELECT is_ansi_nulls_on + FROM sys.databases + WHERE database_id = DB_ID()) = 0) + BEGIN + ALTER DATABASE CURRENT + SET ANSI_NULLS ON; + END + +GO +IF NOT EXISTS (SELECT * + FROM sys.fulltext_catalogs + WHERE name = 'Dicom_Catalog') + BEGIN + CREATE FULLTEXT CATALOG Dicom_Catalog + WITH ACCENT_SENSITIVITY = OFF + AS DEFAULT; + END + + +GO +IF NOT EXISTS (SELECT * + FROM sys.fulltext_indexes + WHERE object_id = object_id('dbo.Study')) + BEGIN + CREATE FULLTEXT INDEX ON Study + (PatientNameWords, ReferringPhysicianNameWords LANGUAGE 1033) + KEY INDEX IX_Study_StudyKey + WITH STOPLIST OFF; + END + + +GO +IF NOT EXISTS (SELECT * + FROM sys.fulltext_indexes + WHERE object_id = object_id('dbo.ExtendedQueryTagPersonName')) + BEGIN + CREATE FULLTEXT INDEX ON ExtendedQueryTagPersonName + (TagValueWords LANGUAGE 1033) + KEY INDEX IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey + WITH STOPLIST OFF; + END + +GO +CREATE OR ALTER PROCEDURE dbo.AddExtendedQueryTagError +@tagKey INT, @errorCode SMALLINT, @watermark BIGINT +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN TRANSACTION; +DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); +IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (UPDLOCK) + WHERE Watermark = @watermark + AND Status = 1) + THROW 50404, 'Instance does not exist or has not been created.', 1; +IF NOT EXISTS (SELECT * + FROM dbo.ExtendedQueryTag WITH (UPDLOCK) + WHERE TagKey = @tagKey + AND TagStatus = 0) + THROW 50404, 'Tag does not exist or is not being added.', 1; +DECLARE @addedCount AS SMALLINT; +SET @addedCount = 1; +MERGE INTO dbo.ExtendedQueryTagError WITH (HOLDLOCK) + AS XQTE +USING (SELECT @tagKey AS TagKey, + @errorCode AS ErrorCode, + @watermark AS Watermark) AS src ON src.TagKey = XQTE.TagKey + AND src.WaterMark = XQTE.Watermark +WHEN MATCHED THEN UPDATE +SET CreatedTime = @currentDate, + ErrorCode = @errorCode, + @addedCount = 0 +WHEN NOT MATCHED THEN INSERT (TagKey, ErrorCode, Watermark, CreatedTime) VALUES (@tagKey, @errorCode, @watermark, @currentDate) OUTPUT INSERTED.TagKey; +UPDATE dbo.ExtendedQueryTag +SET QueryStatus = 0, + ErrorCount = ErrorCount + @addedCount +WHERE TagKey = @tagKey; +COMMIT TRANSACTION; + +GO +CREATE OR ALTER PROCEDURE dbo.AddExtendedQueryTags +@extendedQueryTags dbo.AddExtendedQueryTagsInputTableType_1 READONLY, @maxAllowedCount INT=128, @ready BIT=0 +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN + BEGIN TRANSACTION; + IF (SELECT COUNT(*) + FROM dbo.ExtendedQueryTag AS XQT WITH (UPDLOCK, HOLDLOCK) + FULL OUTER JOIN + @extendedQueryTags AS input + ON XQT.TagPath = input.TagPath) > @maxAllowedCount + THROW 50409, 'extended query tags exceed max allowed count', 1; + DECLARE @existingTags TABLE ( + TagKey INT , + TagStatus TINYINT , + OperationId UNIQUEIDENTIFIER NULL); + INSERT INTO @existingTags (TagKey, TagStatus, OperationId) + SELECT XQT.TagKey, + TagStatus, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @extendedQueryTags AS input + ON input.TagPath = XQT.TagPath + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey; + IF EXISTS (SELECT 1 + FROM @existingTags + WHERE TagStatus <> 0 + OR (TagStatus = 0 + AND OperationId IS NOT NULL)) + THROW 50409, 'extended query tag(s) already exist', 2; + DELETE XQT + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @existingTags AS et + ON XQT.TagKey = et.TagKey; + INSERT INTO dbo.ExtendedQueryTag (TagKey, TagPath, TagPrivateCreator, TagVR, TagLevel, TagStatus, QueryStatus, ErrorCount) + OUTPUT INSERTED.TagKey, INSERTED.TagPath, INSERTED.TagVR, INSERTED.TagPrivateCreator, INSERTED.TagLevel, INSERTED.TagStatus, INSERTED.QueryStatus, INSERTED.ErrorCount + SELECT NEXT VALUE FOR TagKeySequence, + TagPath, + TagPrivateCreator, + TagVR, + TagLevel, + @ready, + 1, + 0 + FROM @extendedQueryTags; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddInstanceV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @patientId NVARCHAR (64), @patientName NVARCHAR (325)=NULL, @referringPhysicianName NVARCHAR (325)=NULL, @studyDate DATE=NULL, @studyDescription NVARCHAR (64)=NULL, @accessionNumber NVARCHAR (64)=NULL, @modality NVARCHAR (16)=NULL, @performedProcedureStepStartDate DATE=NULL, @patientBirthDate DATE=NULL, @manufacturerModelName NVARCHAR (64)=NULL, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT, @transferSyntaxUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT OFF; + BEGIN TRY + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @existingStatus AS TINYINT; + DECLARE @newWatermark AS BIGINT; + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + SELECT @existingStatus = Status + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Instance already exists', @existingStatus; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + SET @instanceKey = NEXT VALUE FOR dbo.InstanceKeySequence; + SELECT @studyKey = StudyKey + FROM dbo.Study WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + BEGIN TRY + SET @studyKey = NEXT VALUE FOR dbo.StudyKeySequence; + INSERT INTO dbo.Study (PartitionKey, StudyKey, StudyInstanceUid, PatientId, PatientName, PatientBirthDate, ReferringPhysicianName, StudyDate, StudyDescription, AccessionNumber) + VALUES (@partitionKey, @studyKey, @studyInstanceUid, @patientId, @patientName, @patientBirthDate, @referringPhysicianName, @studyDate, @studyDescription, @accessionNumber); + END TRY + BEGIN CATCH + IF ERROR_NUMBER() = 2601 + BEGIN + SELECT @studyKey = StudyKey + FROM dbo.Study WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + UPDATE dbo.Study + SET PatientId = (CASE WHEN @patientId IS NOT NULL + AND @patientId <> '' THEN @patientId ELSE PatientId END), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + ELSE + THROW; + END CATCH + ELSE + BEGIN + UPDATE dbo.Study + SET PatientId = (CASE WHEN @patientId IS NOT NULL + AND @patientId <> '' THEN @patientId ELSE PatientId END), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + SELECT @seriesKey = SeriesKey + FROM dbo.Series WITH (UPDLOCK) + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = @seriesInstanceUid + AND PartitionKey = @partitionKey; + IF @@ROWCOUNT = 0 + BEGIN + SET @seriesKey = NEXT VALUE FOR dbo.SeriesKeySequence; + INSERT INTO dbo.Series (PartitionKey, StudyKey, SeriesKey, SeriesInstanceUid, Modality, PerformedProcedureStepStartDate, ManufacturerModelName) + VALUES (@partitionKey, @studyKey, @seriesKey, @seriesInstanceUid, @modality, @performedProcedureStepStartDate, @manufacturerModelName); + END + ELSE + BEGIN + UPDATE dbo.Series + SET Modality = ISNULL(@modality, Modality), + PerformedProcedureStepStartDate = ISNULL(@performedProcedureStepStartDate, PerformedProcedureStepStartDate), + ManufacturerModelName = ISNULL(@manufacturerModelName, ManufacturerModelName) + WHERE SeriesKey = @seriesKey + AND StudyKey = @studyKey + AND PartitionKey = @partitionKey; + END + INSERT INTO dbo.Instance (PartitionKey, StudyKey, SeriesKey, InstanceKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, Status, LastStatusUpdatedDate, CreatedDate, TransferSyntaxUid) + VALUES (@partitionKey, @studyKey, @seriesKey, @instanceKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @newWatermark, @initialStatus, @currentDate, @currentDate, @transferSyntaxUid); + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, @seriesKey, @instanceKey, @newWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @newWatermark; + COMMIT TRANSACTION; + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK; + THROW; + END CATCH +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddPartition +@partitionName VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @createdDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @partitionKey AS INT; + SELECT @partitionKey = PartitionKey + FROM dbo.Partition + WHERE PartitionName = @partitionName; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Partition already exists', 1; + SET @partitionKey = NEXT VALUE FOR dbo.PartitionKeySequence; + INSERT INTO dbo.Partition (PartitionKey, PartitionName, CreatedDate) + VALUES (@partitionKey, @partitionName, @createdDate); + SELECT @partitionKey, + @partitionName, + @createdDate; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddWorkitem +@partitionKey INT, @workitemUid VARCHAR (64), @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @workitemKey AS BIGINT; + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Workitem already exists', 1; + SET @workitemKey = NEXT VALUE FOR dbo.WorkitemKeySequence; + INSERT INTO dbo.Workitem (WorkitemKey, PartitionKey, WorkitemUid, Status, CreatedDate, LastStatusUpdatedDate) + VALUES (@workitemKey, @partitionKey, @workitemUid, @initialStatus, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexWorkitemInstanceCore @partitionKey, @workitemKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @workitemKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddWorkitemV11 +@partitionKey INT, @workitemUid VARCHAR (64), @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @watermark AS BIGINT; + DECLARE @workitemKey AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Workitem already exists', 1; + SET @workitemKey = NEXT VALUE FOR dbo.WorkitemKeySequence; + SET @watermark = NEXT VALUE FOR dbo.WorkitemWatermarkSequence; + INSERT INTO dbo.Workitem (WorkitemKey, PartitionKey, WorkitemUid, Status, Watermark, CreatedDate, LastStatusUpdatedDate) + VALUES (@workitemKey, @partitionKey, @workitemUid, @initialStatus, @watermark, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexWorkitemInstanceCore @partitionKey, @workitemKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; + SELECT @workitemKey, + @watermark; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AssignReindexingOperation +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY, @operationId UNIQUEIDENTIFIER, @returnIfCompleted BIT=0 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + MERGE INTO dbo.ExtendedQueryTagOperation WITH (HOLDLOCK) + AS XQTO + USING (SELECT input.TagKey + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT WITH (HOLDLOCK) + ON input.TagKey = XQT.TagKey + WHERE TagStatus = 0) AS tags ON XQTO.TagKey = tags.TagKey + WHEN NOT MATCHED THEN INSERT (TagKey, OperationId) VALUES (tags.TagKey, @operationId); + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT WITH (HOLDLOCK) + ON input.TagKey = XQT.TagKey + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO WITH (HOLDLOCK) + ON XQT.TagKey = XQTO.TagKey + WHERE (@returnIfCompleted = 1 + AND TagStatus = 1) + OR (OperationId = @operationId + AND TagStatus = 0); + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstance +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE i + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + WHERE Status = 1; + COMMIT TRANSACTION; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + i.Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + WHERE Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstanceV33 +@partitionKey INT, @studyInstanceUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; + COMMIT TRANSACTION; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstanceV46 +@partitionKey INT, @studyInstanceUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; + COMMIT TRANSACTION; + SELECT i.StudyInstanceUid, + i.SeriesInstanceUid, + i.SopInstanceUid, + i.Watermark, + i.TransferSyntaxUid, + i.HasFrameMetadata, + i.OriginalWatermark, + i.NewWatermark, + f.FilePath, + f.ETag + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS f + ON f.InstanceKey = i.InstanceKey + AND f.Watermark = i.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.CompleteReindexing +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE XQT + SET TagStatus = 1 + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @extendedQueryTagKeys AS input + ON XQT.TagKey = input.TagKey + WHERE TagStatus = 0; + DELETE XQTO + OUTPUT DELETED.TagKey + FROM dbo.ExtendedQueryTagOperation AS XQTO + INNER JOIN + dbo.ExtendedQueryTag AS XQT + ON XQTO.TagKey = XQT.TagKey + INNER JOIN + @extendedQueryTagKeys AS input + ON XQT.TagKey = input.TagKey + WHERE TagStatus = 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteDeletedInstance +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT +AS +SET NOCOUNT ON; +DELETE dbo.DeletedInstance +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteDeletedInstanceV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT +AS +SET NOCOUNT ON; +DELETE dbo.DeletedInstance +WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTag +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagStatus AS TINYINT; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey, + @tagStatus = TagStatus + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + IF @tagStatus = 2 + THROW 50412, 'extended query tag is not in Ready or Adding status', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 1 + DELETE dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 2 + DELETE dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 3 + DELETE dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey; + ELSE + DELETE dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV16 +@tagPath VARCHAR (64), @dataType TINYINT, @batchSize INT=1000 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @deletedRows AS INT; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + SET @deletedRows = @batchSize; + WHILE (@deletedRows = @batchSize) + BEGIN + EXECUTE dbo.ISleepIfBusy ; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 1 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 2 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 3 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + SET @deletedRows = @@ROWCOUNT; + COMMIT TRANSACTION; + CHECKPOINT; + END + SET @deletedRows = @batchSize; + WHILE (@deletedRows = @batchSize) + BEGIN + EXECUTE dbo.ISleepIfBusy ; + BEGIN TRANSACTION; + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + SET @deletedRows = @@ROWCOUNT; + COMMIT TRANSACTION; + CHECKPOINT; + END + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV8 +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 1 + DELETE dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 2 + DELETE dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 3 + DELETE dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + DELETE dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteInstanceV6 +@cleanupAfter DATETIMEOFFSET (0), @createdStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @deletedInstances AS TABLE ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64) , + SeriesInstanceUid VARCHAR (64) , + SopInstanceUid VARCHAR (64) , + Status TINYINT , + Watermark BIGINT , + InstanceKey INT , + OriginalWatermark BIGINT , + FilePath NVARCHAR (4000) NULL, + ETag NVARCHAR (4000) NULL); + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @deletedDate AS DATETIME2 = SYSUTCDATETIME(); + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @studyKey = StudyKey, + @seriesKey = CASE @seriesInstanceUid WHEN NULL THEN NULL ELSE SeriesKey END, + @instanceKey = CASE @sopInstanceUid WHEN NULL THEN NULL ELSE InstanceKey END + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid); + DELETE dbo.Instance + OUTPUT deleted.PartitionKey, deleted.StudyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.Status, deleted.Watermark, deleted.InstanceKey, deleted.OriginalWatermark, FP.FilePath, FP.ETag INTO @deletedInstances + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS FP + ON i.InstanceKey = FP.InstanceKey + AND i.Watermark = FP.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.SeriesInstanceUid = ISNULL(@seriesInstanceUid, i.SeriesInstanceUid) + AND i.SopInstanceUid = ISNULL(@sopInstanceUid, i.SopInstanceUid); + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance not found', 1; + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + @deletedInstances AS DI + ON DI.InstanceKey = FP.InstanceKey + AND DI.Watermark = FP.Watermark; + DECLARE @deletedTags AS TABLE ( + TagKey BIGINT); + DELETE XQTE + OUTPUT deleted.TagKey INTO @deletedTags + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + @deletedInstances AS DI + ON XQTE.Watermark = DI.Watermark; + IF EXISTS (SELECT * + FROM @deletedTags) + BEGIN + DECLARE @deletedTagCounts AS TABLE ( + TagKey BIGINT, + ErrorCount INT ); + INSERT INTO @deletedTagCounts (TagKey, ErrorCount) + SELECT TagKey, + COUNT(1) + FROM @deletedTags + GROUP BY TagKey; + UPDATE XQT + SET XQT.ErrorCount = XQT.ErrorCount - DTC.ErrorCount + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @deletedTagCounts AS DTC + ON XQT.TagKey = DTC.TagKey; + END + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + INSERT INTO dbo.DeletedInstance (PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, DeletedDateTime, RetryCount, CleanupAfter, OriginalWatermark, FilePath, ETag) + SELECT PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + @deletedDate, + 0, + @cleanupAfter, + OriginalWatermark, + FilePath, + ETag + FROM @deletedInstances; + IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (HOLDLOCK, UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey)) + BEGIN + DELETE dbo.Series + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + END + IF NOT EXISTS (SELECT * + FROM dbo.Series WITH (HOLDLOCK, UPDLOCK) + WHERE Studykey = @studyKey + AND PartitionKey = @partitionKey) + BEGIN + DELETE dbo.Study + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + END + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 1, + DI.PartitionKey, + DI.StudyInstanceUid, + DI.SeriesInstanceUid, + DI.SopInstanceUid, + DI.Watermark + FROM @deletedInstances AS DI + WHERE Status = @createdStatus; + UPDATE CF + SET CF.CurrentWatermark = NULL + FROM dbo.ChangeFeed AS CF WITH (FORCESEEK) + INNER JOIN + @deletedInstances AS DI + ON CF.PartitionKey = DI.PartitionKey + AND CF.StudyInstanceUid = DI.StudyInstanceUid + AND CF.SeriesInstanceUid = DI.SeriesInstanceUid + AND CF.SopInstanceUid = DI.SopInstanceUid; + COMMIT TRANSACTION; + SELECT d.Watermark, + d.partitionKey, + d.studyInstanceUid, + d.seriesInstanceUid, + d.sopInstanceUid + FROM @deletedInstances AS d; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteWorkitem +@partitionKey INT, @workitemUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @workitemKey AS BIGINT; + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT = 0 + THROW 50413, 'Workitem does not exists', 1; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.Workitem + WHERE WorkItemKey = @workitemKey + AND PartitionKey = @partitionKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstance +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @updatedInstances AS TABLE ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT ); + DELETE @updatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.NewWatermark INTO @updatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM @updatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark + FROM dbo.ChangeFeed AS C + INNER JOIN + @updatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV44 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV50 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @resourceType AS TINYINT = 0; + DECLARE @studyKey AS BIGINT; + DECLARE @maxWatermark AS BIGINT; + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + SELECT @maxWatermark = max(Watermark) + FROM #UpdatedInstances; + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, NULL, NULL, @maxWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV52 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @referringPhysicianName NVARCHAR (325)=NULL, @studyDescription NVARCHAR (64)=NULL, @accessionNumber NVARCHAR (64)=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @resourceType AS TINYINT = 0; + DECLARE @studyKey AS BIGINT; + DECLARE @maxWatermark AS BIGINT; + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + SELECT @maxWatermark = max(Watermark) + FROM #UpdatedInstances; + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, NULL, NULL, @maxWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV54 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @referringPhysicianName NVARCHAR (325)=NULL, @studyDescription NVARCHAR (64)=NULL, @accessionNumber NVARCHAR (64)=NULL, @insertFileProperties dbo.FilePropertyTableType_2 READONLY, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @resourceType AS TINYINT = 0; + DECLARE @studyKey AS BIGINT; + DECLARE @maxWatermark AS BIGINT; + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag, ContentLength) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag, + I.ContentLength + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + SELECT @maxWatermark = max(Watermark) + FROM #UpdatedInstances; + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, NULL, NULL, @maxWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeed +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT Sequence, + Timestamp, + Action, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed + WHERE Sequence BETWEEN @offset + 1 AND @offset + @limit + ORDER BY Sequence; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedByTime +@startTime DATETIMEOFFSET (7), @endTime DATETIMEOFFSET (7), @limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE c.Timestamp >= @startTime + AND c.Timestamp < @endTime + ORDER BY Timestamp, Sequence + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedByTimeV39 +@startTime DATETIMEOFFSET (7), @endTime DATETIMEOFFSET (7), @limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE c.Timestamp >= @startTime + AND c.Timestamp < @endTime + ORDER BY c.Timestamp, c.Sequence + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatest +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) Sequence, + Timestamp, + Action, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed + ORDER BY Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestByTime +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY Timestamp DESC, Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestByTimeV39 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY c.Timestamp DESC, c.Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestV39 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY c.Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestV6 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedV39 +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE c.Sequence BETWEEN @offset + 1 AND @offset + @limit + ORDER BY c.Sequence; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedV6 +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE Sequence BETWEEN @offset + 1 AND @offset + @limit + ORDER BY Sequence; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetContentLengthBackFillInstanceBatches +@batchSize INT, @batchCount INT +AS +BEGIN + SET NOCOUNT ON; + SELECT MIN(Watermark) AS MinWatermark, + MAX(Watermark) AS MaxWatermark + FROM (SELECT TOP (@batchSize * @batchCount) I.Watermark, + (ROW_NUMBER() OVER (ORDER BY I.Watermark DESC) - 1) / @batchSize AS Batch + FROM dbo.Instance AS I + INNER JOIN + dbo.FileProperty AS FP + ON FP.Watermark = I.Watermark + WHERE FP.ContentLength = 0) AS I + GROUP BY Batch + ORDER BY Batch ASC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetContentLengthBackFillInstanceIdentifiersByWatermarkRange +@startWatermark BIGINT, @endWatermark BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT I.StudyInstanceUid, + I.SeriesInstanceUid, + I.SopInstanceUid, + I.Watermark, + P.PartitionName, + P.PartitionKey + FROM dbo.Instance AS I + INNER JOIN + dbo.Partition AS P + ON P.PartitionKey = I.PartitionKey + INNER JOIN + dbo.FileProperty AS FP + ON FP.Watermark = I.Watermark + WHERE I.Watermark BETWEEN @startWatermark AND @endWatermark + AND FP.ContentLength = 0 + AND I.Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetCurrentAndNextWorkitemWatermark +@workitemKey BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + IF NOT EXISTS (SELECT WorkitemKey + FROM dbo.Workitem + WHERE WorkitemKey = @workitemKey) + THROW 50409, 'Workitem does not exist', 1; + DECLARE @proposedWatermark AS BIGINT; + SET @proposedWatermark = NEXT VALUE FOR dbo.WorkitemWatermarkSequence; + SELECT Watermark, + @proposedWatermark AS ProposedWatermark + FROM dbo.Workitem + WHERE WorkitemKey = @workitemKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTag +@tagPath VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + WHERE TagPath = ISNULL(@tagPath, TagPath); +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagErrors +@tagPath VARCHAR (64), @limit INT, @offset INT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF (@@ROWCOUNT = 0) + THROW 50404, 'extended query tag not found', 1; + SELECT TagKey, + ErrorCode, + CreatedTime, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + dbo.Instance AS I + ON XQTE.Watermark = I.Watermark + WHERE XQTE.TagKey = @tagKey + ORDER BY CreatedTime ASC, XQTE.Watermark ASC, TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagErrorsV36 +@tagPath VARCHAR (64), @limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF (@@ROWCOUNT = 0) + THROW 50404, 'extended query tag not found', 1; + SELECT TagKey, + ErrorCode, + CreatedTime, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + dbo.Instance AS I + ON XQTE.Watermark = I.Watermark + INNER JOIN + dbo.Partition AS P + ON P.PartitionKey = I.PartitionKey + WHERE XQTE.TagKey = @tagKey + ORDER BY CreatedTime ASC, XQTE.Watermark ASC, TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagErrorsV6 +@tagPath VARCHAR (64), @limit INT, @offset INT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF (@@ROWCOUNT = 0) + THROW 50404, 'extended query tag not found', 1; + SELECT TagKey, + ErrorCode, + CreatedTime, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + dbo.Instance AS I + ON XQTE.Watermark = I.Watermark + INNER JOIN + dbo.Partition AS P + ON P.PartitionKey = I.PartitionKey + WHERE XQTE.TagKey = @tagKey + ORDER BY CreatedTime ASC, XQTE.Watermark ASC, TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTags +@limit INT, @offset INT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + ORDER BY XQT.TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagsByKey +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT + ON input.TagKey = XQT.TagKey + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagsByOperation +@operationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + WHERE OperationId = @operationId; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagsV36 +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + ORDER BY XQT.TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetIndexedFileMetrics +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT COUNT_BIG(*) AS TotalIndexedFileCount, + SUM(ContentLength) AS TotalIndexedBytes + FROM dbo.FileProperty; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstance +@validStatus TINYINT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceBatches +@batchSize INT, @batchCount INT, @status TINYINT, @maxWatermark BIGINT=NULL +AS +BEGIN + SET NOCOUNT ON; + SELECT MIN(Watermark) AS MinWatermark, + MAX(Watermark) AS MaxWatermark + FROM (SELECT TOP (@batchSize * @batchCount) Watermark, + (ROW_NUMBER() OVER (ORDER BY Watermark DESC) - 1) / @batchSize AS Batch + FROM dbo.Instance + WHERE Watermark <= ISNULL(@maxWatermark, Watermark) + AND Status = @status) AS I + GROUP BY Batch + ORDER BY Batch ASC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceBatchesByTimeStamp +@batchSize INT, @batchCount INT, @status TINYINT, @startTimeStamp DATETIMEOFFSET (0), @endTimeStamp DATETIMEOFFSET (0), @maxWatermark BIGINT=NULL +AS +BEGIN + SET NOCOUNT ON; + SELECT MIN(Watermark) AS MinWatermark, + MAX(Watermark) AS MaxWatermark + FROM (SELECT TOP (@batchSize * @batchCount) Watermark, + (ROW_NUMBER() OVER (ORDER BY Watermark DESC) - 1) / @batchSize AS Batch + FROM dbo.Instance + WHERE Watermark <= ISNULL(@maxWatermark, Watermark) + AND Status = @status + AND CreatedDate >= @startTimeStamp + AND CreatedDate <= @endTimeStamp) AS I + GROUP BY Batch + ORDER BY Batch ASC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstancesByWatermarkRange +@startWatermark BIGINT, @endWatermark BIGINT, @status TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE Watermark BETWEEN @startWatermark AND @endWatermark + AND Status = @status; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstancesByWatermarkRangeV6 +@startWatermark BIGINT, @endWatermark BIGINT, @status TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE Watermark BETWEEN @startWatermark AND @endWatermark + AND Status = @status; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceV6 +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceWithProperties +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceWithPropertiesV32 +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceWithPropertiesV46 +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT i.StudyInstanceUid, + i.SeriesInstanceUid, + i.SopInstanceUid, + i.Watermark, + i.TransferSyntaxUid, + i.HasFrameMetadata, + i.OriginalWatermark, + i.NewWatermark, + f.FilePath, + f.ETag + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS f + ON f.InstanceKey = i.InstanceKey + AND f.Watermark = i.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND i.SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND i.Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetPartition +@partitionName VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT PartitionKey, + PartitionName, + CreatedDate + FROM dbo.Partition + WHERE PartitionName = @partitionName; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetPartitions +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT PartitionKey, + PartitionName, + CreatedDate + FROM dbo.Partition; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetSeriesResult +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT DISTINCT i.StudyInstanceUid, + sv.SeriesInstanceUid, + sv.Modality, + sv.PerformedProcedureStepStartDate, + sv.ManufacturerModelName, + sv.NumberofSeriesRelatedInstances + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + INNER JOIN + dbo.SeriesResultView AS sv + ON i.StudyKey = sv.StudyKey + AND i.SeriesKey = sv.SeriesKey + AND i.PartitionKey = sv.PartitionKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetStudyResult +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT DISTINCT sv.StudyInstanceUid, + sv.PatientId, + sv.PatientName, + sv.ReferringPhysicianName, + sv.StudyDate, + sv.StudyDescription, + sv.AccessionNumber, + sv.PatientBirthDate, + sv.ModalitiesInStudy, + sv.NumberofStudyRelatedInstances + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + INNER JOIN + dbo.StudyResultView AS sv + ON i.StudyKey = sv.StudyKey + AND i.PartitionKey = sv.PartitionKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetWorkitemMetadata +@partitionKey INT, @workitemUid VARCHAR (64), @procedureStepStateTagPath VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT wi.WorkitemUid, + wi.WorkitemKey, + wi.PartitionKey, + wi.[Status], + wi.TransactionUid, + wi.Watermark, + eqt.TagValue AS ProcedureStepState + FROM dbo.WorkitemQueryTag AS wqt + INNER JOIN + dbo.ExtendedQueryTagString AS eqt + ON eqt.ResourceType = 1 + AND eqt.TagKey = wqt.TagKey + AND wqt.TagPath = @procedureStepStateTagPath + INNER JOIN + dbo.Workitem AS wi + ON wi.WorkitemKey = eqt.SopInstanceKey1 + AND wi.PartitionKey = eqt.PartitionKey + WHERE wi.PartitionKey = @partitionKey + AND wi.WorkitemUid = @workitemUid; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem does not exist', 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetWorkitemQueryTags +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TagKey, + TagPath, + TagVR + FROM dbo.WorkItemQueryTag; +END + +GO +CREATE OR ALTER PROCEDURE dbo.IIndexInstanceCoreV9 +@partitionKey INT=1, @studyKey BIGINT, @seriesKey BIGINT, @instanceKey BIGINT, @watermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + DECLARE @resourceType AS TINYINT = 0; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagString + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @stringExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND (T.SopInstanceKey2 IS NULL + OR T.SopInstanceKey2 = @seriesKey) + AND (T.SopInstanceKey3 IS NULL + OR T.SopInstanceKey3 = @instanceKey) + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @longExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagLong + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @longExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND (T.SopInstanceKey2 IS NULL + OR T.SopInstanceKey2 = @seriesKey) + AND (T.SopInstanceKey3 IS NULL + OR T.SopInstanceKey3 = @instanceKey) + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @doubleExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDouble + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @doubleExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND (T.SopInstanceKey2 IS NULL + OR T.SopInstanceKey2 = @seriesKey) + AND (T.SopInstanceKey3 IS NULL + OR T.SopInstanceKey3 = @instanceKey) + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDateTime + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagValueUtc, + input.TagLevel + FROM @dateTimeExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND (T.SopInstanceKey2 IS NULL + OR T.SopInstanceKey2 = @seriesKey) + AND (T.SopInstanceKey3 IS NULL + OR T.SopInstanceKey3 = @instanceKey) + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, TagValueUtc, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, S.TagValueUtc, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagPersonName + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @personNameExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND (T.SopInstanceKey2 IS NULL + OR T.SopInstanceKey2 = @seriesKey) + AND (T.SopInstanceKey3 IS NULL + OR T.SopInstanceKey3 = @instanceKey) + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.IIndexWorkitemInstanceCore +@partitionKey INT=1, @workitemKey BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @newWatermark AS BIGINT; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + INSERT dbo.ExtendedQueryTagString (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) + SELECT input.TagKey, + input.TagValue, + @partitionKey, + @workitemKey, + NULL, + NULL, + @newWatermark, + @workitemResourceType + FROM @stringExtendedQueryTags AS input + INNER JOIN + dbo.WorkitemQueryTag + ON dbo.WorkitemQueryTag.TagKey = input.TagKey; + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + INSERT dbo.ExtendedQueryTagDateTime (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) + SELECT input.TagKey, + input.TagValue, + @partitionKey, + @workitemKey, + NULL, + NULL, + @newWatermark, + @workitemResourceType + FROM @dateTimeExtendedQueryTags AS input + INNER JOIN + dbo.WorkitemQueryTag + ON dbo.WorkitemQueryTag.TagKey = input.TagKey; + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + INSERT dbo.ExtendedQueryTagPersonName (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) + SELECT input.TagKey, + input.TagValue, + @partitionKey, + @workitemKey, + NULL, + NULL, + @newWatermark, + @workitemResourceType + FROM @personNameExtendedQueryTags AS input + INNER JOIN + dbo.WorkitemQueryTag + ON dbo.WorkitemQueryTag.TagKey = input.TagKey; + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.IncrementDeletedInstanceRetry +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @cleanupAfter DATETIMEOFFSET (0) +AS +SET NOCOUNT ON; +DECLARE @retryCount AS INT; +UPDATE dbo.DeletedInstance +SET @retryCount = RetryCount = RetryCount + 1, + CleanupAfter = @cleanupAfter +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; +SELECT @retryCount; + +GO +CREATE OR ALTER PROCEDURE dbo.IncrementDeletedInstanceRetryV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @cleanupAfter DATETIMEOFFSET (0) +AS +SET NOCOUNT ON; +DECLARE @retryCount AS INT; +UPDATE dbo.DeletedInstance +SET @retryCount = RetryCount = RetryCount + 1, + CleanupAfter = @cleanupAfter +WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; +SELECT @retryCount; + +GO +CREATE OR ALTER PROCEDURE dbo.IndexInstanceV6 +@watermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @partitionKey AS BIGINT; + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @status AS TINYINT; + SELECT @partitionKey = PartitionKey, + @studyKey = StudyKey, + @seriesKey = SeriesKey, + @instanceKey = InstanceKey, + @status = Status + FROM dbo.Instance WITH (UPDLOCK) + WHERE Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + IF @status <> 1 + THROW 50409, 'Instance has not yet been stored succssfully', 1; + DECLARE @maxTagLevel AS TINYINT; + SELECT @maxTagLevel = MAX(TagLevel) + FROM (SELECT TagLevel + FROM @stringExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @longExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @doubleExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @dateTimeExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @personNameExtendedQueryTags) AS AllEntries; + IF @maxTagLevel > 1 + BEGIN + SELECT 1 + FROM dbo.Study WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + IF @maxTagLevel > 0 + BEGIN + SELECT 1 + FROM dbo.Series WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + AND SeriesKey = @seriesKey; + END + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, @seriesKey, @instanceKey, @watermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.ISleepIfBusy +AS +BEGIN + DECLARE @throttleCount AS INT; + DECLARE @activeRequestCount AS INT; + DECLARE @sleepersCount AS INT; + DECLARE @throttleActiveRequestCount AS INT; + IF (@@TRANCOUNT > 0) + THROW 50400, 'Cannot sleep in transaction', 1; + WHILE (1 = 1) + BEGIN + SELECT @throttleCount = ISNULL(SUM(CASE WHEN r.wait_type IN ('IO_QUEUE_LIMIT', 'LOG_RATE_GOVERNOR', 'SE_REPL_CATCHUP_THROTTLE', 'SE_REPL_SLOW_SECONDARY_THROTTLE', 'HADR_SYNC_COMMIT') THEN 1 ELSE 0 END), 0), + @sleepersCount = ISNULL(SUM(CASE WHEN r.wait_type IN ('WAITFOR') THEN 1 ELSE 0 END), 0), + @activeRequestCount = COUNT(*) + FROM sys.dm_exec_requests AS r WITH (NOLOCK) + INNER JOIN + sys.dm_exec_sessions AS s WITH (NOLOCK) + ON s.session_id = r.session_id + WHERE r.session_id <> @@spid + AND s.is_user_process = 1; + SET @activeRequestCount = @activeRequestCount - @sleepersCount; + IF (@throttleCount > 0) + BEGIN + RAISERROR ('Throttling due to write waits', 10, 0) + WITH NOWAIT; + WAITFOR DELAY '00:00:02'; + END + ELSE + IF (@activeRequestCount >= 0) + BEGIN + IF (@throttleActiveRequestCount IS NULL) + BEGIN TRY + IF (OBJECT_ID('sys.dm_os_sys_info') IS NOT NULL) + BEGIN + SELECT @throttleActiveRequestCount = cpu_count * 3 + FROM sys.dm_os_sys_info; + IF (@throttleActiveRequestCount < 10) + BEGIN + SET @throttleActiveRequestCount = 10; + END + ELSE + IF (@throttleActiveRequestCount > 100) + BEGIN + SET @throttleActiveRequestCount = 100; + END + END + END TRY + BEGIN CATCH + END CATCH + IF (@throttleActiveRequestCount IS NULL) + BEGIN + SET @throttleActiveRequestCount = 20; + END + IF (@activeRequestCount > @throttleActiveRequestCount) + BEGIN + RAISERROR ('Throttling due to active requests being >= %d. Number of active requests = %d', 10, 0, @throttleActiveRequestCount, @activeRequestCount) + WITH NOWAIT; + WAITFOR DELAY '00:00:01'; + END + ELSE + BEGIN + BREAK; + END + END + ELSE + BEGIN + BREAK; + END + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.RetrieveDeletedInstance +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.DeletedInstance WITH (UPDLOCK, READPAST) + WHERE RetryCount <= @maxRetries + AND CleanupAfter < SYSUTCDATETIME(); +END + +GO +CREATE OR ALTER PROCEDURE dbo.RetrieveDeletedInstanceV42 +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) p.PartitionName, + d.PartitionKey, + d.StudyInstanceUid, + d.SeriesInstanceUid, + d.SopInstanceUid, + d.Watermark, + d.OriginalWatermark, + d.FilePath, + d.ETag + FROM dbo.DeletedInstance AS d WITH (UPDLOCK, READPAST) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = d.PartitionKey + WHERE RetryCount <= @maxRetries + AND CleanupAfter < SYSUTCDATETIME(); +END + +GO +CREATE OR ALTER PROCEDURE dbo.RetrieveDeletedInstanceV6 +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + OriginalWatermark + FROM dbo.DeletedInstance WITH (UPDLOCK, READPAST) + WHERE RetryCount <= @maxRetries + AND CleanupAfter < SYSUTCDATETIME(); +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateExtendedQueryTagQueryStatus +@tagPath VARCHAR (64), @queryStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + UPDATE XQT + SET QueryStatus = @queryStatus + OUTPUT INSERTED.TagKey, INSERTED.TagPath, INSERTED.TagVR, INSERTED.TagPrivateCreator, INSERTED.TagLevel, INSERTED.TagStatus, INSERTED.QueryStatus, INSERTED.ErrorCount, XQTO.OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + WHERE TagPath = @tagPath; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateFilePropertiesContentLength +@filePropertiesToUpdate dbo.FilePropertyTableType_2 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE FP + SET ContentLength = FPTU.ContentLength + FROM dbo.FileProperty AS FP + INNER JOIN + @filePropertiesToUpdate AS FPTU + ON FP.Watermark = FPTU.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateFrameMetadata +@partitionKey INT, @hasFrameMetadata BIT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET HasFrameMetadata = @hasFrameMetadata + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateIndexWorkitemInstanceCore +@workitemKey BIGINT, @partitionKey INT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @newWatermark AS BIGINT; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + UPDATE ets + SET TagValue = input.TagValue, + Watermark = @newWatermark + FROM dbo.ExtendedQueryTagString AS ets + INNER JOIN + @stringExtendedQueryTags AS input + ON ets.TagKey = input.TagKey + WHERE SopInstanceKey1 = @workitemKey + AND ResourceType = @workitemResourceType + AND PartitionKey = @partitionKey + AND ets.TagValue <> input.TagValue; + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + UPDATE etdt + SET TagValue = input.TagValue, + Watermark = @newWatermark + FROM dbo.ExtendedQueryTagDateTime AS etdt + INNER JOIN + @dateTimeExtendedQueryTags AS input + ON etdt.TagKey = input.TagKey + WHERE SopInstanceKey1 = @workitemKey + AND ResourceType = @workitemResourceType + AND PartitionKey = @partitionKey + AND etdt.TagValue <> input.TagValue; + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + UPDATE etpn + SET TagValue = input.TagValue, + Watermark = @newWatermark + FROM dbo.ExtendedQueryTagPersonName AS etpn + INNER JOIN + @personNameExtendedQueryTags AS input + ON etpn.TagKey = input.TagKey + WHERE SopInstanceKey1 = @workitemKey + AND ResourceType = @workitemResourceType + AND PartitionKey = @partitionKey + AND etpn.TagValue <> input.TagValue; + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatus +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN TRANSACTION; +DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); +UPDATE dbo.Instance +SET Status = @status, + LastStatusUpdatedDate = @currentDate +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; +IF @@ROWCOUNT = 0 + BEGIN + THROW 50404, 'Instance does not exist', 1; + END +INSERT INTO dbo.ChangeFeed (Timestamp, Action, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) +VALUES (@currentDate, 0, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark); +UPDATE dbo.ChangeFeed +SET CurrentWatermark = @watermark +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; +COMMIT TRANSACTION; + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatusV37 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT, @maxTagKey INT=NULL, @hasFrameMetadata BIT=0, @path VARCHAR (4000)=NULL, @eTag VARCHAR (4000)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + IF @maxTagKey < (SELECT ISNULL(MAX(TagKey), 0) + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK)) + THROW 50409, 'Max extended query tag key does not match', 10; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @instanceKey AS BIGINT; + UPDATE dbo.Instance + SET Status = @status, + LastStatusUpdatedDate = @CurrentDate, + HasFrameMetadata = @hasFrameMetadata, + @instanceKey = InstanceKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + IF (@path IS NOT NULL + AND @eTag IS NOT NULL + AND @watermark IS NOT NULL) + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + VALUES (@instanceKey, @watermark, @path, @eTag); + INSERT INTO dbo.ChangeFeed (Timestamp, Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark, FilePath) + VALUES (@currentDate, 0, @partitionKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark, @path); + UPDATE dbo.ChangeFeed + SET CurrentWatermark = @watermark + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatusV54 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT, @maxTagKey INT=NULL, @hasFrameMetadata BIT=0, @path VARCHAR (4000)=NULL, @eTag VARCHAR (4000)=NULL, @contentLength BIGINT=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + IF @maxTagKey < (SELECT ISNULL(MAX(TagKey), 0) + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK)) + THROW 50409, 'Max extended query tag key does not match', 10; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @instanceKey AS BIGINT; + UPDATE dbo.Instance + SET Status = @status, + LastStatusUpdatedDate = @CurrentDate, + HasFrameMetadata = @hasFrameMetadata, + @instanceKey = InstanceKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + IF (@path IS NOT NULL + AND @eTag IS NOT NULL + AND @watermark IS NOT NULL) + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag, ContentLength) + VALUES (@instanceKey, @watermark, @path, @eTag, @contentLength); + INSERT INTO dbo.ChangeFeed (Timestamp, Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark, FilePath) + VALUES (@currentDate, 0, @partitionKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark, @path); + UPDATE dbo.ChangeFeed + SET CurrentWatermark = @watermark + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatusV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT, @maxTagKey INT=NULL, @hasFrameMetadata BIT=0 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + IF @maxTagKey < (SELECT ISNULL(MAX(TagKey), 0) + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK)) + THROW 50409, 'Max extended query tag key does not match', 10; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + UPDATE dbo.Instance + SET Status = @status, + LastStatusUpdatedDate = @currentDate, + HasFrameMetadata = @hasFrameMetadata + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + VALUES (0, @partitionKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark); + UPDATE dbo.ChangeFeed + SET CurrentWatermark = @watermark + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemProcedureStepState +@workitemKey BIGINT, @procedureStepStateTagPath VARCHAR (64), @procedureStepState VARCHAR (64), @watermark BIGINT, @proposedWatermark BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @newWatermark AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @currentProcedureStepStateTagValue AS VARCHAR (64); + UPDATE dbo.Workitem + SET Watermark = @proposedWatermark + WHERE WorkitemKey = @workitemKey + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem update failed.', 1; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + WITH TagKeyCTE + AS (SELECT wqt.TagKey, + wqt.TagPath, + eqts.TagValue AS OldTagValue, + eqts.ResourceType, + wi.PartitionKey, + wi.WorkitemKey, + eqts.Watermark AS ExtendedQueryTagWatermark + FROM dbo.WorkitemQueryTag AS wqt + INNER JOIN + dbo.ExtendedQueryTagString AS eqts + ON eqts.TagKey = wqt.TagKey + AND eqts.ResourceType = 1 + INNER JOIN + dbo.Workitem AS wi + ON wi.PartitionKey = eqts.PartitionKey + AND wi.WorkitemKey = eqts.SopInstanceKey1 + WHERE wi.WorkitemKey = @workitemKey) + UPDATE targetTbl + SET targetTbl.TagValue = @procedureStepState, + targetTbl.Watermark = @newWatermark + FROM dbo.ExtendedQueryTagString AS targetTbl + INNER JOIN + TagKeyCTE AS cte + ON targetTbl.ResourceType = cte.ResourceType + AND cte.PartitionKey = targetTbl.PartitionKey + AND cte.WorkitemKey = targetTbl.SopInstanceKey1 + AND cte.TagKey = targetTbl.TagKey + AND cte.OldTagValue = targetTbl.TagValue + AND cte.ExtendedQueryTagWatermark = targetTbl.Watermark + WHERE cte.TagPath = @procedureStepStateTagPath; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem procedure step state update failed.', 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemProcedureStepStateV21 +@workitemKey BIGINT, @procedureStepStateTagPath VARCHAR (64), @procedureStepState VARCHAR (64), @watermark BIGINT, @proposedWatermark BIGINT, @transactionUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @newWatermark AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @currentProcedureStepStateTagValue AS VARCHAR (64); + UPDATE dbo.Workitem + SET Watermark = @proposedWatermark, + TransactionUid = @transactionUid + WHERE WorkitemKey = @workitemKey + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem update failed.', 1; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + WITH TagKeyCTE + AS (SELECT wqt.TagKey, + wqt.TagPath, + eqts.TagValue AS OldTagValue, + eqts.ResourceType, + wi.PartitionKey, + wi.WorkitemKey, + eqts.Watermark AS ExtendedQueryTagWatermark + FROM dbo.WorkitemQueryTag AS wqt + INNER JOIN + dbo.ExtendedQueryTagString AS eqts + ON eqts.TagKey = wqt.TagKey + AND eqts.ResourceType = 1 + INNER JOIN + dbo.Workitem AS wi + ON wi.PartitionKey = eqts.PartitionKey + AND wi.WorkitemKey = eqts.SopInstanceKey1 + WHERE wi.WorkitemKey = @workitemKey) + UPDATE targetTbl + SET targetTbl.TagValue = @procedureStepState, + targetTbl.Watermark = @newWatermark + FROM dbo.ExtendedQueryTagString AS targetTbl + INNER JOIN + TagKeyCTE AS cte + ON targetTbl.ResourceType = cte.ResourceType + AND cte.PartitionKey = targetTbl.PartitionKey + AND cte.WorkitemKey = targetTbl.SopInstanceKey1 + AND cte.TagKey = targetTbl.TagKey + AND cte.OldTagValue = targetTbl.TagValue + AND cte.ExtendedQueryTagWatermark = targetTbl.Watermark + WHERE cte.TagPath = @procedureStepStateTagPath; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem procedure step state update failed.', 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemStatus +@partitionKey INT, @workitemKey BIGINT, @status TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + UPDATE dbo.Workitem + SET Status = @status, + LastStatusUpdatedDate = @currentDate + WHERE PartitionKey = @partitionKey + AND WorkitemKey = @workitemKey; + IF @@ROWCOUNT = 0 + THROW 50404, 'Workitem instance does not exist', 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemTransaction +@workitemKey BIGINT, @partitionKey INT, @watermark BIGINT, @proposedWatermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @newWatermark AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + UPDATE dbo.Workitem + SET Watermark = @proposedWatermark + WHERE WorkitemKey = @workitemKey + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50499, 'Workitem update failed', 1; + BEGIN TRY + EXECUTE dbo.UpdateIndexWorkitemInstanceCore @workitemKey, @partitionKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; +END + +GO +IF NOT EXISTS (SELECT * + FROM sys.views + WHERE Name = 'SeriesResultView') + BEGIN + EXECUTE ('CREATE VIEW dbo.SeriesResultView + WITH SCHEMABINDING + AS + SELECT se.SeriesInstanceUid, + se.Modality, + se.PerformedProcedureStepStartDate, + se.ManufacturerModelName, + (SELECT SUM(1) + FROM dbo.Instance i + WHERE se.PartitionKey = i.PartitionKey + AND se.StudyKey = i.StudyKey + AND se.SeriesKey = i.SeriesKey) AS NumberofSeriesRelatedInstances, + se.PartitionKey, + se.StudyKey, + se.SeriesKey + FROM dbo.Series se'); + END + +GO +IF NOT EXISTS (SELECT * + FROM sys.views + WHERE Name = 'StudyResultView') + BEGIN + EXECUTE ('CREATE VIEW dbo.StudyResultView + WITH SCHEMABINDING + AS + SELECT st.StudyInstanceUid, + st.PatientId, + st.PatientName, + st.ReferringPhysicianName, + st.StudyDate, + st.StudyDescription, + st.AccessionNumber, + st.PatientBirthDate, + (SELECT STRING_AGG(CONVERT(NVARCHAR(max), Modality), '','') + FROM dbo.Series se + WHERE st.StudyKey = se.StudyKey + AND st.PartitionKey = se.PartitionKey) AS ModalitiesInStudy, + (SELECT SUM(1) + FROM dbo.Instance i + WHERE st.PartitionKey = i.PartitionKey + AND st.StudyKey = i.StudyKey) AS NumberofStudyRelatedInstances, + st.PartitionKey, + st.StudyKey + FROM dbo.Study st'); + END + +GO diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V56.Generated.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V56.Generated.cs new file mode 100644 index 0000000000..ce218a4886 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V56.Generated.cs @@ -0,0 +1,2956 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +namespace Microsoft.Health.Dicom.SqlServer.Features.Schema.Model +{ + using Microsoft.Health.SqlServer.Features.Client; + using Microsoft.Health.SqlServer.Features.Schema.Model; + + internal class V56 + { + internal readonly static ChangeFeedTable ChangeFeed = new ChangeFeedTable(); + internal readonly static DeletedInstanceTable DeletedInstance = new DeletedInstanceTable(); + internal readonly static ExtendedQueryTagTable ExtendedQueryTag = new ExtendedQueryTagTable(); + internal readonly static ExtendedQueryTagDateTimeTable ExtendedQueryTagDateTime = new ExtendedQueryTagDateTimeTable(); + internal readonly static ExtendedQueryTagDoubleTable ExtendedQueryTagDouble = new ExtendedQueryTagDoubleTable(); + internal readonly static ExtendedQueryTagErrorTable ExtendedQueryTagError = new ExtendedQueryTagErrorTable(); + internal readonly static ExtendedQueryTagLongTable ExtendedQueryTagLong = new ExtendedQueryTagLongTable(); + internal readonly static ExtendedQueryTagOperationTable ExtendedQueryTagOperation = new ExtendedQueryTagOperationTable(); + internal readonly static ExtendedQueryTagPersonNameTable ExtendedQueryTagPersonName = new ExtendedQueryTagPersonNameTable(); + internal readonly static ExtendedQueryTagStringTable ExtendedQueryTagString = new ExtendedQueryTagStringTable(); + internal readonly static FilePropertyTable FileProperty = new FilePropertyTable(); + internal readonly static InstanceTable Instance = new InstanceTable(); + internal readonly static PartitionTable Partition = new PartitionTable(); + internal readonly static SeriesTable Series = new SeriesTable(); + internal readonly static StudyTable Study = new StudyTable(); + internal readonly static WorkitemTable Workitem = new WorkitemTable(); + internal readonly static WorkitemQueryTagTable WorkitemQueryTag = new WorkitemQueryTagTable(); + internal readonly static AddExtendedQueryTagErrorProcedure AddExtendedQueryTagError = new AddExtendedQueryTagErrorProcedure(); + internal readonly static AddExtendedQueryTagsProcedure AddExtendedQueryTags = new AddExtendedQueryTagsProcedure(); + internal readonly static AddInstanceV6Procedure AddInstanceV6 = new AddInstanceV6Procedure(); + internal readonly static AddPartitionProcedure AddPartition = new AddPartitionProcedure(); + internal readonly static AddWorkitemProcedure AddWorkitem = new AddWorkitemProcedure(); + internal readonly static AddWorkitemV11Procedure AddWorkitemV11 = new AddWorkitemV11Procedure(); + internal readonly static AssignReindexingOperationProcedure AssignReindexingOperation = new AssignReindexingOperationProcedure(); + internal readonly static BeginUpdateInstanceProcedure BeginUpdateInstance = new BeginUpdateInstanceProcedure(); + internal readonly static BeginUpdateInstanceV33Procedure BeginUpdateInstanceV33 = new BeginUpdateInstanceV33Procedure(); + internal readonly static BeginUpdateInstanceV46Procedure BeginUpdateInstanceV46 = new BeginUpdateInstanceV46Procedure(); + internal readonly static CompleteReindexingProcedure CompleteReindexing = new CompleteReindexingProcedure(); + internal readonly static DeleteDeletedInstanceProcedure DeleteDeletedInstance = new DeleteDeletedInstanceProcedure(); + internal readonly static DeleteDeletedInstanceV6Procedure DeleteDeletedInstanceV6 = new DeleteDeletedInstanceV6Procedure(); + internal readonly static DeleteExtendedQueryTagProcedure DeleteExtendedQueryTag = new DeleteExtendedQueryTagProcedure(); + internal readonly static DeleteExtendedQueryTagV16Procedure DeleteExtendedQueryTagV16 = new DeleteExtendedQueryTagV16Procedure(); + internal readonly static DeleteExtendedQueryTagV8Procedure DeleteExtendedQueryTagV8 = new DeleteExtendedQueryTagV8Procedure(); + internal readonly static DeleteInstanceV6Procedure DeleteInstanceV6 = new DeleteInstanceV6Procedure(); + internal readonly static DeleteWorkitemProcedure DeleteWorkitem = new DeleteWorkitemProcedure(); + internal readonly static EndUpdateInstanceProcedure EndUpdateInstance = new EndUpdateInstanceProcedure(); + internal readonly static EndUpdateInstanceV44Procedure EndUpdateInstanceV44 = new EndUpdateInstanceV44Procedure(); + internal readonly static EndUpdateInstanceV50Procedure EndUpdateInstanceV50 = new EndUpdateInstanceV50Procedure(); + internal readonly static EndUpdateInstanceV52Procedure EndUpdateInstanceV52 = new EndUpdateInstanceV52Procedure(); + internal readonly static EndUpdateInstanceV54Procedure EndUpdateInstanceV54 = new EndUpdateInstanceV54Procedure(); + internal readonly static GetChangeFeedProcedure GetChangeFeed = new GetChangeFeedProcedure(); + internal readonly static GetChangeFeedByTimeProcedure GetChangeFeedByTime = new GetChangeFeedByTimeProcedure(); + internal readonly static GetChangeFeedByTimeV39Procedure GetChangeFeedByTimeV39 = new GetChangeFeedByTimeV39Procedure(); + internal readonly static GetChangeFeedLatestProcedure GetChangeFeedLatest = new GetChangeFeedLatestProcedure(); + internal readonly static GetChangeFeedLatestByTimeProcedure GetChangeFeedLatestByTime = new GetChangeFeedLatestByTimeProcedure(); + internal readonly static GetChangeFeedLatestByTimeV39Procedure GetChangeFeedLatestByTimeV39 = new GetChangeFeedLatestByTimeV39Procedure(); + internal readonly static GetChangeFeedLatestV39Procedure GetChangeFeedLatestV39 = new GetChangeFeedLatestV39Procedure(); + internal readonly static GetChangeFeedLatestV6Procedure GetChangeFeedLatestV6 = new GetChangeFeedLatestV6Procedure(); + internal readonly static GetChangeFeedV39Procedure GetChangeFeedV39 = new GetChangeFeedV39Procedure(); + internal readonly static GetChangeFeedV6Procedure GetChangeFeedV6 = new GetChangeFeedV6Procedure(); + internal readonly static GetContentLengthBackFillInstanceBatchesProcedure GetContentLengthBackFillInstanceBatches = new GetContentLengthBackFillInstanceBatchesProcedure(); + internal readonly static GetContentLengthBackFillInstanceIdentifiersByWatermarkRangeProcedure GetContentLengthBackFillInstanceIdentifiersByWatermarkRange = new GetContentLengthBackFillInstanceIdentifiersByWatermarkRangeProcedure(); + internal readonly static GetCurrentAndNextWorkitemWatermarkProcedure GetCurrentAndNextWorkitemWatermark = new GetCurrentAndNextWorkitemWatermarkProcedure(); + internal readonly static GetExtendedQueryTagProcedure GetExtendedQueryTag = new GetExtendedQueryTagProcedure(); + internal readonly static GetExtendedQueryTagErrorsProcedure GetExtendedQueryTagErrors = new GetExtendedQueryTagErrorsProcedure(); + internal readonly static GetExtendedQueryTagErrorsV36Procedure GetExtendedQueryTagErrorsV36 = new GetExtendedQueryTagErrorsV36Procedure(); + internal readonly static GetExtendedQueryTagErrorsV6Procedure GetExtendedQueryTagErrorsV6 = new GetExtendedQueryTagErrorsV6Procedure(); + internal readonly static GetExtendedQueryTagsProcedure GetExtendedQueryTags = new GetExtendedQueryTagsProcedure(); + internal readonly static GetExtendedQueryTagsByKeyProcedure GetExtendedQueryTagsByKey = new GetExtendedQueryTagsByKeyProcedure(); + internal readonly static GetExtendedQueryTagsByOperationProcedure GetExtendedQueryTagsByOperation = new GetExtendedQueryTagsByOperationProcedure(); + internal readonly static GetExtendedQueryTagsV36Procedure GetExtendedQueryTagsV36 = new GetExtendedQueryTagsV36Procedure(); + internal readonly static GetInstanceProcedure GetInstance = new GetInstanceProcedure(); + internal readonly static GetInstanceBatchesProcedure GetInstanceBatches = new GetInstanceBatchesProcedure(); + internal readonly static GetInstanceBatchesByTimeStampProcedure GetInstanceBatchesByTimeStamp = new GetInstanceBatchesByTimeStampProcedure(); + internal readonly static GetInstanceV6Procedure GetInstanceV6 = new GetInstanceV6Procedure(); + internal readonly static GetInstanceWithPropertiesProcedure GetInstanceWithProperties = new GetInstanceWithPropertiesProcedure(); + internal readonly static GetInstanceWithPropertiesV32Procedure GetInstanceWithPropertiesV32 = new GetInstanceWithPropertiesV32Procedure(); + internal readonly static GetInstanceWithPropertiesV46Procedure GetInstanceWithPropertiesV46 = new GetInstanceWithPropertiesV46Procedure(); + internal readonly static GetInstancesByWatermarkRangeProcedure GetInstancesByWatermarkRange = new GetInstancesByWatermarkRangeProcedure(); + internal readonly static GetInstancesByWatermarkRangeV6Procedure GetInstancesByWatermarkRangeV6 = new GetInstancesByWatermarkRangeV6Procedure(); + internal readonly static GetPartitionProcedure GetPartition = new GetPartitionProcedure(); + internal readonly static GetPartitionsProcedure GetPartitions = new GetPartitionsProcedure(); + internal readonly static GetSeriesResultProcedure GetSeriesResult = new GetSeriesResultProcedure(); + internal readonly static GetStudyResultProcedure GetStudyResult = new GetStudyResultProcedure(); + internal readonly static GetWorkitemMetadataProcedure GetWorkitemMetadata = new GetWorkitemMetadataProcedure(); + internal readonly static GetWorkitemQueryTagsProcedure GetWorkitemQueryTags = new GetWorkitemQueryTagsProcedure(); + internal readonly static IIndexInstanceCoreV9Procedure IIndexInstanceCoreV9 = new IIndexInstanceCoreV9Procedure(); + internal readonly static IIndexWorkitemInstanceCoreProcedure IIndexWorkitemInstanceCore = new IIndexWorkitemInstanceCoreProcedure(); + internal readonly static ISleepIfBusyProcedure ISleepIfBusy = new ISleepIfBusyProcedure(); + internal readonly static IncrementDeletedInstanceRetryProcedure IncrementDeletedInstanceRetry = new IncrementDeletedInstanceRetryProcedure(); + internal readonly static IncrementDeletedInstanceRetryV6Procedure IncrementDeletedInstanceRetryV6 = new IncrementDeletedInstanceRetryV6Procedure(); + internal readonly static IndexInstanceV6Procedure IndexInstanceV6 = new IndexInstanceV6Procedure(); + internal readonly static RetrieveDeletedInstanceProcedure RetrieveDeletedInstance = new RetrieveDeletedInstanceProcedure(); + internal readonly static RetrieveDeletedInstanceV42Procedure RetrieveDeletedInstanceV42 = new RetrieveDeletedInstanceV42Procedure(); + internal readonly static RetrieveDeletedInstanceV6Procedure RetrieveDeletedInstanceV6 = new RetrieveDeletedInstanceV6Procedure(); + internal readonly static UpdateExtendedQueryTagQueryStatusProcedure UpdateExtendedQueryTagQueryStatus = new UpdateExtendedQueryTagQueryStatusProcedure(); + internal readonly static UpdateFilePropertiesContentLengthProcedure UpdateFilePropertiesContentLength = new UpdateFilePropertiesContentLengthProcedure(); + internal readonly static UpdateFrameMetadataProcedure UpdateFrameMetadata = new UpdateFrameMetadataProcedure(); + internal readonly static UpdateIndexWorkitemInstanceCoreProcedure UpdateIndexWorkitemInstanceCore = new UpdateIndexWorkitemInstanceCoreProcedure(); + internal readonly static UpdateInstanceStatusProcedure UpdateInstanceStatus = new UpdateInstanceStatusProcedure(); + internal readonly static UpdateInstanceStatusV37Procedure UpdateInstanceStatusV37 = new UpdateInstanceStatusV37Procedure(); + internal readonly static UpdateInstanceStatusV54Procedure UpdateInstanceStatusV54 = new UpdateInstanceStatusV54Procedure(); + internal readonly static UpdateInstanceStatusV6Procedure UpdateInstanceStatusV6 = new UpdateInstanceStatusV6Procedure(); + internal readonly static UpdateWorkitemProcedureStepStateProcedure UpdateWorkitemProcedureStepState = new UpdateWorkitemProcedureStepStateProcedure(); + internal readonly static UpdateWorkitemProcedureStepStateV21Procedure UpdateWorkitemProcedureStepStateV21 = new UpdateWorkitemProcedureStepStateV21Procedure(); + internal readonly static UpdateWorkitemStatusProcedure UpdateWorkitemStatus = new UpdateWorkitemStatusProcedure(); + internal readonly static UpdateWorkitemTransactionProcedure UpdateWorkitemTransaction = new UpdateWorkitemTransactionProcedure(); + + internal class ChangeFeedTable : Table + { + internal ChangeFeedTable() : base("dbo.ChangeFeed") + { + } + + internal readonly BigIntColumn Sequence = new BigIntColumn("Sequence"); + internal readonly DateTimeOffsetColumn Timestamp = new DateTimeOffsetColumn("Timestamp", 7); + internal readonly TinyIntColumn Action = new TinyIntColumn("Action"); + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly VarCharColumn SopInstanceUid = new VarCharColumn("SopInstanceUid", 64); + internal readonly BigIntColumn OriginalWatermark = new BigIntColumn("OriginalWatermark"); + internal readonly NullableBigIntColumn CurrentWatermark = new NullableBigIntColumn("CurrentWatermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly NullableNVarCharColumn FilePath = new NullableNVarCharColumn("FilePath", 4000); + internal readonly Index IXC_ChangeFeed = new Index("IXC_ChangeFeed"); + internal readonly Index IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid = new Index("IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid"); + internal readonly Index IX_ChangeFeed_Sequence = new Index("IX_ChangeFeed_Sequence"); + } + + internal class DeletedInstanceTable : Table + { + internal DeletedInstanceTable() : base("dbo.DeletedInstance") + { + } + + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly VarCharColumn SopInstanceUid = new VarCharColumn("SopInstanceUid", 64); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly DateTimeOffsetColumn DeletedDateTime = new DateTimeOffsetColumn("DeletedDateTime", 0); + internal readonly IntColumn RetryCount = new IntColumn("RetryCount"); + internal readonly DateTimeOffsetColumn CleanupAfter = new DateTimeOffsetColumn("CleanupAfter", 0); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly NullableBigIntColumn OriginalWatermark = new NullableBigIntColumn("OriginalWatermark"); + internal readonly NullableNVarCharColumn FilePath = new NullableNVarCharColumn("FilePath", 4000); + internal readonly NullableNVarCharColumn ETag = new NullableNVarCharColumn("ETag", 4000); + internal readonly Index IXC_DeletedInstance = new Index("IXC_DeletedInstance"); + internal readonly Index IX_DeletedInstance_RetryCount_CleanupAfter = new Index("IX_DeletedInstance_RetryCount_CleanupAfter"); + } + + internal class ExtendedQueryTagTable : Table + { + internal ExtendedQueryTagTable() : base("dbo.ExtendedQueryTag") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly VarCharColumn TagPath = new VarCharColumn("TagPath", 64); + internal readonly VarCharColumn TagVR = new VarCharColumn("TagVR", 2); + internal readonly NullableNVarCharColumn TagPrivateCreator = new NullableNVarCharColumn("TagPrivateCreator", 64); + internal readonly TinyIntColumn TagLevel = new TinyIntColumn("TagLevel"); + internal readonly TinyIntColumn TagStatus = new TinyIntColumn("TagStatus"); + internal readonly TinyIntColumn QueryStatus = new TinyIntColumn("QueryStatus"); + internal readonly IntColumn ErrorCount = new IntColumn("ErrorCount"); + internal readonly Index IXC_ExtendedQueryTag = new Index("IXC_ExtendedQueryTag"); + internal readonly Index IX_ExtendedQueryTag_TagPath = new Index("IX_ExtendedQueryTag_TagPath"); + } + + internal class ExtendedQueryTagDateTimeTable : Table + { + internal ExtendedQueryTagDateTimeTable() : base("dbo.ExtendedQueryTagDateTime") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly DateTime2Column TagValue = new DateTime2Column("TagValue", 7); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly NullableDateTime2Column TagValueUtc = new NullableDateTime2Column("TagValueUtc", 7); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagDateTime = new Index("IXC_ExtendedQueryTagDateTime"); + internal readonly Index IX_ExtendedQueryTagDateTime_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDateTime_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagDateTime_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDateTime_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class ExtendedQueryTagDoubleTable : Table + { + internal ExtendedQueryTagDoubleTable() : base("dbo.ExtendedQueryTagDouble") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly FloatColumn TagValue = new FloatColumn("TagValue", 53); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagDouble = new Index("IXC_ExtendedQueryTagDouble"); + internal readonly Index IX_ExtendedQueryTagDouble_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDouble_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagDouble_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDouble_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class ExtendedQueryTagErrorTable : Table + { + internal ExtendedQueryTagErrorTable() : base("dbo.ExtendedQueryTagError") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly SmallIntColumn ErrorCode = new SmallIntColumn("ErrorCode"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly DateTime2Column CreatedTime = new DateTime2Column("CreatedTime", 7); + internal readonly Index IXC_ExtendedQueryTagError = new Index("IXC_ExtendedQueryTagError"); + internal readonly Index IX_ExtendedQueryTagError_CreatedTime_Watermark_TagKey = new Index("IX_ExtendedQueryTagError_CreatedTime_Watermark_TagKey"); + internal readonly Index IX_ExtendedQueryTagError_Watermark = new Index("IX_ExtendedQueryTagError_Watermark"); + } + + internal class ExtendedQueryTagLongTable : Table + { + internal ExtendedQueryTagLongTable() : base("dbo.ExtendedQueryTagLong") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly BigIntColumn TagValue = new BigIntColumn("TagValue"); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagLong = new Index("IXC_ExtendedQueryTagLong"); + internal readonly Index IX_ExtendedQueryTagLong_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagLong_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagLong_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagLong_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class ExtendedQueryTagOperationTable : Table + { + internal ExtendedQueryTagOperationTable() : base("dbo.ExtendedQueryTagOperation") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly UniqueIdentifierColumn OperationId = new UniqueIdentifierColumn("OperationId"); + internal readonly Index IXC_ExtendedQueryTagOperation = new Index("IXC_ExtendedQueryTagOperation"); + internal readonly Index IX_ExtendedQueryTagOperation_OperationId = new Index("IX_ExtendedQueryTagOperation_OperationId"); + } + + internal class ExtendedQueryTagPersonNameTable : Table + { + internal ExtendedQueryTagPersonNameTable() : base("dbo.ExtendedQueryTagPersonName") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly NVarCharColumn TagValue = new NVarCharColumn("TagValue", 200, "SQL_Latin1_General_CP1_CI_AI"); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal const string WatermarkAndTagKey = "WatermarkAndTagKey"; + internal const string TagValueWords = "TagValueWords"; + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagPersonName = new Index("IXC_ExtendedQueryTagPersonName"); + internal readonly Index IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagPersonName_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagPersonName_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey = new Index("IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey"); + } + + internal class ExtendedQueryTagStringTable : Table + { + internal ExtendedQueryTagStringTable() : base("dbo.ExtendedQueryTagString") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly NVarCharColumn TagValue = new NVarCharColumn("TagValue", 64); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagString = new Index("IXC_ExtendedQueryTagString"); + internal readonly Index IX_ExtendedQueryTagString_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagString_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagString_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagString_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class FilePropertyTable : Table + { + internal FilePropertyTable() : base("dbo.FileProperty") + { + } + + internal readonly BigIntColumn InstanceKey = new BigIntColumn("InstanceKey"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly NVarCharColumn FilePath = new NVarCharColumn("FilePath", 4000); + internal readonly NVarCharColumn ETag = new NVarCharColumn("ETag", 4000); + internal readonly BigIntColumn ContentLength = new BigIntColumn("ContentLength"); + internal readonly Index IXC_FileProperty = new Index("IXC_FileProperty"); + internal readonly Index IXC_FileProperty_InstanceKey_Watermark_ContentLength = new Index("IXC_FileProperty_InstanceKey_Watermark_ContentLength"); + } + + internal class InstanceTable : Table + { + internal InstanceTable() : base("dbo.Instance") + { + } + + internal readonly BigIntColumn InstanceKey = new BigIntColumn("InstanceKey"); + internal readonly BigIntColumn SeriesKey = new BigIntColumn("SeriesKey"); + internal readonly BigIntColumn StudyKey = new BigIntColumn("StudyKey"); + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly VarCharColumn SopInstanceUid = new VarCharColumn("SopInstanceUid", 64); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly TinyIntColumn Status = new TinyIntColumn("Status"); + internal readonly DateTime2Column LastStatusUpdatedDate = new DateTime2Column("LastStatusUpdatedDate", 7); + internal readonly DateTime2Column CreatedDate = new DateTime2Column("CreatedDate", 7); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly NullableVarCharColumn TransferSyntaxUid = new NullableVarCharColumn("TransferSyntaxUid", 64); + internal readonly BitColumn HasFrameMetadata = new BitColumn("HasFrameMetadata"); + internal readonly NullableBigIntColumn OriginalWatermark = new NullableBigIntColumn("OriginalWatermark"); + internal readonly NullableBigIntColumn NewWatermark = new NullableBigIntColumn("NewWatermark"); + internal readonly Index IXC_Instance = new Index("IXC_Instance"); + internal readonly Index IX_Instance_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid = new Index("IX_Instance_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid = new Index("IX_Instance_PartitionKey_Status_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid"); + internal readonly Index IX_Instance_Watermark_Status = new Index("IX_Instance_Watermark_Status"); + internal readonly Index IX_Instance_PartitionKey_SopInstanceUid = new Index("IX_Instance_PartitionKey_SopInstanceUid"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyKey_Watermark = new Index("IX_Instance_PartitionKey_Status_StudyKey_Watermark"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyKey_SeriesKey_Watermark = new Index("IX_Instance_PartitionKey_Status_StudyKey_SeriesKey_Watermark"); + internal readonly Index IX_Instance_PartitionKey_Watermark = new Index("IX_Instance_PartitionKey_Watermark"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyInstanceUid_NewWatermark = new Index("IX_Instance_PartitionKey_Status_StudyInstanceUid_NewWatermark"); + internal readonly Index IX_Instance_Watermark_Status_CreatedDate = new Index("IX_Instance_Watermark_Status_CreatedDate"); + } + + internal class PartitionTable : Table + { + internal PartitionTable() : base("dbo.Partition") + { + } + + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly VarCharColumn PartitionName = new VarCharColumn("PartitionName", 64); + internal readonly DateTime2Column CreatedDate = new DateTime2Column("CreatedDate", 7); + internal readonly Index IXC_Partition = new Index("IXC_Partition"); + internal readonly Index IX_Partition_PartitionName = new Index("IX_Partition_PartitionName"); + } + + internal class SeriesTable : Table + { + internal SeriesTable() : base("dbo.Series") + { + } + + internal readonly BigIntColumn SeriesKey = new BigIntColumn("SeriesKey"); + internal readonly BigIntColumn StudyKey = new BigIntColumn("StudyKey"); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly NullableNVarCharColumn Modality = new NullableNVarCharColumn("Modality", 16); + internal readonly NullableDateColumn PerformedProcedureStepStartDate = new NullableDateColumn("PerformedProcedureStepStartDate"); + internal readonly NullableNVarCharColumn ManufacturerModelName = new NullableNVarCharColumn("ManufacturerModelName", 64); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_Series = new Index("IXC_Series"); + internal readonly Index IX_Series_PartitionKey_StudyKey_SeriesInstanceUid = new Index("IX_Series_PartitionKey_StudyKey_SeriesInstanceUid"); + internal readonly Index IX_Series_PartitionKey_SeriesInstanceUid = new Index("IX_Series_PartitionKey_SeriesInstanceUid"); + internal readonly Index IX_Series_PartitionKey_Modality = new Index("IX_Series_PartitionKey_Modality"); + internal readonly Index IX_Series_PartitionKey_PerformedProcedureStepStartDate = new Index("IX_Series_PartitionKey_PerformedProcedureStepStartDate"); + internal readonly Index IX_Series_PartitionKey_ManufacturerModelName = new Index("IX_Series_PartitionKey_ManufacturerModelName"); + } + + internal class StudyTable : Table + { + internal StudyTable() : base("dbo.Study") + { + } + + internal readonly BigIntColumn StudyKey = new BigIntColumn("StudyKey"); + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly NVarCharColumn PatientId = new NVarCharColumn("PatientId", 64); + internal readonly NullableNVarCharColumn PatientName = new NullableNVarCharColumn("PatientName", 200, "SQL_Latin1_General_CP1_CI_AI"); + internal readonly NullableNVarCharColumn ReferringPhysicianName = new NullableNVarCharColumn("ReferringPhysicianName", 200, "SQL_Latin1_General_CP1_CI_AI"); + internal readonly NullableDateColumn StudyDate = new NullableDateColumn("StudyDate"); + internal readonly NullableNVarCharColumn StudyDescription = new NullableNVarCharColumn("StudyDescription", 64); + internal readonly NullableNVarCharColumn AccessionNumber = new NullableNVarCharColumn("AccessionNumber", 16); + internal const string PatientNameWords = "PatientNameWords"; + internal const string ReferringPhysicianNameWords = "ReferringPhysicianNameWords"; + internal readonly NullableDateColumn PatientBirthDate = new NullableDateColumn("PatientBirthDate"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_Study = new Index("IXC_Study"); + internal readonly Index IX_Study_StudyKey = new Index("IX_Study_StudyKey"); + internal readonly Index IX_Study_PartitionKey_StudyInstanceUid = new Index("IX_Study_PartitionKey_StudyInstanceUid"); + internal readonly Index IX_Study_PartitionKey_PatientId = new Index("IX_Study_PartitionKey_PatientId"); + internal readonly Index IX_Study_PartitionKey_PatientName = new Index("IX_Study_PartitionKey_PatientName"); + internal readonly Index IX_Study_PartitionKey_ReferringPhysicianName = new Index("IX_Study_PartitionKey_ReferringPhysicianName"); + internal readonly Index IX_Study_PartitionKey_StudyDate = new Index("IX_Study_PartitionKey_StudyDate"); + internal readonly Index IX_Study_PartitionKey_StudyDescription = new Index("IX_Study_PartitionKey_StudyDescription"); + internal readonly Index IX_Study_PartitionKey_AccessionNumber = new Index("IX_Study_PartitionKey_AccessionNumber"); + internal readonly Index IX_Study_PartitionKey_PatientBirthDate = new Index("IX_Study_PartitionKey_PatientBirthDate"); + } + + internal class WorkitemTable : Table + { + internal WorkitemTable() : base("dbo.Workitem") + { + } + + internal readonly BigIntColumn WorkitemKey = new BigIntColumn("WorkitemKey"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly VarCharColumn WorkitemUid = new VarCharColumn("WorkitemUid", 64); + internal readonly NullableVarCharColumn TransactionUid = new NullableVarCharColumn("TransactionUid", 64); + internal readonly TinyIntColumn Status = new TinyIntColumn("Status"); + internal readonly DateTime2Column CreatedDate = new DateTime2Column("CreatedDate", 7); + internal readonly DateTime2Column LastStatusUpdatedDate = new DateTime2Column("LastStatusUpdatedDate", 7); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly Index IXC_Workitem = new Index("IXC_Workitem"); + internal readonly Index IX_Workitem_PartitionKey_WorkitemUid = new Index("IX_Workitem_PartitionKey_WorkitemUid"); + internal readonly Index IX_Workitem_WorkitemKey_Watermark = new Index("IX_Workitem_WorkitemKey_Watermark"); + } + + internal class WorkitemQueryTagTable : Table + { + internal WorkitemQueryTagTable() : base("dbo.WorkitemQueryTag") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly VarCharColumn TagPath = new VarCharColumn("TagPath", 64); + internal readonly VarCharColumn TagVR = new VarCharColumn("TagVR", 2); + internal readonly Index IXC_WorkitemQueryTag = new Index("IXC_WorkitemQueryTag"); + internal readonly Index IXC_WorkitemQueryTag_TagPath = new Index("IXC_WorkitemQueryTag_TagPath"); + } + + internal class AddExtendedQueryTagErrorProcedure : StoredProcedure + { + internal AddExtendedQueryTagErrorProcedure() : base("dbo.AddExtendedQueryTagError") + { + } + + private readonly ParameterDefinition _tagKey = new ParameterDefinition("@tagKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _errorCode = new ParameterDefinition("@errorCode", global::System.Data.SqlDbType.SmallInt, false); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 tagKey, System.Int16 errorCode, System.Int64 watermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddExtendedQueryTagError"; + _tagKey.AddParameter(command.Parameters, tagKey); + _errorCode.AddParameter(command.Parameters, errorCode); + _watermark.AddParameter(command.Parameters, watermark); + } + } + + internal class AddExtendedQueryTagsProcedure : StoredProcedure + { + internal AddExtendedQueryTagsProcedure() : base("dbo.AddExtendedQueryTags") + { + } + + private readonly AddExtendedQueryTagsInputTableTypeV1TableValuedParameterDefinition _extendedQueryTags = new AddExtendedQueryTagsInputTableTypeV1TableValuedParameterDefinition("@extendedQueryTags"); + private readonly ParameterDefinition> _maxAllowedCount = new ParameterDefinition>("@maxAllowedCount", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _ready = new ParameterDefinition>("@ready", global::System.Data.SqlDbType.Bit, true); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTags, System.Nullable maxAllowedCount, System.Nullable ready) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddExtendedQueryTags"; + _extendedQueryTags.AddParameter(command.Parameters, extendedQueryTags); + _maxAllowedCount.AddParameter(command.Parameters, maxAllowedCount); + _ready.AddParameter(command.Parameters, ready); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable maxAllowedCount, System.Nullable ready, AddExtendedQueryTagsTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, maxAllowedCount: maxAllowedCount, ready: ready, extendedQueryTags: tableValuedParameters.ExtendedQueryTags); + } + } + + internal class AddExtendedQueryTagsTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddExtendedQueryTagsTvpGenerator(ITableValuedParameterRowGenerator AddExtendedQueryTagsInputTableTypeV1RowGenerator) + { + this.AddExtendedQueryTagsInputTableTypeV1RowGenerator = AddExtendedQueryTagsInputTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator AddExtendedQueryTagsInputTableTypeV1RowGenerator; + + public AddExtendedQueryTagsTableValuedParameters Generate(TInput input) + { + return new AddExtendedQueryTagsTableValuedParameters(AddExtendedQueryTagsInputTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddExtendedQueryTagsTableValuedParameters + { + internal AddExtendedQueryTagsTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTags) + { + this.ExtendedQueryTags = ExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTags { get; } + } + + internal class AddInstanceV6Procedure : StoredProcedure + { + internal AddInstanceV6Procedure() : base("dbo.AddInstanceV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, false, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition _referringPhysicianName = new ParameterDefinition("@referringPhysicianName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _studyDate = new ParameterDefinition>("@studyDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition _studyDescription = new ParameterDefinition("@studyDescription", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _accessionNumber = new ParameterDefinition("@accessionNumber", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _modality = new ParameterDefinition("@modality", global::System.Data.SqlDbType.NVarChar, true, 16); + private readonly ParameterDefinition> _performedProcedureStepStartDate = new ParameterDefinition>("@performedProcedureStepStartDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition _manufacturerModelName = new ParameterDefinition("@manufacturerModelName", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + private readonly ParameterDefinition _initialStatus = new ParameterDefinition("@initialStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _transferSyntaxUid = new ParameterDefinition("@transferSyntaxUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.String patientId, System.String patientName, System.String referringPhysicianName, System.Nullable studyDate, System.String studyDescription, System.String accessionNumber, System.String modality, System.Nullable performedProcedureStepStartDate, System.Nullable patientBirthDate, System.String manufacturerModelName, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags, System.Byte initialStatus, System.String transferSyntaxUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddInstanceV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _referringPhysicianName.AddParameter(command.Parameters, referringPhysicianName); + _studyDate.AddParameter(command.Parameters, studyDate); + _studyDescription.AddParameter(command.Parameters, studyDescription); + _accessionNumber.AddParameter(command.Parameters, accessionNumber); + _modality.AddParameter(command.Parameters, modality); + _performedProcedureStepStartDate.AddParameter(command.Parameters, performedProcedureStepStartDate); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _manufacturerModelName.AddParameter(command.Parameters, manufacturerModelName); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + _initialStatus.AddParameter(command.Parameters, initialStatus); + _transferSyntaxUid.AddParameter(command.Parameters, transferSyntaxUid); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.String patientId, System.String patientName, System.String referringPhysicianName, System.Nullable studyDate, System.String studyDescription, System.String accessionNumber, System.String modality, System.Nullable performedProcedureStepStartDate, System.Nullable patientBirthDate, System.String manufacturerModelName, System.Byte initialStatus, System.String transferSyntaxUid, AddInstanceV6TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, seriesInstanceUid: seriesInstanceUid, sopInstanceUid: sopInstanceUid, patientId: patientId, patientName: patientName, referringPhysicianName: referringPhysicianName, studyDate: studyDate, studyDescription: studyDescription, accessionNumber: accessionNumber, modality: modality, performedProcedureStepStartDate: performedProcedureStepStartDate, patientBirthDate: patientBirthDate, manufacturerModelName: manufacturerModelName, initialStatus: initialStatus, transferSyntaxUid: transferSyntaxUid, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddInstanceV6TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddInstanceV6TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddInstanceV6TableValuedParameters Generate(TInput input) + { + return new AddInstanceV6TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddInstanceV6TableValuedParameters + { + internal AddInstanceV6TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class AddPartitionProcedure : StoredProcedure + { + internal AddPartitionProcedure() : base("dbo.AddPartition") + { + } + + private readonly ParameterDefinition _partitionName = new ParameterDefinition("@partitionName", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.String partitionName) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddPartition"; + _partitionName.AddParameter(command.Parameters, partitionName); + } + } + + internal class AddWorkitemProcedure : StoredProcedure + { + internal AddWorkitemProcedure() : base("dbo.AddWorkitem") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + private readonly ParameterDefinition _initialStatus = new ParameterDefinition("@initialStatus", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags, System.Byte initialStatus) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddWorkitem"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + _initialStatus.AddParameter(command.Parameters, initialStatus); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, System.Byte initialStatus, AddWorkitemTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, workitemUid: workitemUid, initialStatus: initialStatus, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddWorkitemTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddWorkitemTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddWorkitemTableValuedParameters Generate(TInput input) + { + return new AddWorkitemTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddWorkitemTableValuedParameters + { + internal AddWorkitemTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class AddWorkitemV11Procedure : StoredProcedure + { + internal AddWorkitemV11Procedure() : base("dbo.AddWorkitemV11") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + private readonly ParameterDefinition _initialStatus = new ParameterDefinition("@initialStatus", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags, System.Byte initialStatus) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddWorkitemV11"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + _initialStatus.AddParameter(command.Parameters, initialStatus); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, System.Byte initialStatus, AddWorkitemV11TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, workitemUid: workitemUid, initialStatus: initialStatus, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddWorkitemV11TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddWorkitemV11TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddWorkitemV11TableValuedParameters Generate(TInput input) + { + return new AddWorkitemV11TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddWorkitemV11TableValuedParameters + { + internal AddWorkitemV11TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class AssignReindexingOperationProcedure : StoredProcedure + { + internal AssignReindexingOperationProcedure() : base("dbo.AssignReindexingOperation") + { + } + + private readonly ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition _extendedQueryTagKeys = new ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition("@extendedQueryTagKeys"); + private readonly ParameterDefinition _operationId = new ParameterDefinition("@operationId", global::System.Data.SqlDbType.UniqueIdentifier, false); + private readonly ParameterDefinition> _returnIfCompleted = new ParameterDefinition>("@returnIfCompleted", global::System.Data.SqlDbType.Bit, true); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTagKeys, System.Guid operationId, System.Nullable returnIfCompleted) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AssignReindexingOperation"; + _extendedQueryTagKeys.AddParameter(command.Parameters, extendedQueryTagKeys); + _operationId.AddParameter(command.Parameters, operationId); + _returnIfCompleted.AddParameter(command.Parameters, returnIfCompleted); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Guid operationId, System.Nullable returnIfCompleted, AssignReindexingOperationTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, operationId: operationId, returnIfCompleted: returnIfCompleted, extendedQueryTagKeys: tableValuedParameters.ExtendedQueryTagKeys); + } + } + + internal class AssignReindexingOperationTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AssignReindexingOperationTvpGenerator(ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator) + { + this.ExtendedQueryTagKeyTableTypeV1RowGenerator = ExtendedQueryTagKeyTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator; + + public AssignReindexingOperationTableValuedParameters Generate(TInput input) + { + return new AssignReindexingOperationTableValuedParameters(ExtendedQueryTagKeyTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AssignReindexingOperationTableValuedParameters + { + internal AssignReindexingOperationTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys) + { + this.ExtendedQueryTagKeys = ExtendedQueryTagKeys; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys { get; } + } + + internal class BeginUpdateInstanceProcedure : StoredProcedure + { + internal BeginUpdateInstanceProcedure() : base("dbo.BeginUpdateInstance") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.BeginUpdateInstance"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, BeginUpdateInstanceTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class BeginUpdateInstanceTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public BeginUpdateInstanceTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public BeginUpdateInstanceTableValuedParameters Generate(TInput input) + { + return new BeginUpdateInstanceTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct BeginUpdateInstanceTableValuedParameters + { + internal BeginUpdateInstanceTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class BeginUpdateInstanceV33Procedure : StoredProcedure + { + internal BeginUpdateInstanceV33Procedure() : base("dbo.BeginUpdateInstanceV33") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.BeginUpdateInstanceV33"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + } + } + + internal class BeginUpdateInstanceV46Procedure : StoredProcedure + { + internal BeginUpdateInstanceV46Procedure() : base("dbo.BeginUpdateInstanceV46") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.BeginUpdateInstanceV46"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + } + } + + internal class CompleteReindexingProcedure : StoredProcedure + { + internal CompleteReindexingProcedure() : base("dbo.CompleteReindexing") + { + } + + private readonly ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition _extendedQueryTagKeys = new ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition("@extendedQueryTagKeys"); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTagKeys) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.CompleteReindexing"; + _extendedQueryTagKeys.AddParameter(command.Parameters, extendedQueryTagKeys); + } + + public void PopulateCommand(SqlCommandWrapper command, CompleteReindexingTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, extendedQueryTagKeys: tableValuedParameters.ExtendedQueryTagKeys); + } + } + + internal class CompleteReindexingTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public CompleteReindexingTvpGenerator(ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator) + { + this.ExtendedQueryTagKeyTableTypeV1RowGenerator = ExtendedQueryTagKeyTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator; + + public CompleteReindexingTableValuedParameters Generate(TInput input) + { + return new CompleteReindexingTableValuedParameters(ExtendedQueryTagKeyTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct CompleteReindexingTableValuedParameters + { + internal CompleteReindexingTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys) + { + this.ExtendedQueryTagKeys = ExtendedQueryTagKeys; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys { get; } + } + + internal class DeleteDeletedInstanceProcedure : StoredProcedure + { + internal DeleteDeletedInstanceProcedure() : base("dbo.DeleteDeletedInstance") + { + } + + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteDeletedInstance"; + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + } + } + + internal class DeleteDeletedInstanceV6Procedure : StoredProcedure + { + internal DeleteDeletedInstanceV6Procedure() : base("dbo.DeleteDeletedInstanceV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteDeletedInstanceV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + } + } + + internal class DeleteExtendedQueryTagProcedure : StoredProcedure + { + internal DeleteExtendedQueryTagProcedure() : base("dbo.DeleteExtendedQueryTag") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _dataType = new ParameterDefinition("@dataType", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte dataType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteExtendedQueryTag"; + _tagPath.AddParameter(command.Parameters, tagPath); + _dataType.AddParameter(command.Parameters, dataType); + } + } + + internal class DeleteExtendedQueryTagV16Procedure : StoredProcedure + { + internal DeleteExtendedQueryTagV16Procedure() : base("dbo.DeleteExtendedQueryTagV16") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _dataType = new ParameterDefinition("@dataType", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _batchSize = new ParameterDefinition>("@batchSize", global::System.Data.SqlDbType.Int, true); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte dataType, System.Nullable batchSize) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteExtendedQueryTagV16"; + _tagPath.AddParameter(command.Parameters, tagPath); + _dataType.AddParameter(command.Parameters, dataType); + _batchSize.AddParameter(command.Parameters, batchSize); + } + } + + internal class DeleteExtendedQueryTagV8Procedure : StoredProcedure + { + internal DeleteExtendedQueryTagV8Procedure() : base("dbo.DeleteExtendedQueryTagV8") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _dataType = new ParameterDefinition("@dataType", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte dataType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteExtendedQueryTagV8"; + _tagPath.AddParameter(command.Parameters, tagPath); + _dataType.AddParameter(command.Parameters, dataType); + } + } + + internal class DeleteInstanceV6Procedure : StoredProcedure + { + internal DeleteInstanceV6Procedure() : base("dbo.DeleteInstanceV6") + { + } + + private readonly ParameterDefinition _cleanupAfter = new ParameterDefinition("@cleanupAfter", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + private readonly ParameterDefinition _createdStatus = new ParameterDefinition("@createdStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.DateTimeOffset cleanupAfter, System.Byte createdStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteInstanceV6"; + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + _createdStatus.AddParameter(command.Parameters, createdStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class DeleteWorkitemProcedure : StoredProcedure + { + internal DeleteWorkitemProcedure() : base("dbo.DeleteWorkitem") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteWorkitem"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + } + } + + internal class EndUpdateInstanceProcedure : StoredProcedure + { + internal EndUpdateInstanceProcedure() : base("dbo.EndUpdateInstance") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstance"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + } + } + + internal class EndUpdateInstanceV44Procedure : StoredProcedure + { + internal EndUpdateInstanceV44Procedure() : base("dbo.EndUpdateInstanceV44") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly FilePropertyTableTypeTableValuedParameterDefinition _insertFileProperties = new FilePropertyTableTypeTableValuedParameterDefinition("@insertFileProperties"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, global::System.Collections.Generic.IEnumerable insertFileProperties) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstanceV44"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _insertFileProperties.AddParameter(command.Parameters, insertFileProperties); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, EndUpdateInstanceV44TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, patientId: patientId, patientName: patientName, patientBirthDate: patientBirthDate, insertFileProperties: tableValuedParameters.InsertFileProperties); + } + } + + internal class EndUpdateInstanceV44TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public EndUpdateInstanceV44TvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator) + { + this.FilePropertyTableTypeRowGenerator = FilePropertyTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator; + + public EndUpdateInstanceV44TableValuedParameters Generate(TInput input) + { + return new EndUpdateInstanceV44TableValuedParameters(FilePropertyTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct EndUpdateInstanceV44TableValuedParameters + { + internal EndUpdateInstanceV44TableValuedParameters(global::System.Collections.Generic.IEnumerable InsertFileProperties) + { + this.InsertFileProperties = InsertFileProperties; + } + + internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } + } + + internal class EndUpdateInstanceV50Procedure : StoredProcedure + { + internal EndUpdateInstanceV50Procedure() : base("dbo.EndUpdateInstanceV50") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly FilePropertyTableTypeTableValuedParameterDefinition _insertFileProperties = new FilePropertyTableTypeTableValuedParameterDefinition("@insertFileProperties"); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, global::System.Collections.Generic.IEnumerable insertFileProperties, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstanceV50"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _insertFileProperties.AddParameter(command.Parameters, insertFileProperties); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, EndUpdateInstanceV50TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, patientId: patientId, patientName: patientName, patientBirthDate: patientBirthDate, insertFileProperties: tableValuedParameters.InsertFileProperties, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class EndUpdateInstanceV50TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public EndUpdateInstanceV50TvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator, ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.FilePropertyTableTypeRowGenerator = FilePropertyTableTypeRowGenerator; + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator; + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public EndUpdateInstanceV50TableValuedParameters Generate(TInput input) + { + return new EndUpdateInstanceV50TableValuedParameters(FilePropertyTableTypeRowGenerator.GenerateRows(input), InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct EndUpdateInstanceV50TableValuedParameters + { + internal EndUpdateInstanceV50TableValuedParameters(global::System.Collections.Generic.IEnumerable InsertFileProperties, global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.InsertFileProperties = InsertFileProperties; + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class EndUpdateInstanceV52Procedure : StoredProcedure + { + internal EndUpdateInstanceV52Procedure() : base("dbo.EndUpdateInstanceV52") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition _referringPhysicianName = new ParameterDefinition("@referringPhysicianName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition _studyDescription = new ParameterDefinition("@studyDescription", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _accessionNumber = new ParameterDefinition("@accessionNumber", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly FilePropertyTableTypeTableValuedParameterDefinition _insertFileProperties = new FilePropertyTableTypeTableValuedParameterDefinition("@insertFileProperties"); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, System.String referringPhysicianName, System.String studyDescription, System.String accessionNumber, global::System.Collections.Generic.IEnumerable insertFileProperties, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstanceV52"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _referringPhysicianName.AddParameter(command.Parameters, referringPhysicianName); + _studyDescription.AddParameter(command.Parameters, studyDescription); + _accessionNumber.AddParameter(command.Parameters, accessionNumber); + _insertFileProperties.AddParameter(command.Parameters, insertFileProperties); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, System.String referringPhysicianName, System.String studyDescription, System.String accessionNumber, EndUpdateInstanceV52TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, patientId: patientId, patientName: patientName, patientBirthDate: patientBirthDate, referringPhysicianName: referringPhysicianName, studyDescription: studyDescription, accessionNumber: accessionNumber, insertFileProperties: tableValuedParameters.InsertFileProperties, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class EndUpdateInstanceV52TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public EndUpdateInstanceV52TvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator, ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.FilePropertyTableTypeRowGenerator = FilePropertyTableTypeRowGenerator; + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator; + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public EndUpdateInstanceV52TableValuedParameters Generate(TInput input) + { + return new EndUpdateInstanceV52TableValuedParameters(FilePropertyTableTypeRowGenerator.GenerateRows(input), InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct EndUpdateInstanceV52TableValuedParameters + { + internal EndUpdateInstanceV52TableValuedParameters(global::System.Collections.Generic.IEnumerable InsertFileProperties, global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.InsertFileProperties = InsertFileProperties; + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class EndUpdateInstanceV54Procedure : StoredProcedure + { + internal EndUpdateInstanceV54Procedure() : base("dbo.EndUpdateInstanceV54") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition _referringPhysicianName = new ParameterDefinition("@referringPhysicianName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition _studyDescription = new ParameterDefinition("@studyDescription", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _accessionNumber = new ParameterDefinition("@accessionNumber", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly FilePropertyTableTypeV2TableValuedParameterDefinition _insertFileProperties = new FilePropertyTableTypeV2TableValuedParameterDefinition("@insertFileProperties"); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, System.String referringPhysicianName, System.String studyDescription, System.String accessionNumber, global::System.Collections.Generic.IEnumerable insertFileProperties, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstanceV54"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _referringPhysicianName.AddParameter(command.Parameters, referringPhysicianName); + _studyDescription.AddParameter(command.Parameters, studyDescription); + _accessionNumber.AddParameter(command.Parameters, accessionNumber); + _insertFileProperties.AddParameter(command.Parameters, insertFileProperties); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, System.String referringPhysicianName, System.String studyDescription, System.String accessionNumber, EndUpdateInstanceV54TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, patientId: patientId, patientName: patientName, patientBirthDate: patientBirthDate, referringPhysicianName: referringPhysicianName, studyDescription: studyDescription, accessionNumber: accessionNumber, insertFileProperties: tableValuedParameters.InsertFileProperties, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class EndUpdateInstanceV54TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public EndUpdateInstanceV54TvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.FilePropertyTableTypeV2RowGenerator = FilePropertyTableTypeV2RowGenerator; + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public EndUpdateInstanceV54TableValuedParameters Generate(TInput input) + { + return new EndUpdateInstanceV54TableValuedParameters(FilePropertyTableTypeV2RowGenerator.GenerateRows(input), InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct EndUpdateInstanceV54TableValuedParameters + { + internal EndUpdateInstanceV54TableValuedParameters(global::System.Collections.Generic.IEnumerable InsertFileProperties, global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.InsertFileProperties = InsertFileProperties; + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class GetChangeFeedProcedure : StoredProcedure + { + internal GetChangeFeedProcedure() : base("dbo.GetChangeFeed") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeed"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedByTimeProcedure : StoredProcedure + { + internal GetChangeFeedByTimeProcedure() : base("dbo.GetChangeFeedByTime") + { + } + + private readonly ParameterDefinition _startTime = new ParameterDefinition("@startTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _endTime = new ParameterDefinition("@endTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.DateTimeOffset startTime, System.DateTimeOffset endTime, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedByTime"; + _startTime.AddParameter(command.Parameters, startTime); + _endTime.AddParameter(command.Parameters, endTime); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedByTimeV39Procedure : StoredProcedure + { + internal GetChangeFeedByTimeV39Procedure() : base("dbo.GetChangeFeedByTimeV39") + { + } + + private readonly ParameterDefinition _startTime = new ParameterDefinition("@startTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _endTime = new ParameterDefinition("@endTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.DateTimeOffset startTime, System.DateTimeOffset endTime, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedByTimeV39"; + _startTime.AddParameter(command.Parameters, startTime); + _endTime.AddParameter(command.Parameters, endTime); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedLatestProcedure : StoredProcedure + { + internal GetChangeFeedLatestProcedure() : base("dbo.GetChangeFeedLatest") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatest"; + } + } + + internal class GetChangeFeedLatestByTimeProcedure : StoredProcedure + { + internal GetChangeFeedLatestByTimeProcedure() : base("dbo.GetChangeFeedLatestByTime") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestByTime"; + } + } + + internal class GetChangeFeedLatestByTimeV39Procedure : StoredProcedure + { + internal GetChangeFeedLatestByTimeV39Procedure() : base("dbo.GetChangeFeedLatestByTimeV39") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestByTimeV39"; + } + } + + internal class GetChangeFeedLatestV39Procedure : StoredProcedure + { + internal GetChangeFeedLatestV39Procedure() : base("dbo.GetChangeFeedLatestV39") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestV39"; + } + } + + internal class GetChangeFeedLatestV6Procedure : StoredProcedure + { + internal GetChangeFeedLatestV6Procedure() : base("dbo.GetChangeFeedLatestV6") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestV6"; + } + } + + internal class GetChangeFeedV39Procedure : StoredProcedure + { + internal GetChangeFeedV39Procedure() : base("dbo.GetChangeFeedV39") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedV39"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedV6Procedure : StoredProcedure + { + internal GetChangeFeedV6Procedure() : base("dbo.GetChangeFeedV6") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedV6"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetContentLengthBackFillInstanceBatchesProcedure : StoredProcedure + { + internal GetContentLengthBackFillInstanceBatchesProcedure() : base("dbo.GetContentLengthBackFillInstanceBatches") + { + } + + private readonly ParameterDefinition _batchSize = new ParameterDefinition("@batchSize", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _batchCount = new ParameterDefinition("@batchCount", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 batchSize, System.Int32 batchCount) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetContentLengthBackFillInstanceBatches"; + _batchSize.AddParameter(command.Parameters, batchSize); + _batchCount.AddParameter(command.Parameters, batchCount); + } + } + + internal class GetContentLengthBackFillInstanceIdentifiersByWatermarkRangeProcedure : StoredProcedure + { + internal GetContentLengthBackFillInstanceIdentifiersByWatermarkRangeProcedure() : base("dbo.GetContentLengthBackFillInstanceIdentifiersByWatermarkRange") + { + } + + private readonly ParameterDefinition _startWatermark = new ParameterDefinition("@startWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _endWatermark = new ParameterDefinition("@endWatermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 startWatermark, System.Int64 endWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetContentLengthBackFillInstanceIdentifiersByWatermarkRange"; + _startWatermark.AddParameter(command.Parameters, startWatermark); + _endWatermark.AddParameter(command.Parameters, endWatermark); + } + } + + internal class GetCurrentAndNextWorkitemWatermarkProcedure : StoredProcedure + { + internal GetCurrentAndNextWorkitemWatermarkProcedure() : base("dbo.GetCurrentAndNextWorkitemWatermark") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetCurrentAndNextWorkitemWatermark"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + } + } + + internal class GetExtendedQueryTagProcedure : StoredProcedure + { + internal GetExtendedQueryTagProcedure() : base("dbo.GetExtendedQueryTag") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTag"; + _tagPath.AddParameter(command.Parameters, tagPath); + } + } + + internal class GetExtendedQueryTagErrorsProcedure : StoredProcedure + { + internal GetExtendedQueryTagErrorsProcedure() : base("dbo.GetExtendedQueryTagErrors") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Int32 limit, System.Int32 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagErrors"; + _tagPath.AddParameter(command.Parameters, tagPath); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagErrorsV36Procedure : StoredProcedure + { + internal GetExtendedQueryTagErrorsV36Procedure() : base("dbo.GetExtendedQueryTagErrorsV36") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagErrorsV36"; + _tagPath.AddParameter(command.Parameters, tagPath); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagErrorsV6Procedure : StoredProcedure + { + internal GetExtendedQueryTagErrorsV6Procedure() : base("dbo.GetExtendedQueryTagErrorsV6") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Int32 limit, System.Int32 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagErrorsV6"; + _tagPath.AddParameter(command.Parameters, tagPath); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagsProcedure : StoredProcedure + { + internal GetExtendedQueryTagsProcedure() : base("dbo.GetExtendedQueryTags") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int32 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTags"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagsByKeyProcedure : StoredProcedure + { + internal GetExtendedQueryTagsByKeyProcedure() : base("dbo.GetExtendedQueryTagsByKey") + { + } + + private readonly ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition _extendedQueryTagKeys = new ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition("@extendedQueryTagKeys"); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTagKeys) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagsByKey"; + _extendedQueryTagKeys.AddParameter(command.Parameters, extendedQueryTagKeys); + } + + public void PopulateCommand(SqlCommandWrapper command, GetExtendedQueryTagsByKeyTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, extendedQueryTagKeys: tableValuedParameters.ExtendedQueryTagKeys); + } + } + + internal class GetExtendedQueryTagsByKeyTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public GetExtendedQueryTagsByKeyTvpGenerator(ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator) + { + this.ExtendedQueryTagKeyTableTypeV1RowGenerator = ExtendedQueryTagKeyTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator; + + public GetExtendedQueryTagsByKeyTableValuedParameters Generate(TInput input) + { + return new GetExtendedQueryTagsByKeyTableValuedParameters(ExtendedQueryTagKeyTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct GetExtendedQueryTagsByKeyTableValuedParameters + { + internal GetExtendedQueryTagsByKeyTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys) + { + this.ExtendedQueryTagKeys = ExtendedQueryTagKeys; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys { get; } + } + + internal class GetExtendedQueryTagsByOperationProcedure : StoredProcedure + { + internal GetExtendedQueryTagsByOperationProcedure() : base("dbo.GetExtendedQueryTagsByOperation") + { + } + + private readonly ParameterDefinition _operationId = new ParameterDefinition("@operationId", global::System.Data.SqlDbType.UniqueIdentifier, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Guid operationId) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagsByOperation"; + _operationId.AddParameter(command.Parameters, operationId); + } + } + + internal class GetExtendedQueryTagsV36Procedure : StoredProcedure + { + internal GetExtendedQueryTagsV36Procedure() : base("dbo.GetExtendedQueryTagsV36") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagsV36"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetInstanceProcedure : StoredProcedure + { + internal GetInstanceProcedure() : base("dbo.GetInstance") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstance"; + _validStatus.AddParameter(command.Parameters, validStatus); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceBatchesProcedure : StoredProcedure + { + internal GetInstanceBatchesProcedure() : base("dbo.GetInstanceBatches") + { + } + + private readonly ParameterDefinition _batchSize = new ParameterDefinition("@batchSize", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _batchCount = new ParameterDefinition("@batchCount", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxWatermark = new ParameterDefinition>("@maxWatermark", global::System.Data.SqlDbType.BigInt, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 batchSize, System.Int32 batchCount, System.Byte status, System.Nullable maxWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceBatches"; + _batchSize.AddParameter(command.Parameters, batchSize); + _batchCount.AddParameter(command.Parameters, batchCount); + _status.AddParameter(command.Parameters, status); + _maxWatermark.AddParameter(command.Parameters, maxWatermark); + } + } + + internal class GetInstanceBatchesByTimeStampProcedure : StoredProcedure + { + internal GetInstanceBatchesByTimeStampProcedure() : base("dbo.GetInstanceBatchesByTimeStamp") + { + } + + private readonly ParameterDefinition _batchSize = new ParameterDefinition("@batchSize", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _batchCount = new ParameterDefinition("@batchCount", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _startTimeStamp = new ParameterDefinition("@startTimeStamp", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + private readonly ParameterDefinition _endTimeStamp = new ParameterDefinition("@endTimeStamp", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + private readonly ParameterDefinition> _maxWatermark = new ParameterDefinition>("@maxWatermark", global::System.Data.SqlDbType.BigInt, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 batchSize, System.Int32 batchCount, System.Byte status, System.DateTimeOffset startTimeStamp, System.DateTimeOffset endTimeStamp, System.Nullable maxWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceBatchesByTimeStamp"; + _batchSize.AddParameter(command.Parameters, batchSize); + _batchCount.AddParameter(command.Parameters, batchCount); + _status.AddParameter(command.Parameters, status); + _startTimeStamp.AddParameter(command.Parameters, startTimeStamp); + _endTimeStamp.AddParameter(command.Parameters, endTimeStamp); + _maxWatermark.AddParameter(command.Parameters, maxWatermark); + } + } + + internal class GetInstanceV6Procedure : StoredProcedure + { + internal GetInstanceV6Procedure() : base("dbo.GetInstanceV6") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceV6"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceWithPropertiesProcedure : StoredProcedure + { + internal GetInstanceWithPropertiesProcedure() : base("dbo.GetInstanceWithProperties") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceWithProperties"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceWithPropertiesV32Procedure : StoredProcedure + { + internal GetInstanceWithPropertiesV32Procedure() : base("dbo.GetInstanceWithPropertiesV32") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceWithPropertiesV32"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceWithPropertiesV46Procedure : StoredProcedure + { + internal GetInstanceWithPropertiesV46Procedure() : base("dbo.GetInstanceWithPropertiesV46") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceWithPropertiesV46"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstancesByWatermarkRangeProcedure : StoredProcedure + { + internal GetInstancesByWatermarkRangeProcedure() : base("dbo.GetInstancesByWatermarkRange") + { + } + + private readonly ParameterDefinition _startWatermark = new ParameterDefinition("@startWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _endWatermark = new ParameterDefinition("@endWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 startWatermark, System.Int64 endWatermark, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstancesByWatermarkRange"; + _startWatermark.AddParameter(command.Parameters, startWatermark); + _endWatermark.AddParameter(command.Parameters, endWatermark); + _status.AddParameter(command.Parameters, status); + } + } + + internal class GetInstancesByWatermarkRangeV6Procedure : StoredProcedure + { + internal GetInstancesByWatermarkRangeV6Procedure() : base("dbo.GetInstancesByWatermarkRangeV6") + { + } + + private readonly ParameterDefinition _startWatermark = new ParameterDefinition("@startWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _endWatermark = new ParameterDefinition("@endWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 startWatermark, System.Int64 endWatermark, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstancesByWatermarkRangeV6"; + _startWatermark.AddParameter(command.Parameters, startWatermark); + _endWatermark.AddParameter(command.Parameters, endWatermark); + _status.AddParameter(command.Parameters, status); + } + } + + internal class GetPartitionProcedure : StoredProcedure + { + internal GetPartitionProcedure() : base("dbo.GetPartition") + { + } + + private readonly ParameterDefinition _partitionName = new ParameterDefinition("@partitionName", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.String partitionName) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetPartition"; + _partitionName.AddParameter(command.Parameters, partitionName); + } + } + + internal class GetPartitionsProcedure : StoredProcedure + { + internal GetPartitionsProcedure() : base("dbo.GetPartitions") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetPartitions"; + } + } + + internal class GetSeriesResultProcedure : StoredProcedure + { + internal GetSeriesResultProcedure() : base("dbo.GetSeriesResult") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetSeriesResult"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, GetSeriesResultTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class GetSeriesResultTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public GetSeriesResultTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public GetSeriesResultTableValuedParameters Generate(TInput input) + { + return new GetSeriesResultTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct GetSeriesResultTableValuedParameters + { + internal GetSeriesResultTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class GetStudyResultProcedure : StoredProcedure + { + internal GetStudyResultProcedure() : base("dbo.GetStudyResult") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetStudyResult"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, GetStudyResultTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class GetStudyResultTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public GetStudyResultTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public GetStudyResultTableValuedParameters Generate(TInput input) + { + return new GetStudyResultTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct GetStudyResultTableValuedParameters + { + internal GetStudyResultTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class GetWorkitemMetadataProcedure : StoredProcedure + { + internal GetWorkitemMetadataProcedure() : base("dbo.GetWorkitemMetadata") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _procedureStepStateTagPath = new ParameterDefinition("@procedureStepStateTagPath", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, System.String procedureStepStateTagPath) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetWorkitemMetadata"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + _procedureStepStateTagPath.AddParameter(command.Parameters, procedureStepStateTagPath); + } + } + + internal class GetWorkitemQueryTagsProcedure : StoredProcedure + { + internal GetWorkitemQueryTagsProcedure() : base("dbo.GetWorkitemQueryTags") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetWorkitemQueryTags"; + } + } + + internal class IIndexInstanceCoreV9Procedure : StoredProcedure + { + internal IIndexInstanceCoreV9Procedure() : base("dbo.IIndexInstanceCoreV9") + { + } + + private readonly ParameterDefinition> _partitionKey = new ParameterDefinition>("@partitionKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition _studyKey = new ParameterDefinition("@studyKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _seriesKey = new ParameterDefinition("@seriesKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _instanceKey = new ParameterDefinition("@instanceKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 studyKey, System.Int64 seriesKey, System.Int64 instanceKey, System.Int64 watermark, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IIndexInstanceCoreV9"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyKey.AddParameter(command.Parameters, studyKey); + _seriesKey.AddParameter(command.Parameters, seriesKey); + _instanceKey.AddParameter(command.Parameters, instanceKey); + _watermark.AddParameter(command.Parameters, watermark); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 studyKey, System.Int64 seriesKey, System.Int64 instanceKey, System.Int64 watermark, IIndexInstanceCoreV9TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyKey: studyKey, seriesKey: seriesKey, instanceKey: instanceKey, watermark: watermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IIndexInstanceCoreV9TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IIndexInstanceCoreV9TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IIndexInstanceCoreV9TableValuedParameters Generate(TInput input) + { + return new IIndexInstanceCoreV9TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IIndexInstanceCoreV9TableValuedParameters + { + internal IIndexInstanceCoreV9TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class IIndexWorkitemInstanceCoreProcedure : StoredProcedure + { + internal IIndexWorkitemInstanceCoreProcedure() : base("dbo.IIndexWorkitemInstanceCore") + { + } + + private readonly ParameterDefinition> _partitionKey = new ParameterDefinition>("@partitionKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 workitemKey, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IIndexWorkitemInstanceCore"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemKey.AddParameter(command.Parameters, workitemKey); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 workitemKey, IIndexWorkitemInstanceCoreTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, workitemKey: workitemKey, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IIndexWorkitemInstanceCoreTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IIndexWorkitemInstanceCoreTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IIndexWorkitemInstanceCoreTableValuedParameters Generate(TInput input) + { + return new IIndexWorkitemInstanceCoreTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IIndexWorkitemInstanceCoreTableValuedParameters + { + internal IIndexWorkitemInstanceCoreTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class ISleepIfBusyProcedure : StoredProcedure + { + internal ISleepIfBusyProcedure() : base("dbo.ISleepIfBusy") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.ISleepIfBusy"; + } + } + + internal class IncrementDeletedInstanceRetryProcedure : StoredProcedure + { + internal IncrementDeletedInstanceRetryProcedure() : base("dbo.IncrementDeletedInstanceRetry") + { + } + + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _cleanupAfter = new ParameterDefinition("@cleanupAfter", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + + public void PopulateCommand(SqlCommandWrapper command, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.DateTimeOffset cleanupAfter) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IncrementDeletedInstanceRetry"; + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + } + } + + internal class IncrementDeletedInstanceRetryV6Procedure : StoredProcedure + { + internal IncrementDeletedInstanceRetryV6Procedure() : base("dbo.IncrementDeletedInstanceRetryV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _cleanupAfter = new ParameterDefinition("@cleanupAfter", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.DateTimeOffset cleanupAfter) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IncrementDeletedInstanceRetryV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + } + } + + internal class IndexInstanceV6Procedure : StoredProcedure + { + internal IndexInstanceV6Procedure() : base("dbo.IndexInstanceV6") + { + } + + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 watermark, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IndexInstanceV6"; + _watermark.AddParameter(command.Parameters, watermark); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 watermark, IndexInstanceV6TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, watermark: watermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IndexInstanceV6TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IndexInstanceV6TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IndexInstanceV6TableValuedParameters Generate(TInput input) + { + return new IndexInstanceV6TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IndexInstanceV6TableValuedParameters + { + internal IndexInstanceV6TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class RetrieveDeletedInstanceProcedure : StoredProcedure + { + internal RetrieveDeletedInstanceProcedure() : base("dbo.RetrieveDeletedInstance") + { + } + + private readonly ParameterDefinition _count = new ParameterDefinition("@count", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _maxRetries = new ParameterDefinition("@maxRetries", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 count, System.Int32 maxRetries) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.RetrieveDeletedInstance"; + _count.AddParameter(command.Parameters, count); + _maxRetries.AddParameter(command.Parameters, maxRetries); + } + } + + internal class RetrieveDeletedInstanceV42Procedure : StoredProcedure + { + internal RetrieveDeletedInstanceV42Procedure() : base("dbo.RetrieveDeletedInstanceV42") + { + } + + private readonly ParameterDefinition _count = new ParameterDefinition("@count", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _maxRetries = new ParameterDefinition("@maxRetries", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 count, System.Int32 maxRetries) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.RetrieveDeletedInstanceV42"; + _count.AddParameter(command.Parameters, count); + _maxRetries.AddParameter(command.Parameters, maxRetries); + } + } + + internal class RetrieveDeletedInstanceV6Procedure : StoredProcedure + { + internal RetrieveDeletedInstanceV6Procedure() : base("dbo.RetrieveDeletedInstanceV6") + { + } + + private readonly ParameterDefinition _count = new ParameterDefinition("@count", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _maxRetries = new ParameterDefinition("@maxRetries", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 count, System.Int32 maxRetries) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.RetrieveDeletedInstanceV6"; + _count.AddParameter(command.Parameters, count); + _maxRetries.AddParameter(command.Parameters, maxRetries); + } + } + + internal class UpdateExtendedQueryTagQueryStatusProcedure : StoredProcedure + { + internal UpdateExtendedQueryTagQueryStatusProcedure() : base("dbo.UpdateExtendedQueryTagQueryStatus") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _queryStatus = new ParameterDefinition("@queryStatus", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte queryStatus) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateExtendedQueryTagQueryStatus"; + _tagPath.AddParameter(command.Parameters, tagPath); + _queryStatus.AddParameter(command.Parameters, queryStatus); + } + } + + internal class UpdateFilePropertiesContentLengthProcedure : StoredProcedure + { + internal UpdateFilePropertiesContentLengthProcedure() : base("dbo.UpdateFilePropertiesContentLength") + { + } + + private readonly FilePropertyTableTypeV2TableValuedParameterDefinition _filePropertiesToUpdate = new FilePropertyTableTypeV2TableValuedParameterDefinition("@filePropertiesToUpdate"); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable filePropertiesToUpdate) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateFilePropertiesContentLength"; + _filePropertiesToUpdate.AddParameter(command.Parameters, filePropertiesToUpdate); + } + + public void PopulateCommand(SqlCommandWrapper command, UpdateFilePropertiesContentLengthTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, filePropertiesToUpdate: tableValuedParameters.FilePropertiesToUpdate); + } + } + + internal class UpdateFilePropertiesContentLengthTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateFilePropertiesContentLengthTvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeV2RowGenerator) + { + this.FilePropertyTableTypeV2RowGenerator = FilePropertyTableTypeV2RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeV2RowGenerator; + + public UpdateFilePropertiesContentLengthTableValuedParameters Generate(TInput input) + { + return new UpdateFilePropertiesContentLengthTableValuedParameters(FilePropertyTableTypeV2RowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateFilePropertiesContentLengthTableValuedParameters + { + internal UpdateFilePropertiesContentLengthTableValuedParameters(global::System.Collections.Generic.IEnumerable FilePropertiesToUpdate) + { + this.FilePropertiesToUpdate = FilePropertiesToUpdate; + } + + internal global::System.Collections.Generic.IEnumerable FilePropertiesToUpdate { get; } + } + + internal class UpdateFrameMetadataProcedure : StoredProcedure + { + internal UpdateFrameMetadataProcedure() : base("dbo.UpdateFrameMetadata") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _hasFrameMetadata = new ParameterDefinition("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.Boolean hasFrameMetadata, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateFrameMetadata"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.Boolean hasFrameMetadata, UpdateFrameMetadataTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, hasFrameMetadata: hasFrameMetadata, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class UpdateFrameMetadataTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateFrameMetadataTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public UpdateFrameMetadataTableValuedParameters Generate(TInput input) + { + return new UpdateFrameMetadataTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateFrameMetadataTableValuedParameters + { + internal UpdateFrameMetadataTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class UpdateIndexWorkitemInstanceCoreProcedure : StoredProcedure + { + internal UpdateIndexWorkitemInstanceCoreProcedure() : base("dbo.UpdateIndexWorkitemInstanceCore") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateIndexWorkitemInstanceCore"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, UpdateIndexWorkitemInstanceCoreTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, workitemKey: workitemKey, partitionKey: partitionKey, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class UpdateIndexWorkitemInstanceCoreTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateIndexWorkitemInstanceCoreTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public UpdateIndexWorkitemInstanceCoreTableValuedParameters Generate(TInput input) + { + return new UpdateIndexWorkitemInstanceCoreTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateIndexWorkitemInstanceCoreTableValuedParameters + { + internal UpdateIndexWorkitemInstanceCoreTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class UpdateInstanceStatusProcedure : StoredProcedure + { + internal UpdateInstanceStatusProcedure() : base("dbo.UpdateInstanceStatus") + { + } + + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatus"; + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + } + } + + internal class UpdateInstanceStatusV37Procedure : StoredProcedure + { + internal UpdateInstanceStatusV37Procedure() : base("dbo.UpdateInstanceStatusV37") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxTagKey = new ParameterDefinition>("@maxTagKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _hasFrameMetadata = new ParameterDefinition>("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, true); + private readonly ParameterDefinition _path = new ParameterDefinition("@path", global::System.Data.SqlDbType.VarChar, true, 4000); + private readonly ParameterDefinition _eTag = new ParameterDefinition("@eTag", global::System.Data.SqlDbType.VarChar, true, 4000); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status, System.Nullable maxTagKey, System.Nullable hasFrameMetadata, System.String path, System.String eTag) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatusV37"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + _maxTagKey.AddParameter(command.Parameters, maxTagKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + _path.AddParameter(command.Parameters, path); + _eTag.AddParameter(command.Parameters, eTag); + } + } + + internal class UpdateInstanceStatusV54Procedure : StoredProcedure + { + internal UpdateInstanceStatusV54Procedure() : base("dbo.UpdateInstanceStatusV54") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxTagKey = new ParameterDefinition>("@maxTagKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _hasFrameMetadata = new ParameterDefinition>("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, true); + private readonly ParameterDefinition _path = new ParameterDefinition("@path", global::System.Data.SqlDbType.VarChar, true, 4000); + private readonly ParameterDefinition _eTag = new ParameterDefinition("@eTag", global::System.Data.SqlDbType.VarChar, true, 4000); + private readonly ParameterDefinition> _contentLength = new ParameterDefinition>("@contentLength", global::System.Data.SqlDbType.BigInt, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status, System.Nullable maxTagKey, System.Nullable hasFrameMetadata, System.String path, System.String eTag, System.Nullable contentLength) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatusV54"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + _maxTagKey.AddParameter(command.Parameters, maxTagKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + _path.AddParameter(command.Parameters, path); + _eTag.AddParameter(command.Parameters, eTag); + _contentLength.AddParameter(command.Parameters, contentLength); + } + } + + internal class UpdateInstanceStatusV6Procedure : StoredProcedure + { + internal UpdateInstanceStatusV6Procedure() : base("dbo.UpdateInstanceStatusV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxTagKey = new ParameterDefinition>("@maxTagKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _hasFrameMetadata = new ParameterDefinition>("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status, System.Nullable maxTagKey, System.Nullable hasFrameMetadata) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatusV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + _maxTagKey.AddParameter(command.Parameters, maxTagKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + } + } + + internal class UpdateWorkitemProcedureStepStateProcedure : StoredProcedure + { + internal UpdateWorkitemProcedureStepStateProcedure() : base("dbo.UpdateWorkitemProcedureStepState") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _procedureStepStateTagPath = new ParameterDefinition("@procedureStepStateTagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _procedureStepState = new ParameterDefinition("@procedureStepState", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _proposedWatermark = new ParameterDefinition("@proposedWatermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.String procedureStepStateTagPath, System.String procedureStepState, System.Int64 watermark, System.Int64 proposedWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemProcedureStepState"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _procedureStepStateTagPath.AddParameter(command.Parameters, procedureStepStateTagPath); + _procedureStepState.AddParameter(command.Parameters, procedureStepState); + _watermark.AddParameter(command.Parameters, watermark); + _proposedWatermark.AddParameter(command.Parameters, proposedWatermark); + } + } + + internal class UpdateWorkitemProcedureStepStateV21Procedure : StoredProcedure + { + internal UpdateWorkitemProcedureStepStateV21Procedure() : base("dbo.UpdateWorkitemProcedureStepStateV21") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _procedureStepStateTagPath = new ParameterDefinition("@procedureStepStateTagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _procedureStepState = new ParameterDefinition("@procedureStepState", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _proposedWatermark = new ParameterDefinition("@proposedWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _transactionUid = new ParameterDefinition("@transactionUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.String procedureStepStateTagPath, System.String procedureStepState, System.Int64 watermark, System.Int64 proposedWatermark, System.String transactionUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemProcedureStepStateV21"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _procedureStepStateTagPath.AddParameter(command.Parameters, procedureStepStateTagPath); + _procedureStepState.AddParameter(command.Parameters, procedureStepState); + _watermark.AddParameter(command.Parameters, watermark); + _proposedWatermark.AddParameter(command.Parameters, proposedWatermark); + _transactionUid.AddParameter(command.Parameters, transactionUid); + } + } + + internal class UpdateWorkitemStatusProcedure : StoredProcedure + { + internal UpdateWorkitemStatusProcedure() : base("dbo.UpdateWorkitemStatus") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.Int64 workitemKey, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemStatus"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemKey.AddParameter(command.Parameters, workitemKey); + _status.AddParameter(command.Parameters, status); + } + } + + internal class UpdateWorkitemTransactionProcedure : StoredProcedure + { + internal UpdateWorkitemTransactionProcedure() : base("dbo.UpdateWorkitemTransaction") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _proposedWatermark = new ParameterDefinition("@proposedWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, System.Int64 watermark, System.Int64 proposedWatermark, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemTransaction"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermark.AddParameter(command.Parameters, watermark); + _proposedWatermark.AddParameter(command.Parameters, proposedWatermark); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, System.Int64 watermark, System.Int64 proposedWatermark, UpdateWorkitemTransactionTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, workitemKey: workitemKey, partitionKey: partitionKey, watermark: watermark, proposedWatermark: proposedWatermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class UpdateWorkitemTransactionTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateWorkitemTransactionTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public UpdateWorkitemTransactionTableValuedParameters Generate(TInput input) + { + return new UpdateWorkitemTransactionTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateWorkitemTransactionTableValuedParameters + { + internal UpdateWorkitemTransactionTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/VLatest.Generated.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/VLatest.Generated.cs index 618d1e107a..e15585abc8 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/VLatest.Generated.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/VLatest.Generated.cs @@ -74,6 +74,7 @@ internal class VLatest internal readonly static GetExtendedQueryTagsByKeyProcedure GetExtendedQueryTagsByKey = new GetExtendedQueryTagsByKeyProcedure(); internal readonly static GetExtendedQueryTagsByOperationProcedure GetExtendedQueryTagsByOperation = new GetExtendedQueryTagsByOperationProcedure(); internal readonly static GetExtendedQueryTagsV36Procedure GetExtendedQueryTagsV36 = new GetExtendedQueryTagsV36Procedure(); + internal readonly static GetIndexedFileMetricsProcedure GetIndexedFileMetrics = new GetIndexedFileMetricsProcedure(); internal readonly static GetInstanceProcedure GetInstance = new GetInstanceProcedure(); internal readonly static GetInstanceBatchesProcedure GetInstanceBatches = new GetInstanceBatchesProcedure(); internal readonly static GetInstanceBatchesByTimeStampProcedure GetInstanceBatchesByTimeStamp = new GetInstanceBatchesByTimeStampProcedure(); @@ -310,6 +311,7 @@ internal FilePropertyTable() : base("dbo.FileProperty") internal readonly BigIntColumn ContentLength = new BigIntColumn("ContentLength"); internal readonly Index IXC_FileProperty = new Index("IXC_FileProperty"); internal readonly Index IXC_FileProperty_InstanceKey_Watermark_ContentLength = new Index("IXC_FileProperty_InstanceKey_Watermark_ContentLength"); + internal readonly Index IXC_FileProperty_ContentLength = new Index("IXC_FileProperty_ContentLength"); } internal class InstanceTable : Table @@ -1822,6 +1824,19 @@ public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, Syste } } + internal class GetIndexedFileMetricsProcedure : StoredProcedure + { + internal GetIndexedFileMetricsProcedure() : base("dbo.GetIndexedFileMetrics") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetIndexedFileMetrics"; + } + } + internal class GetInstanceProcedure : StoredProcedure { internal GetInstanceProcedure() : base("dbo.GetInstance") diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs index adc1406c25..610e81911a 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs @@ -67,4 +67,5 @@ public enum SchemaVersion V54 = 54, V55 = 55, V56 = 56, + V57 = 57, } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs index 7655cc17b6..1d06ba3df0 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs @@ -7,6 +7,6 @@ namespace Microsoft.Health.Dicom.SqlServer.Features.Schema; public static class SchemaVersionConstants { - public const int Min = (int)SchemaVersion.V51; - public const int Max = (int)SchemaVersion.V56; + public const int Min = (int)SchemaVersion.V54; + public const int Max = (int)SchemaVersion.V57; } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/GetIndexedFileMetrics.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/GetIndexedFileMetrics.sql new file mode 100644 index 0000000000..61ead5ed91 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/GetIndexedFileMetrics.sql @@ -0,0 +1,19 @@ +/***************************************************************************************/ +-- STORED PROCEDURE +-- GetIndexedFileMetrics +-- +-- FIRST SCHEMA VERSION +-- 57 +-- +-- DESCRIPTION +-- Retrieves total sum of content length across all FileProperty rows +-- +/***************************************************************************************/ +CREATE OR ALTER PROCEDURE dbo.GetIndexedFileMetrics + AS +BEGIN + SET NOCOUNT ON + SET XACT_ABORT ON + +SELECT TotalIndexedFileCount=COUNT_BIG(*), TotalIndexedBytes=SUM(ContentLength) FROM dbo.FileProperty +END \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Tables/FileProperty.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Tables/FileProperty.sql index f7d7cd11df..b61b5b9b79 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Tables/FileProperty.sql +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Tables/FileProperty.sql @@ -30,3 +30,9 @@ CREATE NONCLUSTERED INDEX IXC_FileProperty_InstanceKey_Watermark_ContentLength O ContentLength ) WITH (DATA_COMPRESSION = PAGE, ONLINE = ON) + +-- Used to get dailu sum total +CREATE NONCLUSTERED INDEX IXC_FileProperty_ContentLength ON dbo.FileProperty( + ContentLength +) +WITH (DATA_COMPRESSION = PAGE, ONLINE = ON) \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs index 1b6276d028..dcd4ada61d 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs @@ -133,4 +133,10 @@ public async Task UpdateFilePropertiesContentLengthAsync( ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken); await store.UpdateFilePropertiesContentLengthAsync(filePropertiesByWatermark, cancellationToken); } + + public async Task GetIndexedFileMetricsAsync(CancellationToken cancellationToken = default) + { + ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken); + return await store.GetIndexedFileMetricsAsync(cancellationToken); + } } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs index c9f7a8df89..165f977c37 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs @@ -378,4 +378,9 @@ public virtual Task UpdateFilePropertiesContentLengthAsync( { throw new BadRequestException(DicomSqlServerResource.SchemaVersionNeedsToBeUpgraded); } + + public virtual Task GetIndexedFileMetricsAsync(CancellationToken cancellationToken = default) + { + throw new BadRequestException(DicomSqlServerResource.SchemaVersionNeedsToBeUpgraded); + } } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV57.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV57.cs new file mode 100644 index 0000000000..d08a43728e --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV57.cs @@ -0,0 +1,55 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.Health.Dicom.Core.Exceptions; +using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.SqlServer.Features.Schema; +using Microsoft.Health.Dicom.SqlServer.Features.Schema.Model; +using Microsoft.Health.SqlServer.Features.Client; +using Microsoft.Health.SqlServer.Features.Storage; + +namespace Microsoft.Health.Dicom.SqlServer.Features.Store; + +internal class SqlIndexDataStoreV57 : SqlIndexDataStoreV55 +{ + protected static readonly Health.SqlServer.Features.Schema.Model.BigIntColumn TotalIndexedFileCount = new("TotalIndexedFileCount"); + protected static readonly Health.SqlServer.Features.Schema.Model.NullableBigIntColumn TotalIndexedBytes = new("TotalIndexedBytes"); + + public SqlIndexDataStoreV57(SqlConnectionWrapperFactory sqlConnectionWrapperFactory) + : base(sqlConnectionWrapperFactory) + { + } + + public override SchemaVersion Version => SchemaVersion.V57; + + public override async Task GetIndexedFileMetricsAsync(CancellationToken cancellationToken = default) + { + using SqlConnectionWrapper sqlConnectionWrapper = await SqlConnectionWrapperFactory.ObtainSqlConnectionWrapperAsync(cancellationToken, true); + using SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateRetrySqlCommand(); + VLatest.GetIndexedFileMetrics.PopulateCommand(sqlCommandWrapper); + + try + { + using SqlDataReader sqlDataReader = await sqlCommandWrapper.ExecuteReaderAsync(cancellationToken); + + await sqlDataReader.ReadAsync(cancellationToken); + + (long count, long? sum) = sqlDataReader.ReadRow(TotalIndexedFileCount, TotalIndexedBytes); + + return new IndexedFileProperties + { + TotalIndexed = count, + TotalSum = sum ?? 0, + }; + } + catch (SqlException ex) + { + throw new DataStoreException(ex); + } + } +} diff --git a/src/Microsoft.Health.Dicom.SqlServer/Microsoft.Health.Dicom.SqlServer.csproj b/src/Microsoft.Health.Dicom.SqlServer/Microsoft.Health.Dicom.SqlServer.csproj index 02ca7b1768..72da592125 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Microsoft.Health.Dicom.SqlServer.csproj +++ b/src/Microsoft.Health.Dicom.SqlServer/Microsoft.Health.Dicom.SqlServer.csproj @@ -7,7 +7,7 @@ - 56 + 57 Features\Schema\Migrations\$(LatestSchemaVersion).sql diff --git a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs index df2c212e94..7e87bcfbd7 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs @@ -161,6 +161,7 @@ private static IServiceCollection AddSqlIndexDataStores(this IServiceCollection services.TryAddEnumerable(ServiceDescriptor.Scoped()); services.TryAddEnumerable(ServiceDescriptor.Scoped()); services.TryAddEnumerable(ServiceDescriptor.Scoped()); + services.TryAddEnumerable(ServiceDescriptor.Scoped()); return services; } diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/IndexedFilePropertiesCollection.cs b/test/Microsoft.Health.Dicom.Tests.Integration/IndexedFilePropertiesCollection.cs new file mode 100644 index 0000000000..5a43a8db1e --- /dev/null +++ b/test/Microsoft.Health.Dicom.Tests.Integration/IndexedFilePropertiesCollection.cs @@ -0,0 +1,13 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using Xunit; + +namespace Microsoft.Health.Dicom.Tests.Integration; + +[CollectionDefinition("Indexed File Properties Collection", DisableParallelization = true)] +public class IndexedFilePropertiesCollection +{ +} diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IndexedFilePropertiesTests.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IndexedFilePropertiesTests.cs new file mode 100644 index 0000000000..33b4c02f15 --- /dev/null +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IndexedFilePropertiesTests.cs @@ -0,0 +1,101 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using EnsureThat; +using FellowOakDicom; +using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.Partitioning; +using Microsoft.Health.Dicom.Core.Features.Store; +using Microsoft.Health.Dicom.Tests.Common; +using Microsoft.Health.Dicom.Tests.Common.Extensions; +using Xunit; + +namespace Microsoft.Health.Dicom.Tests.Integration.Persistence; + +/// +/// Can not be run in parallel as each inserts data and each queries all of these inserts for testing. +/// +[Collection("Indexed File Properties Collection")] +public class IndexedFilePropertiesTests : IClassFixture +{ + private readonly IIndexDataStore _indexDataStore; + private readonly SqlDataStoreTestsFixture _fixture; + + private static readonly string StudyInstanceUid = TestUidGenerator.Generate(); + private readonly FileProperties _fileProperties = new() { Path = "path.dcm", ETag = "E1230", ContentLength = 10 }; + + public IndexedFilePropertiesTests(SqlDataStoreTestsFixture fixture) + { + _fixture = EnsureArg.IsNotNull(fixture, nameof(fixture)); + _indexDataStore = EnsureArg.IsNotNull(fixture?.IndexDataStore, nameof(fixture.IndexDataStore)); + } + + [Fact] + public async Task GivenNoFilePropertiesIndexed_WhenGetIndexedFileMetricsAsync_ExpectCorrectTotalsRetrieved() + { + IndexedFileProperties indexedFileProperties = await _indexDataStore.GetIndexedFileMetricsAsync(); + + Assert.Equal(0, indexedFileProperties.TotalSum); + Assert.Equal(0, indexedFileProperties.TotalIndexed); + } + + [Fact] + public async Task GivenFilePropertiesIndexed_WhenGetIndexedFileMetricsAsync_ExpectCorrectTotalsRetrieved() + { + var properties = new List + { + await CreateRandomInstanceAsync(fileProperties: _fileProperties), + await CreateRandomInstanceAsync(fileProperties: _fileProperties), + await CreateRandomInstanceAsync(fileProperties: _fileProperties), + await CreateRandomInstanceAsync(fileProperties: _fileProperties), + }; + + IndexedFileProperties indexedFileProperties = await _indexDataStore.GetIndexedFileMetricsAsync(); + + Assert.Equal(properties.Sum(x => x.ContentLength), indexedFileProperties.TotalSum); + Assert.Equal(properties.Count, indexedFileProperties.TotalIndexed); + + // cleanup so other tests are not affected + await _indexDataStore.DeleteStudyIndexAsync(Partition.Default, StudyInstanceUid, DateTime.Now, CancellationToken.None); + } + + [Fact] + public async Task GivenFilePropertiesIndexedWithZeroes_WhenGetIndexedFileMetricsAsync_ExpectCorrectTotalsRetrieved() + { + FileProperties zeroLengthFileProperties = new FileProperties { Path = "zeroLength.dcm", ETag = "E1230", ContentLength = 0 }; + + var properties = new List + { + await CreateRandomInstanceAsync(fileProperties: _fileProperties), + await CreateRandomInstanceAsync(fileProperties: zeroLengthFileProperties), + await CreateRandomInstanceAsync(fileProperties: _fileProperties), + }; + + IndexedFileProperties indexedFileProperties = await _indexDataStore.GetIndexedFileMetricsAsync(); + + Assert.Equal(properties.Sum(x => x.ContentLength), indexedFileProperties.TotalSum); + Assert.Equal(properties.Count, indexedFileProperties.TotalIndexed); + + // cleanup so other tests are not affected + await _indexDataStore.DeleteStudyIndexAsync(Partition.Default, StudyInstanceUid, DateTime.Now, CancellationToken.None); + } + + private async Task CreateRandomInstanceAsync(FileProperties fileProperties, Partition partition = null) + { + DicomDataset dataset = Samples.CreateRandomInstanceDataset(StudyInstanceUid); + partition ??= Partition.Default; + + long watermark = await _indexDataStore.BeginCreateInstanceIndexAsync(partition, dataset); + + await _indexDataStore.EndCreateInstanceIndexAsync(partition.Key, dataset, watermark, fileProperties); + + return fileProperties; + } +} \ No newline at end of file diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs index 2ca522d9e5..cba1d267eb 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs @@ -121,6 +121,7 @@ internal SqlDataStoreTestsFixture(string databaseName, SchemaInformation schemaI new SqlIndexDataStoreV52(SqlConnectionWrapperFactory), new SqlIndexDataStoreV54(SqlConnectionWrapperFactory), new SqlIndexDataStoreV55(SqlConnectionWrapperFactory), + new SqlIndexDataStoreV57(SqlConnectionWrapperFactory), }), NullLogger.Instance);