diff --git a/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/ChangeFeedProcessorTests.cs b/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/ChangeFeedProcessorTests.cs index 138adce021..af4438d391 100644 --- a/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/ChangeFeedProcessorTests.cs +++ b/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/ChangeFeedProcessorTests.cs @@ -8,6 +8,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using FellowOakDicom; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Microsoft.Health.Core.Internal; @@ -280,8 +281,39 @@ public async Task WhenThrowTimeoutRejectedException_ExceptionNotThrown() await _fhirTransactionPipeline.Received(1).ProcessAsync(changeFeeds1[0], DefaultCancellationToken); } + [Theory] + [InlineData(nameof(DicomTagException))] + [InlineData(nameof(MissingRequiredDicomTagException))] + public async Task WhenThrowDicomTagException_ExceptionNotThrown(string exception) + { + ChangeFeedEntry[] changeFeeds1 = new[] + { + ChangeFeedGenerator.Generate(1), + }; + + // Arrange + _changeFeedRetrieveService.RetrieveLatestSequenceAsync(DefaultCancellationToken).Returns(1L); + + _changeFeedRetrieveService.RetrieveChangeFeedAsync(0, ChangeFeedProcessor.DefaultLimit, DefaultCancellationToken).Returns(changeFeeds1); + _changeFeedRetrieveService.RetrieveChangeFeedAsync(1, ChangeFeedProcessor.DefaultLimit, DefaultCancellationToken).Returns(Array.Empty()); + + _fhirTransactionPipeline.When(pipeline => pipeline.ProcessAsync(Arg.Any(), Arg.Any())).Do(pipeline => { ThrowDicomTagException(exception); }); + + // Act + await ExecuteProcessAsync(); + + // Assert + await _changeFeedRetrieveService.Received(2).RetrieveLatestSequenceAsync(DefaultCancellationToken); + + await _changeFeedRetrieveService.ReceivedWithAnyArgs(2).RetrieveChangeFeedAsync(default, default, default); + await _changeFeedRetrieveService.Received(1).RetrieveChangeFeedAsync(0, ChangeFeedProcessor.DefaultLimit, DefaultCancellationToken); + await _changeFeedRetrieveService.Received(1).RetrieveChangeFeedAsync(1, ChangeFeedProcessor.DefaultLimit, DefaultCancellationToken); + + await _fhirTransactionPipeline.Received(1).ProcessAsync(changeFeeds1[0], DefaultCancellationToken); + } + [Fact] - public async Task WhenThrowDicomTagException_ExceptionNotThrown() + public async Task WhenMissingRequiredDicomTagException_ExceptionNotThrown() { ChangeFeedEntry[] changeFeeds1 = new[] { @@ -294,7 +326,7 @@ public async Task WhenThrowDicomTagException_ExceptionNotThrown() _changeFeedRetrieveService.RetrieveChangeFeedAsync(0, ChangeFeedProcessor.DefaultLimit, DefaultCancellationToken).Returns(changeFeeds1); _changeFeedRetrieveService.RetrieveChangeFeedAsync(1, ChangeFeedProcessor.DefaultLimit, DefaultCancellationToken).Returns(Array.Empty()); - _fhirTransactionPipeline.When(pipeline => pipeline.ProcessAsync(Arg.Any(), Arg.Any())).Do(pipeline => { throw new DicomTagException("exception"); }); + _fhirTransactionPipeline.When(pipeline => pipeline.ProcessAsync(Arg.Any(), Arg.Any())).Do(pipeline => { throw new MissingRequiredDicomTagException(nameof(DicomTag.PatientID)); }); // Act await ExecuteProcessAsync(); @@ -463,4 +495,16 @@ private async Task ExecuteProcessAsync(TimeSpan? pollIntervalDuringCatchup = nul await _changeFeedProcessor.ProcessAsync(pollIntervalDuringCatchup.Value, DefaultCancellationToken); } + + private static void ThrowDicomTagException(string exception) + { + if (exception.Equals(nameof(DicomTagException))) + { + throw new DicomTagException("exception"); + } + else if (exception.Equals(nameof(MissingRequiredDicomTagException))) + { + throw new MissingRequiredDicomTagException(nameof(DicomTag.PatientID)); + } + } } diff --git a/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/FhirTransaction/Patient/PatientPipelineStepTests.cs b/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/FhirTransaction/Patient/PatientPipelineStepTests.cs index be0548652a..e6a10a7be3 100644 --- a/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/FhirTransaction/Patient/PatientPipelineStepTests.cs +++ b/converter/dicom-cast/src/Microsoft.Health.DicomCast.Core.UnitTests/Features/Worker/FhirTransaction/Patient/PatientPipelineStepTests.cs @@ -54,13 +54,24 @@ public async Task GivenNullMetadata_WhenRequestIsPrepared_ThenItShouldNotCreateE } [Fact] - public async Task GivenMissingPatientId_WhenPreparingTheRequest_ThenMissingRequiredDicomTagExceptionShouldBeThrown() + public async Task GivenMissingPatientIdTag_WhenPreparingTheRequest_ThenMissingRequiredDicomTagExceptionShouldBeThrown() { var context = new FhirTransactionContext(ChangeFeedGenerator.Generate(metadata: new DicomDataset())); await Assert.ThrowsAsync(() => _patientPipeline.PrepareRequestAsync(context, DefaultCancellationToken)); } + [Fact] + public async Task GivenPatientIdTagPresentWithMissingValue_WhenPreparingTheRequest_ThenMissingRequiredDicomTagExceptionShouldBeThrown() + { + DicomDataset dicomDataset = new DicomDataset(); + dicomDataset.AddOrUpdate(DicomTag.PatientID, new string[] { null }); + + var context = new FhirTransactionContext(ChangeFeedGenerator.Generate(metadata: dicomDataset)); + + await Assert.ThrowsAsync(() => _patientPipeline.PrepareRequestAsync(context, DefaultCancellationToken)); + } + [Fact] public async Task GivenNoExistingPatient_WhenRequestIsPrepared_ThenCorrectEntryComponentShouldBeCreated() { diff --git a/docs/concepts/bulk-update.md b/docs/concepts/bulk-update.md index ebbc21ab9a..5818ca102c 100644 --- a/docs/concepts/bulk-update.md +++ b/docs/concepts/bulk-update.md @@ -211,3 +211,5 @@ There is no change in other APIs. All the other APIs supports only latest versio > Only one update operation can be performed at a time. > There is no way to delete only the latest version or revert back to original version. + +> We do not support updating any field from non-null to a null value. diff --git a/docs/concepts/extended-query-tags.md b/docs/concepts/extended-query-tags.md index d33eb9d519..af847682a7 100644 --- a/docs/concepts/extended-query-tags.md +++ b/docs/concepts/extended-query-tags.md @@ -73,6 +73,8 @@ The following VR types are supported: > Only the first value will be indexed of a single valued data element that incorrectly has multiple values. +> We do not index extended query tags if the value is null or empty. + #### Responses | Name | Type | Description | diff --git a/docs/resources/v2-conformance-statement.md b/docs/resources/v2-conformance-statement.md index 00e8eb836e..3e8daf920c 100644 --- a/docs/resources/v2-conformance-statement.md +++ b/docs/resources/v2-conformance-statement.md @@ -73,7 +73,7 @@ The following DICOM elements are required to be present in every DICOM file atte - SOPClassUID - PatientID -> Note: All identifiers must be between 1 and 64 characters long, and only contain alpha numeric characters or the following special characters: `.`, `-`. PatientID is validated based on its LO VR type. +> Note: All identifiers must be between 1 and 64 characters long, and only contain alpha numeric characters or the following special characters: `.`, `-`. PatientID continues to be a required tag and can have the value as null in the input. PatientID is validated based on its LO VR type. Each file stored must have a unique combination of StudyInstanceUID, SeriesInstanceUID and SopInstanceUID. The warning code `45070` will be returned if a file with the same identifiers already exists. @@ -454,6 +454,8 @@ We support searching on below attributes and search type. | ManufacturerModelName | | X | X | X | X | | | SOPInstanceUID | | | X | | X | X | +> Note: We do not support searching using empty string for any attributes. + #### Search Matching We support below matching types. @@ -877,6 +879,8 @@ We support searching on these attributes: | ProcedureStepState | | StudyInstanceUID | +> Note: We do not support searching using empty string for any attributes. + #### Search Matching We support these matching types: diff --git a/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV1.cs b/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV1.cs index 38f077d04f..99484fb476 100644 --- a/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV1.cs +++ b/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV1.cs @@ -80,8 +80,6 @@ public async Task GivenFullValidation_WhenPatientIDInvalid_ExpectErrorProduced() """does not validate VR LO: value contains invalid character""", result.InvalidTagErrors[DicomTag.PatientID].Error); minimumValidator.DidNotReceive().Validate(Arg.Any()); - - minimumValidator.DidNotReceive().Validate(Arg.Any()); } [Fact] @@ -120,6 +118,71 @@ public async Task GivenPartialValidation_WhenPatientIDInvalid_ExpectTagValidated result.InvalidTagErrors[DicomTag.PatientID].Error); } + [Theory] + [InlineData("")] + [InlineData(null)] + public async Task GivenPatientIdEmpty_WhenValidated_ExpectErrorProduced(string value) + { + var featureConfigurationEnableFullValidation = Substitute.For>(); + featureConfigurationEnableFullValidation.Value.Returns(new FeatureConfiguration { }); + + DicomDataset dicomDataset = Samples.CreateRandomInstanceDataset( + validateItems: false, + patientId: value); + + if (value == null) + dicomDataset.AddOrUpdate(DicomTag.PatientID, new string[] { null }); + + IElementMinimumValidator minimumValidator = Substitute.For(); + + var dicomDatasetValidator = new StoreDatasetValidator( + featureConfigurationEnableFullValidation, + minimumValidator, + _queryTagService, + _storeMeter, + _dicomRequestContextAccessor, + NullLogger.Instance); + + var result = await dicomDatasetValidator.ValidateAsync( + dicomDataset, + null, + new CancellationToken()); + + Assert.Contains( + "DICOM100: (0010,0020) - The required tag '(0010,0020)' is missing.", + result.InvalidTagErrors[DicomTag.PatientID].Error); + } + + [Fact] + public async Task GivenPatientIdTagNotPresent_WhenValidated_ExpectErrorProduced() + { + var featureConfigurationEnableFullValidation = Substitute.For>(); + featureConfigurationEnableFullValidation.Value.Returns(new FeatureConfiguration { }); + + DicomDataset dicomDataset = Samples.CreateRandomInstanceDataset( + validateItems: false); + dicomDataset.Remove(DicomTag.PatientID); + + IElementMinimumValidator minimumValidator = Substitute.For(); + + var dicomDatasetValidator = new StoreDatasetValidator( + featureConfigurationEnableFullValidation, + minimumValidator, + _queryTagService, + _storeMeter, + _dicomRequestContextAccessor, + NullLogger.Instance); + + var result = await dicomDatasetValidator.ValidateAsync( + dicomDataset, + null, + new CancellationToken()); + + Assert.Contains( + "DICOM100: (0010,0020) - The required tag '(0010,0020)' is missing.", + result.InvalidTagErrors[DicomTag.PatientID].Error); + } + [Fact] public async Task GivenDicomTagWithDifferentVR_WhenValidated_ThenShouldReturnInvalidEntries() { diff --git a/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV2.cs b/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV2.cs index e9a9310c81..faccac66e7 100644 --- a/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV2.cs +++ b/src/Microsoft.Health.Dicom.Core.UnitTests/Features/Store/StoreDatasetValidatorTestsV2.cs @@ -189,6 +189,50 @@ public async Task GivenV2Enabled_WhenPatientIDPAddedWithComma_ExpectTagValidated Assert.Empty(result.InvalidTagErrors); } + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData(null)] + public async Task GivenV2Enabled_WhenPatientIDTagPresentAndValueEmpty_ExpectTagValidatedAndWarningsProduced(string value) + { + DicomDataset dicomDataset = Samples.CreateRandomInstanceDataset( + validateItems: false, + patientId: value); + + if (value == null) + dicomDataset.AddOrUpdate(DicomTag.PatientID, new string[] { null }); + + var result = await _dicomDatasetValidator.ValidateAsync( + dicomDataset, + null, + new CancellationToken()); + + Assert.True(result.InvalidTagErrors.Any()); + Assert.Single(result.InvalidTagErrors); + Assert.False(result.HasCoreTagError); + Assert.False(result.InvalidTagErrors[DicomTag.PatientID].IsRequiredCoreTag); + Assert.Equal("DICOM100: (0010,0020) - The required tag '(0010,0020)' is missing.", result.InvalidTagErrors[DicomTag.PatientID].Error); + } + + [Fact] + public async Task GivenV2Enabled_WhenPatientIDTagNotPresent_ExpectErrorProduced() + { + DicomDataset dicomDataset = Samples.CreateRandomInstanceDataset( + validateItems: false); + dicomDataset.Remove(DicomTag.PatientID); + + var result = await _dicomDatasetValidator.ValidateAsync( + dicomDataset, + null, + new CancellationToken()); + + Assert.True(result.InvalidTagErrors.Any()); + Assert.Single(result.InvalidTagErrors); + Assert.True(result.HasCoreTagError); + Assert.True(result.InvalidTagErrors[DicomTag.PatientID].IsRequiredCoreTag); + Assert.Equal("DICOM100: (0010,0020) - The required tag '(0010,0020)' is missing.", result.InvalidTagErrors[DicomTag.PatientID].Error); + } + [Fact] public async Task GivenV2Enabled_WhenNonRequiredTagNull_ExpectTagValidatedAndNoErrorProduced() { diff --git a/src/Microsoft.Health.Dicom.Core/Features/Store/StoreDatasetValidator.cs b/src/Microsoft.Health.Dicom.Core/Features/Store/StoreDatasetValidator.cs index 13355c02d7..7f1b5a959b 100644 --- a/src/Microsoft.Health.Dicom.Core/Features/Store/StoreDatasetValidator.cs +++ b/src/Microsoft.Health.Dicom.Core/Features/Store/StoreDatasetValidator.cs @@ -44,6 +44,14 @@ public class StoreDatasetValidator : IStoreDatasetValidator DicomTag.SOPClassUID, }; + private static readonly IReadOnlySet RequiredV2CoreTags = new HashSet() + { + DicomTag.StudyInstanceUID, + DicomTag.SeriesInstanceUID, + DicomTag.SOPInstanceUID, + DicomTag.SOPClassUID, + }; + public StoreDatasetValidator( IOptions featureConfiguration, IElementMinimumValidator minimumValidator, @@ -74,10 +82,12 @@ public async Task ValidateAsync( EnsureArg.IsNotNull(dicomDataset, nameof(dicomDataset)); var validationResultBuilder = new StoreValidationResultBuilder(); + bool isV2OrAbove = EnableDropMetadata(_dicomRequestContextAccessor.RequestContext.Version); try { ValidateRequiredCoreTags(dicomDataset, requiredStudyInstanceUid); + ValidatePatientId(dicomDataset, isV2OrAbove); } catch (DatasetValidationException ex) when (ex.FailureCode == FailureReasonCodes.ValidationFailure) { @@ -89,7 +99,7 @@ public async Task ValidateAsync( { ValidateAllItems(dicomDataset, validationResultBuilder); } - else if (EnableDropMetadata(_dicomRequestContextAccessor.RequestContext.Version)) + else if (isV2OrAbove) { await ValidateAllItemsWithLeniencyAsync(dicomDataset, validationResultBuilder); } @@ -107,16 +117,35 @@ public async Task ValidateAsync( return validationResultBuilder.Build(); } - private static void ValidateRequiredCoreTags(DicomDataset dicomDataset, string requiredStudyInstanceUid) + private static void ValidatePatientId(DicomDataset dicomDataset, bool isV2OrAbove) { // Ensure required tags are present. - EnsureRequiredTagIsPresent(DicomTag.PatientID); - EnsureRequiredTagIsPresent(DicomTag.SOPClassUID); + if (!isV2OrAbove) + { + EnsureRequiredTagIsPresentWithValue(dicomDataset, DicomTag.PatientID); + } + else + { + if (!dicomDataset.Contains(DicomTag.PatientID)) + { + throw new DatasetValidationException( + FailureReasonCodes.ValidationFailure, + string.Format( + CultureInfo.InvariantCulture, + DicomCoreResource.MissingRequiredTag, + DicomTag.PatientID), DicomTag.PatientID); + } + } + } + + private static void ValidateRequiredCoreTags(DicomDataset dicomDataset, string requiredStudyInstanceUid) + { + EnsureRequiredTagIsPresentWithValue(dicomDataset, DicomTag.SOPClassUID); // The format of the identifiers will be validated by fo-dicom. - string studyInstanceUid = EnsureRequiredTagIsPresent(DicomTag.StudyInstanceUID); - string seriesInstanceUid = EnsureRequiredTagIsPresent(DicomTag.SeriesInstanceUID); - string sopInstanceUid = EnsureRequiredTagIsPresent(DicomTag.SOPInstanceUID); + string studyInstanceUid = EnsureRequiredTagIsPresentWithValue(dicomDataset, DicomTag.StudyInstanceUID); + string seriesInstanceUid = EnsureRequiredTagIsPresentWithValue(dicomDataset, DicomTag.SeriesInstanceUID); + string sopInstanceUid = EnsureRequiredTagIsPresentWithValue(dicomDataset, DicomTag.SOPInstanceUID); // Ensure the StudyInstanceUid != SeriesInstanceUid != sopInstanceUid if (studyInstanceUid == seriesInstanceUid || @@ -142,21 +171,21 @@ private static void ValidateRequiredCoreTags(DicomDataset dicomDataset, string r DicomCoreResource.MismatchStudyInstanceUid, DicomTag.StudyInstanceUID); } + } - string EnsureRequiredTagIsPresent(DicomTag dicomTag) + private static string EnsureRequiredTagIsPresentWithValue(DicomDataset dicomDataset, DicomTag dicomTag) + { + if (dicomDataset.TryGetSingleValue(dicomTag, out string value)) { - if (dicomDataset.TryGetSingleValue(dicomTag, out string value)) - { - return value; - } - - throw new DatasetValidationException( - FailureReasonCodes.ValidationFailure, - string.Format( - CultureInfo.InvariantCulture, - DicomCoreResource.MissingRequiredTag, - dicomTag.ToString()), dicomTag); + return value; } + + throw new DatasetValidationException( + FailureReasonCodes.ValidationFailure, + string.Format( + CultureInfo.InvariantCulture, + DicomCoreResource.MissingRequiredTag, + dicomTag.ToString()), dicomTag); } private async Task ValidateIndexedItemsAsync( @@ -306,7 +335,7 @@ private void GenerateValidationWarnings(DicomDataset dicomDataset, StoreValidati de.Validate(); } } - catch (DicomValidationException ex) + catch (Exception ex) when (ex is DicomValidationException || ex is DatasetValidationException) { validationResultBuilder.Add(ex, item.Tag, isCoreTag: false); if (item.Tag.IsPrivate) @@ -326,6 +355,16 @@ private void GenerateValidationWarnings(DicomDataset dicomDataset, StoreValidati private void ValidateStringItemWithLeniency(string value, DicomElement de, IReadOnlyCollection queryTags) { + if (de.Tag == DicomTag.PatientID && string.IsNullOrWhiteSpace(value)) + { + throw new DatasetValidationException( + FailureReasonCodes.ValidationFailure, + string.Format( + CultureInfo.InvariantCulture, + DicomCoreResource.MissingRequiredTag, + DicomTag.PatientID), DicomTag.PatientID); + } + if (value != null && value.EndsWith('\0')) { ValidateWithoutNullPadding(value, de, queryTags); @@ -351,9 +390,9 @@ private static bool IsIndexableTag(IReadOnlyCollection queryTags, Dico /// /// tag to check if it is required /// whether or not tag is required - public static bool IsCoreTag(DicomTag tag) + public static bool IsV2CoreTag(DicomTag tag) { - return RequiredCoreTags.Contains(tag); + return RequiredV2CoreTags.Contains(tag); } private void ValidateWithoutNullPadding(string value, DicomElement de, IReadOnlyCollection queryTags) diff --git a/src/Microsoft.Health.Dicom.Core/Features/Store/StoreService.cs b/src/Microsoft.Health.Dicom.Core/Features/Store/StoreService.cs index fb89a5137d..78f6cc4c1f 100644 --- a/src/Microsoft.Health.Dicom.Core/Features/Store/StoreService.cs +++ b/src/Microsoft.Health.Dicom.Core/Features/Store/StoreService.cs @@ -264,7 +264,7 @@ private void DropInvalidMetadata(StoreValidationResult storeValidatorResult, Dic var identifier = dicomDataset.ToInstanceIdentifier(partition); foreach ((DicomTag tag, StoreErrorResult result) in storeValidatorResult.InvalidTagErrors) { - if (!StoreDatasetValidator.IsCoreTag(tag)) + if (!StoreDatasetValidator.IsV2CoreTag(tag)) { // drop invalid metadata if not a core tag dicomDataset.Remove(tag); diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/51.diff.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/51.diff.sql new file mode 100644 index 0000000000..ded1927f55 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/51.diff.sql @@ -0,0 +1,257 @@ +SET XACT_ABORT ON + +BEGIN TRANSACTION +GO +/************************************************************* + Stored procedure for adding an instance. +**************************************************************/ +-- +-- STORED PROCEDURE +-- AddInstanceV6 +-- +-- FIRST SCHEMA VERSION +-- 6 +-- +-- DESCRIPTION +-- Adds a DICOM instance, now with partition. +-- +-- PARAMETERS +-- @partitionKey +-- * The system identified of the data partition. +-- @studyInstanceUid +-- * The study instance UID. +-- @seriesInstanceUid +-- * The series instance UID. +-- @sopInstanceUid +-- * The SOP instance UID. +-- @patientId +-- * The Id of the patient. +-- @patientName +-- * The name of the patient. +-- @referringPhysicianName +-- * The referring physician name. +-- @studyDate +-- * The study date. +-- @studyDescription +-- * The study description. +-- @accessionNumber +-- * The accession number associated for the study. +-- @modality +-- * The modality associated for the series. +-- @performedProcedureStepStartDate +-- * The date when the procedure for the series was performed. +-- @stringExtendedQueryTags +-- * String extended query tag data +-- @longExtendedQueryTags +-- * Long extended query tag data +-- @doubleExtendedQueryTags +-- * Double extended query tag data +-- @dateTimeExtendedQueryTags +-- * DateTime extended query tag data +-- @personNameExtendedQueryTags +-- * PersonName extended query tag data +-- @initialStatus +-- * Initial status of the row +-- @transferSyntaxUid +-- * Instance transfer syntax UID + +-- RETURN VALUE +-- The watermark (version). +------------------------------------------------------------------------ +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 + + -- We turn off XACT_ABORT so that we can rollback and retry the INSERT/UPDATE into the study table on failure + SET XACT_ABORT OFF + + -- The transaction is wrapped in a try...catch block in case the INSERT into the study table fails + BEGIN TRY + + BEGIN TRANSACTION + + DECLARE @currentDate DATETIME2(7) = SYSUTCDATETIME() + DECLARE @existingStatus TINYINT + DECLARE @newWatermark BIGINT + DECLARE @studyKey BIGINT + DECLARE @seriesKey BIGINT + DECLARE @instanceKey BIGINT + + SELECT @existingStatus = Status + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + + IF @@ROWCOUNT <> 0 + -- The instance already exists. Set the state = @existingStatus to indicate what state it is in. + THROW 50409, 'Instance already exists', @existingStatus; + + -- The instance does not exist, insert it. + SET @newWatermark = NEXT VALUE FOR dbo.WatermarkSequence + SET @instanceKey = NEXT VALUE FOR dbo.InstanceKeySequence + + -- Insert Study + -- If we fail to INSERT, we instead must UPDATE the newly added value + 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 + + -- While we could obtain a HOLDLOCK on the table, we optimistically obtain an UPDLOCK instead to avoid the range lock on the study table + IF ERROR_NUMBER() = 2601 + BEGIN + + SELECT @studyKey = StudyKey + FROM dbo.Study WITH(UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + + -- Latest wins + UPDATE dbo.Study + SET PatientId = (CASE WHEN @patientId IS NOT NULL AND @patientId <> '' + THEN @patientId + ELSE + PatientId + END), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + + END + ELSE + THROW + + END CATCH + ELSE + BEGIN + -- Latest wins + UPDATE dbo.Study + SET PatientId = (CASE WHEN @patientId IS NOT NULL AND @patientId <> '' + THEN @patientId + ELSE + PatientId + END), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + END + + -- Insert Series + 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 + -- Latest wins + 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 Instance + 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 + + EXEC 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 TRANSACTION; + + THROW + + END CATCH +END +GO + +COMMIT TRANSACTION diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/51.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/51.sql new file mode 100644 index 0000000000..217e5f38e7 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Migrations/51.sql @@ -0,0 +1,3331 @@ + +/************************************************************************************************* + 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 = (CASE WHEN @patientId IS NOT NULL + AND @patientId <> '' THEN @patientId ELSE PatientId END), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + ELSE + THROW; + END CATCH + ELSE + BEGIN + UPDATE dbo.Study + SET PatientId = (CASE WHEN @patientId IS NOT NULL + AND @patientId <> '' THEN @patientId ELSE PatientId END), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), + StudyDate = ISNULL(@studyDate, StudyDate), + StudyDescription = ISNULL(@studyDescription, StudyDescription), + AccessionNumber = ISNULL(@accessionNumber, AccessionNumber) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey; + END + SELECT @seriesKey = SeriesKey + FROM dbo.Series WITH (UPDLOCK) + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = @seriesInstanceUid + AND PartitionKey = @partitionKey; + IF @@ROWCOUNT = 0 + BEGIN + SET @seriesKey = NEXT VALUE FOR dbo.SeriesKeySequence; + INSERT INTO dbo.Series (PartitionKey, StudyKey, SeriesKey, SeriesInstanceUid, Modality, PerformedProcedureStepStartDate, ManufacturerModelName) + VALUES (@partitionKey, @studyKey, @seriesKey, @seriesInstanceUid, @modality, @performedProcedureStepStartDate, @manufacturerModelName); + END + ELSE + BEGIN + UPDATE dbo.Series + SET Modality = ISNULL(@modality, Modality), + PerformedProcedureStepStartDate = ISNULL(@performedProcedureStepStartDate, PerformedProcedureStepStartDate), + ManufacturerModelName = ISNULL(@manufacturerModelName, ManufacturerModelName) + WHERE SeriesKey = @seriesKey + AND StudyKey = @studyKey + AND PartitionKey = @partitionKey; + END + INSERT INTO dbo.Instance (PartitionKey, StudyKey, SeriesKey, InstanceKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, Status, LastStatusUpdatedDate, CreatedDate, TransferSyntaxUid) + VALUES (@partitionKey, @studyKey, @seriesKey, @instanceKey, @studyInstanceUid, @seriesInstanceUid, @sopInstanceUid, @newWatermark, @initialStatus, @currentDate, @currentDate, @transferSyntaxUid); + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, @seriesKey, @instanceKey, @newWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @newWatermark; + COMMIT TRANSACTION; + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK; + THROW; + END CATCH +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddPartition +@partitionName VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @createdDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @partitionKey AS INT; + SELECT @partitionKey = PartitionKey + FROM dbo.Partition + WHERE PartitionName = @partitionName; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Partition already exists', 1; + SET @partitionKey = NEXT VALUE FOR dbo.PartitionKeySequence; + INSERT INTO dbo.Partition (PartitionKey, PartitionName, CreatedDate) + VALUES (@partitionKey, @partitionName, @createdDate); + SELECT @partitionKey, + @partitionName, + @createdDate; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddWorkitem +@partitionKey INT, @workitemUid VARCHAR (64), @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @workitemKey AS BIGINT; + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Workitem already exists', 1; + SET @workitemKey = NEXT VALUE FOR dbo.WorkitemKeySequence; + INSERT INTO dbo.Workitem (WorkitemKey, PartitionKey, WorkitemUid, Status, CreatedDate, LastStatusUpdatedDate) + VALUES (@workitemKey, @partitionKey, @workitemUid, @initialStatus, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexWorkitemInstanceCore @partitionKey, @workitemKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + SELECT @workitemKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AddWorkitemV11 +@partitionKey INT, @workitemUid VARCHAR (64), @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY, @initialStatus TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @watermark AS BIGINT; + DECLARE @workitemKey AS BIGINT; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT <> 0 + THROW 50409, 'Workitem already exists', 1; + SET @workitemKey = NEXT VALUE FOR dbo.WorkitemKeySequence; + SET @watermark = NEXT VALUE FOR dbo.WorkitemWatermarkSequence; + INSERT INTO dbo.Workitem (WorkitemKey, PartitionKey, WorkitemUid, Status, Watermark, CreatedDate, LastStatusUpdatedDate) + VALUES (@workitemKey, @partitionKey, @workitemUid, @initialStatus, @watermark, @currentDate, @currentDate); + BEGIN TRY + EXECUTE dbo.IIndexWorkitemInstanceCore @partitionKey, @workitemKey, @stringExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + COMMIT TRANSACTION; + SELECT @workitemKey, + @watermark; +END + +GO +CREATE OR ALTER PROCEDURE dbo.AssignReindexingOperation +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY, @operationId UNIQUEIDENTIFIER, @returnIfCompleted BIT=0 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + MERGE INTO dbo.ExtendedQueryTagOperation WITH (HOLDLOCK) + AS XQTO + USING (SELECT input.TagKey + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT WITH (HOLDLOCK) + ON input.TagKey = XQT.TagKey + WHERE TagStatus = 0) AS tags ON XQTO.TagKey = tags.TagKey + WHEN NOT MATCHED THEN INSERT (TagKey, OperationId) VALUES (tags.TagKey, @operationId); + SELECT XQT.TagKey, + TagPath, + TagVR, + TagPrivateCreator, + TagLevel, + TagStatus, + QueryStatus, + ErrorCount + FROM @extendedQueryTagKeys AS input + INNER JOIN + dbo.ExtendedQueryTag AS XQT WITH (HOLDLOCK) + ON input.TagKey = XQT.TagKey + LEFT OUTER JOIN + dbo.ExtendedQueryTagOperation AS XQTO WITH (HOLDLOCK) + ON XQT.TagKey = XQTO.TagKey + WHERE (@returnIfCompleted = 1 + AND TagStatus = 1) + OR (OperationId = @operationId + AND TagStatus = 0); + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstance +@partitionKey INT, @watermarkTableType dbo.WatermarkTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE i + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + WHERE Status = 1; + COMMIT TRANSACTION; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + i.Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance AS i + INNER JOIN + @watermarkTableType AS input + ON i.Watermark = input.Watermark + AND i.PartitionKey = @partitionKey + WHERE Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstanceV33 +@partitionKey INT, @studyInstanceUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; + COMMIT TRANSACTION; + SELECT StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + TransferSyntaxUid, + HasFrameMetadata, + OriginalWatermark, + NewWatermark + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.BeginUpdateInstanceV46 +@partitionKey INT, @studyInstanceUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE dbo.Instance + SET NewWatermark = NEXT VALUE FOR dbo.WatermarkSequence + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1; + COMMIT TRANSACTION; + SELECT i.StudyInstanceUid, + i.SeriesInstanceUid, + i.SopInstanceUid, + i.Watermark, + i.TransferSyntaxUid, + i.HasFrameMetadata, + i.OriginalWatermark, + i.NewWatermark, + f.FilePath, + f.ETag + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS f + ON f.InstanceKey = i.InstanceKey + AND f.Watermark = i.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.Status = 1; +END + +GO +CREATE OR ALTER PROCEDURE dbo.CompleteReindexing +@extendedQueryTagKeys dbo.ExtendedQueryTagKeyTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + UPDATE XQT + SET TagStatus = 1 + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @extendedQueryTagKeys AS input + ON XQT.TagKey = input.TagKey + WHERE TagStatus = 0; + DELETE XQTO + OUTPUT DELETED.TagKey + FROM dbo.ExtendedQueryTagOperation AS XQTO + INNER JOIN + dbo.ExtendedQueryTag AS XQT + ON XQTO.TagKey = XQT.TagKey + INNER JOIN + @extendedQueryTagKeys AS input + ON XQT.TagKey = input.TagKey + WHERE TagStatus = 1; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteDeletedInstance +@studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT +AS +SET NOCOUNT ON; +DELETE dbo.DeletedInstance +WHERE StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteDeletedInstanceV6 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64), @sopInstanceUid VARCHAR (64), @watermark BIGINT +AS +SET NOCOUNT ON; +DELETE dbo.DeletedInstance +WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = @seriesInstanceUid + AND SopInstanceUid = @sopInstanceUid + AND Watermark = @watermark; + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTag +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagStatus AS TINYINT; + DECLARE @tagKey AS INT; + SELECT @tagKey = TagKey, + @tagStatus = TagStatus + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + IF @tagStatus = 2 + THROW 50412, 'extended query tag is not in Ready or Adding status', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 1 + DELETE dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 2 + DELETE dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey; + ELSE + IF @dataType = 3 + DELETE dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey; + ELSE + DELETE dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV16 +@tagPath VARCHAR (64), @dataType TINYINT, @batchSize INT=1000 +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + DECLARE @deletedRows AS INT; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + SET @deletedRows = @batchSize; + WHILE (@deletedRows = @batchSize) + BEGIN + EXECUTE dbo.ISleepIfBusy ; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 1 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 2 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 3 + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + SET @deletedRows = @@ROWCOUNT; + COMMIT TRANSACTION; + CHECKPOINT; + END + SET @deletedRows = @batchSize; + WHILE (@deletedRows = @batchSize) + BEGIN + EXECUTE dbo.ISleepIfBusy ; + BEGIN TRANSACTION; + DELETE TOP (@batchSize) + dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + SET @deletedRows = @@ROWCOUNT; + COMMIT TRANSACTION; + CHECKPOINT; + END + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteExtendedQueryTagV8 +@tagPath VARCHAR (64), @dataType TINYINT +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @tagKey AS INT; + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @tagKey = TagKey + FROM dbo.ExtendedQueryTag WITH (XLOCK) + WHERE dbo.ExtendedQueryTag.TagPath = @tagPath; + IF @@ROWCOUNT = 0 + THROW 50404, 'extended query tag not found', 1; + UPDATE dbo.ExtendedQueryTag + SET TagStatus = 2 + WHERE dbo.ExtendedQueryTag.TagKey = @tagKey; + COMMIT TRANSACTION; + BEGIN TRANSACTION; + IF @dataType = 0 + DELETE dbo.ExtendedQueryTagString + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 1 + DELETE dbo.ExtendedQueryTagLong + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 2 + DELETE dbo.ExtendedQueryTagDouble + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + IF @dataType = 3 + DELETE dbo.ExtendedQueryTagDateTime + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + ELSE + DELETE dbo.ExtendedQueryTagPersonName + WHERE TagKey = @tagKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagError + WHERE TagKey = @tagKey; + DELETE dbo.ExtendedQueryTag + WHERE TagKey = @tagKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteInstanceV6 +@cleanupAfter DATETIMEOFFSET (0), @createdStatus TINYINT, @partitionKey INT, @studyInstanceUid VARCHAR (64), @seriesInstanceUid VARCHAR (64)=NULL, @sopInstanceUid VARCHAR (64)=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @deletedInstances AS TABLE ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64) , + SeriesInstanceUid VARCHAR (64) , + SopInstanceUid VARCHAR (64) , + Status TINYINT , + Watermark BIGINT , + InstanceKey INT , + OriginalWatermark BIGINT , + FilePath NVARCHAR (4000) NULL, + ETag NVARCHAR (4000) NULL); + DECLARE @studyKey AS BIGINT; + DECLARE @seriesKey AS BIGINT; + DECLARE @instanceKey AS BIGINT; + DECLARE @deletedDate AS DATETIME2 = SYSUTCDATETIME(); + DECLARE @imageResourceType AS TINYINT = 0; + SELECT @studyKey = StudyKey, + @seriesKey = CASE @seriesInstanceUid WHEN NULL THEN NULL ELSE SeriesKey END, + @instanceKey = CASE @sopInstanceUid WHEN NULL THEN NULL ELSE InstanceKey END + FROM dbo.Instance + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND SopInstanceUid = ISNULL(@sopInstanceUid, SopInstanceUid); + DELETE dbo.Instance + OUTPUT deleted.PartitionKey, deleted.StudyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.Status, deleted.Watermark, deleted.InstanceKey, deleted.OriginalWatermark, FP.FilePath, FP.ETag INTO @deletedInstances + FROM dbo.Instance AS i + LEFT OUTER JOIN + dbo.FileProperty AS FP + ON i.InstanceKey = FP.InstanceKey + AND i.Watermark = FP.Watermark + WHERE i.PartitionKey = @partitionKey + AND i.StudyInstanceUid = @studyInstanceUid + AND i.SeriesInstanceUid = ISNULL(@seriesInstanceUid, i.SeriesInstanceUid) + AND i.SopInstanceUid = ISNULL(@sopInstanceUid, i.SopInstanceUid); + IF @@ROWCOUNT = 0 + THROW 50404, 'Instance not found', 1; + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + @deletedInstances AS DI + ON DI.InstanceKey = FP.InstanceKey + AND DI.Watermark = FP.Watermark; + DECLARE @deletedTags AS TABLE ( + TagKey BIGINT); + DELETE XQTE + OUTPUT deleted.TagKey INTO @deletedTags + FROM dbo.ExtendedQueryTagError AS XQTE + INNER JOIN + @deletedInstances AS DI + ON XQTE.Watermark = DI.Watermark; + IF EXISTS (SELECT * + FROM @deletedTags) + BEGIN + DECLARE @deletedTagCounts AS TABLE ( + TagKey BIGINT, + ErrorCount INT ); + INSERT INTO @deletedTagCounts (TagKey, ErrorCount) + SELECT TagKey, + COUNT(1) + FROM @deletedTags + GROUP BY TagKey; + UPDATE XQT + SET XQT.ErrorCount = XQT.ErrorCount - DTC.ErrorCount + FROM dbo.ExtendedQueryTag AS XQT + INNER JOIN + @deletedTagCounts AS DTC + ON XQT.TagKey = DTC.TagKey; + END + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND SopInstanceKey3 = ISNULL(@instanceKey, SopInstanceKey3) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + INSERT INTO dbo.DeletedInstance (PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, Watermark, DeletedDateTime, RetryCount, CleanupAfter, OriginalWatermark, FilePath, ETag) + SELECT PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark, + @deletedDate, + 0, + @cleanupAfter, + OriginalWatermark, + FilePath, + ETag + FROM @deletedInstances; + IF NOT EXISTS (SELECT * + FROM dbo.Instance WITH (HOLDLOCK, UPDLOCK) + WHERE PartitionKey = @partitionKey + AND StudyKey = @studyKey + AND SeriesKey = ISNULL(@seriesKey, SeriesKey)) + BEGIN + DELETE dbo.Series + WHERE StudyKey = @studyKey + AND SeriesInstanceUid = ISNULL(@seriesInstanceUid, SeriesInstanceUid) + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND SopInstanceKey2 = ISNULL(@seriesKey, SopInstanceKey2) + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + END + IF NOT EXISTS (SELECT * + FROM dbo.Series WITH (HOLDLOCK, UPDLOCK) + WHERE Studykey = @studyKey + AND PartitionKey = @partitionKey) + BEGIN + DELETE dbo.Study + WHERE StudyKey = @studyKey + AND PartitionKey = @partitionKey; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @studyKey + AND PartitionKey = @partitionKey + AND ResourceType = @imageResourceType; + END + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 1, + DI.PartitionKey, + DI.StudyInstanceUid, + DI.SeriesInstanceUid, + DI.SopInstanceUid, + DI.Watermark + FROM @deletedInstances AS DI + WHERE Status = @createdStatus; + UPDATE CF + SET CF.CurrentWatermark = NULL + FROM dbo.ChangeFeed AS CF WITH (FORCESEEK) + INNER JOIN + @deletedInstances AS DI + ON CF.PartitionKey = DI.PartitionKey + AND CF.StudyInstanceUid = DI.StudyInstanceUid + AND CF.SeriesInstanceUid = DI.SeriesInstanceUid + AND CF.SopInstanceUid = DI.SopInstanceUid; + COMMIT TRANSACTION; + SELECT d.Watermark, + d.partitionKey, + d.studyInstanceUid, + d.seriesInstanceUid, + d.sopInstanceUid + FROM @deletedInstances AS d; +END + +GO +CREATE OR ALTER PROCEDURE dbo.DeleteWorkitem +@partitionKey INT, @workitemUid VARCHAR (64) +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @workitemResourceType AS TINYINT = 1; + DECLARE @workitemKey AS BIGINT; + SELECT @workitemKey = WorkitemKey + FROM dbo.Workitem + WHERE PartitionKey = @partitionKey + AND WorkitemUid = @workitemUid; + IF @@ROWCOUNT = 0 + THROW 50413, 'Workitem does not exists', 1; + DELETE dbo.ExtendedQueryTagString + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagLong + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagDouble + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagDateTime + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.ExtendedQueryTagPersonName + WHERE SopInstanceKey1 = @workitemKey + AND PartitionKey = @partitionKey + AND ResourceType = @workitemResourceType; + DELETE dbo.Workitem + WHERE WorkItemKey = @workitemKey + AND PartitionKey = @partitionKey; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstance +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @updatedInstances AS TABLE ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT ); + DELETE @updatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, deleted.NewWatermark INTO @updatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM @updatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark + FROM dbo.ChangeFeed AS C + INNER JOIN + @updatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV44 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate) + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.EndUpdateInstanceV50 +@partitionKey INT, @studyInstanceUid VARCHAR (64), @patientId NVARCHAR (64)=NULL, @patientName NVARCHAR (325)=NULL, @patientBirthDate DATE=NULL, @insertFileProperties dbo.FilePropertyTableType READONLY, @stringExtendedQueryTags dbo.InsertStringExtendedQueryTagTableType_1 READONLY, @longExtendedQueryTags dbo.InsertLongExtendedQueryTagTableType_1 READONLY, @doubleExtendedQueryTags dbo.InsertDoubleExtendedQueryTagTableType_1 READONLY, @dateTimeExtendedQueryTags dbo.InsertDateTimeExtendedQueryTagTableType_2 READONLY, @personNameExtendedQueryTags dbo.InsertPersonNameExtendedQueryTagTableType_1 READONLY +AS +BEGIN + SET NOCOUNT ON; + SET XACT_ABORT ON; + BEGIN TRANSACTION; + DECLARE @currentDate AS DATETIME2 (7) = SYSUTCDATETIME(); + DECLARE @resourceType AS TINYINT = 0; + DECLARE @studyKey AS BIGINT; + DECLARE @maxWatermark AS BIGINT; + CREATE TABLE #UpdatedInstances ( + PartitionKey INT , + StudyInstanceUid VARCHAR (64), + SeriesInstanceUid VARCHAR (64), + SopInstanceUid VARCHAR (64), + Watermark BIGINT , + OriginalWatermark BIGINT , + InstanceKey BIGINT + ); + DELETE #UpdatedInstances; + UPDATE dbo.Instance + SET LastStatusUpdatedDate = @currentDate, + OriginalWatermark = ISNULL(OriginalWatermark, Watermark), + Watermark = NewWatermark, + NewWatermark = NULL + OUTPUT deleted.PartitionKey, @studyInstanceUid, deleted.SeriesInstanceUid, deleted.SopInstanceUid, inserted.Watermark, inserted.OriginalWatermark, deleted.InstanceKey INTO #UpdatedInstances + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid + AND Status = 1 + AND NewWatermark IS NOT NULL; + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstances') + CREATE UNIQUE INDEX IXC_UpdatedInstances + ON #UpdatedInstances(Watermark); + IF NOT EXISTS (SELECT * + FROM tempdb.sys.indexes + WHERE name = 'IXC_UpdatedInstanceKeyWatermark') + CREATE UNIQUE CLUSTERED INDEX IXC_UpdatedInstanceKeyWatermark + ON #UpdatedInstances(InstanceKey, OriginalWatermark); + UPDATE dbo.Study + SET PatientId = ISNULL(@patientId, PatientId), + PatientName = ISNULL(@patientName, PatientName), + PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), + @studyKey = StudyKey + WHERE PartitionKey = @partitionKey + AND StudyInstanceUid = @studyInstanceUid; + IF @@ROWCOUNT = 0 + THROW 50404, 'Study does not exist', 1; + IF EXISTS (SELECT 1 + FROM @insertFileProperties) + DELETE FP + FROM dbo.FileProperty AS FP + INNER JOIN + #UpdatedInstances AS U + ON U.InstanceKey = FP.InstanceKey + WHERE U.OriginalWatermark != FP.Watermark; + INSERT INTO dbo.FileProperty (InstanceKey, Watermark, FilePath, ETag) + SELECT U.InstanceKey, + I.Watermark, + I.FilePath, + I.ETag + FROM @insertFileProperties AS I + INNER JOIN + #UpdatedInstances AS U + ON U.Watermark = I.Watermark; + SELECT @maxWatermark = max(Watermark) + FROM #UpdatedInstances; + BEGIN TRY + EXECUTE dbo.IIndexInstanceCoreV9 @partitionKey, @studyKey, NULL, NULL, @maxWatermark, @stringExtendedQueryTags, @longExtendedQueryTags, @doubleExtendedQueryTags, @dateTimeExtendedQueryTags, @personNameExtendedQueryTags; + END TRY + BEGIN CATCH + THROW; + END CATCH + INSERT INTO dbo.ChangeFeed (Action, PartitionKey, StudyInstanceUid, SeriesInstanceUid, SopInstanceUid, OriginalWatermark) + SELECT 2, + PartitionKey, + StudyInstanceUid, + SeriesInstanceUid, + SopInstanceUid, + Watermark + FROM #UpdatedInstances; + UPDATE C + SET CurrentWatermark = U.Watermark, + FilePath = I.FilePath + FROM dbo.ChangeFeed AS C + INNER JOIN + #UpdatedInstances AS U + ON C.PartitionKey = U.PartitionKey + AND C.StudyInstanceUid = U.StudyInstanceUid + AND C.SeriesInstanceUid = U.SeriesInstanceUid + AND C.SopInstanceUid = U.SopInstanceUid + LEFT OUTER JOIN + @insertFileProperties AS I + ON I.Watermark = U.Watermark; + COMMIT TRANSACTION; +END + +GO +CREATE OR ALTER PROCEDURE dbo.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/V50.Generated.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V50.Generated.cs new file mode 100644 index 0000000000..b26255c399 --- /dev/null +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Model/V50.Generated.cs @@ -0,0 +1,2646 @@ +//------------------------------------------------------------------------------ +// +// 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 V50 + { + internal readonly static ChangeFeedTable ChangeFeed = new ChangeFeedTable(); + internal readonly static DeletedInstanceTable DeletedInstance = new DeletedInstanceTable(); + internal readonly static ExtendedQueryTagTable ExtendedQueryTag = new ExtendedQueryTagTable(); + internal readonly static ExtendedQueryTagDateTimeTable ExtendedQueryTagDateTime = new ExtendedQueryTagDateTimeTable(); + internal readonly static ExtendedQueryTagDoubleTable ExtendedQueryTagDouble = new ExtendedQueryTagDoubleTable(); + internal readonly static ExtendedQueryTagErrorTable ExtendedQueryTagError = new ExtendedQueryTagErrorTable(); + internal readonly static ExtendedQueryTagLongTable ExtendedQueryTagLong = new ExtendedQueryTagLongTable(); + internal readonly static ExtendedQueryTagOperationTable ExtendedQueryTagOperation = new ExtendedQueryTagOperationTable(); + internal readonly static ExtendedQueryTagPersonNameTable ExtendedQueryTagPersonName = new ExtendedQueryTagPersonNameTable(); + internal readonly static ExtendedQueryTagStringTable ExtendedQueryTagString = new ExtendedQueryTagStringTable(); + internal readonly static FilePropertyTable FileProperty = new FilePropertyTable(); + internal readonly static InstanceTable Instance = new InstanceTable(); + internal readonly static PartitionTable Partition = new PartitionTable(); + internal readonly static SeriesTable Series = new SeriesTable(); + internal readonly static StudyTable Study = new StudyTable(); + internal readonly static WorkitemTable Workitem = new WorkitemTable(); + internal readonly static WorkitemQueryTagTable WorkitemQueryTag = new WorkitemQueryTagTable(); + internal readonly static AddExtendedQueryTagErrorProcedure AddExtendedQueryTagError = new AddExtendedQueryTagErrorProcedure(); + internal readonly static AddExtendedQueryTagsProcedure AddExtendedQueryTags = new AddExtendedQueryTagsProcedure(); + internal readonly static AddInstanceV6Procedure AddInstanceV6 = new AddInstanceV6Procedure(); + internal readonly static AddPartitionProcedure AddPartition = new AddPartitionProcedure(); + internal readonly static AddWorkitemProcedure AddWorkitem = new AddWorkitemProcedure(); + internal readonly static AddWorkitemV11Procedure AddWorkitemV11 = new AddWorkitemV11Procedure(); + internal readonly static AssignReindexingOperationProcedure AssignReindexingOperation = new AssignReindexingOperationProcedure(); + internal readonly static BeginUpdateInstanceProcedure BeginUpdateInstance = new BeginUpdateInstanceProcedure(); + internal readonly static BeginUpdateInstanceV33Procedure BeginUpdateInstanceV33 = new BeginUpdateInstanceV33Procedure(); + internal readonly static BeginUpdateInstanceV46Procedure BeginUpdateInstanceV46 = new BeginUpdateInstanceV46Procedure(); + internal readonly static CompleteReindexingProcedure CompleteReindexing = new CompleteReindexingProcedure(); + internal readonly static DeleteDeletedInstanceProcedure DeleteDeletedInstance = new DeleteDeletedInstanceProcedure(); + internal readonly static DeleteDeletedInstanceV6Procedure DeleteDeletedInstanceV6 = new DeleteDeletedInstanceV6Procedure(); + internal readonly static DeleteExtendedQueryTagProcedure DeleteExtendedQueryTag = new DeleteExtendedQueryTagProcedure(); + internal readonly static DeleteExtendedQueryTagV16Procedure DeleteExtendedQueryTagV16 = new DeleteExtendedQueryTagV16Procedure(); + internal readonly static DeleteExtendedQueryTagV8Procedure DeleteExtendedQueryTagV8 = new DeleteExtendedQueryTagV8Procedure(); + internal readonly static DeleteInstanceV6Procedure DeleteInstanceV6 = new DeleteInstanceV6Procedure(); + internal readonly static DeleteWorkitemProcedure DeleteWorkitem = new DeleteWorkitemProcedure(); + internal readonly static EndUpdateInstanceProcedure EndUpdateInstance = new EndUpdateInstanceProcedure(); + internal readonly static EndUpdateInstanceV44Procedure EndUpdateInstanceV44 = new EndUpdateInstanceV44Procedure(); + internal readonly static EndUpdateInstanceV50Procedure EndUpdateInstanceV50 = new EndUpdateInstanceV50Procedure(); + internal readonly static 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 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") + { + } + + 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/SchemaVersion.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs index d39246acf8..b3446942a3 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersion.cs @@ -61,4 +61,5 @@ public enum SchemaVersion V48 = 48, V49 = 49, V50 = 50, + V51 = 51, } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/SchemaVersionConstants.cs index cb3da1c23b..8613d24610 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.V50; + public const int Max = (int)SchemaVersion.V51; } diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/AddInstanceV6.sql b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/AddInstanceV6.sql index 1ea7743287..858c648777 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/AddInstanceV6.sql +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Schema/Sql/Sprocs/AddInstanceV6.sql @@ -141,7 +141,11 @@ BEGIN -- Latest wins UPDATE dbo.Study - SET PatientId = ISNULL(@patientId, PatientId), + SET PatientId = (CASE WHEN @patientId IS NOT NULL AND @patientId <> '' + THEN @patientId + ELSE + PatientId + END), PatientName = ISNULL(@patientName, PatientName), PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), @@ -160,7 +164,11 @@ BEGIN BEGIN -- Latest wins UPDATE dbo.Study - SET PatientId = ISNULL(@patientId, PatientId), + SET PatientId = (CASE WHEN @patientId IS NOT NULL AND @patientId <> '' + THEN @patientId + ELSE + PatientId + END), PatientName = ISNULL(@patientName, PatientName), PatientBirthDate = ISNULL(@patientBirthDate, PatientBirthDate), ReferringPhysicianName = ISNULL(@referringPhysicianName, ReferringPhysicianName), diff --git a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs index b60dfa95d8..1208d2f489 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Features/Store/SqlIndexDataStoreV37.cs @@ -97,7 +97,7 @@ public override async Task BeginCreateInstanceIndexAsync(Partition partiti dicomDataset.GetString(DicomTag.StudyInstanceUID), dicomDataset.GetString(DicomTag.SeriesInstanceUID), dicomDataset.GetString(DicomTag.SOPInstanceUID), - dicomDataset.GetFirstValueOrDefault(DicomTag.PatientID), + dicomDataset.GetFirstValueOrDefault(DicomTag.PatientID) ?? String.Empty, dicomDataset.GetFirstValueOrDefault(DicomTag.PatientName), dicomDataset.GetFirstValueOrDefault(DicomTag.ReferringPhysicianName), dicomDataset.GetStringDateAsDate(DicomTag.StudyDate), 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 e645e7860b..61db4e173e 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 @@ - 50 + 51 Features\Schema\Migrations\$(LatestSchemaVersion).sql diff --git a/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/StoreTransactionTestsLatest.cs b/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/StoreTransactionTestsLatest.cs index 7afb6fb6e9..fdf2f88952 100644 --- a/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/StoreTransactionTestsLatest.cs +++ b/test/Microsoft.Health.Dicom.Web.Tests.E2E/Rest/StoreTransactionTestsLatest.cs @@ -267,6 +267,74 @@ public async Task GivenInstanceWithPatientIdInvalidWithNullPadding_WhenStoreInst ResponseHelper.ConvertToFailedSopSequenceEntry(dicomFile1.Dataset, ValidationHelpers.ValidationFailedFailureCode)); } + [Fact] + public async Task GivenStoringMultipleInstanceInStudy_WhenInitialInstanceHasNullPatientId_ThenExpectPatientIdCorrectlyUpdated() + { + // STOW using a null patient ID + DicomFile dicomFile1 = new DicomFile( + Samples.CreateRandomInstanceDataset(validateItems: false)); + dicomFile1.Dataset.AddOrUpdate(DicomTag.PatientID, new string[] { null }); + + DicomWebResponse response = await _instancesManager.StoreAsync(dicomFile1); + + // assert on response + Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + DicomDataset responseDataset = await response.GetValueAsync(); + DicomSequence refSopSequence = responseDataset.GetSequence(DicomTag.ReferencedSOPSequence); + Assert.Single(refSopSequence); + DicomDataset firstInstance = refSopSequence.Items[0]; + DicomSequence failedAttributesSequence = firstInstance.GetSequence(DicomTag.FailedAttributesSequence); + // Assert on the warning produced when storing the instance with null patientId + Assert.Contains( + "DICOM100: (0010,0020) - The required tag '(0010,0020)' is missing.", + failedAttributesSequence.Items[0].GetString(DicomTag.ErrorComment)); + + // Verify that patientId is stored as null using QIDO + string studyInstanceUID = dicomFile1.Dataset.GetString(DicomTag.StudyInstanceUID); + await VerifyPatientId(studyInstanceUID, null); + + // STOW using a non null patient ID + string patientId = "123"; + DicomFile dicomFile2 = new DicomFile( + Samples.CreateRandomInstanceDataset(studyInstanceUid: studyInstanceUID, patientId: patientId, validateItems: false)); + response = await _instancesManager.StoreAsync(dicomFile2); + + // assert on response + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + responseDataset = await response.GetValueAsync(); + refSopSequence = responseDataset.GetSequence(DicomTag.ReferencedSOPSequence); + Assert.Single(refSopSequence); + + firstInstance = refSopSequence.Items[0]; + failedAttributesSequence = firstInstance.GetSequence(DicomTag.FailedAttributesSequence); + // Assert that no warning or error produced when storing the instance with a non null patientId + Assert.Empty(failedAttributesSequence); + + // Verify the new non-null Patient Id using QIDO + await VerifyPatientId(studyInstanceUID, patientId); + + // STOW using a null patient ID again to make sure that the patientId is not updated + DicomFile dicomFile3 = new DicomFile( + Samples.CreateRandomInstanceDataset(studyInstanceUid: studyInstanceUID, validateItems: false)); + dicomFile3.Dataset.AddOrUpdate(DicomTag.PatientID, new string[] { null }); + response = await _instancesManager.StoreAsync(dicomFile3); + + // assert on response + Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + responseDataset = await response.GetValueAsync(); + refSopSequence = responseDataset.GetSequence(DicomTag.ReferencedSOPSequence); + Assert.Single(refSopSequence); + firstInstance = refSopSequence.Items[0]; + failedAttributesSequence = firstInstance.GetSequence(DicomTag.FailedAttributesSequence); + // Assert on the warning produced when storing the instance again with null patientId + Assert.Contains( + "DICOM100: (0010,0020) - The required tag '(0010,0020)' is missing.", + failedAttributesSequence.Items[0].GetString(DicomTag.ErrorComment)); + + // Verify that the patientId is not updated using QIDO + await VerifyPatientId(studyInstanceUID, patientId); + } + [Fact] public async Task GivenDatasetWithInvalidVrValue_WhenStoring_TheServerShouldReturnAccepted() { @@ -310,4 +378,17 @@ public async Task GivenLargeMultiPartRequest_WhenStoring_ThenServerShouldReturnO using DicomWebResponse stow = await _instancesManager.StoreAsync(files); Assert.Equal(HttpStatusCode.OK, stow.StatusCode); } + + private async Task VerifyPatientId(string studyInstanceUid, string expectedPatiendId) + { + using DicomWebAsyncEnumerableResponse response = await _client.QueryStudyAsync($"StudyInstanceUID={studyInstanceUid}"); + + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("application/dicom+json", response.ContentHeaders.ContentType.MediaType); + + DicomDataset[] datasets = await response.ToArrayAsync(); + string actualPatientID = datasets.Select(x => x.GetSingleValueOrDefault(DicomTag.PatientID, null)).SingleOrDefault(); + + Assert.Equal(expectedPatiendId, actualPatientID); + } }