Ejemplo n.º 1
0
        public async Task GivenListOfResourcesWithDupResourceId_WhenBulkMergeToStore_ThenDistinctResourceShouldBeImported()
        {
            List <SqlBulkCopyDataWrapper> resources = new List <SqlBulkCopyDataWrapper>();
            long startSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.Now);

            SqlBulkCopyDataWrapper resource1 = CreateTestResource(Guid.NewGuid().ToString(), startSurrogateId);
            SqlBulkCopyDataWrapper resource2 = CreateTestResource(Guid.NewGuid().ToString(), startSurrogateId + 1);

            resources.Add(resource1);
            resources.Add(resource2);

            SqlBulkCopyDataWrapper[] result = (await _sqlServerFhirDataBulkOperation.BulkMergeResourceAsync(resources, CancellationToken.None)).ToArray();
            int rCount = await GetResourceCountAsync("Resource", startSurrogateId, startSurrogateId + 2);

            Assert.Equal(2, result.Count());
            Assert.Equal(2, rCount);

            resource1.ResourceSurrogateId = startSurrogateId + 2;
            resource1.ResourceSurrogateId = startSurrogateId + 3;
            result = (await _sqlServerFhirDataBulkOperation.BulkMergeResourceAsync(resources, CancellationToken.None)).ToArray();
            rCount = await GetResourceCountAsync("Resource", startSurrogateId, startSurrogateId + 4);

            Assert.Empty(result);
            Assert.Equal(2, rCount);
        }
Ejemplo n.º 2
0
        public async Task GivenImportedBatchResources_WhenCleanData_ThenRecordsShouldBeDeleted()
        {
            long  startSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.Now);
            int   count            = 1001;
            short typeId           = _fixture.SqlServerFhirModel.GetResourceTypeId("Patient");

            List <string> tableNames = new List <string>();

            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateResourceTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateDateTimeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateNumberSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateQuantitySearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateReferenceSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateReferenceTokenCompositeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateStringSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenDateTimeCompositeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenNumberNumberCompositeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenQuantityCompositeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenStringCompositeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenTextSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenTokenCompositeSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateUriSearchParamsTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateCompartmentAssignmentTable));
            tableNames.Add(await ImportDataAsync(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateResourceWriteClaimTable));

            await _sqlServerFhirDataBulkOperation.CleanBatchResourceAsync("Patient", startSurrogateId, startSurrogateId + count - 1, CancellationToken.None);

            foreach (string tableName in tableNames)
            {
                int rCount = await GetResourceCountAsync(tableName, startSurrogateId, startSurrogateId + count);

                Assert.Equal(1, rCount);
            }
        }
Ejemplo n.º 3
0
        public async Task GivenBatchInValidResources_WhenBulkCopy_ThenExceptionShouldBeThrow()
        {
            long startSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.Now);
            int  count            = 1001;

            DataTable inputTable = TestBulkDataProvider.GenerateInValidUriSearchParamsTable(count, startSurrogateId, 0);
            await Assert.ThrowsAnyAsync <Exception>(async() => await _sqlServerFhirDataBulkOperation.BulkCopyDataAsync(inputTable, CancellationToken.None));
        }
Ejemplo n.º 4
0
        public override Expression VisitBinary(BinaryExpression expression, object context)
        {
            if (expression.FieldName != FieldName.DateTimeStart && expression.FieldName != FieldName.DateTimeEnd)
            {
                throw new ArgumentOutOfRangeException(expression.FieldName.ToString());
            }

            // ResourceSurrogateId has millisecond datetime precision, with lower bits added in to make the value unique.

            DateTime original  = ((DateTimeOffset)expression.Value).UtcDateTime;
            DateTime truncated = original.TruncateToMillisecond();

            switch (expression.BinaryOperator)
            {
            case BinaryOperator.GreaterThan:
                return(Expression.GreaterThanOrEqual(
                           SqlFieldName.ResourceSurrogateId,
                           null,
                           ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(truncated.AddTicks(TimeSpan.TicksPerMillisecond))));

            case BinaryOperator.GreaterThanOrEqual:
                if (original == truncated)
                {
                    return(Expression.GreaterThanOrEqual(
                               SqlFieldName.ResourceSurrogateId,
                               null,
                               ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(truncated)));
                }

                goto case BinaryOperator.GreaterThan;

            case BinaryOperator.LessThan:
                if (original == truncated)
                {
                    return(Expression.LessThan(
                               SqlFieldName.ResourceSurrogateId,
                               null,
                               ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(truncated)));
                }

                goto case BinaryOperator.LessThanOrEqual;

            case BinaryOperator.LessThanOrEqual:
                return(Expression.LessThan(
                           SqlFieldName.ResourceSurrogateId,
                           null,
                           ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(truncated.AddTicks(TimeSpan.TicksPerMillisecond))));

            case BinaryOperator.NotEqual:
            case BinaryOperator.Equal:     // expecting eq to have been rewritten as a range
            default:
                throw new ArgumentOutOfRangeException(expression.BinaryOperator.ToString());
            }
        }
Ejemplo n.º 5
0
        public void GivenADateTime_WhenRepresentedAsASurrogateId_HasTheExpectedRange()
        {
            var  baseDate = DateTime.MinValue;
            long baseId   = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(baseDate);

            Assert.Equal(baseDate, ResourceSurrogateIdHelper.ResourceSurrogateIdToLastUpdated(baseId + 79999));
            Assert.Equal(TimeSpan.FromTicks(TimeSpan.TicksPerMillisecond), ResourceSurrogateIdHelper.ResourceSurrogateIdToLastUpdated(baseId + 80000) - baseDate);

            long maxBaseId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(ResourceSurrogateIdHelper.MaxDateTime);

            Assert.Equal(ResourceSurrogateIdHelper.MaxDateTime.TruncateToMillisecond(), ResourceSurrogateIdHelper.ResourceSurrogateIdToLastUpdated(maxBaseId));
            Assert.Equal(ResourceSurrogateIdHelper.MaxDateTime.TruncateToMillisecond(), ResourceSurrogateIdHelper.ResourceSurrogateIdToLastUpdated(maxBaseId + 79999));
        }
Ejemplo n.º 6
0
        public async Task GivenListOfResources_WhenBulkMergeToStoreTwice_ThenSecondMergeShouldFail()
        {
            List <SqlBulkCopyDataWrapper> resources = new List <SqlBulkCopyDataWrapper>();
            long startSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.Now);

            string resourceId = Guid.NewGuid().ToString();
            SqlBulkCopyDataWrapper resource1 = CreateTestResource(resourceId, startSurrogateId);
            SqlBulkCopyDataWrapper resource2 = CreateTestResource(resourceId, startSurrogateId + 1);

            resources.Add(resource1);
            resources.Add(resource2);

            SqlBulkCopyDataWrapper[] result = (await _sqlServerFhirDataBulkOperation.BulkMergeResourceAsync(resources, CancellationToken.None)).ToArray();
            int rCount = await GetResourceCountAsync("Resource", startSurrogateId, startSurrogateId + 2);

            Assert.Single(result);
            Assert.Equal(1, rCount);
        }
Ejemplo n.º 7
0
        public async Task GivenDuplicateResources_WhenBulkMergeToStore_ThenOnlyDistinctResourcesImported()
        {
            long   startSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.Now);
            int    count            = 100;
            string resourceId       = Guid.NewGuid().ToString();

            List <SqlBulkCopyDataWrapper> resources = new List <SqlBulkCopyDataWrapper>();

            for (int i = 0; i < count; ++i)
            {
                resources.Add(CreateTestResource(resourceId, startSurrogateId + i));
            }

            SqlBulkCopyDataWrapper[] result = (await _sqlServerFhirDataBulkOperation.BulkMergeResourceAsync(resources, CancellationToken.None)).ToArray();
            int rCount = await GetResourceCountAsync("Resource", startSurrogateId, startSurrogateId + count);

            Assert.Single(result);
            Assert.Equal(1, rCount);
        }
Ejemplo n.º 8
0
        public async Task GivenBatchResources_WhenBulkCopy_ThenRecordsShouldBeAdded()
        {
            long  startSurrogateId = ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.Now);
            int   count            = 1001;
            short typeId           = _fixture.SqlServerFhirModel.GetResourceTypeId("Patient");

            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateDateTimeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateNumberSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateQuantitySearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateReferenceSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateReferenceTokenCompositeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateStringSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenDateTimeCompositeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenNumberNumberCompositeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenQuantityCompositeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenStringCompositeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenTextSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateTokenTokenCompositeSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateUriSearchParamsTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateCompartmentAssignmentTable);
            await VerifyDataForBulkImport(_sqlServerFhirDataBulkOperation, startSurrogateId, count, typeId, TestBulkDataProvider.GenerateResourceWriteClaimTable);
        }
Ejemplo n.º 9
0
 public void GivenADateTimeLargerThanTheLargestThatCanBeRepresentedAsASurrogateId_WhenTurnedIntoASurrogateId_Throws()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.MaxValue));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Get current surrogateId from datetime
 /// </summary>
 /// <returns>Current surrogated id.</returns>
 public long GetCurrentSequenceId()
 {
     return(ResourceSurrogateIdHelper.LastUpdatedToResourceSurrogateId(DateTime.UtcNow));
 }