diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/ExtendedQueryTag/SqlExtendedQueryTagStoreV8.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/ExtendedQueryTag/SqlExtendedQueryTagStoreV8.cs new file mode 100644 index 0000000000..b0988dfb04 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/ExtendedQueryTag/SqlExtendedQueryTagStoreV8.cs @@ -0,0 +1,53 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Microsoft.Extensions.Logging; +using Microsoft.Health.Dicom.Core.Exceptions; +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.ExtendedQueryTag +{ + internal class SqlExtendedQueryTagStoreV8 : SqlExtendedQueryTagStoreV4 + { + public SqlExtendedQueryTagStoreV8( + SqlConnectionWrapperFactory sqlConnectionWrapperFactory, + ILogger logger) + : base(sqlConnectionWrapperFactory, logger) + { + } + + public override SchemaVersion Version => SchemaVersion.V8; + + public override async Task DeleteExtendedQueryTagAsync(string tagPath, string vr, CancellationToken cancellationToken = default) + { + using (SqlConnectionWrapper sqlConnectionWrapper = await ConnectionWrapperFactory.ObtainSqlConnectionWrapperAsync(cancellationToken)) + using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand()) + { + VLatest.DeleteExtendedQueryTagV8.PopulateCommand(sqlCommandWrapper, tagPath, (byte)ExtendedQueryTagLimit.ExtendedQueryTagVRAndDataTypeMapping[vr]); + + try + { + await sqlCommandWrapper.ExecuteNonQueryAsync(cancellationToken); + } + catch (SqlException ex) + { + throw ex.Number switch + { + SqlErrorCodes.NotFound => new ExtendedQueryTagNotFoundException( + string.Format(CultureInfo.InvariantCulture, DicomSqlServerResource.ExtendedQueryTagNotFound, tagPath)), + _ => new DataStoreException(ex), + }; + } + } + } + } +} diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/8.diff.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/8.diff.sql new file mode 100644 index 0000000000..cb90015057 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/8.diff.sql @@ -0,0 +1,96 @@ +/**************************************************************************************** +Guidelines to create migration scripts - https://github.com/microsoft/healthcare-shared-components/tree/master/src/Microsoft.Health.SqlServer/SqlSchemaScriptsGuidelines.md + +This diff is broken up into several sections: + - The first transaction contains changes to tables and stored procedures. + - The second transaction contains updates to indexes. + - IMPORTANT: Avoid rebuiling indexes inside the transaction, it locks the table during the transaction. +******************************************************************************************/ +SET XACT_ABORT ON + +/************************************************************* + Configure database +**************************************************************/ + +-- Enable RCSI +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 + +-- Avoid blocking queries when statistics need to be rebuilt +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 + +-- Use ANSI behavior for null values +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 + +/***************************************************************************************/ +-- STORED PROCEDURE +-- DeleteExtendedQueryTagV8 +-- +-- DESCRIPTION +-- Delete specific extended query tag +-- +-- PARAMETERS +-- @tagPath +-- * The extended query tag path +-- @dataType +-- * the data type of extended query tag. 0 -- String, 1 -- Long, 2 -- Double, 3 -- DateTime, 4 -- PersonName +/***************************************************************************************/ +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV8 + @tagPath VARCHAR(64), + @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON + SET XACT_ABORT ON + + BEGIN TRANSACTION + + DECLARE @tagKey INT + + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH(XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath + + -- Check existence + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1 + + -- Update status to Deleting + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey + + COMMIT TRANSACTION + + BEGIN TRANSACTION + + -- Delete index data + IF @dataType = 0 + DELETE FROM dbo.ExtendedQueryTagString WHERE TagKey = @tagKey + ELSE IF @dataType = 1 + DELETE FROM dbo.ExtendedQueryTagLong WHERE TagKey = @tagKey + ELSE IF @dataType = 2 + DELETE FROM dbo.ExtendedQueryTagDouble WHERE TagKey = @tagKey + ELSE IF @dataType = 3 + DELETE FROM dbo.ExtendedQueryTagDateTime WHERE TagKey = @tagKey + ELSE + DELETE FROM dbo.ExtendedQueryTagPersonName WHERE TagKey = @tagKey + + -- Delete errors + DELETE FROM dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey + + -- Delete tag + DELETE FROM dbo.ExtendedQueryTag + WHERE TagKey = @tagKey + + COMMIT TRANSACTION +END +GO diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/8.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/8.sql new file mode 100644 index 0000000000..17d5960006 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/8.sql @@ -0,0 +1,2441 @@ + +/************************************************************************************************* + 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 TABLE dbo.ChangeFeed ( + Sequence BIGINT IDENTITY (1, 1) NOT NULL, + Timestamp DATETIMEOFFSET (7) 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 +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ChangeFeed + ON dbo.ChangeFeed(Sequence); + +CREATE NONCLUSTERED INDEX IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.ChangeFeed(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) 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 +) +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) 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, + StudyKey BIGINT NOT NULL, + SeriesKey BIGINT NULL, + InstanceKey BIGINT NULL, + Watermark BIGINT NOT NULL, + TagValueUtc DATETIME2 (7) NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagDateTime + ON dbo.ExtendedQueryTagDateTime(TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagDateTime_TagKey_PartitionKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagDateTime(TagKey, PartitionKey, StudyKey, SeriesKey, InstanceKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDateTime_PartitionKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagDateTime(PartitionKey, StudyKey, SeriesKey, InstanceKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagDouble ( + TagKey INT NOT NULL, + TagValue FLOAT (53) NOT NULL, + StudyKey BIGINT NOT NULL, + SeriesKey BIGINT NULL, + InstanceKey BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagDouble + ON dbo.ExtendedQueryTagDouble(TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagDouble_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagDouble(TagKey, PartitionKey, StudyKey, SeriesKey, InstanceKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDouble_PartitionKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagDouble(PartitionKey, StudyKey, SeriesKey, InstanceKey) 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, + StudyKey BIGINT NOT NULL, + SeriesKey BIGINT NULL, + InstanceKey BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagLong + ON dbo.ExtendedQueryTagLong(TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagLong_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagLong(TagKey, PartitionKey, StudyKey, SeriesKey, InstanceKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagLong_PartitionKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagLong(PartitionKey, StudyKey, SeriesKey, InstanceKey) 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, + StudyKey BIGINT NOT NULL, + SeriesKey BIGINT NULL, + InstanceKey BIGINT NULL, + Watermark BIGINT NOT NULL, + WatermarkAndTagKey AS CONCAT(TagKey, '.', Watermark), + TagValueWords AS REPLACE(REPLACE(TagValue, '^', ' '), '=', ' ') PERSISTED, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagPersonName + ON dbo.ExtendedQueryTagPersonName(TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagPersonName(TagKey, PartitionKey, StudyKey, SeriesKey, InstanceKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagPersonName_PartitionKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagPersonName(PartitionKey, StudyKey, SeriesKey, InstanceKey) 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, + StudyKey BIGINT NOT NULL, + SeriesKey BIGINT NULL, + InstanceKey BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagString + ON dbo.ExtendedQueryTagString(TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagString_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagString(TagKey, PartitionKey, StudyKey, SeriesKey, InstanceKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagString_PartitionKey_StudyKey_SeriesKey_InstanceKey + ON dbo.ExtendedQueryTagString(PartitionKey, StudyKey, SeriesKey, InstanceKey) WITH (DATA_COMPRESSION = PAGE); + +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 +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Instance + ON dbo.Instance(SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid_PartitionKey + ON dbo.Instance(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, PartitionKey) + INCLUDE(Status, Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_StudyInstanceUid_Status_PartitionKey + ON dbo.Instance(StudyInstanceUid, Status, PartitionKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_StudyInstanceUid_SeriesInstanceUid_Status_PartitionKey + ON dbo.Instance(StudyInstanceUid, SeriesInstanceUid, Status, PartitionKey) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_SopInstanceUid_Status_PartitionKey + ON dbo.Instance(SopInstanceUid, Status, PartitionKey) + INCLUDE(StudyInstanceUid, SeriesInstanceUid, Watermark) 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_SeriesKey_Status_Watermark + ON dbo.Instance(SeriesKey, Status, Watermark) + INCLUDE(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_StudyKey_Status_Watermark + ON dbo.Instance(StudyKey, Status, Watermark) + INCLUDE(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_SeriesKey + ON dbo.Series(SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Series_SeriesInstanceUid_PartitionKey + ON dbo.Series(SeriesInstanceUid, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_Modality_PartitionKey + ON dbo.Series(Modality, PartitionKey) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PerformedProcedureStepStartDate_PartitionKey + ON dbo.Series(PerformedProcedureStepStartDate, PartitionKey) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_ManufacturerModelName_PartitionKey + ON dbo.Series(ManufacturerModelName, PartitionKey) + 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_StudyInstanceUid_PartitionKey + ON dbo.Study(StudyInstanceUid, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PatientId_PartitionKey + ON dbo.Study(PatientId, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PatientName_PartitionKey + ON dbo.Study(PatientName, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_ReferringPhysicianName_PartitionKey + ON dbo.Study(ReferringPhysicianName, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_StudyDate_PartitionKey + ON dbo.Study(StudyDate, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_StudyDescription_PartitionKey + ON dbo.Study(StudyDescription, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_AccessionNumber_PartitionKey + ON dbo.Study(AccessionNumber, PartitionKey) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PatientBirthDate_PartitionKey + ON dbo.Study(PatientBirthDate, PartitionKey) + INCLUDE(StudyKey) 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); + +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 (HOLDLOCK) + 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 (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.AddInstance +@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_1 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +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 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 StudyInstanceUid = @studyInstanceUid; +IF @@ROWCOUNT = 0 + BEGIN + SET @studyKey = NEXT VALUE FOR dbo.StudyKeySequence; + INSERT INTO dbo.Study (StudyKey, StudyInstanceUid, PatientId, PatientName, PatientBirthDate, ReferringPhysicianName, StudyDate, StudyDescription, AccessionNumber) + VALUES (@studyKey, @studyInstanceUid, @patientId, @patientName, @patientBirthDate, @referringPhysicianName, @studyDate, @studyDescription, @accessionNumber); + END +ELSE + BEGIN + UPDATE dbo.Study + SET PatientId = @patientId, + PatientName = @patientName, + PatientBirthDate = @patientBirthDate, + ReferringPhysicianName = @referringPhysicianName, + StudyDate = @studyDate, + StudyDescription = @studyDescription, + AccessionNumber = @accessionNumber + WHERE StudyKey = @studyKey; + END +SELECT @seriesKey = SeriesKey +FROM dbo.Series WITH (UPDLOCK) +WHERE StudyKey = @studyKey + AND SeriesInstanceUid = @seriesInstanceUid; +IF @@ROWCOUNT = 0 + BEGIN + SET @seriesKey = NEXT VALUE FOR dbo.SeriesKeySequence; + INSERT INTO dbo.Series (StudyKey, SeriesKey, SeriesInstanceUid, Modality, PerformedProcedureStepStartDate, ManufacturerModelName) + VALUES (@studyKey, @seriesKey, @seriesInstanceUid, @modality, @performedProcedureStepStartDate, @manufacturerModelName); + END +ELSE + BEGIN + UPDATE dbo.Series + SET Modality = @modality, + PerformedProcedureStepStartDate = @performedProcedureStepStartDate, + ManufacturerModelName = @manufacturerModelName + WHERE SeriesKey = @seriesKey + AND StudyKey = @studyKey; + END +INSERT INTO dbo.Instance (StudyKey, SeriesKey, InstanceKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, Status, LastStatusUpdatedDate, CreatedDate) +VALUES (@studyKey, @seriesKey, @instanceKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @newWatermark, @initialStatus, @currentDate, @currentDate); +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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + END +IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDateTime + AS T + USING (SELECT input.TagKey, + input.TagValue, + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + END +SELECT @newWatermark; +COMMIT TRANSACTION; + +GO +CREATE OR ALTER PROCEDURE dbo.AddInstanceV2 +@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 +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +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 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 StudyInstanceUid = @studyInstanceUid; +IF @@ROWCOUNT = 0 + BEGIN + SET @studyKey = NEXT VALUE FOR dbo.StudyKeySequence; + INSERT INTO dbo.Study (StudyKey, StudyInstanceUid, PatientId, PatientName, PatientBirthDate, ReferringPhysicianName, StudyDate, StudyDescription, AccessionNumber) + VALUES (@studyKey, @studyInstanceUid, @patientId, @patientName, @patientBirthDate, @referringPhysicianName, @studyDate, @studyDescription, @accessionNumber); + END +ELSE + BEGIN + UPDATE dbo.Study + SET PatientId = @patientId, + PatientName = @patientName, + PatientBirthDate = @patientBirthDate, + ReferringPhysicianName = @referringPhysicianName, + StudyDate = @studyDate, + StudyDescription = @studyDescription, + AccessionNumber = @accessionNumber + WHERE StudyKey = @studyKey; + END +SELECT @seriesKey = SeriesKey +FROM dbo.Series WITH (UPDLOCK) +WHERE StudyKey = @studyKey + AND SeriesInstanceUid = @seriesInstanceUid; +IF @@ROWCOUNT = 0 + BEGIN + SET @seriesKey = NEXT VALUE FOR dbo.SeriesKeySequence; + INSERT INTO dbo.Series (StudyKey, SeriesKey, SeriesInstanceUid, Modality, PerformedProcedureStepStartDate, ManufacturerModelName) + VALUES (@studyKey, @seriesKey, @seriesInstanceUid, @modality, @performedProcedureStepStartDate, @manufacturerModelName); + END +ELSE + BEGIN + UPDATE dbo.Series + SET Modality = @modality, + PerformedProcedureStepStartDate = @performedProcedureStepStartDate, + ManufacturerModelName = @manufacturerModelName + WHERE SeriesKey = @seriesKey + AND StudyKey = @studyKey; + END +INSERT INTO dbo.Instance (StudyKey, SeriesKey, InstanceKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, Status, LastStatusUpdatedDate, CreatedDate) +VALUES (@studyKey, @seriesKey, @instanceKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @newWatermark, @initialStatus, @currentDate, @currentDate); +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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark, TagValueUtc) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark, S.TagValueUtc); + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = @newWatermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @newWatermark); + END +SELECT @newWatermark; +COMMIT TRANSACTION; + +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 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + 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 + 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 + ELSE + BEGIN + UPDATE dbo.Study + SET PatientId = @patientId, + PatientName = @patientName, + PatientBirthDate = @patientBirthDate, + ReferringPhysicianName = @referringPhysicianName, + StudyDate = @studyDate, + StudyDescription = @studyDescription, + AccessionNumber = @accessionNumber + WHERE 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 = @modality, + PerformedProcedureStepStartDate = @performedProcedureStepStartDate, + 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) + VALUES (@partitionKey, @studyKey, @seriesKey, @instanceKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @newWatermark, @initialStatus, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexInstanceCore @partitionKey, @studyKey, @seriesKey, @instanceKey, @newWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @newWatermark; + COMMIT TRANSACTION; +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; + 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.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.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.DeleteExtendedQueryTagV8 +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + 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; + 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.ExtendedQueryTagError + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteInstance +@cleanupAfter DATETIMEOFFSET (0), @createdStatus TINYINT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN TRANSACTION; +DECLARE @deletedInstances AS TABLE ( + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Status TINYINT , + Watermark BIGINT ); +DECLARE @studyKey AS BIGINT; +DECLARE @seriesKey AS BIGINT; +DECLARE @instanceKey AS BIGINT; +DECLARE @deletedDate AS DATETIME2 = SYSUTCDATETIME(); +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 StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid); +DELETE dbo.Instance +OUTPUT deleted.StudyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.Status, deleted.Watermark INTO @deletedInstances +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid); +IF @@ROWCOUNT = 0 + THROW 50404, 'Instance not found', 1; +DECLARE @deletedTags AS TABLE ( + TagKey BIGINT); +DELETE XQTE +OUTPUT deleted.TagKey INTO @deletedTags +FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + @deletedInstances AS d + ON XQTE.Watermark = d.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 StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey); +DELETE dbo.ExtendedQueryTagLong +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey); +DELETE dbo.ExtendedQueryTagDouble +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey); +DELETE dbo.ExtendedQueryTagDateTime +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey); +DELETE dbo.ExtendedQueryTagPersonName +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey); +INSERT INTO dbo.DeletedInstance (StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, DeletedDateTime, RetryCount, CleanupAfter) +SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + @deletedDate, + 0, + @cleanupAfter +FROM @deletedInstances; +INSERT INTO dbo.ChangeFeed (TimeStamp, Action, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) +SELECT @deletedDate, + 1, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark +FROM @deletedInstances +WHERE Status = @createdStatus; +UPDATE cf +SET cf.CurrentWatermark = NULL +FROM dbo.ChangeFeed AS cf WITH (FORCESEEK) + INNER JOIN + @deletedInstances AS d + ON cf.StudyInstanceUid = d.StudyInstanceUid + AND cf.SeriesInstanceUid = d.SeriesInstanceUid + AND cf.SopInstanceUid = d.SopInstanceUid; +IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (HOLDLOCK, UPDLOCK) + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid)) + BEGIN + DELETE dbo.Series + WHERE Studykey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid); + DELETE dbo.ExtendedQueryTagString + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey); + DELETE dbo.ExtendedQueryTagLong + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey); + DELETE dbo.ExtendedQueryTagDouble + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey); + DELETE dbo.ExtendedQueryTagDateTime + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey); + DELETE dbo.ExtendedQueryTagPersonName + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey); + END +IF NOT EXISTS (SELECT * + FROM dbo.Series WITH (HOLDLOCK, UPDLOCK) + WHERE Studykey = @studyKey) + BEGIN + DELETE dbo.Study + WHERE Studykey = @studyKey; + DELETE dbo.ExtendedQueryTagString + WHERE StudyKey = @studyKey; + DELETE dbo.ExtendedQueryTagLong + WHERE StudyKey = @studyKey; + DELETE dbo.ExtendedQueryTagDouble + WHERE StudyKey = @studyKey; + DELETE dbo.ExtendedQueryTagDateTime + WHERE StudyKey = @studyKey; + DELETE dbo.ExtendedQueryTagPersonName + WHERE StudyKey = @studyKey; + END +COMMIT TRANSACTION; + +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 +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 ); +DECLARE @studyKey AS BIGINT; +DECLARE @seriesKey AS BIGINT; +DECLARE @instanceKey AS BIGINT; +DECLARE @deletedDate AS DATETIME2 = SYSUTCDATETIME(); +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 INTO @deletedInstances +WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid); +IF @@ROWCOUNT = 0 + THROW 50404, 'Instance not found', 1; +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 StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey) + AND PartitionKey = @partitionKey; +DELETE dbo.ExtendedQueryTagLong +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey) + AND PartitionKey = @partitionKey; +DELETE dbo.ExtendedQueryTagDouble +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey) + AND PartitionKey = @partitionKey; +DELETE dbo.ExtendedQueryTagDateTime +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey) + AND PartitionKey = @partitionKey; +DELETE dbo.ExtendedQueryTagPersonName +WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND InstanceKey = ISNULL(@instanceKey, InstanceKey) + AND PartitionKey = @partitionKey; +INSERT INTO dbo.DeletedInstance (PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, DeletedDateTime, RetryCount, CleanupAfter) +SELECT PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + @deletedDate, + 0, + @cleanupAfter +FROM @deletedInstances; +INSERT INTO dbo.ChangeFeed (TimeStamp, Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) +SELECT @deletedDate, + 1, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark +FROM @deletedInstances +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; +IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (HOLDLOCK, UPDLOCK) + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid)) + BEGIN + DELETE dbo.Series + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagLong + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagDouble + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagDateTime + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagPersonName + WHERE StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey) + AND PartitionKey = @partitionKey; + 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 StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagLong + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagDouble + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagDateTime + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagPersonName + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + END +COMMIT TRANSACTION; + +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.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.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 + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY Sequence DESC; +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 + 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.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.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.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.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.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.IIndexInstanceCore +@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 + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagString WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey, Watermark) 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); + END + IF EXISTS (SELECT 1 + FROM @longExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagLong WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey, Watermark) 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); + END + IF EXISTS (SELECT 1 + FROM @doubleExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDouble WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey, Watermark) 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); + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDateTime WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = S.TagValue, + T.TagValueUtc = S.TagValueUtc + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey, Watermark, TagValueUtc) 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); + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagPersonName WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = S.TagValue + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, StudyKey, SeriesKey, InstanceKey, Watermark) 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); + 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.IndexInstance +@watermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_1 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @status AS TINYINT; + SELECT @studyKey = StudyKey, + @seriesKey = SeriesKey, + @instanceKey = InstanceKey, + @status = Status + FROM dbo.Instance WITH (HOLDLOCK) + WHERE Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exists', 1; + IF @status <> 1 + THROW 50409, 'Instance has not yet been stored succssfully', 1; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagString WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @longExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagLong WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @doubleExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDouble WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDateTime WITH (HOLDLOCK) + AS T + USING (SELECT input.TagKey, + input.TagValue, + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagPersonName WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.IndexInstanceV2 +@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 @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @status AS TINYINT; + SELECT @studyKey = StudyKey, + @seriesKey = SeriesKey, + @instanceKey = InstanceKey, + @status = Status + FROM dbo.Instance WITH (HOLDLOCK) + WHERE Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exists', 1; + IF @status <> 1 + THROW 50409, 'Instance has not yet been stored succssfully', 1; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagString WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @longExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagLong WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @doubleExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDouble WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDateTime WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark, TagValueUtc) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, S.TagValueUtc); + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagPersonName WITH (HOLDLOCK) + 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.TagKey = S.TagKey + AND T.StudyKey = @studyKey + AND ISNULL(T.SeriesKey, @seriesKey) = @seriesKey + AND ISNULL(T.InstanceKey, @instanceKey) = @instanceKey + WHEN MATCHED THEN UPDATE + SET T.Watermark = IIF (@watermark > T.Watermark, @watermark, T.Watermark), + T.TagValue = IIF (@watermark > T.Watermark, S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, StudyKey, SeriesKey, InstanceKey, Watermark) VALUES (S.TagKey, S.TagValue, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark); + END + COMMIT TRANSACTION; +END + +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 (HOLDLOCK) + WHERE Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exists', 1; + IF @status <> 1 + THROW 50409, 'Instance has not yet been stored succssfully', 1; + BEGIN TRY + EXECUTE dbo.IIndexInstanceCore @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.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.RetrieveDeletedInstanceV6 +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + 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.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.UpdateInstanceStatusV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT, @maxTagKey INT=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(); + UPDATE dbo.Instance + SET Status = @status, + LastStatusUpdatedDate = @currentDate + 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 (Timestamp, Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + VALUES (@currentDate, 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 diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V7.Generated.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V7.Generated.cs new file mode 100644 index 0000000000..31a27eebeb --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V7.Generated.cs @@ -0,0 +1,1718 @@ +//------------------------------------------------------------------------------ +// +// 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 V7 + { + 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 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 AddExtendedQueryTagErrorProcedure AddExtendedQueryTagError = new AddExtendedQueryTagErrorProcedure(); + internal readonly static AddExtendedQueryTagsProcedure AddExtendedQueryTags = new AddExtendedQueryTagsProcedure(); + internal readonly static AddInstanceProcedure AddInstance = new AddInstanceProcedure(); + internal readonly static AddInstanceV2Procedure AddInstanceV2 = new AddInstanceV2Procedure(); + internal readonly static AddInstanceV6Procedure AddInstanceV6 = new AddInstanceV6Procedure(); + internal readonly static AddPartitionProcedure AddPartition = new AddPartitionProcedure(); + internal readonly static AssignReindexingOperationProcedure AssignReindexingOperation = new AssignReindexingOperationProcedure(); + 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 DeleteInstanceProcedure DeleteInstance = new DeleteInstanceProcedure(); + internal readonly static DeleteInstanceV6Procedure DeleteInstanceV6 = new DeleteInstanceV6Procedure(); + internal readonly static GetChangeFeedProcedure GetChangeFeed = new GetChangeFeedProcedure(); + internal readonly static GetChangeFeedLatestProcedure GetChangeFeedLatest = new GetChangeFeedLatestProcedure(); + internal readonly static GetChangeFeedLatestV6Procedure GetChangeFeedLatestV6 = new GetChangeFeedLatestV6Procedure(); + internal readonly static GetChangeFeedV6Procedure GetChangeFeedV6 = new GetChangeFeedV6Procedure(); + internal readonly static GetExtendedQueryTagProcedure GetExtendedQueryTag = new GetExtendedQueryTagProcedure(); + internal readonly static GetExtendedQueryTagErrorsProcedure GetExtendedQueryTagErrors = new GetExtendedQueryTagErrorsProcedure(); + 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 GetInstanceProcedure GetInstance = new GetInstanceProcedure(); + internal readonly static GetInstanceBatchesProcedure GetInstanceBatches = new GetInstanceBatchesProcedure(); + internal readonly static GetInstanceV6Procedure GetInstanceV6 = new GetInstanceV6Procedure(); + 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 IIndexInstanceCoreProcedure IIndexInstanceCore = new IIndexInstanceCoreProcedure(); + internal readonly static IncrementDeletedInstanceRetryProcedure IncrementDeletedInstanceRetry = new IncrementDeletedInstanceRetryProcedure(); + internal readonly static IncrementDeletedInstanceRetryV6Procedure IncrementDeletedInstanceRetryV6 = new IncrementDeletedInstanceRetryV6Procedure(); + internal readonly static IndexInstanceProcedure IndexInstance = new IndexInstanceProcedure(); + internal readonly static IndexInstanceV2Procedure IndexInstanceV2 = new IndexInstanceV2Procedure(); + internal readonly static IndexInstanceV6Procedure IndexInstanceV6 = new IndexInstanceV6Procedure(); + internal readonly static RetrieveDeletedInstanceProcedure RetrieveDeletedInstance = new RetrieveDeletedInstanceProcedure(); + internal readonly static RetrieveDeletedInstanceV6Procedure RetrieveDeletedInstanceV6 = new RetrieveDeletedInstanceV6Procedure(); + internal readonly static UpdateExtendedQueryTagQueryStatusProcedure UpdateExtendedQueryTagQueryStatus = new UpdateExtendedQueryTagQueryStatusProcedure(); + internal readonly static UpdateInstanceStatusProcedure UpdateInstanceStatus = new UpdateInstanceStatusProcedure(); + internal readonly static UpdateInstanceStatusV6Procedure UpdateInstanceStatusV6 = new UpdateInstanceStatusV6Procedure(); + + 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 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 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 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 StudyKey = new BigIntColumn("StudyKey"); + internal readonly NullableBigIntColumn SeriesKey = new NullableBigIntColumn("SeriesKey"); + internal readonly NullableBigIntColumn InstanceKey = new NullableBigIntColumn("InstanceKey"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly NullableDateTime2Column TagValueUtc = new NullableDateTime2Column("TagValueUtc", 7); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_ExtendedQueryTagDateTime = new Index("IXC_ExtendedQueryTagDateTime"); + internal readonly Index IX_ExtendedQueryTagDateTime_TagKey_PartitionKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagDateTime_TagKey_PartitionKey_StudyKey_SeriesKey_InstanceKey"); + internal readonly Index IX_ExtendedQueryTagDateTime_PartitionKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagDateTime_PartitionKey_StudyKey_SeriesKey_InstanceKey"); + } + + 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 StudyKey = new BigIntColumn("StudyKey"); + internal readonly NullableBigIntColumn SeriesKey = new NullableBigIntColumn("SeriesKey"); + internal readonly NullableBigIntColumn InstanceKey = new NullableBigIntColumn("InstanceKey"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_ExtendedQueryTagDouble = new Index("IXC_ExtendedQueryTagDouble"); + internal readonly Index IX_ExtendedQueryTagDouble_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagDouble_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey"); + internal readonly Index IX_ExtendedQueryTagDouble_PartitionKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagDouble_PartitionKey_StudyKey_SeriesKey_InstanceKey"); + } + + 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 StudyKey = new BigIntColumn("StudyKey"); + internal readonly NullableBigIntColumn SeriesKey = new NullableBigIntColumn("SeriesKey"); + internal readonly NullableBigIntColumn InstanceKey = new NullableBigIntColumn("InstanceKey"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_ExtendedQueryTagLong = new Index("IXC_ExtendedQueryTagLong"); + internal readonly Index IX_ExtendedQueryTagLong_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagLong_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey"); + internal readonly Index IX_ExtendedQueryTagLong_PartitionKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagLong_PartitionKey_StudyKey_SeriesKey_InstanceKey"); + } + + 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 StudyKey = new BigIntColumn("StudyKey"); + internal readonly NullableBigIntColumn SeriesKey = new NullableBigIntColumn("SeriesKey"); + internal readonly NullableBigIntColumn InstanceKey = new NullableBigIntColumn("InstanceKey"); + 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 Index IXC_ExtendedQueryTagPersonName = new Index("IXC_ExtendedQueryTagPersonName"); + internal readonly Index IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey"); + internal readonly Index IX_ExtendedQueryTagPersonName_PartitionKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagPersonName_PartitionKey_StudyKey_SeriesKey_InstanceKey"); + 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 StudyKey = new BigIntColumn("StudyKey"); + internal readonly NullableBigIntColumn SeriesKey = new NullableBigIntColumn("SeriesKey"); + internal readonly NullableBigIntColumn InstanceKey = new NullableBigIntColumn("InstanceKey"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_ExtendedQueryTagString = new Index("IXC_ExtendedQueryTagString"); + internal readonly Index IX_ExtendedQueryTagString_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagString_PartitionKey_TagKey_StudyKey_SeriesKey_InstanceKey"); + internal readonly Index IX_ExtendedQueryTagString_PartitionKey_StudyKey_SeriesKey_InstanceKey = new Index("IX_ExtendedQueryTagString_PartitionKey_StudyKey_SeriesKey_InstanceKey"); + } + + 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 Index IXC_Instance = new Index("IXC_Instance"); + internal readonly Index IX_Instance_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid_PartitionKey = new Index("IX_Instance_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid_PartitionKey"); + internal readonly Index IX_Instance_StudyInstanceUid_Status_PartitionKey = new Index("IX_Instance_StudyInstanceUid_Status_PartitionKey"); + internal readonly Index IX_Instance_StudyInstanceUid_SeriesInstanceUid_Status_PartitionKey = new Index("IX_Instance_StudyInstanceUid_SeriesInstanceUid_Status_PartitionKey"); + internal readonly Index IX_Instance_SopInstanceUid_Status_PartitionKey = new Index("IX_Instance_SopInstanceUid_Status_PartitionKey"); + internal readonly Index IX_Instance_Watermark_Status = new Index("IX_Instance_Watermark_Status"); + internal readonly Index IX_Instance_SeriesKey_Status_Watermark = new Index("IX_Instance_SeriesKey_Status_Watermark"); + internal readonly Index IX_Instance_StudyKey_Status_Watermark = new Index("IX_Instance_StudyKey_Status_Watermark"); + } + + 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_SeriesKey = new Index("IX_Series_SeriesKey"); + internal readonly Index IX_Series_SeriesInstanceUid_PartitionKey = new Index("IX_Series_SeriesInstanceUid_PartitionKey"); + internal readonly Index IX_Series_Modality_PartitionKey = new Index("IX_Series_Modality_PartitionKey"); + internal readonly Index IX_Series_PerformedProcedureStepStartDate_PartitionKey = new Index("IX_Series_PerformedProcedureStepStartDate_PartitionKey"); + internal readonly Index IX_Series_ManufacturerModelName_PartitionKey = new Index("IX_Series_ManufacturerModelName_PartitionKey"); + } + + 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_StudyInstanceUid_PartitionKey = new Index("IX_Study_StudyInstanceUid_PartitionKey"); + internal readonly Index IX_Study_PatientId_PartitionKey = new Index("IX_Study_PatientId_PartitionKey"); + internal readonly Index IX_Study_PatientName_PartitionKey = new Index("IX_Study_PatientName_PartitionKey"); + internal readonly Index IX_Study_ReferringPhysicianName_PartitionKey = new Index("IX_Study_ReferringPhysicianName_PartitionKey"); + internal readonly Index IX_Study_StudyDate_PartitionKey = new Index("IX_Study_StudyDate_PartitionKey"); + internal readonly Index IX_Study_StudyDescription_PartitionKey = new Index("IX_Study_StudyDescription_PartitionKey"); + internal readonly Index IX_Study_AccessionNumber_PartitionKey = new Index("IX_Study_AccessionNumber_PartitionKey"); + internal readonly Index IX_Study_PatientBirthDate_PartitionKey = new Index("IX_Study_PatientBirthDate_PartitionKey"); + } + + 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 AddInstanceProcedure : StoredProcedure + { + internal AddInstanceProcedure() : base("dbo.AddInstance") + { + } + + 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 InsertDateTimeExtendedQueryTagTableTypeV1TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@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.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) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddInstance"; + _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); + } + + public void PopulateCommand(SqlCommandWrapper command, 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, AddInstanceTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, 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, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddInstanceTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddInstanceTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddInstanceTableValuedParameters Generate(TInput input) + { + return new AddInstanceTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddInstanceTableValuedParameters + { + internal AddInstanceTableValuedParameters(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 AddInstanceV2Procedure : StoredProcedure + { + internal AddInstanceV2Procedure() : base("dbo.AddInstanceV2") + { + } + + 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); + + public void PopulateCommand(SqlCommandWrapper command, 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) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddInstanceV2"; + _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); + } + + public void PopulateCommand(SqlCommandWrapper command, 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, AddInstanceV2TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, 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, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddInstanceV2TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddInstanceV2TvpGenerator(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 AddInstanceV2TableValuedParameters Generate(TInput input) + { + return new AddInstanceV2TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddInstanceV2TableValuedParameters + { + internal AddInstanceV2TableValuedParameters(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 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); + + 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) + { + 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); + } + + 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, 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, 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 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 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 DeleteInstanceProcedure : StoredProcedure + { + internal DeleteInstanceProcedure() : base("dbo.DeleteInstance") + { + } + + 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 _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.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteInstance"; + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + _createdStatus.AddParameter(command.Parameters, createdStatus); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + 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 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 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 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 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 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 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 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 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 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 IIndexInstanceCoreProcedure : StoredProcedure + { + internal IIndexInstanceCoreProcedure() : base("dbo.IIndexInstanceCore") + { + } + + 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.IIndexInstanceCore"; + _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, IIndexInstanceCoreTableValuedParameters 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 IIndexInstanceCoreTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IIndexInstanceCoreTvpGenerator(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 IIndexInstanceCoreTableValuedParameters Generate(TInput input) + { + return new IIndexInstanceCoreTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IIndexInstanceCoreTableValuedParameters + { + internal IIndexInstanceCoreTableValuedParameters(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 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 IndexInstanceProcedure : StoredProcedure + { + internal IndexInstanceProcedure() : base("dbo.IndexInstance") + { + } + + 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 InsertDateTimeExtendedQueryTagTableTypeV1TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@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.IndexInstance"; + _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, IndexInstanceTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, watermark: watermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IndexInstanceTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IndexInstanceTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IndexInstanceTableValuedParameters Generate(TInput input) + { + return new IndexInstanceTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IndexInstanceTableValuedParameters + { + internal IndexInstanceTableValuedParameters(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 IndexInstanceV2Procedure : StoredProcedure + { + internal IndexInstanceV2Procedure() : base("dbo.IndexInstanceV2") + { + } + + 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.IndexInstanceV2"; + _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, IndexInstanceV2TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, watermark: watermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IndexInstanceV2TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IndexInstanceV2TvpGenerator(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 IndexInstanceV2TableValuedParameters Generate(TInput input) + { + return new IndexInstanceV2TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IndexInstanceV2TableValuedParameters + { + internal IndexInstanceV2TableValuedParameters(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 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 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 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 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); + + 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) + { + 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); + } + } + } +} \ 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 d63caaf152..417a614fef 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 @@ -38,6 +38,7 @@ internal class VLatest internal readonly static DeleteDeletedInstanceProcedure DeleteDeletedInstance = new DeleteDeletedInstanceProcedure(); internal readonly static DeleteDeletedInstanceV6Procedure DeleteDeletedInstanceV6 = new DeleteDeletedInstanceV6Procedure(); internal readonly static DeleteExtendedQueryTagProcedure DeleteExtendedQueryTag = new DeleteExtendedQueryTagProcedure(); + internal readonly static DeleteExtendedQueryTagV8Procedure DeleteExtendedQueryTagV8 = new DeleteExtendedQueryTagV8Procedure(); internal readonly static DeleteInstanceProcedure DeleteInstance = new DeleteInstanceProcedure(); internal readonly static DeleteInstanceV6Procedure DeleteInstanceV6 = new DeleteInstanceV6Procedure(); internal readonly static GetChangeFeedProcedure GetChangeFeed = new GetChangeFeedProcedure(); @@ -878,6 +879,24 @@ public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, Sy } } + 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 DeleteInstanceProcedure : StoredProcedure { internal DeleteInstanceProcedure() : base("dbo.DeleteInstance") diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs index 35dab2c5a0..e013e609c8 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs @@ -18,5 +18,6 @@ public enum SchemaVersion V5 = 5, V6 = 6, V7 = 7, + V8 = 8, } } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs index 3d34e6ce20..c904196bcd 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs @@ -8,7 +8,7 @@ namespace Microsoft.Health.Dicom.SqlServer.Features.Schema public static class SchemaVersionConstants { public const int Min = (int)SchemaVersion.V4; - public const int Max = (int)SchemaVersion.V7; + public const int Max = (int)SchemaVersion.V8; public const int SupportExtendedQueryTagSchemaVersion = (int)SchemaVersion.V4; public const int SupportDTAndTMInExtendedQueryTagSchemaVersion = (int)SchemaVersion.V5; public const int SupportDataPartitionSchemaVersion = (int)SchemaVersion.V6; diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Scripts/DatabaseSettings.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Scripts/DatabaseSettings.sql new file mode 100644 index 0000000000..2371240fcd --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Scripts/DatabaseSettings.sql @@ -0,0 +1,20 @@ +/************************************************************* + Configure database +**************************************************************/ + +-- Enable RCSI +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 + +-- Avoid blocking queries when statistics need to be rebuilt +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 + +-- Use ANSI behavior for null values +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 diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTag.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTag.sql index cca3a4d6f7..e1115e0726 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTag.sql +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTag.sql @@ -65,4 +65,4 @@ BEGIN WHERE TagKey = @tagKey COMMIT TRANSACTION -END \ No newline at end of file +END diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTagV8.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTagV8.sql new file mode 100644 index 0000000000..d0f1178b79 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/DeleteExtendedQueryTagV8.sql @@ -0,0 +1,64 @@ +/***************************************************************************************/ +-- STORED PROCEDURE +-- DeleteExtendedQueryTagV8 +-- +-- DESCRIPTION +-- Delete specific extended query tag +-- +-- PARAMETERS +-- @tagPath +-- * The extended query tag path +-- @dataType +-- * the data type of extended query tag. 0 -- String, 1 -- Long, 2 -- Double, 3 -- DateTime, 4 -- PersonName +/***************************************************************************************/ +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV8 + @tagPath VARCHAR(64), + @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON + SET XACT_ABORT ON + + BEGIN TRANSACTION + + DECLARE @tagKey INT + + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH(XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath + + -- Check existence + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1 + + -- Update status to Deleting + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey + + COMMIT TRANSACTION + + BEGIN TRANSACTION + + -- Delete index data + IF @dataType = 0 + DELETE FROM dbo.ExtendedQueryTagString WHERE TagKey = @tagKey + ELSE IF @dataType = 1 + DELETE FROM dbo.ExtendedQueryTagLong WHERE TagKey = @tagKey + ELSE IF @dataType = 2 + DELETE FROM dbo.ExtendedQueryTagDouble WHERE TagKey = @tagKey + ELSE IF @dataType = 3 + DELETE FROM dbo.ExtendedQueryTagDateTime WHERE TagKey = @tagKey + ELSE + DELETE FROM dbo.ExtendedQueryTagPersonName WHERE TagKey = @tagKey + + -- Delete errors + DELETE FROM dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey + + -- Delete tag + DELETE FROM dbo.ExtendedQueryTag + WHERE TagKey = @tagKey + + COMMIT TRANSACTION +END 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 847fd510f7..a540461c27 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 @@ - 7 + 8 Features\Schema\Migrations\$(LatestSchemaVersion).sql @@ -61,6 +61,7 @@ + @@ -71,7 +72,6 @@ - diff --git a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs index 429b66f475..006cd609d5 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs @@ -149,6 +149,7 @@ private static IServiceCollection AddSqlExtendedQueryTagStores(this IServiceColl 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/Persistence/ExtendedQueryTagStoreTestHelper.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTestHelper.cs index daa1b89110..498f55ccf5 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTestHelper.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTestHelper.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Data.SqlClient; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.SqlServer.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.SqlServer.Features.Schema.Model; using Microsoft.Health.Dicom.Tests.Integration.Persistence.Models; @@ -123,6 +124,23 @@ private async Task> GetExtendedQueryTagRo return results; } + public async Task SetTagStatusAsync(int tagKey, ExtendedQueryTagStatus status, CancellationToken cancellationToken) + { + using var sqlConnection = new SqlConnection(_connectionString); + await sqlConnection.OpenAsync(cancellationToken); + + using SqlCommand sqlCommand = sqlConnection.CreateCommand(); + sqlCommand.CommandText = @" +UPDATE dbo.ExtendedQueryTag +SET TagStatus = @tagStatus +WHERE dbo.ExtendedQueryTag.TagKey = @tagKey +"; + + sqlCommand.Parameters.Add(new SqlParameter("@tagKey", tagKey)); + sqlCommand.Parameters.Add(new SqlParameter("@tagStatus", (byte)status)); + await sqlCommand.ExecuteNonQueryAsync(cancellationToken); + } + public async Task ClearExtendedQueryTagTablesAsync() { await SqlTestUtils.ClearTableAsync(_connectionString, VLatest.ExtendedQueryTag.TableName); diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTests.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTests.cs index fd6ea95a90..2cb0115bc5 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTests.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ExtendedQueryTagStoreTests.cs @@ -131,6 +131,17 @@ public async Task GivenExistingExtendedQueryTag_WhenDeleteExtendedQueryTag_ThenT await VerifyTagNotExistAsync(extendedQueryTagEntry.Path); } + [Fact] + public async Task GivenPartiallyDeletedExtendedQueryTag_WhenDeleteExtendedQueryTag_ThenTagShouldBeRemoved() + { + DicomTag tag = DicomTag.DeviceSerialNumber; + AddExtendedQueryTagEntry extendedQueryTagEntry = tag.BuildAddExtendedQueryTagEntry(); + IReadOnlyList keys = await AddExtendedQueryTagsAsync(new AddExtendedQueryTagEntry[] { extendedQueryTagEntry }); + await _extendedQueryTagStoreTestHelper.SetTagStatusAsync(keys.Single(), ExtendedQueryTagStatus.Deleting); + await _extendedQueryTagStore.DeleteExtendedQueryTagAsync(extendedQueryTagEntry.Path, extendedQueryTagEntry.VR); + await VerifyTagNotExistAsync(extendedQueryTagEntry.Path); + } + [Fact] public async Task GivenNonExistingExtendedQueryTag_WhenDeleteExtendedQueryTag_ThenShouldThrowException() { diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IExtendedQueryTagStoreTestHelper.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IExtendedQueryTagStoreTestHelper.cs index 25e2ab4034..f42e19be4c 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IExtendedQueryTagStoreTestHelper.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/IExtendedQueryTagStoreTestHelper.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.SqlServer.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Tests.Integration.Persistence.Models; @@ -24,5 +25,7 @@ internal Task> GetExtendedQueryTagDataAsy CancellationToken cancellationToken = default); internal Task> GetExtendedQueryTagDataForTagKeyAsync(ExtendedQueryTagDataType dataType, int tagKey, CancellationToken cancellationToken = default); + + Task SetTagStatusAsync(int tagKey, ExtendedQueryTagStatus status, CancellationToken cancellationToken = default); } } diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs index c5d1f4d705..45536e168e 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs @@ -128,6 +128,7 @@ internal SqlDataStoreTestsFixture(string databaseName, SchemaInformation schemaI new SqlExtendedQueryTagStoreV1(), new SqlExtendedQueryTagStoreV2(SqlConnectionWrapperFactory, NullLogger.Instance), new SqlExtendedQueryTagStoreV4(SqlConnectionWrapperFactory, NullLogger.Instance), + new SqlExtendedQueryTagStoreV8(SqlConnectionWrapperFactory, NullLogger.Instance), })); ExtendedQueryTagErrorStore = new SqlExtendedQueryTagErrorStore(new VersionedCache(