diff --git a/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs b/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs index f63036442c..b7b4bb00a5 100644 --- a/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs +++ b/src/Microsoft.Health.Dicom.Core/Features/Store/IIndexDataStore.cs @@ -163,9 +163,10 @@ public interface IIndexDataStore /// /// The DICOM dataset to index. /// A list of instance metadata to use to update file properties for newly stored blob file from "update" + /// Queryable dicom tags /// The cancellation token. /// A task that represents the asynchronous add operation. - Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, CancellationToken cancellationToken = default); + Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, IEnumerable queryTags, CancellationToken cancellationToken = default); /// /// Asynchronously updates DICOM instance HasFrameMetadata to 1 diff --git a/src/Microsoft.Health.Dicom.Functions.App/host.json b/src/Microsoft.Health.Dicom.Functions.App/host.json index 06a4ded735..92a5408082 100644 --- a/src/Microsoft.Health.Dicom.Functions.App/host.json +++ b/src/Microsoft.Health.Dicom.Functions.App/host.json @@ -89,7 +89,7 @@ "Frequency": "0 0 * * *", "MinimumAgeDays": 7, "Statuses": [ "Completed" ], - "ExcludeFunctions": [ "MigratingFrameRangeFilesAsync", "UpdateInstancesV3Async", "UpdateInstancesV4Async" ] + "ExcludeFunctions": [ "MigratingFrameRangeFilesAsync", "UpdateInstancesV4Async", "UpdateInstancesV5Async" ] }, "SqlServer": { "Retry": { diff --git a/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Activity.cs b/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Activity.cs index 109533d96c..1ab329ee22 100644 --- a/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Activity.cs +++ b/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Activity.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -11,6 +12,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Health.Dicom.Core.Exceptions; using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Core.Features.Model; using Microsoft.Health.Dicom.Core.Features.Partitioning; using Microsoft.Health.Dicom.Functions.Update.Models; @@ -137,14 +139,14 @@ public async Task GivenCompleteInstanceArgument_WhenCompleting_ThenShouldComplet var studyInstanceUid = TestUidGenerator.Generate(); var instanceMetadataList = new List(); - _indexStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUid, new DicomDataset(), instanceMetadataList, CancellationToken.None).Returns(Task.CompletedTask); + _indexStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUid, new DicomDataset(), instanceMetadataList, Array.Empty(), CancellationToken.None).Returns(Task.CompletedTask); var ds = new DicomDataset { { DicomTag.PatientName, "Patient Name" } }; - await _updateDurableFunction.CompleteUpdateStudyV3Async( + await _updateDurableFunction.CompleteUpdateStudyV4Async( new CompleteStudyArgumentsV2( Partition.DefaultKey, studyInstanceUid, @@ -154,7 +156,7 @@ await _updateDurableFunction.CompleteUpdateStudyV3Async( await _indexStore .Received(1) - .EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUid, Arg.Is(x => x.GetSingleValue(DicomTag.PatientName) == "Patient Name"), instanceMetadataList, CancellationToken.None); + .EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUid, Arg.Is(x => x.GetSingleValue(DicomTag.PatientName) == "Patient Name"), instanceMetadataList, Arg.Any>(), CancellationToken.None); } [Fact] diff --git a/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Orchestration.cs b/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Orchestration.cs index afe8b559f4..6d1e5a5359 100644 --- a/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Orchestration.cs +++ b/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.Orchestration.cs @@ -87,7 +87,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstances_ThenComple .Returns(new UpdateInstanceResponse(instanceMetadataList, new List())); context .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()) .Returns(Task.CompletedTask); @@ -105,7 +105,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstances_ThenComple .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior context @@ -127,7 +127,7 @@ await context await context .Received(1) .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()); await context @@ -208,7 +208,7 @@ public async Task GivenV4OrchestrationWithInputAndExternalStoreEnabled_WhenUpdat .Returns(new UpdateInstanceResponse(instanceMetadataList, new List())); context .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Is(GetPredicate(expectedInput.Partition.Key, studyInstanceUid, expectedInput.ChangeDataset, instanceMetadataList))) .Returns(Task.CompletedTask); @@ -226,7 +226,7 @@ public async Task GivenV4OrchestrationWithInputAndExternalStoreEnabled_WhenUpdat .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunctionWithExternalStore.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunctionWithExternalStore.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior context @@ -248,7 +248,7 @@ await context await context .Received(1) .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Is(GetPredicate(expectedInput.Partition.Key, studyInstanceUid, expectedInput.ChangeDataset, instanceMetadataList))); context @@ -329,7 +329,7 @@ public async Task GivenV4OrchestrationWithInputAndExternalStoreNotEnabled_WhenUp .Returns(new UpdateInstanceResponse(instanceMetadataList, new List())); context .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Is(GetPredicate(expectedInput.Partition.Key, studyInstanceUid, expectedInput.ChangeDataset, new List()))) .Returns(Task.CompletedTask); @@ -347,7 +347,7 @@ public async Task GivenV4OrchestrationWithInputAndExternalStoreNotEnabled_WhenUp .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior context @@ -369,7 +369,7 @@ await context await context .Received(1) .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Is(GetPredicate(expectedInput.Partition.Key, studyInstanceUid, expectedInput.ChangeDataset, null, expectEmptyList: true))); context @@ -426,7 +426,7 @@ public async Task GivenV4OrchestrationWithNoInstancesFound_WhenUpdatingInstances .Returns(new UpdateInstanceResponse(instanceMetadataList, new List())); context .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()) .Returns(Task.CompletedTask); @@ -444,7 +444,7 @@ public async Task GivenV4OrchestrationWithNoInstancesFound_WhenUpdatingInstances .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior context @@ -465,7 +465,7 @@ await context await context .DidNotReceive() .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()); context @@ -520,7 +520,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstancesWithExcepti .Returns(expectedInput); // Invoke the orchestration - await Assert.ThrowsAsync(() => _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance)); + await Assert.ThrowsAsync(() => _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance)); // Assert behavior context @@ -541,7 +541,7 @@ await context await context .DidNotReceive() .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()); context @@ -629,7 +629,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstancesWithExcepti .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior await context @@ -718,7 +718,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstancesWithDataSto .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior await context @@ -792,7 +792,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstances_ThenComple .Returns(new UpdateInstanceResponse(instanceMetadataList, new List())); context .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()) .Returns(Task.CompletedTask); @@ -804,7 +804,7 @@ public async Task GivenV4OrchestrationWithInput_WhenUpdatingInstances_ThenComple .Returns(Task.CompletedTask); // Invoke the orchestration - await _updateDurableFunction.UpdateInstancesV4Async(context, NullLogger.Instance); + await _updateDurableFunction.UpdateInstancesV5Async(context, NullLogger.Instance); // Assert behavior context @@ -825,7 +825,7 @@ await context await context .Received(1) .CallActivityWithRetryAsync( - nameof(UpdateDurableFunction.CompleteUpdateStudyV3Async), + nameof(UpdateDurableFunction.CompleteUpdateStudyV4Async), _options.RetryOptions, Arg.Any()); context diff --git a/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.cs b/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.cs index a5d44ec163..cba6e135df 100644 --- a/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.cs +++ b/src/Microsoft.Health.Dicom.Functions.UnitTests/Update/UpdateDurableFunctionTests.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Options; using Microsoft.Health.Dicom.Core.Configs; using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Core.Features.Retrieve; using Microsoft.Health.Dicom.Core.Features.Store; using Microsoft.Health.Dicom.Core.Features.Telemetry; @@ -56,6 +57,7 @@ public UpdateDurableFunctionTests() _metadataStore, _fileStore, _updateInstanceService, + Substitute.For(), _updateMeter, Options.Create(_jsonSerializerOptions), Options.Create(new FeatureConfiguration())); @@ -66,6 +68,7 @@ public UpdateDurableFunctionTests() _metadataStore, _fileStore, _updateInstanceService, + Substitute.For(), _updateMeter, Options.Create(_jsonSerializerOptions), Options.Create(new FeatureConfiguration { EnableExternalStore = true, })); diff --git a/src/Microsoft.Health.Dicom.Functions/Update/Models/UpdateInstanceBlobArgumentsV2.cs b/src/Microsoft.Health.Dicom.Functions/Update/Models/UpdateInstanceBlobArgumentsV2.cs index 0d781a4b3c..57c624171e 100644 --- a/src/Microsoft.Health.Dicom.Functions/Update/Models/UpdateInstanceBlobArgumentsV2.cs +++ b/src/Microsoft.Health.Dicom.Functions/Update/Models/UpdateInstanceBlobArgumentsV2.cs @@ -1,4 +1,4 @@ -// ------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------------------------------------------- @@ -11,7 +11,7 @@ namespace Microsoft.Health.Dicom.Functions.Update.Models; /// -/// Represents input to +/// Represents input to /// public class UpdateInstanceBlobArgumentsV2 { diff --git a/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Activity.cs b/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Activity.cs index 4004cf7444..6fb26217d7 100644 --- a/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Activity.cs +++ b/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Activity.cs @@ -17,8 +17,10 @@ using Microsoft.Extensions.Logging; using Microsoft.Health.Dicom.Core.Exceptions; using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Core.Features.Model; using Microsoft.Health.Dicom.Core.Features.Partitioning; +using Microsoft.Health.Dicom.Core.Features.Update; using Microsoft.Health.Dicom.Functions.Update.Models; namespace Microsoft.Health.Dicom.Functions.Update; @@ -53,79 +55,6 @@ public async Task> UpdateInstanceWatermarkV2Async( return instanceMetadata; } - /// - /// Asynchronously batches the instance watermarks and calls the update instance. - /// - /// BatchUpdateArguments - /// A diagnostic logger. - /// - /// The result of the task contains the updated instances with file properties representing newly created blobs. - /// - /// - /// or is . - /// - [FunctionName(nameof(UpdateInstanceBlobsV2Async))] - [Obsolete("This function is obsolete. Use UpdateInstanceBlobsV3Async instead.")] - public async Task> UpdateInstanceBlobsV2Async( - [ActivityTrigger] UpdateInstanceBlobArgumentsV2 arguments, - ILogger logger) - { - EnsureArg.IsNotNull(arguments, nameof(arguments)); - EnsureArg.IsNotNull(arguments.ChangeDataset, nameof(arguments.ChangeDataset)); - EnsureArg.IsNotNull(arguments.InstanceMetadataList, nameof(arguments.InstanceMetadataList)); - EnsureArg.IsNotNull(arguments.Partition, nameof(arguments.Partition)); - EnsureArg.IsNotNull(logger, nameof(logger)); - - DicomDataset datasetToUpdate = GetDeserializedDataset(arguments.ChangeDataset); - - int processed = 0; - - logger.LogInformation("Beginning to update all instance blobs, Total count {TotalCount}", arguments.InstanceMetadataList.Count); - - ConcurrentBag updatedInstances = new ConcurrentBag(); - while (processed < arguments.InstanceMetadataList.Count) - { - int batchSize = Math.Min(_options.BatchSize, arguments.InstanceMetadataList.Count - processed); - var batch = arguments.InstanceMetadataList.Skip(processed).Take(batchSize).ToList(); - - logger.LogInformation("Beginning to update instance blobs for range [{Start}, {End}]. Total batch size {BatchSize}.", - batch[0], - batch[^1], - batchSize); - - await Parallel.ForEachAsync( - batch, - new ParallelOptions - { - CancellationToken = default, - MaxDegreeOfParallelism = _options.MaxParallelThreads, - }, - async (instance, token) => - { - FileProperties fileProperties = await _updateInstanceService.UpdateInstanceBlobAsync(instance, datasetToUpdate, arguments.Partition, token); - updatedInstances.Add( - new InstanceMetadata( - instance.VersionedInstanceIdentifier, - new InstanceProperties - { - FileProperties = fileProperties, - NewVersion = instance.InstanceProperties.NewVersion, - OriginalVersion = instance.InstanceProperties.OriginalVersion - })); - }); - - logger.LogInformation("Completed updating instance blobs starting with [{Start}, {End}]. Total batchSize {BatchSize}.", - batch[0], - batch[^1], - batchSize); - - processed += batchSize; - } - - logger.LogInformation("Completed updating all instance blobs"); - return updatedInstances; - } - /// /// Asynchronously batches the instance watermarks and calls the update instance. /// @@ -200,14 +129,14 @@ await Parallel.ForEachAsync( /// CompleteInstanceArguments /// A diagnostic logger. /// - /// A task representing the operation. + /// A task representing the operation. /// /// /// or is . /// - [FunctionName(nameof(CompleteUpdateStudyV2Async))] - [Obsolete("This function is obsolete. Use CompleteUpdateStudyV3Async instead.")] - public async Task CompleteUpdateStudyV2Async([ActivityTrigger] CompleteStudyArgumentsV2 arguments, ILogger logger) + [FunctionName(nameof(CompleteUpdateStudyV3Async))] + [Obsolete("This function is obsolete. Use CompleteUpdateStudyV4Async instead.")] + public async Task CompleteUpdateStudyV3Async([ActivityTrigger] CompleteStudyArgumentsV2 arguments, ILogger logger) { EnsureArg.IsNotNull(arguments, nameof(arguments)); EnsureArg.IsNotNull(arguments.ChangeDataset, nameof(arguments.ChangeDataset)); @@ -217,22 +146,15 @@ public async Task CompleteUpdateStudyV2Async([ActivityTrigger] CompleteStudyArgu logger.LogInformation("Completing updating operation for study."); - try - { - await _indexStore.EndUpdateInstanceAsync( - arguments.PartitionKey, - arguments.StudyInstanceUid, - GetDeserializedDataset(arguments.ChangeDataset), - arguments.InstanceMetadataList, - CancellationToken.None); - - logger.LogInformation("Updating study completed successfully."); - } - catch (StudyNotFoundException) - { - // TODO: Study deleted, we need to cleanup all the newly updated blobs. - logger.LogWarning("Failed to update to study. Possibly deleted."); - } + await _indexStore.EndUpdateInstanceAsync( + arguments.PartitionKey, + arguments.StudyInstanceUid, + GetDeserializedDataset(arguments.ChangeDataset), + arguments.InstanceMetadataList, + Array.Empty(), + CancellationToken.None); + + logger.LogInformation("Updating study completed successfully."); } /// @@ -241,13 +163,13 @@ await _indexStore.EndUpdateInstanceAsync( /// CompleteInstanceArguments /// A diagnostic logger. /// - /// A task representing the operation. + /// A task representing the operation. /// /// /// or is . /// - [FunctionName(nameof(CompleteUpdateStudyV3Async))] - public async Task CompleteUpdateStudyV3Async([ActivityTrigger] CompleteStudyArgumentsV2 arguments, ILogger logger) + [FunctionName(nameof(CompleteUpdateStudyV4Async))] + public async Task CompleteUpdateStudyV4Async([ActivityTrigger] CompleteStudyArgumentsV2 arguments, ILogger logger) { EnsureArg.IsNotNull(arguments, nameof(arguments)); EnsureArg.IsNotNull(arguments.ChangeDataset, nameof(arguments.ChangeDataset)); @@ -257,11 +179,22 @@ public async Task CompleteUpdateStudyV3Async([ActivityTrigger] CompleteStudyArgu logger.LogInformation("Completing updating operation for study."); + IReadOnlyCollection queryTags = await _queryTagService.GetQueryTagsAsync(cancellationToken: CancellationToken.None); + + // Filter extended query tag at study level + var filteredQueryTags = queryTags.Where(x => x.IsExtendedQueryTag && UpdateTags.UpdateStudyFilterTags.Contains(x.Tag) && x.Level == QueryTagLevel.Study).ToList(); + + if (filteredQueryTags.Count > 0) + { + logger.LogInformation("Updating study with extended query tags. Extended query tag count {Count}", filteredQueryTags.Count); + } + await _indexStore.EndUpdateInstanceAsync( arguments.PartitionKey, arguments.StudyInstanceUid, GetDeserializedDataset(arguments.ChangeDataset), arguments.InstanceMetadataList, + filteredQueryTags, CancellationToken.None); logger.LogInformation("Updating study completed successfully."); diff --git a/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Orchestration.cs b/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Orchestration.cs index f26de8207c..74c8922740 100644 --- a/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Orchestration.cs +++ b/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.Orchestration.cs @@ -31,14 +31,14 @@ public partial class UpdateDurableFunction /// /// The context for the orchestration instance. /// A diagnostic logger. - /// A task representing the operation. + /// A task representing the operation. /// /// or is . /// /// Orchestration instance ID is invalid. - [FunctionName(nameof(UpdateInstancesV3Async))] - [Obsolete("Use UpdateInstancesV4Async instead")] - public async Task UpdateInstancesV3Async( + [FunctionName(nameof(UpdateInstancesV4Async))] + [Obsolete("This function is obsolete. Use UpdateInstancesV5Async instead.")] + public async Task UpdateInstancesV4Async( [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger) { @@ -65,7 +65,6 @@ public async Task UpdateInstancesV3Async( logger.LogInformation("Updated all instances new watermark in a study. Found {InstanceCount} instance for study", instances.Count); var totalNoOfInstances = input.TotalNumberOfInstanceUpdated; - int numberofStudyFailed = input.NumberOfStudyFailed; if (instances.Count > 0) { @@ -73,37 +72,36 @@ public async Task UpdateInstancesV3Async( try { - instanceMetadataList = await context.CallActivityWithRetryAsync>( - nameof(UpdateInstanceBlobsV2Async), + UpdateInstanceResponse response = await context.CallActivityWithRetryAsync( + nameof(UpdateInstanceBlobsV3Async), _options.RetryOptions, new UpdateInstanceBlobArgumentsV2(input.Partition, instances, input.ChangeDataset)); - await context.CallActivityWithRetryAsync( - nameof(CompleteUpdateStudyV2Async), - _options.RetryOptions, - new CompleteStudyArgumentsV2(input.Partition.Key, studyInstanceUid, input.ChangeDataset, GetInstanceMetadataList(instanceMetadataList))); + instanceMetadataList = response.InstanceMetadataList; + + if (response.Errors?.Count > 0) + { + isFailedToUpdateStudy = true; + logger.LogWarning("Failed to update instances for study. Total instance failed for study {TotalFailed}", response.Errors.Count); + await HandleException(context, input, studyInstanceUid, instances, response.Errors); + } + else + { + await context.CallActivityWithRetryAsync( + nameof(CompleteUpdateStudyV3Async), + _options.RetryOptions, + new CompleteStudyArgumentsV2(input.Partition.Key, studyInstanceUid, input.ChangeDataset, GetInstanceMetadataList(instanceMetadataList))); - totalNoOfInstances += instances.Count; + totalNoOfInstances += instances.Count; + } } catch (FunctionFailedException ex) { isFailedToUpdateStudy = true; logger.LogError(ex, "Failed to update instances for study", ex); - var errors = new List - { - $"Failed to update instances for study {studyInstanceUid}", - }; - - if (input.Errors != null) - errors.AddRange(errors); - input.Errors = errors; - - numberofStudyFailed++; - - // Cleanup the new version when the update activity fails - await TryCleanupActivityV3(context, instances, input.Partition); + await HandleException(context, input, studyInstanceUid, instances, null); } if (!isFailedToUpdateStudy) @@ -135,7 +133,7 @@ await context.CallActivityWithRetryAsync( Partition = input.Partition, PartitionKey = input.PartitionKey, NumberOfStudyCompleted = numberOfStudyCompleted, - NumberOfStudyFailed = numberofStudyFailed, + NumberOfStudyFailed = input.NumberOfStudyFailed, TotalNumberOfInstanceUpdated = totalNoOfInstances, Errors = input.Errors, CreatedTime = input.CreatedTime ?? await context.GetCreatedTimeAsync(_options.RetryOptions), @@ -143,6 +141,11 @@ await context.CallActivityWithRetryAsync( } else { + if (input.TotalNumberOfInstanceUpdated > 0) + { + replaySafeCounter.Add(input.TotalNumberOfInstanceUpdated); + } + if (input.Errors?.Count > 0) { logger.LogWarning("Update operation completed with errors. {NumberOfStudyUpdated}, {NumberOfStudyFailed}, {TotalNumberOfInstanceUpdated}.", @@ -159,11 +162,6 @@ await context.CallActivityWithRetryAsync( input.NumberOfStudyCompleted, input.TotalNumberOfInstanceUpdated); } - - if (input.TotalNumberOfInstanceUpdated > 0) - { - replaySafeCounter.Add(input.TotalNumberOfInstanceUpdated); - } } } @@ -176,13 +174,13 @@ await context.CallActivityWithRetryAsync( /// /// The context for the orchestration instance. /// A diagnostic logger. - /// A task representing the operation. + /// A task representing the operation. /// /// or is . /// /// Orchestration instance ID is invalid. - [FunctionName(nameof(UpdateInstancesV4Async))] - public async Task UpdateInstancesV4Async( + [FunctionName(nameof(UpdateInstancesV5Async))] + public async Task UpdateInstancesV5Async( [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger) { @@ -232,7 +230,7 @@ public async Task UpdateInstancesV4Async( else { await context.CallActivityWithRetryAsync( - nameof(CompleteUpdateStudyV3Async), + nameof(CompleteUpdateStudyV4Async), _options.RetryOptions, new CompleteStudyArgumentsV2(input.Partition.Key, studyInstanceUid, input.ChangeDataset, GetInstanceMetadataList(instanceMetadataList))); diff --git a/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.cs b/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.cs index fce0838500..431035554e 100644 --- a/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.cs +++ b/src/Microsoft.Health.Dicom.Functions/Update/UpdateDurableFunction.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Options; using Microsoft.Health.Dicom.Core.Configs; using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Core.Features.Retrieve; using Microsoft.Health.Dicom.Core.Features.Store; using Microsoft.Health.Dicom.Core.Features.Telemetry; @@ -26,6 +27,7 @@ public partial class UpdateDurableFunction private readonly IMetadataStore _metadataStore; private readonly IFileStore _fileStore; private readonly IUpdateInstanceService _updateInstanceService; + private readonly IQueryTagService _queryTagService; private readonly UpdateMeter _updateMeter; private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly bool _externalStoreEnabled; @@ -37,6 +39,7 @@ public UpdateDurableFunction( IMetadataStore metadataStore, IFileStore fileStore, IUpdateInstanceService updateInstanceService, + IQueryTagService queryTagService, UpdateMeter updateMeter, IOptions jsonSerializerOptions, IOptions featureConfiguration) @@ -47,6 +50,7 @@ public UpdateDurableFunction( _metadataStore = EnsureArg.IsNotNull(metadataStore, nameof(metadataStore)); _fileStore = EnsureArg.IsNotNull(fileStore, nameof(fileStore)); _updateInstanceService = EnsureArg.IsNotNull(updateInstanceService, nameof(updateInstanceService)); + _queryTagService = EnsureArg.IsNotNull(queryTagService, nameof(queryTagService)); _jsonSerializerOptions = EnsureArg.IsNotNull(jsonSerializerOptions?.Value, nameof(jsonSerializerOptions)); _updateMeter = EnsureArg.IsNotNull(updateMeter, nameof(updateMeter)); _options = EnsureArg.IsNotNull(configOptions?.Value, nameof(configOptions)); diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/50.diff.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/50.diff.sql new file mode 100644 index 0000000000..a039246dbf --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/50.diff.sql @@ -0,0 +1,166 @@ +SET XACT_ABORT ON + +BEGIN TRANSACTION +GO + +/************************************************************* + Stored procedures for updating an instance status. +**************************************************************/ +-- +-- STORED PROCEDURE +-- EndUpdateInstanceV50 +-- +-- DESCRIPTION +-- Bulk update all instances in a study, creates new entry in changefeed and fileProperty for each new file added. +-- +-- PARAMETERS +-- @partitionKey +-- * The partition key. +-- @studyInstanceUid +-- * The study instance UID. +-- @patientId +-- * The Id of the patient. +-- @patientName +-- * The name of the patient. +-- @patientBirthDate +-- * The patient's birth date. +-- @insertFileProperties +-- * A table type containing the file properties to insert. +-- +-- RETURN VALUE +-- None +-- +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV50 + @partitionKey INT, + @studyInstanceUid VARCHAR(64), + @patientId NVARCHAR(64) = NULL, + @patientName NVARCHAR(325) = NULL, + @patientBirthDate DATE = NULL, + @insertFileProperties dbo.FilePropertyTableType READONLY, + @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, + @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, + @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, + @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, + @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON + + SET XACT_ABORT ON + BEGIN TRANSACTION + + DECLARE @currentDate DATETIME2(7) = SYSUTCDATETIME() + DECLARE @resourceType TINYINT = 0 + DECLARE @studyKey BIGINT + DECLARE @maxWatermark BIGINT + + CREATE TABLE #UpdatedInstances + (PartitionKey INT, + StudyInstanceUid VARCHAR(64), + SeriesInstanceUid VARCHAR(64), + SopInstanceUid VARCHAR(64), + Watermark BIGINT, + OriginalWatermark BIGINT, + InstanceKey BIGINT) + + DELETE FROM #UpdatedInstances + + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL + + -- Create index on temp table so we can join on watermark when we need to update change feed with file path. + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances ON #UpdatedInstances (Watermark) + + -- Create index on temp table so we can join on instance key and watermark when we need to insert file + -- properties when instance key alone is does not specify a unique row on the table + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark ON #UpdatedInstances (InstanceKey, OriginalWatermark) + + -- Only updating patient information in a study + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + + -- The study does not exist. May be deleted + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1 + + -- Delete from file properties any rows with "stale" watermarks if we will be inserting new ones + IF EXISTS (SELECT 1 FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty as FP + INNER JOIN #UpdatedInstances U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark + + -- Insert new file properties from added blobs, @insertFileProperties will be empty when external store not + -- enabled + INSERT INTO dbo.FileProperty + (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, I.Watermark, I.FilePath, I.ETag + FROM @insertFileProperties I + INNER JOIN #UpdatedInstances U + ON U.Watermark = I.Watermark + + SELECT + @maxWatermark = max(Watermark) + FROM #UpdatedInstances + + -- Update extended query tags value if any + BEGIN TRY + EXEC dbo.IIndexInstanceCoreV9 + @partitionKey, + @studyKey, + null, -- passing null to series key and instance + null, + @maxWatermark, + @stringExtendedQueryTags, + @longExtendedQueryTags, + @doubleExtendedQueryTags, + @dateTimeExtendedQueryTags, + @personNameExtendedQueryTags + END TRY + BEGIN CATCH + THROW + END CATCH + + -- Insert into change feed table for update action type + INSERT INTO dbo.ChangeFeed + (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark + FROM #UpdatedInstances + + -- Update existing instance currentWatermark to latest and update file path + UPDATE C + SET CurrentWatermark = U.Watermark, FilePath = I.FilePath + FROM dbo.ChangeFeed C + JOIN #UpdatedInstances U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN @insertFileProperties I + ON I.Watermark = U.Watermark + + COMMIT TRANSACTION +END +GO + +COMMIT TRANSACTION diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/50.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/50.sql new file mode 100644 index 0000000000..36eabf8025 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/50.sql @@ -0,0 +1,3329 @@ + +/************************************************************************************************* + Auto-Generated from Sql build task. Do not manually edit it. +**************************************************************************************************/ +SET XACT_ABORT ON +BEGIN TRAN +IF EXISTS (SELECT * + FROM sys.tables + WHERE name = 'Instance') + BEGIN + ROLLBACK; + RETURN; + END + +CREATE SEQUENCE dbo.WatermarkSequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.StudyKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.SeriesKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.InstanceKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 1000000; + +CREATE SEQUENCE dbo.TagKeySequence + AS INT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE SEQUENCE dbo.PartitionKeySequence + AS INT + START WITH 2 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE SEQUENCE dbo.WorkitemKeySequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE SEQUENCE dbo.WorkitemWatermarkSequence + AS BIGINT + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + NO CYCLE + CACHE 10000; + +CREATE TABLE dbo.ChangeFeed ( + Sequence BIGINT IDENTITY (1, 1) NOT NULL, + Timestamp DATETIMEOFFSET (7) DEFAULT SYSDATETIMEOFFSET() NOT NULL, + Action TINYINT NOT NULL, + StudyInstanceUid VARCHAR (64) NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + SopInstanceUid VARCHAR (64) NOT NULL, + OriginalWatermark BIGINT NOT NULL, + CurrentWatermark BIGINT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + FilePath NVARCHAR (4000) NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ChangeFeed + ON dbo.ChangeFeed(Timestamp, Sequence); + +CREATE NONCLUSTERED INDEX IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.ChangeFeed(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ChangeFeed_Sequence + ON dbo.ChangeFeed(Sequence) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.DeletedInstance ( + StudyInstanceUid VARCHAR (64) NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + SopInstanceUid VARCHAR (64) NOT NULL, + Watermark BIGINT NOT NULL, + DeletedDateTime DATETIMEOFFSET (0) NOT NULL, + RetryCount INT NOT NULL, + CleanupAfter DATETIMEOFFSET (0) NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + OriginalWatermark BIGINT NULL, + FilePath NVARCHAR (4000) NULL, + ETag NVARCHAR (4000) NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_DeletedInstance + ON dbo.DeletedInstance(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark); + +CREATE NONCLUSTERED INDEX IX_DeletedInstance_RetryCount_CleanupAfter + ON dbo.DeletedInstance(RetryCount, CleanupAfter) + INCLUDE(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, OriginalWatermark, FilePath, ETag) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTag ( + TagKey INT NOT NULL, + TagPath VARCHAR (64) NOT NULL, + TagVR VARCHAR (2) NOT NULL, + TagPrivateCreator NVARCHAR (64) NULL, + TagLevel TINYINT NOT NULL, + TagStatus TINYINT NOT NULL, + QueryStatus TINYINT DEFAULT 1 NOT NULL, + ErrorCount INT DEFAULT 0 NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTag + ON dbo.ExtendedQueryTag(TagKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTag_TagPath + ON dbo.ExtendedQueryTag(TagPath); + +CREATE TABLE dbo.ExtendedQueryTagDateTime ( + TagKey INT NOT NULL, + TagValue DATETIME2 (7) NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + TagValueUtc DATETIME2 (7) NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagDateTime + ON dbo.ExtendedQueryTagDateTime(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDateTime_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDateTime(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDateTime_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDateTime(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagDouble ( + TagKey INT NOT NULL, + TagValue FLOAT (53) NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagDouble + ON dbo.ExtendedQueryTagDouble(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDouble_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDouble(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagDouble_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagDouble(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagError ( + TagKey INT NOT NULL, + ErrorCode SMALLINT NOT NULL, + Watermark BIGINT NOT NULL, + CreatedTime DATETIME2 (7) NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagError + ON dbo.ExtendedQueryTagError(TagKey, Watermark); + +CREATE UNIQUE NONCLUSTERED INDEX IX_ExtendedQueryTagError_CreatedTime_Watermark_TagKey + ON dbo.ExtendedQueryTagError(CreatedTime, Watermark, TagKey) + INCLUDE(ErrorCode); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagError_Watermark + ON dbo.ExtendedQueryTagError(Watermark); + +CREATE TABLE dbo.ExtendedQueryTagLong ( + TagKey INT NOT NULL, + TagValue BIGINT NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagLong + ON dbo.ExtendedQueryTagLong(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagLong_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagLong(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagLong_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagLong(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagOperation ( + TagKey INT NOT NULL, + OperationId UNIQUEIDENTIFIER NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagOperation + ON dbo.ExtendedQueryTagOperation(TagKey); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagOperation_OperationId + ON dbo.ExtendedQueryTagOperation(OperationId) + INCLUDE(TagKey); + +CREATE TABLE dbo.ExtendedQueryTagPersonName ( + TagKey INT NOT NULL, + TagValue NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + WatermarkAndTagKey AS CONCAT(TagKey, '.', Watermark), + TagValueWords AS REPLACE(REPLACE(TagValue, '^', ' '), '=', ' ') PERSISTED, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagPersonName + ON dbo.ExtendedQueryTagPersonName(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagPersonName(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagPersonName_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagPersonName(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey + ON dbo.ExtendedQueryTagPersonName(WatermarkAndTagKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.ExtendedQueryTagString ( + TagKey INT NOT NULL, + TagValue NVARCHAR (64) NOT NULL, + SopInstanceKey1 BIGINT NOT NULL, + SopInstanceKey2 BIGINT NULL, + SopInstanceKey3 BIGINT NULL, + Watermark BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + ResourceType TINYINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_ExtendedQueryTagString + ON dbo.ExtendedQueryTagString(PartitionKey, ResourceType, TagKey, TagValue, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagString_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagString(PartitionKey, ResourceType, TagKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) + INCLUDE(Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_ExtendedQueryTagString_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 + ON dbo.ExtendedQueryTagString(PartitionKey, ResourceType, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.FileProperty ( + InstanceKey BIGINT NOT NULL, + Watermark BIGINT NOT NULL, + FilePath NVARCHAR (4000) NOT NULL, + ETag NVARCHAR (4000) NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_FileProperty + ON dbo.FileProperty(InstanceKey, Watermark) WITH (DATA_COMPRESSION = PAGE, ONLINE = ON); + +CREATE TABLE dbo.Instance ( + InstanceKey BIGINT NOT NULL, + SeriesKey BIGINT NOT NULL, + StudyKey BIGINT NOT NULL, + StudyInstanceUid VARCHAR (64) NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + SopInstanceUid VARCHAR (64) NOT NULL, + Watermark BIGINT NOT NULL, + Status TINYINT NOT NULL, + LastStatusUpdatedDate DATETIME2 (7) NOT NULL, + CreatedDate DATETIME2 (7) NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + TransferSyntaxUid VARCHAR (64) NULL, + HasFrameMetadata BIT DEFAULT 0 NOT NULL, + OriginalWatermark BIGINT NULL, + NewWatermark BIGINT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Instance + ON dbo.Instance(PartitionKey, StudyKey, SeriesKey, InstanceKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.Instance(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) + INCLUDE(Status, Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid + ON dbo.Instance(PartitionKey, Status, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) + INCLUDE(Watermark, TransferSyntaxUid, HasFrameMetadata) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_Watermark_Status + ON dbo.Instance(Watermark, Status) + INCLUDE(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_PartitionKey_SopInstanceUid + ON dbo.Instance(PartitionKey, SopInstanceUid) + INCLUDE(SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyKey_Watermark + ON dbo.Instance(PartitionKey, Status, StudyKey, Watermark) + INCLUDE(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyKey_SeriesKey_Watermark + ON dbo.Instance(PartitionKey, Status, StudyKey, SeriesKey, Watermark) + INCLUDE(StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Instance_PartitionKey_Watermark + ON dbo.Instance(PartitionKey, Watermark) + INCLUDE(StudyKey, SeriesKey, StudyInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_PartitionKey_Status_StudyInstanceUid_NewWatermark + ON dbo.Instance(PartitionKey, Status, StudyInstanceUid, NewWatermark) + INCLUDE(SeriesInstanceUid, SopInstanceUid, Watermark, OriginalWatermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Instance_Watermark_Status_CreatedDate + ON dbo.Instance(Watermark, Status, CreatedDate) + INCLUDE(PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.Partition ( + PartitionKey INT NOT NULL, + PartitionName VARCHAR (64) NOT NULL, + CreatedDate DATETIME2 (7) NOT NULL +); + +CREATE UNIQUE CLUSTERED INDEX IXC_Partition + ON dbo.Partition(PartitionKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Partition_PartitionName + ON dbo.Partition(PartitionName) + INCLUDE(PartitionKey); + +INSERT INTO dbo.Partition (PartitionKey, PartitionName, CreatedDate) +VALUES (1, 'Microsoft.Default', SYSUTCDATETIME()); + +CREATE TABLE dbo.Series ( + SeriesKey BIGINT NOT NULL, + StudyKey BIGINT NOT NULL, + SeriesInstanceUid VARCHAR (64) NOT NULL, + Modality NVARCHAR (16) NULL, + PerformedProcedureStepStartDate DATE NULL, + ManufacturerModelName NVARCHAR (64) NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Series + ON dbo.Series(PartitionKey, StudyKey, SeriesKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Series_PartitionKey_StudyKey_SeriesInstanceUid + ON dbo.Series(PartitionKey, StudyKey, SeriesInstanceUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_SeriesInstanceUid + ON dbo.Series(PartitionKey, SeriesInstanceUid) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_Modality + ON dbo.Series(PartitionKey, Modality) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_PerformedProcedureStepStartDate + ON dbo.Series(PartitionKey, PerformedProcedureStepStartDate) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Series_PartitionKey_ManufacturerModelName + ON dbo.Series(PartitionKey, ManufacturerModelName) + INCLUDE(StudyKey, SeriesKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.Study ( + StudyKey BIGINT NOT NULL, + StudyInstanceUid VARCHAR (64) NOT NULL, + PatientId NVARCHAR (64) NOT NULL, + PatientName NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI NULL, + ReferringPhysicianName NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI NULL, + StudyDate DATE NULL, + StudyDescription NVARCHAR (64) NULL, + AccessionNumber NVARCHAR (16) NULL, + PatientNameWords AS REPLACE(REPLACE(PatientName, '^', ' '), '=', ' ') PERSISTED, + ReferringPhysicianNameWords AS REPLACE(REPLACE(ReferringPhysicianName, '^', ' '), '=', ' ') PERSISTED, + PatientBirthDate DATE NULL, + PartitionKey INT DEFAULT 1 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Study + ON dbo.Study(PartitionKey, StudyKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Study_StudyKey + ON dbo.Study(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Study_PartitionKey_StudyInstanceUid + ON dbo.Study(PartitionKey, StudyInstanceUid) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_PatientId + ON dbo.Study(PartitionKey, PatientId) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_PatientName + ON dbo.Study(PartitionKey, PatientName) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_ReferringPhysicianName + ON dbo.Study(PartitionKey, ReferringPhysicianName) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_StudyDate + ON dbo.Study(PartitionKey, StudyDate) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_StudyDescription + ON dbo.Study(PartitionKey, StudyDescription) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_AccessionNumber + ON dbo.Study(PartitionKey, AccessionNumber) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE NONCLUSTERED INDEX IX_Study_PartitionKey_PatientBirthDate + ON dbo.Study(PartitionKey, PatientBirthDate) + INCLUDE(StudyKey) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.Workitem ( + WorkitemKey BIGINT NOT NULL, + PartitionKey INT DEFAULT 1 NOT NULL, + WorkitemUid VARCHAR (64) NOT NULL, + TransactionUid VARCHAR (64) NULL, + Status TINYINT NOT NULL, + CreatedDate DATETIME2 (7) NOT NULL, + LastStatusUpdatedDate DATETIME2 (7) NOT NULL, + Watermark BIGINT DEFAULT 0 NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_Workitem + ON dbo.Workitem(PartitionKey, WorkitemKey); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Workitem_PartitionKey_WorkitemUid + ON dbo.Workitem(PartitionKey, WorkitemUid) + INCLUDE(Watermark, WorkitemKey, Status, TransactionUid) WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE NONCLUSTERED INDEX IX_Workitem_WorkitemKey_Watermark + ON dbo.Workitem(WorkitemKey, Watermark) WITH (DATA_COMPRESSION = PAGE); + +CREATE TABLE dbo.WorkitemQueryTag ( + TagKey INT NOT NULL, + TagPath VARCHAR (64) NOT NULL, + TagVR VARCHAR (2) NOT NULL +) +WITH (DATA_COMPRESSION = PAGE); + +CREATE UNIQUE CLUSTERED INDEX IXC_WorkitemQueryTag + ON dbo.WorkitemQueryTag(TagKey); + +CREATE UNIQUE NONCLUSTERED INDEX IXC_WorkitemQueryTag_TagPath + ON dbo.WorkitemQueryTag(TagPath) WITH (DATA_COMPRESSION = PAGE); + +CREATE TYPE dbo.AddExtendedQueryTagsInputTableType_1 AS TABLE ( + TagPath VARCHAR (64) , + TagVR VARCHAR (2) , + TagPrivateCreator NVARCHAR (64), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertStringExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue NVARCHAR (64), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertDoubleExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue FLOAT (53), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertLongExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue BIGINT , + TagLevel TINYINT); + +CREATE TYPE dbo.InsertDateTimeExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue DATETIME2 (7), + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertDateTimeExtendedQueryTagTableType_2 AS TABLE ( + TagKey INT , + TagValue DATETIME2 (7), + TagValueUtc DATETIME2 (7) NULL, + TagLevel TINYINT ); + +CREATE TYPE dbo.InsertPersonNameExtendedQueryTagTableType_1 AS TABLE ( + TagKey INT , + TagValue NVARCHAR (200) COLLATE SQL_Latin1_General_CP1_CI_AI, + TagLevel TINYINT ); + +CREATE TYPE dbo.ExtendedQueryTagKeyTableType_1 AS TABLE ( + TagKey INT); + +CREATE TYPE dbo.WatermarkTableType AS TABLE ( + Watermark BIGINT); + +CREATE TYPE dbo.FilePropertyTableType AS TABLE ( + Watermark BIGINT NOT NULL INDEX IXC_FilePropertyTableType CLUSTERED, + FilePath NVARCHAR (4000) NOT NULL, + ETag NVARCHAR (4000) NOT NULL); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00100010', 'PN'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00100020', 'LO'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '0040A370.00080050', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '0040A370.00401001', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404005', 'DT'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404025.00080100', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404026.00080100', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00741000', 'CS'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '00404027.00080100', 'SQ'); + +INSERT INTO dbo.WorkitemQueryTag (TagKey, TagPath, TagVR) +VALUES ( NEXT VALUE FOR TagKeySequence, '0020000D', 'UI'); + +COMMIT +GO +IF ((SELECT is_read_committed_snapshot_on + FROM sys.databases + WHERE database_id = DB_ID()) = 0) + BEGIN + ALTER DATABASE CURRENT + SET READ_COMMITTED_SNAPSHOT ON; + END + +IF ((SELECT is_auto_update_stats_async_on + FROM sys.databases + WHERE database_id = DB_ID()) = 0) + BEGIN + ALTER DATABASE CURRENT + SET AUTO_UPDATE_STATISTICS_ASYNC ON; + END + +IF ((SELECT is_ansi_nulls_on + FROM sys.databases + WHERE database_id = DB_ID()) = 0) + BEGIN + ALTER DATABASE CURRENT + SET ANSI_NULLS ON; + END + +GO +IF NOT EXISTS (SELECT * + FROM sys.fulltext_catalogs + WHERE name = 'Dicom_Catalog') + BEGIN + CREATE FULLTEXT CATALOG Dicom_Catalog + WITH ACCENT_SENSITIVITY = OFF + AS DEFAULT; + END + + +GO +IF NOT EXISTS (SELECT * + FROM sys.fulltext_indexes + WHERE object_id = object_id('dbo.Study')) + BEGIN + CREATE FULLTEXT INDEX ON Study + (PatientNameWords, ReferringPhysicianNameWords LANGUAGE 1033) + KEY INDEX IX_Study_StudyKey + WITH STOPLIST OFF; + END + + +GO +IF NOT EXISTS (SELECT * + FROM sys.fulltext_indexes + WHERE object_id = object_id('dbo.ExtendedQueryTagPersonName')) + BEGIN + CREATE FULLTEXT INDEX ON ExtendedQueryTagPersonName + (TagValueWords LANGUAGE 1033) + KEY INDEX IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey + WITH STOPLIST OFF; + END + +GO +CREATE OR ALTER PROCEDURE dbo.AddExtendedQueryTagError +@tagKey INT, @errorCode SMALLINT, @watermark BIGINT +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN TRANSACTION; +DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); +IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (UPDLOCK) + WHERE Watermark = @watermark + AND Status = 1) + THROW 50404, 'Instance does not exist or has not been created.', 1; +IF NOT EXISTS (SELECT * + FROM dbo.ExtendedQueryTag WITH (UPDLOCK) + WHERE TagKey = @tagKey + AND TagStatus = 0) + THROW 50404, 'Tag does not exist or is not being added.', 1; +DECLARE @addedCount AS SMALLINT; +SET @addedCount = 1; +MERGE INTO dbo.ExtendedQueryTagError WITH (HOLDLOCK) + AS XQTE +USING (SELECT @tagKey AS TagKey, + @errorCode AS ErrorCode, + @watermark AS Watermark) AS src ON src.TagKey = XQTE.TagKey + AND src.WaterMark = XQTE.Watermark +WHEN MATCHED THEN UPDATE +SET CreatedTime = @currentDate, + ErrorCode = @errorCode, + @addedCount = 0 +WHEN NOT MATCHED THEN INSERT (TagKey, ErrorCode, Watermark, CreatedTime) VALUES (@tagKey, @errorCode, @watermark, @currentDate) OUTPUT INSERTED.TagKey; +UPDATE dbo.ExtendedQueryTag +SET QueryStatus = 0, + ErrorCount = ErrorCount + @addedCount +WHERE TagKey = @tagKey; +COMMIT TRANSACTION; + +GO +CREATE OR ALTER PROCEDURE dbo.AddExtendedQueryTags +@extendedQueryTags dbo.AddExtendedQueryTagsInputTableType_1 READONLY, @maxAllowedCount INT=128, @ready BIT=0 +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN + BEGIN TRANSACTION; + IF (SELECT COUNT(*) + FROM dbo.ExtendedQueryTag AS XQT WITH (UPDLOCK, HOLDLOCK) + FULL OUTER JOIN + @extendedQueryTags AS input + ON XQT.TagPath = input.TagPath) > @maxAllowedCount + THROW 50409, 'extended query tags exceed max allowed count', 1; + DECLARE @existingTags TABLE ( + TagKey INT , + TagStatus TINYINT , + OperationId UNIQUEIDENTIFIER NULL); + INSERT INTO @existingTags (TagKey, TagStatus, OperationId) + SELECT XQT.TagKey, + TagStatus, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @extendedQueryTags AS input + ON input.TagPath = XQT.TagPath + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey; + IF EXISTS (SELECT 1 + FROM @existingTags + WHERE TagStatus <> 0 + OR (TagStatus = 0 + AND OperationId IS NOT NULL)) + THROW 50409, 'extended query tag(s) already exist', 2; + DELETE XQT + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @existingTags AS et + ON XQT.TagKey = et.TagKey; + INSERT INTO dbo.ExtendedQueryTag (TagKey, TagPath, TagPrivateCreator, TagVR, TagLevel, TagStatus, QueryStatus, ErrorCount) + OUTPUT INSERTED.TagKey, INSERTED.TagPath, INSERTED.TagVR, INSERTED.TagPrivateCreator, INSERTED.TagLevel, INSERTED.TagStatus, INSERTED.QueryStatus, INSERTED.ErrorCount + SELECT NEXT VALUE FOR TagKeySequence, + TagPath, + TagPrivateCreator, + TagVR, + TagLevel, + @ready, + 1, + 0 + FROM @extendedQueryTags; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddInstanceV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @patientId NVARCHAR (64), @patientName NVARCHAR (325)=NULL, @referringPhysicianName NVARCHAR (325)=NULL, @studyDate DATE=NULL, @studyDescription NVARCHAR (64)=NULL, @accessionNumber NVARCHAR (64)=NULL, @modality NVARCHAR (16)=NULL, @performedProcedureStepStartDate DATE=NULL, @patientBirthDate DATE=NULL, @manufacturerModelName NVARCHAR (64)=NULL, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT, @transferSyntaxUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT OFF; + BEGIN TRY + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @existingStatus AS TINYINT; + DECLARE @newWatermark AS BIGINT; + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + SELECT @existingStatus = Status + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Instance already exists', @existingStatus; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + SET @instanceKey = NEXT VALUE FOR dbo.InstanceKeySequence; + SELECT @studyKey = StudyKey + FROM dbo.Study WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + BEGIN TRY + SET @studyKey = NEXT VALUE FOR dbo.StudyKeySequence; + INSERT INTO dbo.Study (PartitionKey, StudyKey, StudyInstanceUid, PatientId, PatientName, PatientBirthDate, ReferringPhysicianName, StudyDate, StudyDescription, AccessionNumber) + VALUES (@partitionKey, @studyKey, @studyInstanceUid, @patientId, @patientName, @patientBirthDate, @referringPhysicianName, @studyDate, @studyDescription, @accessionNumber); + END TRY + BEGIN CATCH + IF ERROR_NUMBER() = 2601 + BEGIN + SELECT @studyKey = StudyKey + FROM dbo.Study WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + ELSE + THROW; + END CATCH + ELSE + BEGIN + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + SELECT @seriesKey = SeriesKey + FROM dbo.Series WITH (UPDLOCK) + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = @seriesInstanceUid + AND PartitionKey = @partitionKey; + IF @@ROWCOUNT = 0 + BEGIN + SET @seriesKey = NEXT VALUE FOR dbo.SeriesKeySequence; + INSERT INTO dbo.Series (PartitionKey, StudyKey, SeriesKey, SeriesInstanceUid, Modality, PerformedProcedureStepStartDate, ManufacturerModelName) + VALUES (@partitionKey, @studyKey, @seriesKey, @seriesInstanceUid, @modality, @performedProcedureStepStartDate, @manufacturerModelName); + END + ELSE + BEGIN + UPDATE dbo.Series + SET Modality = ISNULL(@modality, Modality), + PerformedProcedureStepStartDate = ISNULL(@performedProcedureStepStartDate, PerformedProcedureStepStartDate), + ManufacturerModelName = ISNULL(@manufacturerModelName, ManufacturerModelName) + WHERE SeriesKey = @seriesKey + AND StudyKey = @studyKey + AND PartitionKey = @partitionKey; + END + INSERT INTO dbo.Instance (PartitionKey, StudyKey, SeriesKey, InstanceKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, Status, LastStatusUpdatedDate, CreatedDate, TransferSyntaxUid) + VALUES (@partitionKey, @studyKey, @seriesKey, @instanceKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @newWatermark, @initialStatus, @currentDate, @currentDate, @transferSyntaxUid); + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, @seriesKey, @instanceKey, @newWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @newWatermark; + COMMIT TRANSACTION; + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK; + THROW; + END CATCH +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddPartition +@partitionName VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @createdDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @partitionKey AS INT; + SELECT @partitionKey = PartitionKey + FROM dbo.Partition + WHERE PartitionName = @partitionName; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Partition already exists', 1; + SET @partitionKey = NEXT VALUE FOR dbo.PartitionKeySequence; + INSERT INTO dbo.Partition (PartitionKey, PartitionName, CreatedDate) + VALUES (@partitionKey, @partitionName, @createdDate); + SELECT @partitionKey, + @partitionName, + @createdDate; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddWorkitem +@partitionKey INT, @workitemUid VARCHAR (64), @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @workitemKey AS BIGINT; + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Workitem already exists', 1; + SET @workitemKey = NEXT VALUE FOR dbo.WorkitemKeySequence; + INSERT INTO dbo.Workitem (WorkitemKey, PartitionKey, WorkitemUid, Status, CreatedDate, LastStatusUpdatedDate) + VALUES (@workitemKey, @partitionKey, @workitemUid, @initialStatus, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexWorkitemInstanceCore @partitionKey, @workitemKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @workitemKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddWorkitemV11 +@partitionKey INT, @workitemUid VARCHAR (64), @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @watermark AS BIGINT; + DECLARE @workitemKey AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Workitem already exists', 1; + SET @workitemKey = NEXT VALUE FOR dbo.WorkitemKeySequence; + SET @watermark = NEXT VALUE FOR dbo.WorkitemWatermarkSequence; + INSERT INTO dbo.Workitem (WorkitemKey, PartitionKey, WorkitemUid, Status, Watermark, CreatedDate, LastStatusUpdatedDate) + VALUES (@workitemKey, @partitionKey, @workitemUid, @initialStatus, @watermark, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexWorkitemInstanceCore @partitionKey, @workitemKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; + SELECT @workitemKey, + @watermark; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AssignReindexingOperation +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY, @operationId UNIQUEIDENTIFIER, @returnIfCompleted BIT=0 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + MERGE INTO dbo.ExtendedQueryTagOperation WITH (HOLDLOCK) + AS XQTO + USING (SELECT input.TagKey + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT WITH (HOLDLOCK) + ON input.TagKey = XQT.TagKey + WHERE TagStatus = 0) AS tags ON XQTO.TagKey = tags.TagKey + WHEN NOT MATCHED THEN INSERT (TagKey, OperationId) VALUES (tags.TagKey, @operationId); + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT WITH (HOLDLOCK) + ON input.TagKey = XQT.TagKey + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO WITH (HOLDLOCK) + ON XQT.TagKey = XQTO.TagKey + WHERE (@returnIfCompleted = 1 + AND TagStatus = 1) + OR (OperationId = @operationId + AND TagStatus = 0); + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstance +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE i + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + WHERE Status = 1; + COMMIT TRANSACTION; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + i.Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + WHERE Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstanceV33 +@partitionKey INT, @studyInstanceUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; + COMMIT TRANSACTION; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstanceV46 +@partitionKey INT, @studyInstanceUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; + COMMIT TRANSACTION; + SELECT i.StudyInstanceUid, + i.SeriesInstanceUid, + i.SopInstanceUid, + i.Watermark, + i.TransferSyntaxUid, + i.HasFrameMetadata, + i.OriginalWatermark, + i.NewWatermark, + f.FilePath, + f.ETag + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS f + ON f.InstanceKey = i.InstanceKey + AND f.Watermark = i.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.CompleteReindexing +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE XQT + SET TagStatus = 1 + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @extendedQueryTagKeys AS input + ON XQT.TagKey = input.TagKey + WHERE TagStatus = 0; + DELETE XQTO + OUTPUT DELETED.TagKey + FROM dbo.ExtendedQueryTagOperation AS XQTO + INNER JOIN + dbo.ExtendedQueryTag AS XQT + ON XQTO.TagKey = XQT.TagKey + INNER JOIN + @extendedQueryTagKeys AS input + ON XQT.TagKey = input.TagKey + WHERE TagStatus = 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteDeletedInstance +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT +AS +SET NOCOUNT ON; +DELETE dbo.DeletedInstance +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteDeletedInstanceV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT +AS +SET NOCOUNT ON; +DELETE dbo.DeletedInstance +WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTag +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagStatus AS TINYINT; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey, + @tagStatus = TagStatus + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + IF @tagStatus = 2 + THROW 50412, 'extended query tag is not in Ready or Adding status', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 1 + DELETE dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 2 + DELETE dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 3 + DELETE dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey; + ELSE + DELETE dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV16 +@tagPath VARCHAR (64), @dataType TINYINT, @batchSize INT=1000 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @deletedRows AS INT; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + SET @deletedRows = @batchSize; + WHILE (@deletedRows = @batchSize) + BEGIN + EXECUTE dbo.ISleepIfBusy ; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 1 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 2 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 3 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + SET @deletedRows = @@ROWCOUNT; + COMMIT TRANSACTION; + CHECKPOINT; + END + SET @deletedRows = @batchSize; + WHILE (@deletedRows = @batchSize) + BEGIN + EXECUTE dbo.ISleepIfBusy ; + BEGIN TRANSACTION; + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + SET @deletedRows = @@ROWCOUNT; + COMMIT TRANSACTION; + CHECKPOINT; + END + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV8 +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 1 + DELETE dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 2 + DELETE dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 3 + DELETE dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + DELETE dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteInstanceV6 +@cleanupAfter DATETIMEOFFSET (0), @createdStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @deletedInstances AS TABLE ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64) , + SeriesInstanceUid VARCHAR (64) , + SopInstanceUid VARCHAR (64) , + Status TINYINT , + Watermark BIGINT , + InstanceKey INT , + OriginalWatermark BIGINT , + FilePath NVARCHAR (4000) NULL, + ETag NVARCHAR (4000) NULL); + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @deletedDate AS DATETIME2 = SYSUTCDATETIME(); + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @studyKey = StudyKey, + @seriesKey = CASE @seriesInstanceUid WHEN NULL THEN NULL ELSE SeriesKey END, + @instanceKey = CASE @sopInstanceUid WHEN NULL THEN NULL ELSE InstanceKey END + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid); + DELETE dbo.Instance + OUTPUT deleted.PartitionKey, deleted.StudyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.Status, deleted.Watermark, deleted.InstanceKey, deleted.OriginalWatermark, FP.FilePath, FP.ETag INTO @deletedInstances + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS FP + ON i.InstanceKey = FP.InstanceKey + AND i.Watermark = FP.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.SeriesInstanceUid = ISNULL(@seriesInstanceUid, i.SeriesInstanceUid) + AND i.SopInstanceUid = ISNULL(@sopInstanceUid, i.SopInstanceUid); + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance not found', 1; + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + @deletedInstances AS DI + ON DI.InstanceKey = FP.InstanceKey + AND DI.Watermark = FP.Watermark; + DECLARE @deletedTags AS TABLE ( + TagKey BIGINT); + DELETE XQTE + OUTPUT deleted.TagKey INTO @deletedTags + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + @deletedInstances AS DI + ON XQTE.Watermark = DI.Watermark; + IF EXISTS (SELECT * + FROM @deletedTags) + BEGIN + DECLARE @deletedTagCounts AS TABLE ( + TagKey BIGINT, + ErrorCount INT ); + INSERT INTO @deletedTagCounts (TagKey, ErrorCount) + SELECT TagKey, + COUNT(1) + FROM @deletedTags + GROUP BY TagKey; + UPDATE XQT + SET XQT.ErrorCount = XQT.ErrorCount - DTC.ErrorCount + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @deletedTagCounts AS DTC + ON XQT.TagKey = DTC.TagKey; + END + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + INSERT INTO dbo.DeletedInstance (PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, DeletedDateTime, RetryCount, CleanupAfter, OriginalWatermark, FilePath, ETag) + SELECT PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + @deletedDate, + 0, + @cleanupAfter, + OriginalWatermark, + FilePath, + ETag + FROM @deletedInstances; + IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (HOLDLOCK, UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey)) + BEGIN + DELETE dbo.Series + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + END + IF NOT EXISTS (SELECT * + FROM dbo.Series WITH (HOLDLOCK, UPDLOCK) + WHERE Studykey = @studyKey + AND PartitionKey = @partitionKey) + BEGIN + DELETE dbo.Study + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + END + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 1, + DI.PartitionKey, + DI.StudyInstanceUid, + DI.SeriesInstanceUid, + DI.SopInstanceUid, + DI.Watermark + FROM @deletedInstances AS DI + WHERE Status = @createdStatus; + UPDATE CF + SET CF.CurrentWatermark = NULL + FROM dbo.ChangeFeed AS CF WITH (FORCESEEK) + INNER JOIN + @deletedInstances AS DI + ON CF.PartitionKey = DI.PartitionKey + AND CF.StudyInstanceUid = DI.StudyInstanceUid + AND CF.SeriesInstanceUid = DI.SeriesInstanceUid + AND CF.SopInstanceUid = DI.SopInstanceUid; + COMMIT TRANSACTION; + SELECT d.Watermark, + d.partitionKey, + d.studyInstanceUid, + d.seriesInstanceUid, + d.sopInstanceUid + FROM @deletedInstances AS d; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteWorkitem +@partitionKey INT, @workitemUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @workitemKey AS BIGINT; + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT = 0 + THROW 50413, 'Workitem does not exists', 1; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.Workitem + WHERE WorkItemKey = @workitemKey + AND PartitionKey = @partitionKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstance +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @updatedInstances AS TABLE ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT ); + DELETE @updatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.NewWatermark INTO @updatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM @updatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark + FROM dbo.ChangeFeed AS C + INNER JOIN + @updatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV44 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV50 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @resourceType AS TINYINT = 0; + DECLARE @studyKey AS BIGINT; + DECLARE @maxWatermark AS BIGINT; + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + SELECT @maxWatermark = max(Watermark) + FROM #UpdatedInstances; + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, NULL, NULL, @maxWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeed +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT Sequence, + Timestamp, + Action, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed + WHERE Sequence BETWEEN @offset + 1 AND @offset + @limit + ORDER BY Sequence; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedByTime +@startTime DATETIMEOFFSET (7), @endTime DATETIMEOFFSET (7), @limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE c.Timestamp >= @startTime + AND c.Timestamp < @endTime + ORDER BY Timestamp, Sequence + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedByTimeV39 +@startTime DATETIMEOFFSET (7), @endTime DATETIMEOFFSET (7), @limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE c.Timestamp >= @startTime + AND c.Timestamp < @endTime + ORDER BY c.Timestamp, c.Sequence + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatest +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) Sequence, + Timestamp, + Action, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed + ORDER BY Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestByTime +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY Timestamp DESC, Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestByTimeV39 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY c.Timestamp DESC, c.Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestV39 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY c.Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedLatestV6 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TOP (1) Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + ORDER BY Sequence DESC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedV39 +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT c.Sequence, + c.Timestamp, + c.Action, + p.PartitionName, + c.StudyInstanceUid, + c.SeriesInstanceUid, + c.SopInstanceUid, + c.OriginalWatermark, + c.CurrentWatermark, + c.FilePath + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE c.Sequence BETWEEN @offset + 1 AND @offset + @limit + ORDER BY c.Sequence; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetChangeFeedV6 +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT Sequence, + Timestamp, + Action, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + OriginalWatermark, + CurrentWatermark + FROM dbo.ChangeFeed AS c WITH (HOLDLOCK) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = c.PartitionKey + WHERE Sequence BETWEEN @offset + 1 AND @offset + @limit + ORDER BY Sequence; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetCurrentAndNextWorkitemWatermark +@workitemKey BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + IF NOT EXISTS (SELECT WorkitemKey + FROM dbo.Workitem + WHERE WorkitemKey = @workitemKey) + THROW 50409, 'Workitem does not exist', 1; + DECLARE @proposedWatermark AS BIGINT; + SET @proposedWatermark = NEXT VALUE FOR dbo.WorkitemWatermarkSequence; + SELECT Watermark, + @proposedWatermark AS ProposedWatermark + FROM dbo.Workitem + WHERE WorkitemKey = @workitemKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTag +@tagPath VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + WHERE TagPath = ISNULL(@tagPath, TagPath); +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagErrors +@tagPath VARCHAR (64), @limit INT, @offset INT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF (@@ROWCOUNT = 0) + THROW 50404, 'extended query tag not found', 1; + SELECT TagKey, + ErrorCode, + CreatedTime, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + dbo.Instance AS I + ON XQTE.Watermark = I.Watermark + WHERE XQTE.TagKey = @tagKey + ORDER BY CreatedTime ASC, XQTE.Watermark ASC, TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagErrorsV36 +@tagPath VARCHAR (64), @limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF (@@ROWCOUNT = 0) + THROW 50404, 'extended query tag not found', 1; + SELECT TagKey, + ErrorCode, + CreatedTime, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + dbo.Instance AS I + ON XQTE.Watermark = I.Watermark + INNER JOIN + dbo.Partition AS P + ON P.PartitionKey = I.PartitionKey + WHERE XQTE.TagKey = @tagKey + ORDER BY CreatedTime ASC, XQTE.Watermark ASC, TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagErrorsV6 +@tagPath VARCHAR (64), @limit INT, @offset INT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF (@@ROWCOUNT = 0) + THROW 50404, 'extended query tag not found', 1; + SELECT TagKey, + ErrorCode, + CreatedTime, + PartitionName, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + dbo.Instance AS I + ON XQTE.Watermark = I.Watermark + INNER JOIN + dbo.Partition AS P + ON P.PartitionKey = I.PartitionKey + WHERE XQTE.TagKey = @tagKey + ORDER BY CreatedTime ASC, XQTE.Watermark ASC, TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTags +@limit INT, @offset INT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + ORDER BY XQT.TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagsByKey +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT + ON input.TagKey = XQT.TagKey + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagsByOperation +@operationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + WHERE OperationId = @operationId; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetExtendedQueryTagsV36 +@limit INT, @offset BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount, + OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + ORDER BY XQT.TagKey ASC + OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstance +@validStatus TINYINT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceBatches +@batchSize INT, @batchCount INT, @status TINYINT, @maxWatermark BIGINT=NULL +AS +BEGIN + SET NOCOUNT ON; + SELECT MIN(Watermark) AS MinWatermark, + MAX(Watermark) AS MaxWatermark + FROM (SELECT TOP (@batchSize * @batchCount) Watermark, + (ROW_NUMBER() OVER (ORDER BY Watermark DESC) - 1) / @batchSize AS Batch + FROM dbo.Instance + WHERE Watermark <= ISNULL(@maxWatermark, Watermark) + AND Status = @status) AS I + GROUP BY Batch + ORDER BY Batch ASC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceBatchesByTimeStamp +@batchSize INT, @batchCount INT, @status TINYINT, @startTimeStamp DATETIMEOFFSET (0), @endTimeStamp DATETIMEOFFSET (0), @maxWatermark BIGINT=NULL +AS +BEGIN + SET NOCOUNT ON; + SELECT MIN(Watermark) AS MinWatermark, + MAX(Watermark) AS MaxWatermark + FROM (SELECT TOP (@batchSize * @batchCount) Watermark, + (ROW_NUMBER() OVER (ORDER BY Watermark DESC) - 1) / @batchSize AS Batch + FROM dbo.Instance + WHERE Watermark <= ISNULL(@maxWatermark, Watermark) + AND Status = @status + AND CreatedDate >= @startTimeStamp + AND CreatedDate <= @endTimeStamp) AS I + GROUP BY Batch + ORDER BY Batch ASC; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstancesByWatermarkRange +@startWatermark BIGINT, @endWatermark BIGINT, @status TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE Watermark BETWEEN @startWatermark AND @endWatermark + AND Status = @status; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstancesByWatermarkRangeV6 +@startWatermark BIGINT, @endWatermark BIGINT, @status TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE Watermark BETWEEN @startWatermark AND @endWatermark + AND Status = @status; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceV6 +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceWithProperties +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceWithPropertiesV32 +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetInstanceWithPropertiesV46 +@validStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT i.StudyInstanceUid, + i.SeriesInstanceUid, + i.SopInstanceUid, + i.Watermark, + i.TransferSyntaxUid, + i.HasFrameMetadata, + i.OriginalWatermark, + i.NewWatermark, + f.FilePath, + f.ETag + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS f + ON f.InstanceKey = i.InstanceKey + AND f.Watermark = i.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND i.SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid) + AND i.Status = @validStatus; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetPartition +@partitionName VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT PartitionKey, + PartitionName, + CreatedDate + FROM dbo.Partition + WHERE PartitionName = @partitionName; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetPartitions +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT PartitionKey, + PartitionName, + CreatedDate + FROM dbo.Partition; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetSeriesResult +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT i.StudyInstanceUid, + sv.SeriesInstanceUid, + sv.Modality, + sv.PerformedProcedureStepStartDate, + sv.ManufacturerModelName, + sv.NumberofSeriesRelatedInstances + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + INNER JOIN + dbo.SeriesResultView AS sv + ON i.StudyKey = sv.StudyKey + AND i.SeriesKey = sv.SeriesKey + AND i.PartitionKey = sv.PartitionKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetStudyResult +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT sv.StudyInstanceUid, + sv.PatientId, + sv.PatientName, + sv.ReferringPhysicianName, + sv.StudyDate, + sv.StudyDescription, + sv.AccessionNumber, + sv.PatientBirthDate, + sv.ModalitiesInStudy, + sv.NumberofStudyRelatedInstances + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + INNER JOIN + dbo.StudyResultView AS sv + ON i.StudyKey = sv.StudyKey + AND i.PartitionKey = sv.PartitionKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetWorkitemMetadata +@partitionKey INT, @workitemUid VARCHAR (64), @procedureStepStateTagPath VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT wi.WorkitemUid, + wi.WorkitemKey, + wi.PartitionKey, + wi.[Status], + wi.TransactionUid, + wi.Watermark, + eqt.TagValue AS ProcedureStepState + FROM dbo.WorkitemQueryTag AS wqt + INNER JOIN + dbo.ExtendedQueryTagString AS eqt + ON eqt.ResourceType = 1 + AND eqt.TagKey = wqt.TagKey + AND wqt.TagPath = @procedureStepStateTagPath + INNER JOIN + dbo.Workitem AS wi + ON wi.WorkitemKey = eqt.SopInstanceKey1 + AND wi.PartitionKey = eqt.PartitionKey + WHERE wi.PartitionKey = @partitionKey + AND wi.WorkitemUid = @workitemUid; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem does not exist', 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.GetWorkitemQueryTags +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + SELECT TagKey, + TagPath, + TagVR + FROM dbo.WorkItemQueryTag; +END + +GO +CREATE OR ALTER PROCEDURE dbo.IIndexInstanceCoreV9 +@partitionKey INT=1, @studyKey BIGINT, @seriesKey BIGINT, @instanceKey BIGINT, @watermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + DECLARE @resourceType AS TINYINT = 0; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagString + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @stringExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND ISNULL(T.SopInstanceKey2, @seriesKey) = @seriesKey + AND ISNULL(T.SopInstanceKey3, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @longExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagLong + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @longExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND ISNULL(T.SopInstanceKey2, @seriesKey) = @seriesKey + AND ISNULL(T.SopInstanceKey3, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @doubleExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDouble + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @doubleExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND ISNULL(T.SopInstanceKey2, @seriesKey) = @seriesKey + AND ISNULL(T.SopInstanceKey3, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagDateTime + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagValueUtc, + input.TagLevel + FROM @dateTimeExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND ISNULL(T.SopInstanceKey2, @seriesKey) = @seriesKey + AND ISNULL(T.SopInstanceKey3, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, TagValueUtc, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, S.TagValueUtc, @resourceType); + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + MERGE INTO dbo.ExtendedQueryTagPersonName + AS T + USING (SELECT input.TagKey, + input.TagValue, + input.TagLevel + FROM @personNameExtendedQueryTags AS input + INNER JOIN + dbo.ExtendedQueryTag WITH (REPEATABLEREAD) + ON dbo.ExtendedQueryTag.TagKey = input.TagKey + AND dbo.ExtendedQueryTag.TagStatus <> 2) AS S ON T.ResourceType = @resourceType + AND T.TagKey = S.TagKey + AND T.PartitionKey = @partitionKey + AND T.SopInstanceKey1 = @studyKey + AND ISNULL(T.SopInstanceKey2, @seriesKey) = @seriesKey + AND ISNULL(T.SopInstanceKey3, @instanceKey) = @instanceKey + WHEN MATCHED AND @watermark > T.Watermark THEN UPDATE + SET T.Watermark = @watermark, + T.TagValue = ISNULL(S.TagValue, T.TagValue) + WHEN NOT MATCHED THEN INSERT (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) VALUES (S.TagKey, S.TagValue, @partitionKey, @studyKey, (CASE WHEN S.TagLevel <> 2 THEN @seriesKey ELSE NULL END), (CASE WHEN S.TagLevel = 0 THEN @instanceKey ELSE NULL END), @watermark, @resourceType); + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.IIndexWorkitemInstanceCore +@partitionKey INT=1, @workitemKey BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @newWatermark AS BIGINT; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + INSERT dbo.ExtendedQueryTagString (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) + SELECT input.TagKey, + input.TagValue, + @partitionKey, + @workitemKey, + NULL, + NULL, + @newWatermark, + @workitemResourceType + FROM @stringExtendedQueryTags AS input + INNER JOIN + dbo.WorkitemQueryTag + ON dbo.WorkitemQueryTag.TagKey = input.TagKey; + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + INSERT dbo.ExtendedQueryTagDateTime (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) + SELECT input.TagKey, + input.TagValue, + @partitionKey, + @workitemKey, + NULL, + NULL, + @newWatermark, + @workitemResourceType + FROM @dateTimeExtendedQueryTags AS input + INNER JOIN + dbo.WorkitemQueryTag + ON dbo.WorkitemQueryTag.TagKey = input.TagKey; + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + INSERT dbo.ExtendedQueryTagPersonName (TagKey, TagValue, PartitionKey, SopInstanceKey1, SopInstanceKey2, SopInstanceKey3, Watermark, ResourceType) + SELECT input.TagKey, + input.TagValue, + @partitionKey, + @workitemKey, + NULL, + NULL, + @newWatermark, + @workitemResourceType + FROM @personNameExtendedQueryTags AS input + INNER JOIN + dbo.WorkitemQueryTag + ON dbo.WorkitemQueryTag.TagKey = input.TagKey; + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.IncrementDeletedInstanceRetry +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @cleanupAfter DATETIMEOFFSET (0) +AS +SET NOCOUNT ON; +DECLARE @retryCount AS INT; +UPDATE dbo.DeletedInstance +SET @retryCount = RetryCount = RetryCount + 1, + CleanupAfter = @cleanupAfter +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; +SELECT @retryCount; + +GO +CREATE OR ALTER PROCEDURE dbo.IncrementDeletedInstanceRetryV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @cleanupAfter DATETIMEOFFSET (0) +AS +SET NOCOUNT ON; +DECLARE @retryCount AS INT; +UPDATE dbo.DeletedInstance +SET @retryCount = RetryCount = RetryCount + 1, + CleanupAfter = @cleanupAfter +WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; +SELECT @retryCount; + +GO +CREATE OR ALTER PROCEDURE dbo.IndexInstanceV6 +@watermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @partitionKey AS BIGINT; + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @status AS TINYINT; + SELECT @partitionKey = PartitionKey, + @studyKey = StudyKey, + @seriesKey = SeriesKey, + @instanceKey = InstanceKey, + @status = Status + FROM dbo.Instance WITH (UPDLOCK) + WHERE Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + IF @status <> 1 + THROW 50409, 'Instance has not yet been stored succssfully', 1; + DECLARE @maxTagLevel AS TINYINT; + SELECT @maxTagLevel = MAX(TagLevel) + FROM (SELECT TagLevel + FROM @stringExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @longExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @doubleExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @dateTimeExtendedQueryTags + UNION ALL + SELECT TagLevel + FROM @personNameExtendedQueryTags) AS AllEntries; + IF @maxTagLevel > 1 + BEGIN + SELECT 1 + FROM dbo.Study WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + IF @maxTagLevel > 0 + BEGIN + SELECT 1 + FROM dbo.Series WITH (UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + AND SeriesKey = @seriesKey; + END + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, @seriesKey, @instanceKey, @watermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.ISleepIfBusy +AS +BEGIN + DECLARE @throttleCount AS INT; + DECLARE @activeRequestCount AS INT; + DECLARE @sleepersCount AS INT; + DECLARE @throttleActiveRequestCount AS INT; + IF (@@TRANCOUNT > 0) + THROW 50400, 'Cannot sleep in transaction', 1; + WHILE (1 = 1) + BEGIN + SELECT @throttleCount = ISNULL(SUM(CASE WHEN r.wait_type IN ('IO_QUEUE_LIMIT', 'LOG_RATE_GOVERNOR', 'SE_REPL_CATCHUP_THROTTLE', 'SE_REPL_SLOW_SECONDARY_THROTTLE', 'HADR_SYNC_COMMIT') THEN 1 ELSE 0 END), 0), + @sleepersCount = ISNULL(SUM(CASE WHEN r.wait_type IN ('WAITFOR') THEN 1 ELSE 0 END), 0), + @activeRequestCount = COUNT(*) + FROM sys.dm_exec_requests AS r WITH (NOLOCK) + INNER JOIN + sys.dm_exec_sessions AS s WITH (NOLOCK) + ON s.session_id = r.session_id + WHERE r.session_id <> @@spid + AND s.is_user_process = 1; + SET @activeRequestCount = @activeRequestCount - @sleepersCount; + IF (@throttleCount > 0) + BEGIN + RAISERROR ('Throttling due to write waits', 10, 0) + WITH NOWAIT; + WAITFOR DELAY '00:00:02'; + END + ELSE + IF (@activeRequestCount >= 0) + BEGIN + IF (@throttleActiveRequestCount IS NULL) + BEGIN TRY + IF (OBJECT_ID('sys.dm_os_sys_info') IS NOT NULL) + BEGIN + SELECT @throttleActiveRequestCount = cpu_count * 3 + FROM sys.dm_os_sys_info; + IF (@throttleActiveRequestCount < 10) + BEGIN + SET @throttleActiveRequestCount = 10; + END + ELSE + IF (@throttleActiveRequestCount > 100) + BEGIN + SET @throttleActiveRequestCount = 100; + END + END + END TRY + BEGIN CATCH + END CATCH + IF (@throttleActiveRequestCount IS NULL) + BEGIN + SET @throttleActiveRequestCount = 20; + END + IF (@activeRequestCount > @throttleActiveRequestCount) + BEGIN + RAISERROR ('Throttling due to active requests being >= %d. Number of active requests = %d', 10, 0, @throttleActiveRequestCount, @activeRequestCount) + WITH NOWAIT; + WAITFOR DELAY '00:00:01'; + END + ELSE + BEGIN + BREAK; + END + END + ELSE + BEGIN + BREAK; + END + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.RetrieveDeletedInstance +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM dbo.DeletedInstance WITH (UPDLOCK, READPAST) + WHERE RetryCount <= @maxRetries + AND CleanupAfter < SYSUTCDATETIME(); +END + +GO +CREATE OR ALTER PROCEDURE dbo.RetrieveDeletedInstanceV42 +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) p.PartitionName, + d.PartitionKey, + d.StudyInstanceUid, + d.SeriesInstanceUid, + d.SopInstanceUid, + d.Watermark, + d.OriginalWatermark, + d.FilePath, + d.ETag + FROM dbo.DeletedInstance AS d WITH (UPDLOCK, READPAST) + INNER JOIN + dbo.Partition AS p + ON p.PartitionKey = d.PartitionKey + WHERE RetryCount <= @maxRetries + AND CleanupAfter < SYSUTCDATETIME(); +END + +GO +CREATE OR ALTER PROCEDURE dbo.RetrieveDeletedInstanceV6 +@count INT, @maxRetries INT +AS +BEGIN + SET NOCOUNT ON; + SELECT TOP (@count) PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + OriginalWatermark + FROM dbo.DeletedInstance WITH (UPDLOCK, READPAST) + WHERE RetryCount <= @maxRetries + AND CleanupAfter < SYSUTCDATETIME(); +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateExtendedQueryTagQueryStatus +@tagPath VARCHAR (64), @queryStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + UPDATE XQT + SET QueryStatus = @queryStatus + OUTPUT INSERTED.TagKey, INSERTED.TagPath, INSERTED.TagVR, INSERTED.TagPrivateCreator, INSERTED.TagLevel, INSERTED.TagStatus, INSERTED.QueryStatus, INSERTED.ErrorCount, XQTO.OperationId + FROM dbo.ExtendedQueryTag AS XQT + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO + ON XQT.TagKey = XQTO.TagKey + WHERE TagPath = @tagPath; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateFrameMetadata +@partitionKey INT, @hasFrameMetadata BIT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET HasFrameMetadata = @hasFrameMetadata + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateIndexWorkitemInstanceCore +@workitemKey BIGINT, @partitionKey INT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @newWatermark AS BIGINT; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + IF EXISTS (SELECT 1 + FROM @stringExtendedQueryTags) + BEGIN + UPDATE ets + SET TagValue = input.TagValue, + Watermark = @newWatermark + FROM dbo.ExtendedQueryTagString AS ets + INNER JOIN + @stringExtendedQueryTags AS input + ON ets.TagKey = input.TagKey + WHERE SopInstanceKey1 = @workitemKey + AND ResourceType = @workitemResourceType + AND PartitionKey = @partitionKey + AND ets.TagValue <> input.TagValue; + END + IF EXISTS (SELECT 1 + FROM @dateTimeExtendedQueryTags) + BEGIN + UPDATE etdt + SET TagValue = input.TagValue, + Watermark = @newWatermark + FROM dbo.ExtendedQueryTagDateTime AS etdt + INNER JOIN + @dateTimeExtendedQueryTags AS input + ON etdt.TagKey = input.TagKey + WHERE SopInstanceKey1 = @workitemKey + AND ResourceType = @workitemResourceType + AND PartitionKey = @partitionKey + AND etdt.TagValue <> input.TagValue; + END + IF EXISTS (SELECT 1 + FROM @personNameExtendedQueryTags) + BEGIN + UPDATE etpn + SET TagValue = input.TagValue, + Watermark = @newWatermark + FROM dbo.ExtendedQueryTagPersonName AS etpn + INNER JOIN + @personNameExtendedQueryTags AS input + ON etpn.TagKey = input.TagKey + WHERE SopInstanceKey1 = @workitemKey + AND ResourceType = @workitemResourceType + AND PartitionKey = @partitionKey + AND etpn.TagValue <> input.TagValue; + END +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatus +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT +AS +SET NOCOUNT ON; +SET XACT_ABORT ON; +BEGIN TRANSACTION; +DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); +UPDATE dbo.Instance +SET Status = @status, + LastStatusUpdatedDate = @currentDate +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; +IF @@ROWCOUNT = 0 + BEGIN + THROW 50404, 'Instance does not exist', 1; + END +INSERT INTO dbo.ChangeFeed (Timestamp, Action, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) +VALUES (@currentDate, 0, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark); +UPDATE dbo.ChangeFeed +SET CurrentWatermark = @watermark +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; +COMMIT TRANSACTION; + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatusV37 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT, @maxTagKey INT=NULL, @hasFrameMetadata BIT=0, @path VARCHAR (4000)=NULL, @eTag VARCHAR (4000)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + IF @maxTagKey < (SELECT ISNULL(MAX(TagKey), 0) + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK)) + THROW 50409, 'Max extended query tag key does not match', 10; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @instanceKey AS BIGINT; + UPDATE dbo.Instance + SET Status = @status, + LastStatusUpdatedDate = @CurrentDate, + HasFrameMetadata = @hasFrameMetadata, + @instanceKey = InstanceKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + IF (@path IS NOT NULL + AND @eTag IS NOT NULL + AND @watermark IS NOT NULL) + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + VALUES (@instanceKey, @watermark, @path, @eTag); + INSERT INTO dbo.ChangeFeed (Timestamp, Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark, FilePath) + VALUES (@currentDate, 0, @partitionKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark, @path); + UPDATE dbo.ChangeFeed + SET CurrentWatermark = @watermark + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateInstanceStatusV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT, @status TINYINT, @maxTagKey INT=NULL, @hasFrameMetadata BIT=0 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + IF @maxTagKey < (SELECT ISNULL(MAX(TagKey), 0) + FROM dbo.ExtendedQueryTag WITH (HOLDLOCK)) + THROW 50409, 'Max extended query tag key does not match', 10; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + UPDATE dbo.Instance + SET Status = @status, + LastStatusUpdatedDate = @currentDate, + HasFrameMetadata = @hasFrameMetadata + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance does not exist', 1; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + VALUES (0, @partitionKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @watermark); + UPDATE dbo.ChangeFeed + SET CurrentWatermark = @watermark + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemProcedureStepState +@workitemKey BIGINT, @procedureStepStateTagPath VARCHAR (64), @procedureStepState VARCHAR (64), @watermark BIGINT, @proposedWatermark BIGINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @newWatermark AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @currentProcedureStepStateTagValue AS VARCHAR (64); + UPDATE dbo.Workitem + SET Watermark = @proposedWatermark + WHERE WorkitemKey = @workitemKey + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem update failed.', 1; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + WITH TagKeyCTE + AS (SELECT wqt.TagKey, + wqt.TagPath, + eqts.TagValue AS OldTagValue, + eqts.ResourceType, + wi.PartitionKey, + wi.WorkitemKey, + eqts.Watermark AS ExtendedQueryTagWatermark + FROM dbo.WorkitemQueryTag AS wqt + INNER JOIN + dbo.ExtendedQueryTagString AS eqts + ON eqts.TagKey = wqt.TagKey + AND eqts.ResourceType = 1 + INNER JOIN + dbo.Workitem AS wi + ON wi.PartitionKey = eqts.PartitionKey + AND wi.WorkitemKey = eqts.SopInstanceKey1 + WHERE wi.WorkitemKey = @workitemKey) + UPDATE targetTbl + SET targetTbl.TagValue = @procedureStepState, + targetTbl.Watermark = @newWatermark + FROM dbo.ExtendedQueryTagString AS targetTbl + INNER JOIN + TagKeyCTE AS cte + ON targetTbl.ResourceType = cte.ResourceType + AND cte.PartitionKey = targetTbl.PartitionKey + AND cte.WorkitemKey = targetTbl.SopInstanceKey1 + AND cte.TagKey = targetTbl.TagKey + AND cte.OldTagValue = targetTbl.TagValue + AND cte.ExtendedQueryTagWatermark = targetTbl.Watermark + WHERE cte.TagPath = @procedureStepStateTagPath; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem procedure step state update failed.', 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemProcedureStepStateV21 +@workitemKey BIGINT, @procedureStepStateTagPath VARCHAR (64), @procedureStepState VARCHAR (64), @watermark BIGINT, @proposedWatermark BIGINT, @transactionUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @newWatermark AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @currentProcedureStepStateTagValue AS VARCHAR (64); + UPDATE dbo.Workitem + SET Watermark = @proposedWatermark, + TransactionUid = @transactionUid + WHERE WorkitemKey = @workitemKey + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem update failed.', 1; + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence; + WITH TagKeyCTE + AS (SELECT wqt.TagKey, + wqt.TagPath, + eqts.TagValue AS OldTagValue, + eqts.ResourceType, + wi.PartitionKey, + wi.WorkitemKey, + eqts.Watermark AS ExtendedQueryTagWatermark + FROM dbo.WorkitemQueryTag AS wqt + INNER JOIN + dbo.ExtendedQueryTagString AS eqts + ON eqts.TagKey = wqt.TagKey + AND eqts.ResourceType = 1 + INNER JOIN + dbo.Workitem AS wi + ON wi.PartitionKey = eqts.PartitionKey + AND wi.WorkitemKey = eqts.SopInstanceKey1 + WHERE wi.WorkitemKey = @workitemKey) + UPDATE targetTbl + SET targetTbl.TagValue = @procedureStepState, + targetTbl.Watermark = @newWatermark + FROM dbo.ExtendedQueryTagString AS targetTbl + INNER JOIN + TagKeyCTE AS cte + ON targetTbl.ResourceType = cte.ResourceType + AND cte.PartitionKey = targetTbl.PartitionKey + AND cte.WorkitemKey = targetTbl.SopInstanceKey1 + AND cte.TagKey = targetTbl.TagKey + AND cte.OldTagValue = targetTbl.TagValue + AND cte.ExtendedQueryTagWatermark = targetTbl.Watermark + WHERE cte.TagPath = @procedureStepStateTagPath; + IF @@ROWCOUNT = 0 + THROW 50409, 'Workitem procedure step state update failed.', 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemStatus +@partitionKey INT, @workitemKey BIGINT, @status TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + UPDATE dbo.Workitem + SET Status = @status, + LastStatusUpdatedDate = @currentDate + WHERE PartitionKey = @partitionKey + AND WorkitemKey = @workitemKey; + IF @@ROWCOUNT = 0 + THROW 50404, 'Workitem instance does not exist', 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.UpdateWorkitemTransaction +@workitemKey BIGINT, @partitionKey INT, @watermark BIGINT, @proposedWatermark BIGINT, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @newWatermark AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + UPDATE dbo.Workitem + SET Watermark = @proposedWatermark + WHERE WorkitemKey = @workitemKey + AND Watermark = @watermark; + IF @@ROWCOUNT = 0 + THROW 50499, 'Workitem update failed', 1; + BEGIN TRY + EXECUTE dbo.UpdateIndexWorkitemInstanceCore @workitemKey, @partitionKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; +END + +GO +IF NOT EXISTS (SELECT * + FROM sys.views + WHERE Name = 'SeriesResultView') + BEGIN + EXECUTE ('CREATE VIEW dbo.SeriesResultView + WITH SCHEMABINDING + AS + SELECT se.SeriesInstanceUid, + se.Modality, + se.PerformedProcedureStepStartDate, + se.ManufacturerModelName, + (SELECT SUM(1) + FROM dbo.Instance i + WHERE se.PartitionKey = i.PartitionKey + AND se.StudyKey = i.StudyKey + AND se.SeriesKey = i.SeriesKey) AS NumberofSeriesRelatedInstances, + se.PartitionKey, + se.StudyKey, + se.SeriesKey + FROM dbo.Series se'); + END + +GO +IF NOT EXISTS (SELECT * + FROM sys.views + WHERE Name = 'StudyResultView') + BEGIN + EXECUTE ('CREATE VIEW dbo.StudyResultView + WITH SCHEMABINDING + AS + SELECT st.StudyInstanceUid, + st.PatientId, + st.PatientName, + st.ReferringPhysicianName, + st.StudyDate, + st.StudyDescription, + st.AccessionNumber, + st.PatientBirthDate, + (SELECT STRING_AGG(CONVERT(NVARCHAR(max), Modality), '','') + FROM dbo.Series se + WHERE st.StudyKey = se.StudyKey + AND st.PartitionKey = se.PartitionKey) AS ModalitiesInStudy, + (SELECT SUM(1) + FROM dbo.Instance i + WHERE st.PartitionKey = i.PartitionKey + AND st.StudyKey = i.StudyKey) AS NumberofStudyRelatedInstances, + st.PartitionKey, + st.StudyKey + FROM dbo.Study st'); + END + +GO diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V49.Generated.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V49.Generated.cs new file mode 100644 index 0000000000..012bc2b525 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V49.Generated.cs @@ -0,0 +1,2559 @@ +//------------------------------------------------------------------------------ +// +// 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 V49 + { + internal readonly static ChangeFeedTable ChangeFeed = new ChangeFeedTable(); + internal readonly static DeletedInstanceTable DeletedInstance = new DeletedInstanceTable(); + internal readonly static ExtendedQueryTagTable ExtendedQueryTag = new ExtendedQueryTagTable(); + internal readonly static ExtendedQueryTagDateTimeTable ExtendedQueryTagDateTime = new ExtendedQueryTagDateTimeTable(); + internal readonly static ExtendedQueryTagDoubleTable ExtendedQueryTagDouble = new ExtendedQueryTagDoubleTable(); + internal readonly static ExtendedQueryTagErrorTable ExtendedQueryTagError = new ExtendedQueryTagErrorTable(); + internal readonly static ExtendedQueryTagLongTable ExtendedQueryTagLong = new ExtendedQueryTagLongTable(); + internal readonly static ExtendedQueryTagOperationTable ExtendedQueryTagOperation = new ExtendedQueryTagOperationTable(); + internal readonly static ExtendedQueryTagPersonNameTable ExtendedQueryTagPersonName = new ExtendedQueryTagPersonNameTable(); + internal readonly static ExtendedQueryTagStringTable ExtendedQueryTagString = new ExtendedQueryTagStringTable(); + internal readonly static FilePropertyTable FileProperty = new FilePropertyTable(); + internal readonly static InstanceTable Instance = new InstanceTable(); + internal readonly static PartitionTable Partition = new PartitionTable(); + internal readonly static SeriesTable Series = new SeriesTable(); + internal readonly static StudyTable Study = new StudyTable(); + internal readonly static WorkitemTable Workitem = new WorkitemTable(); + internal readonly static WorkitemQueryTagTable WorkitemQueryTag = new WorkitemQueryTagTable(); + internal readonly static AddExtendedQueryTagErrorProcedure AddExtendedQueryTagError = new AddExtendedQueryTagErrorProcedure(); + internal readonly static AddExtendedQueryTagsProcedure AddExtendedQueryTags = new AddExtendedQueryTagsProcedure(); + internal readonly static AddInstanceV6Procedure AddInstanceV6 = new AddInstanceV6Procedure(); + internal readonly static AddPartitionProcedure AddPartition = new AddPartitionProcedure(); + internal readonly static AddWorkitemProcedure AddWorkitem = new AddWorkitemProcedure(); + internal readonly static AddWorkitemV11Procedure AddWorkitemV11 = new AddWorkitemV11Procedure(); + internal readonly static AssignReindexingOperationProcedure AssignReindexingOperation = new AssignReindexingOperationProcedure(); + internal readonly static BeginUpdateInstanceProcedure BeginUpdateInstance = new BeginUpdateInstanceProcedure(); + internal readonly static BeginUpdateInstanceV33Procedure BeginUpdateInstanceV33 = new BeginUpdateInstanceV33Procedure(); + internal readonly static BeginUpdateInstanceV46Procedure BeginUpdateInstanceV46 = new BeginUpdateInstanceV46Procedure(); + internal readonly static CompleteReindexingProcedure CompleteReindexing = new CompleteReindexingProcedure(); + internal readonly static DeleteDeletedInstanceProcedure DeleteDeletedInstance = new DeleteDeletedInstanceProcedure(); + internal readonly static DeleteDeletedInstanceV6Procedure DeleteDeletedInstanceV6 = new DeleteDeletedInstanceV6Procedure(); + internal readonly static DeleteExtendedQueryTagProcedure DeleteExtendedQueryTag = new DeleteExtendedQueryTagProcedure(); + internal readonly static DeleteExtendedQueryTagV16Procedure DeleteExtendedQueryTagV16 = new DeleteExtendedQueryTagV16Procedure(); + internal readonly static DeleteExtendedQueryTagV8Procedure DeleteExtendedQueryTagV8 = new DeleteExtendedQueryTagV8Procedure(); + internal readonly static DeleteInstanceV6Procedure DeleteInstanceV6 = new DeleteInstanceV6Procedure(); + internal readonly static DeleteWorkitemProcedure DeleteWorkitem = new DeleteWorkitemProcedure(); + internal readonly static EndUpdateInstanceProcedure EndUpdateInstance = new EndUpdateInstanceProcedure(); + internal readonly static EndUpdateInstanceV44Procedure EndUpdateInstanceV44 = new EndUpdateInstanceV44Procedure(); + internal readonly static GetChangeFeedProcedure GetChangeFeed = new GetChangeFeedProcedure(); + internal readonly static GetChangeFeedByTimeProcedure GetChangeFeedByTime = new GetChangeFeedByTimeProcedure(); + internal readonly static GetChangeFeedByTimeV39Procedure GetChangeFeedByTimeV39 = new GetChangeFeedByTimeV39Procedure(); + internal readonly static GetChangeFeedLatestProcedure GetChangeFeedLatest = new GetChangeFeedLatestProcedure(); + internal readonly static GetChangeFeedLatestByTimeProcedure GetChangeFeedLatestByTime = new GetChangeFeedLatestByTimeProcedure(); + internal readonly static GetChangeFeedLatestByTimeV39Procedure GetChangeFeedLatestByTimeV39 = new GetChangeFeedLatestByTimeV39Procedure(); + internal readonly static GetChangeFeedLatestV39Procedure GetChangeFeedLatestV39 = new GetChangeFeedLatestV39Procedure(); + internal readonly static GetChangeFeedLatestV6Procedure GetChangeFeedLatestV6 = new GetChangeFeedLatestV6Procedure(); + internal readonly static GetChangeFeedV39Procedure GetChangeFeedV39 = new GetChangeFeedV39Procedure(); + internal readonly static GetChangeFeedV6Procedure GetChangeFeedV6 = new GetChangeFeedV6Procedure(); + internal readonly static GetCurrentAndNextWorkitemWatermarkProcedure GetCurrentAndNextWorkitemWatermark = new GetCurrentAndNextWorkitemWatermarkProcedure(); + internal readonly static GetExtendedQueryTagProcedure GetExtendedQueryTag = new GetExtendedQueryTagProcedure(); + internal readonly static GetExtendedQueryTagErrorsProcedure GetExtendedQueryTagErrors = new GetExtendedQueryTagErrorsProcedure(); + internal readonly static GetExtendedQueryTagErrorsV36Procedure GetExtendedQueryTagErrorsV36 = new GetExtendedQueryTagErrorsV36Procedure(); + internal readonly static GetExtendedQueryTagErrorsV6Procedure GetExtendedQueryTagErrorsV6 = new GetExtendedQueryTagErrorsV6Procedure(); + internal readonly static GetExtendedQueryTagsProcedure GetExtendedQueryTags = new GetExtendedQueryTagsProcedure(); + internal readonly static GetExtendedQueryTagsByKeyProcedure GetExtendedQueryTagsByKey = new GetExtendedQueryTagsByKeyProcedure(); + internal readonly static GetExtendedQueryTagsByOperationProcedure GetExtendedQueryTagsByOperation = new GetExtendedQueryTagsByOperationProcedure(); + internal readonly static GetExtendedQueryTagsV36Procedure GetExtendedQueryTagsV36 = new GetExtendedQueryTagsV36Procedure(); + internal readonly static GetInstanceProcedure GetInstance = new GetInstanceProcedure(); + internal readonly static GetInstanceBatchesProcedure GetInstanceBatches = new GetInstanceBatchesProcedure(); + internal readonly static GetInstanceBatchesByTimeStampProcedure GetInstanceBatchesByTimeStamp = new GetInstanceBatchesByTimeStampProcedure(); + internal readonly static GetInstanceV6Procedure GetInstanceV6 = new GetInstanceV6Procedure(); + internal readonly static GetInstanceWithPropertiesProcedure GetInstanceWithProperties = new GetInstanceWithPropertiesProcedure(); + internal readonly static GetInstanceWithPropertiesV32Procedure GetInstanceWithPropertiesV32 = new GetInstanceWithPropertiesV32Procedure(); + internal readonly static GetInstanceWithPropertiesV46Procedure GetInstanceWithPropertiesV46 = new GetInstanceWithPropertiesV46Procedure(); + internal readonly static GetInstancesByWatermarkRangeProcedure GetInstancesByWatermarkRange = new GetInstancesByWatermarkRangeProcedure(); + internal readonly static GetInstancesByWatermarkRangeV6Procedure GetInstancesByWatermarkRangeV6 = new GetInstancesByWatermarkRangeV6Procedure(); + internal readonly static GetPartitionProcedure GetPartition = new GetPartitionProcedure(); + internal readonly static GetPartitionsProcedure GetPartitions = new GetPartitionsProcedure(); + internal readonly static GetSeriesResultProcedure GetSeriesResult = new GetSeriesResultProcedure(); + internal readonly static GetStudyResultProcedure GetStudyResult = new GetStudyResultProcedure(); + internal readonly static GetWorkitemMetadataProcedure GetWorkitemMetadata = new GetWorkitemMetadataProcedure(); + internal readonly static GetWorkitemQueryTagsProcedure GetWorkitemQueryTags = new GetWorkitemQueryTagsProcedure(); + internal readonly static IIndexInstanceCoreV9Procedure IIndexInstanceCoreV9 = new IIndexInstanceCoreV9Procedure(); + internal readonly static IIndexWorkitemInstanceCoreProcedure IIndexWorkitemInstanceCore = new IIndexWorkitemInstanceCoreProcedure(); + internal readonly static ISleepIfBusyProcedure ISleepIfBusy = new ISleepIfBusyProcedure(); + internal readonly static IncrementDeletedInstanceRetryProcedure IncrementDeletedInstanceRetry = new IncrementDeletedInstanceRetryProcedure(); + internal readonly static IncrementDeletedInstanceRetryV6Procedure IncrementDeletedInstanceRetryV6 = new IncrementDeletedInstanceRetryV6Procedure(); + internal readonly static IndexInstanceV6Procedure IndexInstanceV6 = new IndexInstanceV6Procedure(); + internal readonly static RetrieveDeletedInstanceProcedure RetrieveDeletedInstance = new RetrieveDeletedInstanceProcedure(); + internal readonly static RetrieveDeletedInstanceV42Procedure RetrieveDeletedInstanceV42 = new RetrieveDeletedInstanceV42Procedure(); + internal readonly static RetrieveDeletedInstanceV6Procedure RetrieveDeletedInstanceV6 = new RetrieveDeletedInstanceV6Procedure(); + internal readonly static UpdateExtendedQueryTagQueryStatusProcedure UpdateExtendedQueryTagQueryStatus = new UpdateExtendedQueryTagQueryStatusProcedure(); + internal readonly static UpdateFrameMetadataProcedure UpdateFrameMetadata = new UpdateFrameMetadataProcedure(); + internal readonly static UpdateIndexWorkitemInstanceCoreProcedure UpdateIndexWorkitemInstanceCore = new UpdateIndexWorkitemInstanceCoreProcedure(); + internal readonly static UpdateInstanceStatusProcedure UpdateInstanceStatus = new UpdateInstanceStatusProcedure(); + internal readonly static UpdateInstanceStatusV37Procedure UpdateInstanceStatusV37 = new UpdateInstanceStatusV37Procedure(); + internal readonly static UpdateInstanceStatusV6Procedure UpdateInstanceStatusV6 = new UpdateInstanceStatusV6Procedure(); + internal readonly static UpdateWorkitemProcedureStepStateProcedure UpdateWorkitemProcedureStepState = new UpdateWorkitemProcedureStepStateProcedure(); + internal readonly static UpdateWorkitemProcedureStepStateV21Procedure UpdateWorkitemProcedureStepStateV21 = new UpdateWorkitemProcedureStepStateV21Procedure(); + internal readonly static UpdateWorkitemStatusProcedure UpdateWorkitemStatus = new UpdateWorkitemStatusProcedure(); + internal readonly static UpdateWorkitemTransactionProcedure UpdateWorkitemTransaction = new UpdateWorkitemTransactionProcedure(); + + internal class ChangeFeedTable : Table + { + internal ChangeFeedTable() : base("dbo.ChangeFeed") + { + } + + internal readonly BigIntColumn Sequence = new BigIntColumn("Sequence"); + internal readonly DateTimeOffsetColumn Timestamp = new DateTimeOffsetColumn("Timestamp", 7); + internal readonly TinyIntColumn Action = new TinyIntColumn("Action"); + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly VarCharColumn SopInstanceUid = new VarCharColumn("SopInstanceUid", 64); + internal readonly BigIntColumn OriginalWatermark = new BigIntColumn("OriginalWatermark"); + internal readonly NullableBigIntColumn CurrentWatermark = new NullableBigIntColumn("CurrentWatermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly NullableNVarCharColumn FilePath = new NullableNVarCharColumn("FilePath", 4000); + internal readonly Index IXC_ChangeFeed = new Index("IXC_ChangeFeed"); + internal readonly Index IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid = new Index("IX_ChangeFeed_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid"); + internal readonly Index IX_ChangeFeed_Sequence = new Index("IX_ChangeFeed_Sequence"); + } + + internal class DeletedInstanceTable : Table + { + internal DeletedInstanceTable() : base("dbo.DeletedInstance") + { + } + + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly VarCharColumn SopInstanceUid = new VarCharColumn("SopInstanceUid", 64); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly DateTimeOffsetColumn DeletedDateTime = new DateTimeOffsetColumn("DeletedDateTime", 0); + internal readonly IntColumn RetryCount = new IntColumn("RetryCount"); + internal readonly DateTimeOffsetColumn CleanupAfter = new DateTimeOffsetColumn("CleanupAfter", 0); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly NullableBigIntColumn OriginalWatermark = new NullableBigIntColumn("OriginalWatermark"); + internal readonly NullableNVarCharColumn FilePath = new NullableNVarCharColumn("FilePath", 4000); + internal readonly NullableNVarCharColumn ETag = new NullableNVarCharColumn("ETag", 4000); + internal readonly Index IXC_DeletedInstance = new Index("IXC_DeletedInstance"); + internal readonly Index IX_DeletedInstance_RetryCount_CleanupAfter = new Index("IX_DeletedInstance_RetryCount_CleanupAfter"); + } + + internal class ExtendedQueryTagTable : Table + { + internal ExtendedQueryTagTable() : base("dbo.ExtendedQueryTag") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly VarCharColumn TagPath = new VarCharColumn("TagPath", 64); + internal readonly VarCharColumn TagVR = new VarCharColumn("TagVR", 2); + internal readonly NullableNVarCharColumn TagPrivateCreator = new NullableNVarCharColumn("TagPrivateCreator", 64); + internal readonly TinyIntColumn TagLevel = new TinyIntColumn("TagLevel"); + internal readonly TinyIntColumn TagStatus = new TinyIntColumn("TagStatus"); + internal readonly TinyIntColumn QueryStatus = new TinyIntColumn("QueryStatus"); + internal readonly IntColumn ErrorCount = new IntColumn("ErrorCount"); + internal readonly Index IXC_ExtendedQueryTag = new Index("IXC_ExtendedQueryTag"); + internal readonly Index IX_ExtendedQueryTag_TagPath = new Index("IX_ExtendedQueryTag_TagPath"); + } + + internal class ExtendedQueryTagDateTimeTable : Table + { + internal ExtendedQueryTagDateTimeTable() : base("dbo.ExtendedQueryTagDateTime") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly DateTime2Column TagValue = new DateTime2Column("TagValue", 7); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly NullableDateTime2Column TagValueUtc = new NullableDateTime2Column("TagValueUtc", 7); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagDateTime = new Index("IXC_ExtendedQueryTagDateTime"); + internal readonly Index IX_ExtendedQueryTagDateTime_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDateTime_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagDateTime_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDateTime_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class ExtendedQueryTagDoubleTable : Table + { + internal ExtendedQueryTagDoubleTable() : base("dbo.ExtendedQueryTagDouble") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly FloatColumn TagValue = new FloatColumn("TagValue", 53); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagDouble = new Index("IXC_ExtendedQueryTagDouble"); + internal readonly Index IX_ExtendedQueryTagDouble_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDouble_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagDouble_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagDouble_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class ExtendedQueryTagErrorTable : Table + { + internal ExtendedQueryTagErrorTable() : base("dbo.ExtendedQueryTagError") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly SmallIntColumn ErrorCode = new SmallIntColumn("ErrorCode"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly DateTime2Column CreatedTime = new DateTime2Column("CreatedTime", 7); + internal readonly Index IXC_ExtendedQueryTagError = new Index("IXC_ExtendedQueryTagError"); + internal readonly Index IX_ExtendedQueryTagError_CreatedTime_Watermark_TagKey = new Index("IX_ExtendedQueryTagError_CreatedTime_Watermark_TagKey"); + internal readonly Index IX_ExtendedQueryTagError_Watermark = new Index("IX_ExtendedQueryTagError_Watermark"); + } + + internal class ExtendedQueryTagLongTable : Table + { + internal ExtendedQueryTagLongTable() : base("dbo.ExtendedQueryTagLong") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly BigIntColumn TagValue = new BigIntColumn("TagValue"); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagLong = new Index("IXC_ExtendedQueryTagLong"); + internal readonly Index IX_ExtendedQueryTagLong_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagLong_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagLong_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagLong_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class ExtendedQueryTagOperationTable : Table + { + internal ExtendedQueryTagOperationTable() : base("dbo.ExtendedQueryTagOperation") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly UniqueIdentifierColumn OperationId = new UniqueIdentifierColumn("OperationId"); + internal readonly Index IXC_ExtendedQueryTagOperation = new Index("IXC_ExtendedQueryTagOperation"); + internal readonly Index IX_ExtendedQueryTagOperation_OperationId = new Index("IX_ExtendedQueryTagOperation_OperationId"); + } + + internal class ExtendedQueryTagPersonNameTable : Table + { + internal ExtendedQueryTagPersonNameTable() : base("dbo.ExtendedQueryTagPersonName") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly NVarCharColumn TagValue = new NVarCharColumn("TagValue", 200, "SQL_Latin1_General_CP1_CI_AI"); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal const string WatermarkAndTagKey = "WatermarkAndTagKey"; + internal const string TagValueWords = "TagValueWords"; + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagPersonName = new Index("IXC_ExtendedQueryTagPersonName"); + internal readonly Index IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagPersonName_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagPersonName_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagPersonName_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey = new Index("IXC_ExtendedQueryTagPersonName_WatermarkAndTagKey"); + } + + internal class ExtendedQueryTagStringTable : Table + { + internal ExtendedQueryTagStringTable() : base("dbo.ExtendedQueryTagString") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly NVarCharColumn TagValue = new NVarCharColumn("TagValue", 64); + internal readonly BigIntColumn SopInstanceKey1 = new BigIntColumn("SopInstanceKey1"); + internal readonly NullableBigIntColumn SopInstanceKey2 = new NullableBigIntColumn("SopInstanceKey2"); + internal readonly NullableBigIntColumn SopInstanceKey3 = new NullableBigIntColumn("SopInstanceKey3"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly TinyIntColumn ResourceType = new TinyIntColumn("ResourceType"); + internal readonly Index IXC_ExtendedQueryTagString = new Index("IXC_ExtendedQueryTagString"); + internal readonly Index IX_ExtendedQueryTagString_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagString_PartitionKey_TagKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + internal readonly Index IX_ExtendedQueryTagString_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3 = new Index("IX_ExtendedQueryTagString_PartitionKey_ResourceType_SopInstanceKey1_SopInstanceKey2_SopInstanceKey3"); + } + + internal class FilePropertyTable : Table + { + internal FilePropertyTable() : base("dbo.FileProperty") + { + } + + internal readonly BigIntColumn InstanceKey = new BigIntColumn("InstanceKey"); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly NVarCharColumn FilePath = new NVarCharColumn("FilePath", 4000); + internal readonly NVarCharColumn ETag = new NVarCharColumn("ETag", 4000); + internal readonly Index IXC_FileProperty = new Index("IXC_FileProperty"); + } + + internal class InstanceTable : Table + { + internal InstanceTable() : base("dbo.Instance") + { + } + + internal readonly BigIntColumn InstanceKey = new BigIntColumn("InstanceKey"); + internal readonly BigIntColumn SeriesKey = new BigIntColumn("SeriesKey"); + internal readonly BigIntColumn StudyKey = new BigIntColumn("StudyKey"); + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly VarCharColumn SopInstanceUid = new VarCharColumn("SopInstanceUid", 64); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly TinyIntColumn Status = new TinyIntColumn("Status"); + internal readonly DateTime2Column LastStatusUpdatedDate = new DateTime2Column("LastStatusUpdatedDate", 7); + internal readonly DateTime2Column CreatedDate = new DateTime2Column("CreatedDate", 7); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly NullableVarCharColumn TransferSyntaxUid = new NullableVarCharColumn("TransferSyntaxUid", 64); + internal readonly BitColumn HasFrameMetadata = new BitColumn("HasFrameMetadata"); + internal readonly NullableBigIntColumn OriginalWatermark = new NullableBigIntColumn("OriginalWatermark"); + internal readonly NullableBigIntColumn NewWatermark = new NullableBigIntColumn("NewWatermark"); + internal readonly Index IXC_Instance = new Index("IXC_Instance"); + internal readonly Index IX_Instance_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid = new Index("IX_Instance_PartitionKey_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid = new Index("IX_Instance_PartitionKey_Status_StudyInstanceUid_SeriesInstanceUid_SopInstanceUid"); + internal readonly Index IX_Instance_Watermark_Status = new Index("IX_Instance_Watermark_Status"); + internal readonly Index IX_Instance_PartitionKey_SopInstanceUid = new Index("IX_Instance_PartitionKey_SopInstanceUid"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyKey_Watermark = new Index("IX_Instance_PartitionKey_Status_StudyKey_Watermark"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyKey_SeriesKey_Watermark = new Index("IX_Instance_PartitionKey_Status_StudyKey_SeriesKey_Watermark"); + internal readonly Index IX_Instance_PartitionKey_Watermark = new Index("IX_Instance_PartitionKey_Watermark"); + internal readonly Index IX_Instance_PartitionKey_Status_StudyInstanceUid_NewWatermark = new Index("IX_Instance_PartitionKey_Status_StudyInstanceUid_NewWatermark"); + internal readonly Index IX_Instance_Watermark_Status_CreatedDate = new Index("IX_Instance_Watermark_Status_CreatedDate"); + } + + internal class PartitionTable : Table + { + internal PartitionTable() : base("dbo.Partition") + { + } + + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly VarCharColumn PartitionName = new VarCharColumn("PartitionName", 64); + internal readonly DateTime2Column CreatedDate = new DateTime2Column("CreatedDate", 7); + internal readonly Index IXC_Partition = new Index("IXC_Partition"); + internal readonly Index IX_Partition_PartitionName = new Index("IX_Partition_PartitionName"); + } + + internal class SeriesTable : Table + { + internal SeriesTable() : base("dbo.Series") + { + } + + internal readonly BigIntColumn SeriesKey = new BigIntColumn("SeriesKey"); + internal readonly BigIntColumn StudyKey = new BigIntColumn("StudyKey"); + internal readonly VarCharColumn SeriesInstanceUid = new VarCharColumn("SeriesInstanceUid", 64); + internal readonly NullableNVarCharColumn Modality = new NullableNVarCharColumn("Modality", 16); + internal readonly NullableDateColumn PerformedProcedureStepStartDate = new NullableDateColumn("PerformedProcedureStepStartDate"); + internal readonly NullableNVarCharColumn ManufacturerModelName = new NullableNVarCharColumn("ManufacturerModelName", 64); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_Series = new Index("IXC_Series"); + internal readonly Index IX_Series_PartitionKey_StudyKey_SeriesInstanceUid = new Index("IX_Series_PartitionKey_StudyKey_SeriesInstanceUid"); + internal readonly Index IX_Series_PartitionKey_SeriesInstanceUid = new Index("IX_Series_PartitionKey_SeriesInstanceUid"); + internal readonly Index IX_Series_PartitionKey_Modality = new Index("IX_Series_PartitionKey_Modality"); + internal readonly Index IX_Series_PartitionKey_PerformedProcedureStepStartDate = new Index("IX_Series_PartitionKey_PerformedProcedureStepStartDate"); + internal readonly Index IX_Series_PartitionKey_ManufacturerModelName = new Index("IX_Series_PartitionKey_ManufacturerModelName"); + } + + internal class StudyTable : Table + { + internal StudyTable() : base("dbo.Study") + { + } + + internal readonly BigIntColumn StudyKey = new BigIntColumn("StudyKey"); + internal readonly VarCharColumn StudyInstanceUid = new VarCharColumn("StudyInstanceUid", 64); + internal readonly NVarCharColumn PatientId = new NVarCharColumn("PatientId", 64); + internal readonly NullableNVarCharColumn PatientName = new NullableNVarCharColumn("PatientName", 200, "SQL_Latin1_General_CP1_CI_AI"); + internal readonly NullableNVarCharColumn ReferringPhysicianName = new NullableNVarCharColumn("ReferringPhysicianName", 200, "SQL_Latin1_General_CP1_CI_AI"); + internal readonly NullableDateColumn StudyDate = new NullableDateColumn("StudyDate"); + internal readonly NullableNVarCharColumn StudyDescription = new NullableNVarCharColumn("StudyDescription", 64); + internal readonly NullableNVarCharColumn AccessionNumber = new NullableNVarCharColumn("AccessionNumber", 16); + internal const string PatientNameWords = "PatientNameWords"; + internal const string ReferringPhysicianNameWords = "ReferringPhysicianNameWords"; + internal readonly NullableDateColumn PatientBirthDate = new NullableDateColumn("PatientBirthDate"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly Index IXC_Study = new Index("IXC_Study"); + internal readonly Index IX_Study_StudyKey = new Index("IX_Study_StudyKey"); + internal readonly Index IX_Study_PartitionKey_StudyInstanceUid = new Index("IX_Study_PartitionKey_StudyInstanceUid"); + internal readonly Index IX_Study_PartitionKey_PatientId = new Index("IX_Study_PartitionKey_PatientId"); + internal readonly Index IX_Study_PartitionKey_PatientName = new Index("IX_Study_PartitionKey_PatientName"); + internal readonly Index IX_Study_PartitionKey_ReferringPhysicianName = new Index("IX_Study_PartitionKey_ReferringPhysicianName"); + internal readonly Index IX_Study_PartitionKey_StudyDate = new Index("IX_Study_PartitionKey_StudyDate"); + internal readonly Index IX_Study_PartitionKey_StudyDescription = new Index("IX_Study_PartitionKey_StudyDescription"); + internal readonly Index IX_Study_PartitionKey_AccessionNumber = new Index("IX_Study_PartitionKey_AccessionNumber"); + internal readonly Index IX_Study_PartitionKey_PatientBirthDate = new Index("IX_Study_PartitionKey_PatientBirthDate"); + } + + internal class WorkitemTable : Table + { + internal WorkitemTable() : base("dbo.Workitem") + { + } + + internal readonly BigIntColumn WorkitemKey = new BigIntColumn("WorkitemKey"); + internal readonly IntColumn PartitionKey = new IntColumn("PartitionKey"); + internal readonly VarCharColumn WorkitemUid = new VarCharColumn("WorkitemUid", 64); + internal readonly NullableVarCharColumn TransactionUid = new NullableVarCharColumn("TransactionUid", 64); + internal readonly TinyIntColumn Status = new TinyIntColumn("Status"); + internal readonly DateTime2Column CreatedDate = new DateTime2Column("CreatedDate", 7); + internal readonly DateTime2Column LastStatusUpdatedDate = new DateTime2Column("LastStatusUpdatedDate", 7); + internal readonly BigIntColumn Watermark = new BigIntColumn("Watermark"); + internal readonly Index IXC_Workitem = new Index("IXC_Workitem"); + internal readonly Index IX_Workitem_PartitionKey_WorkitemUid = new Index("IX_Workitem_PartitionKey_WorkitemUid"); + internal readonly Index IX_Workitem_WorkitemKey_Watermark = new Index("IX_Workitem_WorkitemKey_Watermark"); + } + + internal class WorkitemQueryTagTable : Table + { + internal WorkitemQueryTagTable() : base("dbo.WorkitemQueryTag") + { + } + + internal readonly IntColumn TagKey = new IntColumn("TagKey"); + internal readonly VarCharColumn TagPath = new VarCharColumn("TagPath", 64); + internal readonly VarCharColumn TagVR = new VarCharColumn("TagVR", 2); + internal readonly Index IXC_WorkitemQueryTag = new Index("IXC_WorkitemQueryTag"); + internal readonly Index IXC_WorkitemQueryTag_TagPath = new Index("IXC_WorkitemQueryTag_TagPath"); + } + + internal class AddExtendedQueryTagErrorProcedure : StoredProcedure + { + internal AddExtendedQueryTagErrorProcedure() : base("dbo.AddExtendedQueryTagError") + { + } + + private readonly ParameterDefinition _tagKey = new ParameterDefinition("@tagKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _errorCode = new ParameterDefinition("@errorCode", global::System.Data.SqlDbType.SmallInt, false); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 tagKey, System.Int16 errorCode, System.Int64 watermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddExtendedQueryTagError"; + _tagKey.AddParameter(command.Parameters, tagKey); + _errorCode.AddParameter(command.Parameters, errorCode); + _watermark.AddParameter(command.Parameters, watermark); + } + } + + internal class AddExtendedQueryTagsProcedure : StoredProcedure + { + internal AddExtendedQueryTagsProcedure() : base("dbo.AddExtendedQueryTags") + { + } + + private readonly AddExtendedQueryTagsInputTableTypeV1TableValuedParameterDefinition _extendedQueryTags = new AddExtendedQueryTagsInputTableTypeV1TableValuedParameterDefinition("@extendedQueryTags"); + private readonly ParameterDefinition> _maxAllowedCount = new ParameterDefinition>("@maxAllowedCount", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _ready = new ParameterDefinition>("@ready", global::System.Data.SqlDbType.Bit, true); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTags, System.Nullable maxAllowedCount, System.Nullable ready) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddExtendedQueryTags"; + _extendedQueryTags.AddParameter(command.Parameters, extendedQueryTags); + _maxAllowedCount.AddParameter(command.Parameters, maxAllowedCount); + _ready.AddParameter(command.Parameters, ready); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable maxAllowedCount, System.Nullable ready, AddExtendedQueryTagsTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, maxAllowedCount: maxAllowedCount, ready: ready, extendedQueryTags: tableValuedParameters.ExtendedQueryTags); + } + } + + internal class AddExtendedQueryTagsTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddExtendedQueryTagsTvpGenerator(ITableValuedParameterRowGenerator AddExtendedQueryTagsInputTableTypeV1RowGenerator) + { + this.AddExtendedQueryTagsInputTableTypeV1RowGenerator = AddExtendedQueryTagsInputTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator AddExtendedQueryTagsInputTableTypeV1RowGenerator; + + public AddExtendedQueryTagsTableValuedParameters Generate(TInput input) + { + return new AddExtendedQueryTagsTableValuedParameters(AddExtendedQueryTagsInputTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddExtendedQueryTagsTableValuedParameters + { + internal AddExtendedQueryTagsTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTags) + { + this.ExtendedQueryTags = ExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTags { get; } + } + + internal class AddInstanceV6Procedure : StoredProcedure + { + internal AddInstanceV6Procedure() : base("dbo.AddInstanceV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, false, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition _referringPhysicianName = new ParameterDefinition("@referringPhysicianName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _studyDate = new ParameterDefinition>("@studyDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition _studyDescription = new ParameterDefinition("@studyDescription", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _accessionNumber = new ParameterDefinition("@accessionNumber", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _modality = new ParameterDefinition("@modality", global::System.Data.SqlDbType.NVarChar, true, 16); + private readonly ParameterDefinition> _performedProcedureStepStartDate = new ParameterDefinition>("@performedProcedureStepStartDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly ParameterDefinition _manufacturerModelName = new ParameterDefinition("@manufacturerModelName", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + private readonly ParameterDefinition _initialStatus = new ParameterDefinition("@initialStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _transferSyntaxUid = new ParameterDefinition("@transferSyntaxUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.String patientId, System.String patientName, System.String referringPhysicianName, System.Nullable studyDate, System.String studyDescription, System.String accessionNumber, System.String modality, System.Nullable performedProcedureStepStartDate, System.Nullable patientBirthDate, System.String manufacturerModelName, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags, System.Byte initialStatus, System.String transferSyntaxUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddInstanceV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _referringPhysicianName.AddParameter(command.Parameters, referringPhysicianName); + _studyDate.AddParameter(command.Parameters, studyDate); + _studyDescription.AddParameter(command.Parameters, studyDescription); + _accessionNumber.AddParameter(command.Parameters, accessionNumber); + _modality.AddParameter(command.Parameters, modality); + _performedProcedureStepStartDate.AddParameter(command.Parameters, performedProcedureStepStartDate); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _manufacturerModelName.AddParameter(command.Parameters, manufacturerModelName); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + _initialStatus.AddParameter(command.Parameters, initialStatus); + _transferSyntaxUid.AddParameter(command.Parameters, transferSyntaxUid); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.String patientId, System.String patientName, System.String referringPhysicianName, System.Nullable studyDate, System.String studyDescription, System.String accessionNumber, System.String modality, System.Nullable performedProcedureStepStartDate, System.Nullable patientBirthDate, System.String manufacturerModelName, System.Byte initialStatus, System.String transferSyntaxUid, AddInstanceV6TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, seriesInstanceUid: seriesInstanceUid, sopInstanceUid: sopInstanceUid, patientId: patientId, patientName: patientName, referringPhysicianName: referringPhysicianName, studyDate: studyDate, studyDescription: studyDescription, accessionNumber: accessionNumber, modality: modality, performedProcedureStepStartDate: performedProcedureStepStartDate, patientBirthDate: patientBirthDate, manufacturerModelName: manufacturerModelName, initialStatus: initialStatus, transferSyntaxUid: transferSyntaxUid, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddInstanceV6TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddInstanceV6TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddInstanceV6TableValuedParameters Generate(TInput input) + { + return new AddInstanceV6TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddInstanceV6TableValuedParameters + { + internal AddInstanceV6TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class AddPartitionProcedure : StoredProcedure + { + internal AddPartitionProcedure() : base("dbo.AddPartition") + { + } + + private readonly ParameterDefinition _partitionName = new ParameterDefinition("@partitionName", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.String partitionName) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddPartition"; + _partitionName.AddParameter(command.Parameters, partitionName); + } + } + + internal class AddWorkitemProcedure : StoredProcedure + { + internal AddWorkitemProcedure() : base("dbo.AddWorkitem") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + private readonly ParameterDefinition _initialStatus = new ParameterDefinition("@initialStatus", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags, System.Byte initialStatus) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddWorkitem"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + _initialStatus.AddParameter(command.Parameters, initialStatus); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, System.Byte initialStatus, AddWorkitemTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, workitemUid: workitemUid, initialStatus: initialStatus, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddWorkitemTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddWorkitemTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddWorkitemTableValuedParameters Generate(TInput input) + { + return new AddWorkitemTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddWorkitemTableValuedParameters + { + internal AddWorkitemTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class AddWorkitemV11Procedure : StoredProcedure + { + internal AddWorkitemV11Procedure() : base("dbo.AddWorkitemV11") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + private readonly ParameterDefinition _initialStatus = new ParameterDefinition("@initialStatus", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags, System.Byte initialStatus) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AddWorkitemV11"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + _initialStatus.AddParameter(command.Parameters, initialStatus); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, System.Byte initialStatus, AddWorkitemV11TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, workitemUid: workitemUid, initialStatus: initialStatus, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class AddWorkitemV11TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AddWorkitemV11TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public AddWorkitemV11TableValuedParameters Generate(TInput input) + { + return new AddWorkitemV11TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AddWorkitemV11TableValuedParameters + { + internal AddWorkitemV11TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class AssignReindexingOperationProcedure : StoredProcedure + { + internal AssignReindexingOperationProcedure() : base("dbo.AssignReindexingOperation") + { + } + + private readonly ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition _extendedQueryTagKeys = new ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition("@extendedQueryTagKeys"); + private readonly ParameterDefinition _operationId = new ParameterDefinition("@operationId", global::System.Data.SqlDbType.UniqueIdentifier, false); + private readonly ParameterDefinition> _returnIfCompleted = new ParameterDefinition>("@returnIfCompleted", global::System.Data.SqlDbType.Bit, true); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTagKeys, System.Guid operationId, System.Nullable returnIfCompleted) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.AssignReindexingOperation"; + _extendedQueryTagKeys.AddParameter(command.Parameters, extendedQueryTagKeys); + _operationId.AddParameter(command.Parameters, operationId); + _returnIfCompleted.AddParameter(command.Parameters, returnIfCompleted); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Guid operationId, System.Nullable returnIfCompleted, AssignReindexingOperationTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, operationId: operationId, returnIfCompleted: returnIfCompleted, extendedQueryTagKeys: tableValuedParameters.ExtendedQueryTagKeys); + } + } + + internal class AssignReindexingOperationTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public AssignReindexingOperationTvpGenerator(ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator) + { + this.ExtendedQueryTagKeyTableTypeV1RowGenerator = ExtendedQueryTagKeyTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator; + + public AssignReindexingOperationTableValuedParameters Generate(TInput input) + { + return new AssignReindexingOperationTableValuedParameters(ExtendedQueryTagKeyTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct AssignReindexingOperationTableValuedParameters + { + internal AssignReindexingOperationTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys) + { + this.ExtendedQueryTagKeys = ExtendedQueryTagKeys; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys { get; } + } + + internal class BeginUpdateInstanceProcedure : StoredProcedure + { + internal BeginUpdateInstanceProcedure() : base("dbo.BeginUpdateInstance") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.BeginUpdateInstance"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, BeginUpdateInstanceTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class BeginUpdateInstanceTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public BeginUpdateInstanceTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public BeginUpdateInstanceTableValuedParameters Generate(TInput input) + { + return new BeginUpdateInstanceTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct BeginUpdateInstanceTableValuedParameters + { + internal BeginUpdateInstanceTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class BeginUpdateInstanceV33Procedure : StoredProcedure + { + internal BeginUpdateInstanceV33Procedure() : base("dbo.BeginUpdateInstanceV33") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.BeginUpdateInstanceV33"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + } + } + + internal class BeginUpdateInstanceV46Procedure : StoredProcedure + { + internal BeginUpdateInstanceV46Procedure() : base("dbo.BeginUpdateInstanceV46") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.BeginUpdateInstanceV46"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + } + } + + internal class CompleteReindexingProcedure : StoredProcedure + { + internal CompleteReindexingProcedure() : base("dbo.CompleteReindexing") + { + } + + private readonly ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition _extendedQueryTagKeys = new ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition("@extendedQueryTagKeys"); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTagKeys) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.CompleteReindexing"; + _extendedQueryTagKeys.AddParameter(command.Parameters, extendedQueryTagKeys); + } + + public void PopulateCommand(SqlCommandWrapper command, CompleteReindexingTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, extendedQueryTagKeys: tableValuedParameters.ExtendedQueryTagKeys); + } + } + + internal class CompleteReindexingTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public CompleteReindexingTvpGenerator(ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator) + { + this.ExtendedQueryTagKeyTableTypeV1RowGenerator = ExtendedQueryTagKeyTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator; + + public CompleteReindexingTableValuedParameters Generate(TInput input) + { + return new CompleteReindexingTableValuedParameters(ExtendedQueryTagKeyTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct CompleteReindexingTableValuedParameters + { + internal CompleteReindexingTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys) + { + this.ExtendedQueryTagKeys = ExtendedQueryTagKeys; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys { get; } + } + + internal class DeleteDeletedInstanceProcedure : StoredProcedure + { + internal DeleteDeletedInstanceProcedure() : base("dbo.DeleteDeletedInstance") + { + } + + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteDeletedInstance"; + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + } + } + + internal class DeleteDeletedInstanceV6Procedure : StoredProcedure + { + internal DeleteDeletedInstanceV6Procedure() : base("dbo.DeleteDeletedInstanceV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteDeletedInstanceV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + } + } + + internal class DeleteExtendedQueryTagProcedure : StoredProcedure + { + internal DeleteExtendedQueryTagProcedure() : base("dbo.DeleteExtendedQueryTag") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _dataType = new ParameterDefinition("@dataType", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte dataType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteExtendedQueryTag"; + _tagPath.AddParameter(command.Parameters, tagPath); + _dataType.AddParameter(command.Parameters, dataType); + } + } + + internal class DeleteExtendedQueryTagV16Procedure : StoredProcedure + { + internal DeleteExtendedQueryTagV16Procedure() : base("dbo.DeleteExtendedQueryTagV16") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _dataType = new ParameterDefinition("@dataType", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _batchSize = new ParameterDefinition>("@batchSize", global::System.Data.SqlDbType.Int, true); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte dataType, System.Nullable batchSize) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteExtendedQueryTagV16"; + _tagPath.AddParameter(command.Parameters, tagPath); + _dataType.AddParameter(command.Parameters, dataType); + _batchSize.AddParameter(command.Parameters, batchSize); + } + } + + internal class DeleteExtendedQueryTagV8Procedure : StoredProcedure + { + internal DeleteExtendedQueryTagV8Procedure() : base("dbo.DeleteExtendedQueryTagV8") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _dataType = new ParameterDefinition("@dataType", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte dataType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteExtendedQueryTagV8"; + _tagPath.AddParameter(command.Parameters, tagPath); + _dataType.AddParameter(command.Parameters, dataType); + } + } + + internal class DeleteInstanceV6Procedure : StoredProcedure + { + internal DeleteInstanceV6Procedure() : base("dbo.DeleteInstanceV6") + { + } + + private readonly ParameterDefinition _cleanupAfter = new ParameterDefinition("@cleanupAfter", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + private readonly ParameterDefinition _createdStatus = new ParameterDefinition("@createdStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.DateTimeOffset cleanupAfter, System.Byte createdStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteInstanceV6"; + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + _createdStatus.AddParameter(command.Parameters, createdStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class DeleteWorkitemProcedure : StoredProcedure + { + internal DeleteWorkitemProcedure() : base("dbo.DeleteWorkitem") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.DeleteWorkitem"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + } + } + + internal class EndUpdateInstanceProcedure : StoredProcedure + { + internal EndUpdateInstanceProcedure() : base("dbo.EndUpdateInstance") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstance"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + } + } + + internal class EndUpdateInstanceV44Procedure : StoredProcedure + { + internal EndUpdateInstanceV44Procedure() : base("dbo.EndUpdateInstanceV44") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly FilePropertyTableTypeTableValuedParameterDefinition _insertFileProperties = new FilePropertyTableTypeTableValuedParameterDefinition("@insertFileProperties"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, global::System.Collections.Generic.IEnumerable insertFileProperties) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstanceV44"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _insertFileProperties.AddParameter(command.Parameters, insertFileProperties); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, EndUpdateInstanceV44TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, patientId: patientId, patientName: patientName, patientBirthDate: patientBirthDate, insertFileProperties: tableValuedParameters.InsertFileProperties); + } + } + + internal class EndUpdateInstanceV44TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public EndUpdateInstanceV44TvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator) + { + this.FilePropertyTableTypeRowGenerator = FilePropertyTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator; + + public EndUpdateInstanceV44TableValuedParameters Generate(TInput input) + { + return new EndUpdateInstanceV44TableValuedParameters(FilePropertyTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct EndUpdateInstanceV44TableValuedParameters + { + internal EndUpdateInstanceV44TableValuedParameters(global::System.Collections.Generic.IEnumerable InsertFileProperties) + { + this.InsertFileProperties = InsertFileProperties; + } + + internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } + } + + internal class GetChangeFeedProcedure : StoredProcedure + { + internal GetChangeFeedProcedure() : base("dbo.GetChangeFeed") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeed"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedByTimeProcedure : StoredProcedure + { + internal GetChangeFeedByTimeProcedure() : base("dbo.GetChangeFeedByTime") + { + } + + private readonly ParameterDefinition _startTime = new ParameterDefinition("@startTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _endTime = new ParameterDefinition("@endTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.DateTimeOffset startTime, System.DateTimeOffset endTime, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedByTime"; + _startTime.AddParameter(command.Parameters, startTime); + _endTime.AddParameter(command.Parameters, endTime); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedByTimeV39Procedure : StoredProcedure + { + internal GetChangeFeedByTimeV39Procedure() : base("dbo.GetChangeFeedByTimeV39") + { + } + + private readonly ParameterDefinition _startTime = new ParameterDefinition("@startTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _endTime = new ParameterDefinition("@endTime", global::System.Data.SqlDbType.DateTimeOffset, false, 7); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.DateTimeOffset startTime, System.DateTimeOffset endTime, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedByTimeV39"; + _startTime.AddParameter(command.Parameters, startTime); + _endTime.AddParameter(command.Parameters, endTime); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedLatestProcedure : StoredProcedure + { + internal GetChangeFeedLatestProcedure() : base("dbo.GetChangeFeedLatest") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatest"; + } + } + + internal class GetChangeFeedLatestByTimeProcedure : StoredProcedure + { + internal GetChangeFeedLatestByTimeProcedure() : base("dbo.GetChangeFeedLatestByTime") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestByTime"; + } + } + + internal class GetChangeFeedLatestByTimeV39Procedure : StoredProcedure + { + internal GetChangeFeedLatestByTimeV39Procedure() : base("dbo.GetChangeFeedLatestByTimeV39") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestByTimeV39"; + } + } + + internal class GetChangeFeedLatestV39Procedure : StoredProcedure + { + internal GetChangeFeedLatestV39Procedure() : base("dbo.GetChangeFeedLatestV39") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestV39"; + } + } + + internal class GetChangeFeedLatestV6Procedure : StoredProcedure + { + internal GetChangeFeedLatestV6Procedure() : base("dbo.GetChangeFeedLatestV6") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedLatestV6"; + } + } + + internal class GetChangeFeedV39Procedure : StoredProcedure + { + internal GetChangeFeedV39Procedure() : base("dbo.GetChangeFeedV39") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedV39"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetChangeFeedV6Procedure : StoredProcedure + { + internal GetChangeFeedV6Procedure() : base("dbo.GetChangeFeedV6") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetChangeFeedV6"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetCurrentAndNextWorkitemWatermarkProcedure : StoredProcedure + { + internal GetCurrentAndNextWorkitemWatermarkProcedure() : base("dbo.GetCurrentAndNextWorkitemWatermark") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetCurrentAndNextWorkitemWatermark"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + } + } + + internal class GetExtendedQueryTagProcedure : StoredProcedure + { + internal GetExtendedQueryTagProcedure() : base("dbo.GetExtendedQueryTag") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTag"; + _tagPath.AddParameter(command.Parameters, tagPath); + } + } + + internal class GetExtendedQueryTagErrorsProcedure : StoredProcedure + { + internal GetExtendedQueryTagErrorsProcedure() : base("dbo.GetExtendedQueryTagErrors") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Int32 limit, System.Int32 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagErrors"; + _tagPath.AddParameter(command.Parameters, tagPath); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagErrorsV36Procedure : StoredProcedure + { + internal GetExtendedQueryTagErrorsV36Procedure() : base("dbo.GetExtendedQueryTagErrorsV36") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagErrorsV36"; + _tagPath.AddParameter(command.Parameters, tagPath); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagErrorsV6Procedure : StoredProcedure + { + internal GetExtendedQueryTagErrorsV6Procedure() : base("dbo.GetExtendedQueryTagErrorsV6") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Int32 limit, System.Int32 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagErrorsV6"; + _tagPath.AddParameter(command.Parameters, tagPath); + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagsProcedure : StoredProcedure + { + internal GetExtendedQueryTagsProcedure() : base("dbo.GetExtendedQueryTags") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int32 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTags"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetExtendedQueryTagsByKeyProcedure : StoredProcedure + { + internal GetExtendedQueryTagsByKeyProcedure() : base("dbo.GetExtendedQueryTagsByKey") + { + } + + private readonly ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition _extendedQueryTagKeys = new ExtendedQueryTagKeyTableTypeV1TableValuedParameterDefinition("@extendedQueryTagKeys"); + + public void PopulateCommand(SqlCommandWrapper command, global::System.Collections.Generic.IEnumerable extendedQueryTagKeys) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagsByKey"; + _extendedQueryTagKeys.AddParameter(command.Parameters, extendedQueryTagKeys); + } + + public void PopulateCommand(SqlCommandWrapper command, GetExtendedQueryTagsByKeyTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, extendedQueryTagKeys: tableValuedParameters.ExtendedQueryTagKeys); + } + } + + internal class GetExtendedQueryTagsByKeyTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public GetExtendedQueryTagsByKeyTvpGenerator(ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator) + { + this.ExtendedQueryTagKeyTableTypeV1RowGenerator = ExtendedQueryTagKeyTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator ExtendedQueryTagKeyTableTypeV1RowGenerator; + + public GetExtendedQueryTagsByKeyTableValuedParameters Generate(TInput input) + { + return new GetExtendedQueryTagsByKeyTableValuedParameters(ExtendedQueryTagKeyTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct GetExtendedQueryTagsByKeyTableValuedParameters + { + internal GetExtendedQueryTagsByKeyTableValuedParameters(global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys) + { + this.ExtendedQueryTagKeys = ExtendedQueryTagKeys; + } + + internal global::System.Collections.Generic.IEnumerable ExtendedQueryTagKeys { get; } + } + + internal class GetExtendedQueryTagsByOperationProcedure : StoredProcedure + { + internal GetExtendedQueryTagsByOperationProcedure() : base("dbo.GetExtendedQueryTagsByOperation") + { + } + + private readonly ParameterDefinition _operationId = new ParameterDefinition("@operationId", global::System.Data.SqlDbType.UniqueIdentifier, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Guid operationId) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagsByOperation"; + _operationId.AddParameter(command.Parameters, operationId); + } + } + + internal class GetExtendedQueryTagsV36Procedure : StoredProcedure + { + internal GetExtendedQueryTagsV36Procedure() : base("dbo.GetExtendedQueryTagsV36") + { + } + + private readonly ParameterDefinition _limit = new ParameterDefinition("@limit", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _offset = new ParameterDefinition("@offset", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 limit, System.Int64 offset) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetExtendedQueryTagsV36"; + _limit.AddParameter(command.Parameters, limit); + _offset.AddParameter(command.Parameters, offset); + } + } + + internal class GetInstanceProcedure : StoredProcedure + { + internal GetInstanceProcedure() : base("dbo.GetInstance") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstance"; + _validStatus.AddParameter(command.Parameters, validStatus); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceBatchesProcedure : StoredProcedure + { + internal GetInstanceBatchesProcedure() : base("dbo.GetInstanceBatches") + { + } + + private readonly ParameterDefinition _batchSize = new ParameterDefinition("@batchSize", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _batchCount = new ParameterDefinition("@batchCount", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxWatermark = new ParameterDefinition>("@maxWatermark", global::System.Data.SqlDbType.BigInt, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 batchSize, System.Int32 batchCount, System.Byte status, System.Nullable maxWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceBatches"; + _batchSize.AddParameter(command.Parameters, batchSize); + _batchCount.AddParameter(command.Parameters, batchCount); + _status.AddParameter(command.Parameters, status); + _maxWatermark.AddParameter(command.Parameters, maxWatermark); + } + } + + internal class GetInstanceBatchesByTimeStampProcedure : StoredProcedure + { + internal GetInstanceBatchesByTimeStampProcedure() : base("dbo.GetInstanceBatchesByTimeStamp") + { + } + + private readonly ParameterDefinition _batchSize = new ParameterDefinition("@batchSize", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _batchCount = new ParameterDefinition("@batchCount", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _startTimeStamp = new ParameterDefinition("@startTimeStamp", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + private readonly ParameterDefinition _endTimeStamp = new ParameterDefinition("@endTimeStamp", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + private readonly ParameterDefinition> _maxWatermark = new ParameterDefinition>("@maxWatermark", global::System.Data.SqlDbType.BigInt, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 batchSize, System.Int32 batchCount, System.Byte status, System.DateTimeOffset startTimeStamp, System.DateTimeOffset endTimeStamp, System.Nullable maxWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceBatchesByTimeStamp"; + _batchSize.AddParameter(command.Parameters, batchSize); + _batchCount.AddParameter(command.Parameters, batchCount); + _status.AddParameter(command.Parameters, status); + _startTimeStamp.AddParameter(command.Parameters, startTimeStamp); + _endTimeStamp.AddParameter(command.Parameters, endTimeStamp); + _maxWatermark.AddParameter(command.Parameters, maxWatermark); + } + } + + internal class GetInstanceV6Procedure : StoredProcedure + { + internal GetInstanceV6Procedure() : base("dbo.GetInstanceV6") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceV6"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceWithPropertiesProcedure : StoredProcedure + { + internal GetInstanceWithPropertiesProcedure() : base("dbo.GetInstanceWithProperties") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceWithProperties"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceWithPropertiesV32Procedure : StoredProcedure + { + internal GetInstanceWithPropertiesV32Procedure() : base("dbo.GetInstanceWithPropertiesV32") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceWithPropertiesV32"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstanceWithPropertiesV46Procedure : StoredProcedure + { + internal GetInstanceWithPropertiesV46Procedure() : base("dbo.GetInstanceWithPropertiesV46") + { + } + + private readonly ParameterDefinition _validStatus = new ParameterDefinition("@validStatus", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, true, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Byte validStatus, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstanceWithPropertiesV46"; + _validStatus.AddParameter(command.Parameters, validStatus); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + } + } + + internal class GetInstancesByWatermarkRangeProcedure : StoredProcedure + { + internal GetInstancesByWatermarkRangeProcedure() : base("dbo.GetInstancesByWatermarkRange") + { + } + + private readonly ParameterDefinition _startWatermark = new ParameterDefinition("@startWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _endWatermark = new ParameterDefinition("@endWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 startWatermark, System.Int64 endWatermark, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstancesByWatermarkRange"; + _startWatermark.AddParameter(command.Parameters, startWatermark); + _endWatermark.AddParameter(command.Parameters, endWatermark); + _status.AddParameter(command.Parameters, status); + } + } + + internal class GetInstancesByWatermarkRangeV6Procedure : StoredProcedure + { + internal GetInstancesByWatermarkRangeV6Procedure() : base("dbo.GetInstancesByWatermarkRangeV6") + { + } + + private readonly ParameterDefinition _startWatermark = new ParameterDefinition("@startWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _endWatermark = new ParameterDefinition("@endWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 startWatermark, System.Int64 endWatermark, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetInstancesByWatermarkRangeV6"; + _startWatermark.AddParameter(command.Parameters, startWatermark); + _endWatermark.AddParameter(command.Parameters, endWatermark); + _status.AddParameter(command.Parameters, status); + } + } + + internal class GetPartitionProcedure : StoredProcedure + { + internal GetPartitionProcedure() : base("dbo.GetPartition") + { + } + + private readonly ParameterDefinition _partitionName = new ParameterDefinition("@partitionName", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.String partitionName) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetPartition"; + _partitionName.AddParameter(command.Parameters, partitionName); + } + } + + internal class GetPartitionsProcedure : StoredProcedure + { + internal GetPartitionsProcedure() : base("dbo.GetPartitions") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetPartitions"; + } + } + + internal class GetSeriesResultProcedure : StoredProcedure + { + internal GetSeriesResultProcedure() : base("dbo.GetSeriesResult") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetSeriesResult"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, GetSeriesResultTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class GetSeriesResultTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public GetSeriesResultTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public GetSeriesResultTableValuedParameters Generate(TInput input) + { + return new GetSeriesResultTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct GetSeriesResultTableValuedParameters + { + internal GetSeriesResultTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class GetStudyResultProcedure : StoredProcedure + { + internal GetStudyResultProcedure() : base("dbo.GetStudyResult") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetStudyResult"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, GetStudyResultTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class GetStudyResultTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public GetStudyResultTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public GetStudyResultTableValuedParameters Generate(TInput input) + { + return new GetStudyResultTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct GetStudyResultTableValuedParameters + { + internal GetStudyResultTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class GetWorkitemMetadataProcedure : StoredProcedure + { + internal GetWorkitemMetadataProcedure() : base("dbo.GetWorkitemMetadata") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemUid = new ParameterDefinition("@workitemUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _procedureStepStateTagPath = new ParameterDefinition("@procedureStepStateTagPath", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String workitemUid, System.String procedureStepStateTagPath) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetWorkitemMetadata"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemUid.AddParameter(command.Parameters, workitemUid); + _procedureStepStateTagPath.AddParameter(command.Parameters, procedureStepStateTagPath); + } + } + + internal class GetWorkitemQueryTagsProcedure : StoredProcedure + { + internal GetWorkitemQueryTagsProcedure() : base("dbo.GetWorkitemQueryTags") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.GetWorkitemQueryTags"; + } + } + + internal class IIndexInstanceCoreV9Procedure : StoredProcedure + { + internal IIndexInstanceCoreV9Procedure() : base("dbo.IIndexInstanceCoreV9") + { + } + + private readonly ParameterDefinition> _partitionKey = new ParameterDefinition>("@partitionKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition _studyKey = new ParameterDefinition("@studyKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _seriesKey = new ParameterDefinition("@seriesKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _instanceKey = new ParameterDefinition("@instanceKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 studyKey, System.Int64 seriesKey, System.Int64 instanceKey, System.Int64 watermark, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IIndexInstanceCoreV9"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyKey.AddParameter(command.Parameters, studyKey); + _seriesKey.AddParameter(command.Parameters, seriesKey); + _instanceKey.AddParameter(command.Parameters, instanceKey); + _watermark.AddParameter(command.Parameters, watermark); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 studyKey, System.Int64 seriesKey, System.Int64 instanceKey, System.Int64 watermark, IIndexInstanceCoreV9TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyKey: studyKey, seriesKey: seriesKey, instanceKey: instanceKey, watermark: watermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IIndexInstanceCoreV9TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IIndexInstanceCoreV9TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IIndexInstanceCoreV9TableValuedParameters Generate(TInput input) + { + return new IIndexInstanceCoreV9TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IIndexInstanceCoreV9TableValuedParameters + { + internal IIndexInstanceCoreV9TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class IIndexWorkitemInstanceCoreProcedure : StoredProcedure + { + internal IIndexWorkitemInstanceCoreProcedure() : base("dbo.IIndexWorkitemInstanceCore") + { + } + + private readonly ParameterDefinition> _partitionKey = new ParameterDefinition>("@partitionKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 workitemKey, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IIndexWorkitemInstanceCore"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemKey.AddParameter(command.Parameters, workitemKey); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Nullable partitionKey, System.Int64 workitemKey, IIndexWorkitemInstanceCoreTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, workitemKey: workitemKey, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IIndexWorkitemInstanceCoreTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IIndexWorkitemInstanceCoreTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IIndexWorkitemInstanceCoreTableValuedParameters Generate(TInput input) + { + return new IIndexWorkitemInstanceCoreTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IIndexWorkitemInstanceCoreTableValuedParameters + { + internal IIndexWorkitemInstanceCoreTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class ISleepIfBusyProcedure : StoredProcedure + { + internal ISleepIfBusyProcedure() : base("dbo.ISleepIfBusy") + { + } + + public void PopulateCommand(SqlCommandWrapper command) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.ISleepIfBusy"; + } + } + + internal class IncrementDeletedInstanceRetryProcedure : StoredProcedure + { + internal IncrementDeletedInstanceRetryProcedure() : base("dbo.IncrementDeletedInstanceRetry") + { + } + + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _cleanupAfter = new ParameterDefinition("@cleanupAfter", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + + public void PopulateCommand(SqlCommandWrapper command, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.DateTimeOffset cleanupAfter) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IncrementDeletedInstanceRetry"; + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + } + } + + internal class IncrementDeletedInstanceRetryV6Procedure : StoredProcedure + { + internal IncrementDeletedInstanceRetryV6Procedure() : base("dbo.IncrementDeletedInstanceRetryV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _cleanupAfter = new ParameterDefinition("@cleanupAfter", global::System.Data.SqlDbType.DateTimeOffset, false, 0); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.DateTimeOffset cleanupAfter) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IncrementDeletedInstanceRetryV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _cleanupAfter.AddParameter(command.Parameters, cleanupAfter); + } + } + + internal class IndexInstanceV6Procedure : StoredProcedure + { + internal IndexInstanceV6Procedure() : base("dbo.IndexInstanceV6") + { + } + + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 watermark, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.IndexInstanceV6"; + _watermark.AddParameter(command.Parameters, watermark); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 watermark, IndexInstanceV6TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, watermark: watermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class IndexInstanceV6TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public IndexInstanceV6TvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public IndexInstanceV6TableValuedParameters Generate(TInput input) + { + return new IndexInstanceV6TableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct IndexInstanceV6TableValuedParameters + { + internal IndexInstanceV6TableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class RetrieveDeletedInstanceProcedure : StoredProcedure + { + internal RetrieveDeletedInstanceProcedure() : base("dbo.RetrieveDeletedInstance") + { + } + + private readonly ParameterDefinition _count = new ParameterDefinition("@count", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _maxRetries = new ParameterDefinition("@maxRetries", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 count, System.Int32 maxRetries) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.RetrieveDeletedInstance"; + _count.AddParameter(command.Parameters, count); + _maxRetries.AddParameter(command.Parameters, maxRetries); + } + } + + internal class RetrieveDeletedInstanceV42Procedure : StoredProcedure + { + internal RetrieveDeletedInstanceV42Procedure() : base("dbo.RetrieveDeletedInstanceV42") + { + } + + private readonly ParameterDefinition _count = new ParameterDefinition("@count", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _maxRetries = new ParameterDefinition("@maxRetries", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 count, System.Int32 maxRetries) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.RetrieveDeletedInstanceV42"; + _count.AddParameter(command.Parameters, count); + _maxRetries.AddParameter(command.Parameters, maxRetries); + } + } + + internal class RetrieveDeletedInstanceV6Procedure : StoredProcedure + { + internal RetrieveDeletedInstanceV6Procedure() : base("dbo.RetrieveDeletedInstanceV6") + { + } + + private readonly ParameterDefinition _count = new ParameterDefinition("@count", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _maxRetries = new ParameterDefinition("@maxRetries", global::System.Data.SqlDbType.Int, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 count, System.Int32 maxRetries) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.RetrieveDeletedInstanceV6"; + _count.AddParameter(command.Parameters, count); + _maxRetries.AddParameter(command.Parameters, maxRetries); + } + } + + internal class UpdateExtendedQueryTagQueryStatusProcedure : StoredProcedure + { + internal UpdateExtendedQueryTagQueryStatusProcedure() : base("dbo.UpdateExtendedQueryTagQueryStatus") + { + } + + private readonly ParameterDefinition _tagPath = new ParameterDefinition("@tagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _queryStatus = new ParameterDefinition("@queryStatus", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String tagPath, System.Byte queryStatus) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateExtendedQueryTagQueryStatus"; + _tagPath.AddParameter(command.Parameters, tagPath); + _queryStatus.AddParameter(command.Parameters, queryStatus); + } + } + + internal class UpdateFrameMetadataProcedure : StoredProcedure + { + internal UpdateFrameMetadataProcedure() : base("dbo.UpdateFrameMetadata") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _hasFrameMetadata = new ParameterDefinition("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, false); + private readonly WatermarkTableTypeTableValuedParameterDefinition _watermarkTableType = new WatermarkTableTypeTableValuedParameterDefinition("@watermarkTableType"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.Boolean hasFrameMetadata, global::System.Collections.Generic.IEnumerable watermarkTableType) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateFrameMetadata"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + _watermarkTableType.AddParameter(command.Parameters, watermarkTableType); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.Boolean hasFrameMetadata, UpdateFrameMetadataTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, hasFrameMetadata: hasFrameMetadata, watermarkTableType: tableValuedParameters.WatermarkTableType); + } + } + + internal class UpdateFrameMetadataTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateFrameMetadataTvpGenerator(ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator) + { + this.WatermarkTableTypeRowGenerator = WatermarkTableTypeRowGenerator; + } + + private readonly ITableValuedParameterRowGenerator WatermarkTableTypeRowGenerator; + + public UpdateFrameMetadataTableValuedParameters Generate(TInput input) + { + return new UpdateFrameMetadataTableValuedParameters(WatermarkTableTypeRowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateFrameMetadataTableValuedParameters + { + internal UpdateFrameMetadataTableValuedParameters(global::System.Collections.Generic.IEnumerable WatermarkTableType) + { + this.WatermarkTableType = WatermarkTableType; + } + + internal global::System.Collections.Generic.IEnumerable WatermarkTableType { get; } + } + + internal class UpdateIndexWorkitemInstanceCoreProcedure : StoredProcedure + { + internal UpdateIndexWorkitemInstanceCoreProcedure() : base("dbo.UpdateIndexWorkitemInstanceCore") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateIndexWorkitemInstanceCore"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, UpdateIndexWorkitemInstanceCoreTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, workitemKey: workitemKey, partitionKey: partitionKey, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class UpdateIndexWorkitemInstanceCoreTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateIndexWorkitemInstanceCoreTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public UpdateIndexWorkitemInstanceCoreTableValuedParameters Generate(TInput input) + { + return new UpdateIndexWorkitemInstanceCoreTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateIndexWorkitemInstanceCoreTableValuedParameters + { + internal UpdateIndexWorkitemInstanceCoreTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + + internal class UpdateInstanceStatusProcedure : StoredProcedure + { + internal UpdateInstanceStatusProcedure() : base("dbo.UpdateInstanceStatus") + { + } + + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatus"; + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + } + } + + internal class UpdateInstanceStatusV37Procedure : StoredProcedure + { + internal UpdateInstanceStatusV37Procedure() : base("dbo.UpdateInstanceStatusV37") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxTagKey = new ParameterDefinition>("@maxTagKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _hasFrameMetadata = new ParameterDefinition>("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, true); + private readonly ParameterDefinition _path = new ParameterDefinition("@path", global::System.Data.SqlDbType.VarChar, true, 4000); + private readonly ParameterDefinition _eTag = new ParameterDefinition("@eTag", global::System.Data.SqlDbType.VarChar, true, 4000); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status, System.Nullable maxTagKey, System.Nullable hasFrameMetadata, System.String path, System.String eTag) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatusV37"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + _maxTagKey.AddParameter(command.Parameters, maxTagKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + _path.AddParameter(command.Parameters, path); + _eTag.AddParameter(command.Parameters, eTag); + } + } + + internal class UpdateInstanceStatusV6Procedure : StoredProcedure + { + internal UpdateInstanceStatusV6Procedure() : base("dbo.UpdateInstanceStatusV6") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _seriesInstanceUid = new ParameterDefinition("@seriesInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _sopInstanceUid = new ParameterDefinition("@sopInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + private readonly ParameterDefinition> _maxTagKey = new ParameterDefinition>("@maxTagKey", global::System.Data.SqlDbType.Int, true); + private readonly ParameterDefinition> _hasFrameMetadata = new ParameterDefinition>("@hasFrameMetadata", global::System.Data.SqlDbType.Bit, true); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String seriesInstanceUid, System.String sopInstanceUid, System.Int64 watermark, System.Byte status, System.Nullable maxTagKey, System.Nullable hasFrameMetadata) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateInstanceStatusV6"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _seriesInstanceUid.AddParameter(command.Parameters, seriesInstanceUid); + _sopInstanceUid.AddParameter(command.Parameters, sopInstanceUid); + _watermark.AddParameter(command.Parameters, watermark); + _status.AddParameter(command.Parameters, status); + _maxTagKey.AddParameter(command.Parameters, maxTagKey); + _hasFrameMetadata.AddParameter(command.Parameters, hasFrameMetadata); + } + } + + internal class UpdateWorkitemProcedureStepStateProcedure : StoredProcedure + { + internal UpdateWorkitemProcedureStepStateProcedure() : base("dbo.UpdateWorkitemProcedureStepState") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _procedureStepStateTagPath = new ParameterDefinition("@procedureStepStateTagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _procedureStepState = new ParameterDefinition("@procedureStepState", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _proposedWatermark = new ParameterDefinition("@proposedWatermark", global::System.Data.SqlDbType.BigInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.String procedureStepStateTagPath, System.String procedureStepState, System.Int64 watermark, System.Int64 proposedWatermark) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemProcedureStepState"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _procedureStepStateTagPath.AddParameter(command.Parameters, procedureStepStateTagPath); + _procedureStepState.AddParameter(command.Parameters, procedureStepState); + _watermark.AddParameter(command.Parameters, watermark); + _proposedWatermark.AddParameter(command.Parameters, proposedWatermark); + } + } + + internal class UpdateWorkitemProcedureStepStateV21Procedure : StoredProcedure + { + internal UpdateWorkitemProcedureStepStateV21Procedure() : base("dbo.UpdateWorkitemProcedureStepStateV21") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _procedureStepStateTagPath = new ParameterDefinition("@procedureStepStateTagPath", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _procedureStepState = new ParameterDefinition("@procedureStepState", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _proposedWatermark = new ParameterDefinition("@proposedWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _transactionUid = new ParameterDefinition("@transactionUid", global::System.Data.SqlDbType.VarChar, false, 64); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.String procedureStepStateTagPath, System.String procedureStepState, System.Int64 watermark, System.Int64 proposedWatermark, System.String transactionUid) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemProcedureStepStateV21"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _procedureStepStateTagPath.AddParameter(command.Parameters, procedureStepStateTagPath); + _procedureStepState.AddParameter(command.Parameters, procedureStepState); + _watermark.AddParameter(command.Parameters, watermark); + _proposedWatermark.AddParameter(command.Parameters, proposedWatermark); + _transactionUid.AddParameter(command.Parameters, transactionUid); + } + } + + internal class UpdateWorkitemStatusProcedure : StoredProcedure + { + internal UpdateWorkitemStatusProcedure() : base("dbo.UpdateWorkitemStatus") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _status = new ParameterDefinition("@status", global::System.Data.SqlDbType.TinyInt, false); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.Int64 workitemKey, System.Byte status) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemStatus"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _workitemKey.AddParameter(command.Parameters, workitemKey); + _status.AddParameter(command.Parameters, status); + } + } + + internal class UpdateWorkitemTransactionProcedure : StoredProcedure + { + internal UpdateWorkitemTransactionProcedure() : base("dbo.UpdateWorkitemTransaction") + { + } + + private readonly ParameterDefinition _workitemKey = new ParameterDefinition("@workitemKey", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _watermark = new ParameterDefinition("@watermark", global::System.Data.SqlDbType.BigInt, false); + private readonly ParameterDefinition _proposedWatermark = new ParameterDefinition("@proposedWatermark", global::System.Data.SqlDbType.BigInt, false); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, System.Int64 watermark, System.Int64 proposedWatermark, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.UpdateWorkitemTransaction"; + _workitemKey.AddParameter(command.Parameters, workitemKey); + _partitionKey.AddParameter(command.Parameters, partitionKey); + _watermark.AddParameter(command.Parameters, watermark); + _proposedWatermark.AddParameter(command.Parameters, proposedWatermark); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int64 workitemKey, System.Int32 partitionKey, System.Int64 watermark, System.Int64 proposedWatermark, UpdateWorkitemTransactionTableValuedParameters tableValuedParameters) + { + PopulateCommand(command, workitemKey: workitemKey, partitionKey: partitionKey, watermark: watermark, proposedWatermark: proposedWatermark, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class UpdateWorkitemTransactionTvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public UpdateWorkitemTransactionTvpGenerator(ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public UpdateWorkitemTransactionTableValuedParameters Generate(TInput input) + { + return new UpdateWorkitemTransactionTableValuedParameters(InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct UpdateWorkitemTransactionTableValuedParameters + { + internal UpdateWorkitemTransactionTableValuedParameters(global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/VLatest.Generated.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/VLatest.Generated.cs index 10281398de..422c8662fc 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 @@ -50,6 +50,7 @@ internal class VLatest internal readonly static DeleteWorkitemProcedure DeleteWorkitem = new DeleteWorkitemProcedure(); internal readonly static EndUpdateInstanceProcedure EndUpdateInstance = new EndUpdateInstanceProcedure(); internal readonly static EndUpdateInstanceV44Procedure EndUpdateInstanceV44 = new EndUpdateInstanceV44Procedure(); + internal readonly static EndUpdateInstanceV50Procedure EndUpdateInstanceV50 = new EndUpdateInstanceV50Procedure(); internal readonly static GetChangeFeedProcedure GetChangeFeed = new GetChangeFeedProcedure(); internal readonly static GetChangeFeedByTimeProcedure GetChangeFeedByTime = new GetChangeFeedByTimeProcedure(); internal readonly static GetChangeFeedByTimeV39Procedure GetChangeFeedByTimeV39 = new GetChangeFeedByTimeV39Procedure(); @@ -1154,6 +1155,92 @@ internal EndUpdateInstanceV44TableValuedParameters(global::System.Collections.Ge internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } } + internal class EndUpdateInstanceV50Procedure : StoredProcedure + { + internal EndUpdateInstanceV50Procedure() : base("dbo.EndUpdateInstanceV50") + { + } + + private readonly ParameterDefinition _partitionKey = new ParameterDefinition("@partitionKey", global::System.Data.SqlDbType.Int, false); + private readonly ParameterDefinition _studyInstanceUid = new ParameterDefinition("@studyInstanceUid", global::System.Data.SqlDbType.VarChar, false, 64); + private readonly ParameterDefinition _patientId = new ParameterDefinition("@patientId", global::System.Data.SqlDbType.NVarChar, true, 64); + private readonly ParameterDefinition _patientName = new ParameterDefinition("@patientName", global::System.Data.SqlDbType.NVarChar, true, 325); + private readonly ParameterDefinition> _patientBirthDate = new ParameterDefinition>("@patientBirthDate", global::System.Data.SqlDbType.Date, true); + private readonly FilePropertyTableTypeTableValuedParameterDefinition _insertFileProperties = new FilePropertyTableTypeTableValuedParameterDefinition("@insertFileProperties"); + private readonly InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition _stringExtendedQueryTags = new InsertStringExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@stringExtendedQueryTags"); + private readonly InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition _longExtendedQueryTags = new InsertLongExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@longExtendedQueryTags"); + private readonly InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition _doubleExtendedQueryTags = new InsertDoubleExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@doubleExtendedQueryTags"); + private readonly InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition _dateTimeExtendedQueryTags = new InsertDateTimeExtendedQueryTagTableTypeV2TableValuedParameterDefinition("@dateTimeExtendedQueryTags"); + private readonly InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition _personNameExtendedQueryTags = new InsertPersonNameExtendedQueryTagTableTypeV1TableValuedParameterDefinition("@personNameExtendedQueryTags"); + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, global::System.Collections.Generic.IEnumerable insertFileProperties, global::System.Collections.Generic.IEnumerable stringExtendedQueryTags, global::System.Collections.Generic.IEnumerable longExtendedQueryTags, global::System.Collections.Generic.IEnumerable doubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable dateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable personNameExtendedQueryTags) + { + command.CommandType = global::System.Data.CommandType.StoredProcedure; + command.CommandText = "dbo.EndUpdateInstanceV50"; + _partitionKey.AddParameter(command.Parameters, partitionKey); + _studyInstanceUid.AddParameter(command.Parameters, studyInstanceUid); + _patientId.AddParameter(command.Parameters, patientId); + _patientName.AddParameter(command.Parameters, patientName); + _patientBirthDate.AddParameter(command.Parameters, patientBirthDate); + _insertFileProperties.AddParameter(command.Parameters, insertFileProperties); + _stringExtendedQueryTags.AddParameter(command.Parameters, stringExtendedQueryTags); + _longExtendedQueryTags.AddParameter(command.Parameters, longExtendedQueryTags); + _doubleExtendedQueryTags.AddParameter(command.Parameters, doubleExtendedQueryTags); + _dateTimeExtendedQueryTags.AddParameter(command.Parameters, dateTimeExtendedQueryTags); + _personNameExtendedQueryTags.AddParameter(command.Parameters, personNameExtendedQueryTags); + } + + public void PopulateCommand(SqlCommandWrapper command, System.Int32 partitionKey, System.String studyInstanceUid, System.String patientId, System.String patientName, System.Nullable patientBirthDate, EndUpdateInstanceV50TableValuedParameters tableValuedParameters) + { + PopulateCommand(command, partitionKey: partitionKey, studyInstanceUid: studyInstanceUid, patientId: patientId, patientName: patientName, patientBirthDate: patientBirthDate, insertFileProperties: tableValuedParameters.InsertFileProperties, stringExtendedQueryTags: tableValuedParameters.StringExtendedQueryTags, longExtendedQueryTags: tableValuedParameters.LongExtendedQueryTags, doubleExtendedQueryTags: tableValuedParameters.DoubleExtendedQueryTags, dateTimeExtendedQueryTags: tableValuedParameters.DateTimeExtendedQueryTags, personNameExtendedQueryTags: tableValuedParameters.PersonNameExtendedQueryTags); + } + } + + internal class EndUpdateInstanceV50TvpGenerator : IStoredProcedureTableValuedParametersGenerator + { + public EndUpdateInstanceV50TvpGenerator(ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator, ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator, ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator, ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator) + { + this.FilePropertyTableTypeRowGenerator = FilePropertyTableTypeRowGenerator; + this.InsertStringExtendedQueryTagTableTypeV1RowGenerator = InsertStringExtendedQueryTagTableTypeV1RowGenerator; + this.InsertLongExtendedQueryTagTableTypeV1RowGenerator = InsertLongExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDoubleExtendedQueryTagTableTypeV1RowGenerator = InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + this.InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator = InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + this.InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator = InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + } + + private readonly ITableValuedParameterRowGenerator FilePropertyTableTypeRowGenerator; + private readonly ITableValuedParameterRowGenerator InsertStringExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertLongExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDoubleExtendedQueryTagTableTypeV1RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator; + private readonly ITableValuedParameterRowGenerator InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator; + + public EndUpdateInstanceV50TableValuedParameters Generate(TInput input) + { + return new EndUpdateInstanceV50TableValuedParameters(FilePropertyTableTypeRowGenerator.GenerateRows(input), InsertStringExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertLongExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDoubleExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input), InsertDateTimeExtendedQueryTagTableTypeV2RowGenerator.GenerateRows(input), InsertPersonNameExtendedQueryTagTableTypeV1RowGenerator.GenerateRows(input)); + } + } + + internal struct EndUpdateInstanceV50TableValuedParameters + { + internal EndUpdateInstanceV50TableValuedParameters(global::System.Collections.Generic.IEnumerable InsertFileProperties, global::System.Collections.Generic.IEnumerable StringExtendedQueryTags, global::System.Collections.Generic.IEnumerable LongExtendedQueryTags, global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags, global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags, global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags) + { + this.InsertFileProperties = InsertFileProperties; + this.StringExtendedQueryTags = StringExtendedQueryTags; + this.LongExtendedQueryTags = LongExtendedQueryTags; + this.DoubleExtendedQueryTags = DoubleExtendedQueryTags; + this.DateTimeExtendedQueryTags = DateTimeExtendedQueryTags; + this.PersonNameExtendedQueryTags = PersonNameExtendedQueryTags; + } + + internal global::System.Collections.Generic.IEnumerable InsertFileProperties { get; } + internal global::System.Collections.Generic.IEnumerable StringExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable LongExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DoubleExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable DateTimeExtendedQueryTags { get; } + internal global::System.Collections.Generic.IEnumerable PersonNameExtendedQueryTags { get; } + } + internal class GetChangeFeedProcedure : StoredProcedure { internal GetChangeFeedProcedure() : base("dbo.GetChangeFeed") diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs index 6bbb5b8924..d39246acf8 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs @@ -60,4 +60,5 @@ public enum SchemaVersion V47 = 47, V48 = 48, V49 = 49, + V50 = 50, } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs index 00f78fa3f1..cb3da1c23b 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs @@ -8,5 +8,5 @@ namespace Microsoft.Health.Dicom.SqlServer.Features.Schema; public static class SchemaVersionConstants { public const int Min = (int)SchemaVersion.V37; - public const int Max = (int)SchemaVersion.V49; + public const int Max = (int)SchemaVersion.V50; } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/EndUpdateInstanceV50.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/EndUpdateInstanceV50.sql new file mode 100644 index 0000000000..df94a95872 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/EndUpdateInstanceV50.sql @@ -0,0 +1,158 @@ +/************************************************************* + Stored procedures for updating an instance status. +**************************************************************/ +-- +-- STORED PROCEDURE +-- EndUpdateInstanceV50 +-- +-- DESCRIPTION +-- Bulk update all instances in a study, creates new entry in changefeed and fileProperty for each new file added. +-- +-- PARAMETERS +-- @partitionKey +-- * The partition key. +-- @studyInstanceUid +-- * The study instance UID. +-- @patientId +-- * The Id of the patient. +-- @patientName +-- * The name of the patient. +-- @patientBirthDate +-- * The patient's birth date. +-- @insertFileProperties +-- * A table type containing the file properties to insert. +-- +-- RETURN VALUE +-- None +-- +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV50 + @partitionKey INT, + @studyInstanceUid VARCHAR(64), + @patientId NVARCHAR(64) = NULL, + @patientName NVARCHAR(325) = NULL, + @patientBirthDate DATE = NULL, + @insertFileProperties dbo.FilePropertyTableType READONLY, + @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, + @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, + @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, + @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, + @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON + + SET XACT_ABORT ON + BEGIN TRANSACTION + + DECLARE @currentDate DATETIME2(7) = SYSUTCDATETIME() + DECLARE @resourceType TINYINT = 0 + DECLARE @studyKey BIGINT + DECLARE @maxWatermark BIGINT + + CREATE TABLE #UpdatedInstances + (PartitionKey INT, + StudyInstanceUid VARCHAR(64), + SeriesInstanceUid VARCHAR(64), + SopInstanceUid VARCHAR(64), + Watermark BIGINT, + OriginalWatermark BIGINT, + InstanceKey BIGINT) + + DELETE FROM #UpdatedInstances + + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL + + -- Create index on temp table so we can join on watermark when we need to update change feed with file path. + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances ON #UpdatedInstances (Watermark) + + -- Create index on temp table so we can join on instance key and watermark when we need to insert file + -- properties when instance key alone is does not specify a unique row on the table + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark ON #UpdatedInstances (InstanceKey, OriginalWatermark) + + -- Only updating patient information in a study + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + + -- The study does not exist. May be deleted + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1 + + -- Delete from file properties any rows with "stale" watermarks if we will be inserting new ones + IF EXISTS (SELECT 1 FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty as FP + INNER JOIN #UpdatedInstances U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark + + -- Insert new file properties from added blobs, @insertFileProperties will be empty when external store not + -- enabled + INSERT INTO dbo.FileProperty + (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, I.Watermark, I.FilePath, I.ETag + FROM @insertFileProperties I + INNER JOIN #UpdatedInstances U + ON U.Watermark = I.Watermark + + SELECT + @maxWatermark = max(Watermark) + FROM #UpdatedInstances + + -- Update extended query tags value if any + BEGIN TRY + EXEC dbo.IIndexInstanceCoreV9 + @partitionKey, + @studyKey, + null, -- passing null to series key and instance + null, + @maxWatermark, + @stringExtendedQueryTags, + @longExtendedQueryTags, + @doubleExtendedQueryTags, + @dateTimeExtendedQueryTags, + @personNameExtendedQueryTags + END TRY + BEGIN CATCH + THROW + END CATCH + + -- Insert into change feed table for update action type + INSERT INTO dbo.ChangeFeed + (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark + FROM #UpdatedInstances + + -- Update existing instance currentWatermark to latest and update file path + UPDATE C + SET CurrentWatermark = U.Watermark, FilePath = I.FilePath + FROM dbo.ChangeFeed C + JOIN #UpdatedInstances U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN @insertFileProperties I + ON I.Watermark = U.Watermark + + COMMIT TRANSACTION +END diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs index f5b073f34b..d021e70f57 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStore.cs @@ -114,10 +114,10 @@ public async Task> BeginUpdateInstancesAsync(Par return await store.BeginUpdateInstancesAsync(partition, studyInstanceUid, cancellationToken); } - public async Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, CancellationToken cancellationToken = default) + public async Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, IEnumerable queryTags, CancellationToken cancellationToken = default) { ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken); - await store.EndUpdateInstanceAsync(partitionKey, studyInstanceUid, dicomDataset, instanceMetadataList, cancellationToken); + await store.EndUpdateInstanceAsync(partitionKey, studyInstanceUid, dicomDataset, instanceMetadataList, queryTags, cancellationToken); } public async Task UpdateFrameDataAsync(int partitionKey, IEnumerable versions, bool hasFrameMetadata, CancellationToken cancellationToken = default) diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs index 624eb259e4..1d48e7a426 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV1.cs @@ -357,7 +357,7 @@ public virtual Task> BeginUpdateInstancesAsync(P throw new BadRequestException(DicomSqlServerResource.SchemaVersionNeedsToBeUpgraded); } - public virtual Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, CancellationToken cancellationToken = default) + public virtual Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, IEnumerable queryTags, CancellationToken cancellationToken = default) { throw new BadRequestException(DicomSqlServerResource.SchemaVersionNeedsToBeUpgraded); } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs index a198b269ea..b60dfa95d8 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs @@ -443,6 +443,7 @@ public override async Task EndUpdateInstanceAsync( string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, + IEnumerable queryTags, CancellationToken cancellationToken) { EnsureArg.IsNotNull(dicomDataset, nameof(dicomDataset)); diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV44.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV44.cs index d2fcfe63ca..45384f0f0b 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV44.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV44.cs @@ -12,6 +12,7 @@ using Microsoft.Data.SqlClient; using Microsoft.Health.Dicom.Core.Exceptions; using Microsoft.Health.Dicom.Core.Extensions; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Core.Features.Model; using Microsoft.Health.Dicom.SqlServer.Features.Schema; using Microsoft.Health.Dicom.SqlServer.Features.Schema.Model; @@ -37,6 +38,7 @@ public override async Task EndUpdateInstanceAsync( string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList instanceMetadataList, + IEnumerable queryTags, CancellationToken cancellationToken) { EnsureArg.IsNotNull(dicomDataset, nameof(dicomDataset)); diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV50.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV50.cs new file mode 100644 index 0000000000..ab3172975c --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV50.cs @@ -0,0 +1,88 @@ +// ------------------------------------------------------------------------------------------------- +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using EnsureThat; +using FellowOakDicom; +using Microsoft.Data.SqlClient; +using Microsoft.Health.Dicom.Core.Exceptions; +using Microsoft.Health.Dicom.Core.Extensions; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; +using Microsoft.Health.Dicom.Core.Features.Model; +using Microsoft.Health.Dicom.SqlServer.Features.ExtendedQueryTag; +using Microsoft.Health.Dicom.SqlServer.Features.Schema; +using Microsoft.Health.Dicom.SqlServer.Features.Schema.Model; +using Microsoft.Health.SqlServer.Features.Client; +using Microsoft.Health.SqlServer.Features.Storage; + +namespace Microsoft.Health.Dicom.SqlServer.Features.Store; + +/// +/// Sql IndexDataStore version 50 +/// +internal class SqlIndexDataStoreV50 : SqlIndexDataStoreV49 +{ + public SqlIndexDataStoreV50(SqlConnectionWrapperFactory sqlConnectionWrapperFactory) + : base(sqlConnectionWrapperFactory) + { + } + + public override SchemaVersion Version => SchemaVersion.V50; + + public override async Task EndUpdateInstanceAsync( + int partitionKey, + string studyInstanceUid, + DicomDataset dicomDataset, + IReadOnlyList instanceMetadataList, + IEnumerable queryTags, + CancellationToken cancellationToken) + { + EnsureArg.IsNotNull(dicomDataset, nameof(dicomDataset)); + EnsureArg.IsNotNull(instanceMetadataList, nameof(instanceMetadataList)); + + var filePropertiesRows = instanceMetadataList.Select(instanceMetadata + => new FilePropertyTableTypeRow( + instanceMetadata.InstanceProperties.NewVersion.Value, + instanceMetadata.InstanceProperties.FileProperties.Path, + instanceMetadata.InstanceProperties.FileProperties.ETag)) + .ToList(); + + ExtendedQueryTagDataRows rows = ExtendedQueryTagDataRowsBuilder.Build(dicomDataset, queryTags, Version); + var parameters = new VLatest.EndUpdateInstanceV50TableValuedParameters( + filePropertiesRows, + rows.StringRows, + rows.LongRows, + rows.DoubleRows, + rows.DateTimeWithUtcRows, + rows.PersonNameRows); + + using SqlConnectionWrapper sqlConnectionWrapper = await SqlConnectionWrapperFactory.ObtainSqlConnectionWrapperAsync(cancellationToken); + using SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateRetrySqlCommand(); + VLatest.EndUpdateInstanceV50.PopulateCommand( + sqlCommandWrapper, + partitionKey, + studyInstanceUid, + dicomDataset.GetFirstValueOrDefault(DicomTag.PatientID), + dicomDataset.GetFirstValueOrDefault(DicomTag.PatientName), + dicomDataset.GetStringDateAsDate(DicomTag.PatientBirthDate), + parameters); + + try + { + await sqlCommandWrapper.ExecuteScalarAsync(cancellationToken); + } + catch (SqlException ex) + { + throw ex.Number switch + { + SqlErrorCodes.NotFound => new StudyNotFoundException(), + _ => new DataStoreException(ex), + }; + } + } +} diff --git a/src/Microsoft.Health.Dicom.SqlServer/Microsoft.Health.Dicom.SqlServer.csproj b/src/Microsoft.Health.Dicom.SqlServer/Microsoft.Health.Dicom.SqlServer.csproj index 0ce16e9296..e645e7860b 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 @@ - 49 + 50 Features\Schema\Migrations\$(LatestSchemaVersion).sql diff --git a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs index f4d22ed4f1..5384dbabeb 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs @@ -164,6 +164,7 @@ private static IServiceCollection AddSqlIndexDataStores(this IServiceCollection services.TryAddEnumerable(ServiceDescriptor.Scoped()); services.TryAddEnumerable(ServiceDescriptor.Scoped()); services.TryAddEnumerable(ServiceDescriptor.Scoped()); + services.TryAddEnumerable(ServiceDescriptor.Scoped()); return services; } diff --git a/src/Microsoft.Health.Dicom.Web/appsettings.json b/src/Microsoft.Health.Dicom.Web/appsettings.json index 26dd5970ec..14665a4fb7 100644 --- a/src/Microsoft.Health.Dicom.Web/appsettings.json +++ b/src/Microsoft.Health.Dicom.Web/appsettings.json @@ -58,7 +58,7 @@ } }, "Update": { - "Name": "UpdateInstancesV4Async" + "Name": "UpdateInstancesV5Async" } }, "DicomServer": { diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ChangeFeedTests.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ChangeFeedTests.cs index 67694fb4c8..31bfc86128 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ChangeFeedTests.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/ChangeFeedTests.cs @@ -13,6 +13,7 @@ using Microsoft.Health.Dicom.Core.Extensions; using Microsoft.Health.Dicom.Core.Features.ChangeFeed; using Microsoft.Health.Dicom.Core.Features.Common; +using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag; using Microsoft.Health.Dicom.Core.Features.Model; using Microsoft.Health.Dicom.Core.Features.Partitioning; using Microsoft.Health.Dicom.Core.Features.Query; @@ -146,7 +147,7 @@ public async Task GivenInstances_WhenBulkUpdateInstancesInAStudyAndExternalStore var dicomDataset = new DicomDataset(); dicomDataset.AddOrUpdate(DicomTag.PatientName, "FirstName_NewLastName"); - await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List()); + await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List(), Array.Empty()); var instanceMetadataList = (await _instanceStore.GetInstanceIdentifierWithPropertiesAsync(Partition.Default, studyInstanceUID1)).ToList(); @@ -188,7 +189,7 @@ public async Task GivenInstances_WhenBulkUpdateInstancesInAStudyAndFilePropertie var dicomDataset = new DicomDataset(); dicomDataset.AddOrUpdate(DicomTag.PatientName, "FirstName_NewLastName"); - await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, metadataListByWatermark.Values.ToList()); + await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, metadataListByWatermark.Values.ToList(), Array.Empty()); var instanceMetadataList = (await _instanceStore.GetInstanceIdentifierWithPropertiesAsync(Partition.Default, studyInstanceUID1)).ToList(); diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/InstanceStoreTests.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/InstanceStoreTests.cs index 4421d2e947..00cee9ef03 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/InstanceStoreTests.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/InstanceStoreTests.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -289,7 +290,7 @@ await _indexDataStore.BeginUpdateInstancesAsync( var dicomDataset = new DicomDataset(); dicomDataset.AddOrUpdate(DicomTag.PatientName, "FirstName_NewLastName"); - await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List()); + await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List(), Array.Empty()); var instanceMetadataList = (await _instanceStore.GetInstanceIdentifierWithPropertiesAsync(Partition.Default, studyInstanceUID1)).ToList(); @@ -337,7 +338,7 @@ public async Task GivenInstances_WhenBulkUpdateInstancesInAStudyAndFilePropertie var dicomDataset = new DicomDataset(); dicomDataset.AddOrUpdate(DicomTag.PatientName, "FirstName_NewLastName"); - await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List() { CreateExpectedInstance(updatedInstance) }); + await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List() { CreateExpectedInstance(updatedInstance) }, Array.Empty()); var instanceMetadataList = (await _instanceStore.GetInstanceIdentifierWithPropertiesAsync(Partition.Default, studyInstanceUID1)).ToList(); Assert.Single(instanceMetadataList); @@ -359,7 +360,7 @@ public async Task GivenInstances_WhenBulkUpdateInstancesInAStudyAndFilePropertie IReadOnlyList secondUpdatedInstanceMetadata = await _indexDataStore.BeginUpdateInstancesAsync(new Partition(originalInstance.PartitionKey, Partition.UnknownName), studyInstanceUID1); Assert.Single(secondUpdatedInstanceMetadata); var secondUpdatedInstance = secondUpdatedInstanceMetadata[0]; - await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List() { CreateExpectedInstance(secondUpdatedInstance) }); + await _indexDataStore.EndUpdateInstanceAsync(Partition.DefaultKey, studyInstanceUID1, dicomDataset, new List() { CreateExpectedInstance(secondUpdatedInstance) }, Array.Empty()); var retrievedInstances = (await _instanceStore.GetInstanceIdentifierWithPropertiesAsync(Partition.Default, studyInstanceUID1)).ToList(); Assert.Single(retrievedInstances); diff --git a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs index 046117cda1..4751130a31 100644 --- a/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs +++ b/test/Microsoft.Health.Dicom.Tests.Integration/Persistence/SqlDataStoreTestsFixture.cs @@ -122,6 +122,7 @@ internal SqlDataStoreTestsFixture(string databaseName, SchemaInformation schemaI new SqlIndexDataStoreV46(SqlConnectionWrapperFactory), new SqlIndexDataStoreV47(SqlConnectionWrapperFactory), new SqlIndexDataStoreV49(SqlConnectionWrapperFactory), + new SqlIndexDataStoreV50(SqlConnectionWrapperFactory), }), NullLogger.Instance); diff --git a/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/UpdateInstanceTests.cs b/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/UpdateInstanceTests.cs index e1ee4f60f8..ddbab8b096 100644 --- a/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/UpdateInstanceTests.cs +++ b/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/UpdateInstanceTests.cs @@ -11,6 +11,8 @@ using EnsureThat; using FellowOakDicom; using Microsoft.Health.Dicom.Client; +using Microsoft.Health.Dicom.Client.Models; +using Microsoft.Health.Dicom.Core.Extensions; using Microsoft.Health.Dicom.Tests.Common; using Microsoft.Health.Dicom.Web.Tests.E2E.Common; using Microsoft.Health.Operations; @@ -25,12 +27,14 @@ namespace Microsoft.Health.Dicom.Web.Tests.E2E.Rest; public class UpdateInstanceTests : IClassFixture>, IAsyncLifetime { private readonly IDicomWebClient _client; + private readonly DicomTagsManager _tagManager; private readonly DicomInstancesManager _instancesManager; public UpdateInstanceTests(WebJobsIntegrationTestFixture fixture) { EnsureArg.IsNotNull(fixture, nameof(fixture)); _client = fixture.GetDicomWebClient(); + _tagManager = new DicomTagsManager(_client); _instancesManager = new DicomInstancesManager(_client); } @@ -101,10 +105,61 @@ public async Task GivenInstanceUpdated_WhenDeleting_ThenItShouldDeleteBothOrigin await VerifyDeleteStudyAsync(studyInstanceUid1, dicomFile1, requestOriginalVersion: true); } - private async Task UpdateStudyAsync(string studyInstanceUid, string expectedPatientName) + [Fact] + public async Task WhenUpdatingDicomMetadataWithExtendedQueryTagForASingleStudy_ThenItShouldUpdateCorrectly() + { + DicomTag ageTag = DicomTag.PatientAge; + DicomTag patientSexTag = DicomTag.PatientSex; + string tagValue = "053Y"; + + // Try to delete these extended query tags. + await _tagManager.DeleteExtendedQueryTagAsync(ageTag.GetPath()); + + string studyInstanceUid = TestUidGenerator.Generate(); + + DicomFile dicomFile1 = Samples.CreateRandomDicomFile(studyInstanceUid); + dicomFile1.Dataset.Add(ageTag, tagValue); + + DicomFile dicomFile2 = Samples.CreateRandomDicomFile(studyInstanceUid); + dicomFile2.Dataset.Add(ageTag, tagValue); + + DicomFile dicomFile3 = Samples.CreateRandomDicomFile(studyInstanceUid); + dicomFile3.Dataset.Add(ageTag, tagValue); + + // Upload files + Assert.True((await _instancesManager.StoreStudyAsync(new[] { dicomFile1, dicomFile2, dicomFile3 })).IsSuccessStatusCode); + + // Add extended query tag + Assert.Equal( + OperationStatus.Succeeded, + await _tagManager.AddTagsAsync( + new AddExtendedQueryTagEntry { Path = ageTag.GetPath(), VR = ageTag.GetDefaultVR().Code, Level = QueryTagLevel.Study }, + new AddExtendedQueryTagEntry { Path = patientSexTag.GetPath(), VR = patientSexTag.GetDefaultVR().Code, Level = QueryTagLevel.Study })); + + // Update study + await UpdateStudyAsync(studyInstanceUid, "New^PatientName", "054Y", "M"); + + // Verify using QIDO + DicomWebAsyncEnumerableResponse queryResponse = await _client.QueryInstancesAsync($"{ageTag.GetPath()}=054Y&{patientSexTag.GetPath()}=M"); + DicomDataset[] instances = await queryResponse.ToArrayAsync(); + Assert.Equal(3, instances.Length); + } + + private async Task UpdateStudyAsync(string studyInstanceUid, string expectedPatientName, string age = null, string patientSex = null) { var datasetToUpdate = new DicomDataset(); datasetToUpdate.AddOrUpdate(DicomTag.PatientName, expectedPatientName); + + if (!string.IsNullOrEmpty(age)) + { + datasetToUpdate.AddOrUpdate(DicomTag.PatientAge, age); + } + + if (!string.IsNullOrEmpty(patientSex)) + { + datasetToUpdate.AddOrUpdate(DicomTag.PatientSex, patientSex); + } + Assert.Equal(OperationStatus.Succeeded, await _instancesManager.UpdateStudyAsync(new List { studyInstanceUid }, datasetToUpdate)); }