Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding handling for SqlTruncate errors #2553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PropertyGroup>
<RuntimePackageVersion>5.0.0</RuntimePackageVersion>
<AspNetPackageVersion>5.0.15</AspNetPackageVersion>
<HealthcareSharedPackageVersion>6.1.8</HealthcareSharedPackageVersion>
<HealthcareSharedPackageVersion>6.1.10</HealthcareSharedPackageVersion>
<Hl7FhirVersion>3.6.0</Hl7FhirVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// -------------------------------------------------------------------------------------------------

using Microsoft.Health.Fhir.Core.Features.Search;
using Microsoft.Health.Fhir.ValueSets;

namespace Microsoft.Health.Fhir.Core.Configs
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using EnsureThat;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Specification;
using Hl7.FhirPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// -------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.Health.Fhir.Api.Features.Bundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Net;
using EnsureThat;
Expand Down Expand Up @@ -230,6 +231,11 @@ public override void OnActionExecuted(ActionExecutedContext context)
context.Result = CreateOperationOutcomeResult(sqlException.Message, OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Timeout, HttpStatusCode.RequestTimeout);
context.ExceptionHandled = true;
}
else if (context.Exception is SqlTruncateException sqltruncateException)
{
context.Result = CreateOperationOutcomeResult(sqltruncateException.Message, OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Value, HttpStatusCode.BadRequest);
context.ExceptionHandled = true;
}
else if (context.Exception.InnerException != null)
{
Exception outerException = context.Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
<EmbeddedResource Include="TestFiles\Normative\ObservationWithBloodPressure.json" />
<EmbeddedResource Include="TestFiles\Normative\ObservationWithLongEyeColor.json" />
<EmbeddedResource Include="TestFiles\Normative\ObservationWithEyeColor.json" />
<EmbeddedResource Include="TestFiles\Normative\ObservationWithInvalidDecimalSpecification.json" />
<EmbeddedResource Include="TestFiles\Normative\ObservationWithInvalidStatus.json" />
<EmbeddedResource Include="TestFiles\Normative\ObservationWithInvalidStatus.xml" />
<EmbeddedResource Include="TestFiles\Normative\ObservationWithNoCode.json" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"resourceType": "Observation",
"id": "observation-id",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: f001</p><p><b>identifier</b>: 6323 (OFFICIAL)</p><p><b>status</b>: final</p><p><b>code</b>: Glucose [Moles/volume] in Blood <span>(Details : {LOINC code '15074-8' = 'Glucose [Moles/volume] in Blood', given as 'Glucose [Moles/volume] in Blood'})</span></p><p><b>subject</b>: <a>P. van de Heuvel</a></p><p><b>effective</b>: 02/04/2013 9:30:10 AM --&gt; (ongoing)</p><p><b>issued</b>: 03/04/2013 3:30:10 PM</p><p><b>performer</b>: <a>A. Langeveld</a></p><p><b>value</b>: 6.3 mmol/l<span> (Details: UCUM code mmol/L = 'mmol/L')</span></p><p><b>interpretation</b>: High <span>(Details : {http://hl7.org/fhir/v2/0078 code 'H' = 'High', given as 'High'})</span></p><h3>ReferenceRanges</h3><table><tr><td>-</td><td><b>Low</b></td><td><b>High</b></td></tr><tr><td>*</td><td>3.1 mmol/l<span> (Details: UCUM code mmol/L = 'mmol/L')</span></td><td>6.2 mmol/l<span> (Details: UCUM code mmol/L = 'mmol/L')</span></td></tr></table></div>"
},
"identifier": [
{
"use": "official",
"system": "http://www.bmc.nl/zorgportal/identifiers/observations",
"value": "6323"
}
],
"status": "final",
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "15074-8",
"display": "Glucose [Moles/volume] in Blood"
}
]
},
"subject": {
"reference": "Patient/patient-id",
"display": "P. van de Heuvel"
},
"valueQuantity": {
"value": 1234567890123456789.0123456789,
"unit": "mmol/l",
"system": "http://unitsofmeasure.org",
"code": "mmol/L"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Hl7.Fhir.Model;
using Microsoft.Health.Fhir.Client;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Fhir.Tests.Common.FixtureParameters;
using Xunit;
using Task = System.Threading.Tasks.Task;

Expand All @@ -34,6 +35,15 @@ public async Task GivenAnObservationDefinition_WhenCreating_ThenTheCorrectRespon
Assert.NotNull(actual);
}

[Fact]
[HttpIntegrationFixtureArgumentSets(DataStore.SqlServer)]
public async Task GivenAnObservation_WithInvalidDecimalSpecification_ThenBadRequestShouldBeReturned()
{
var resource = Samples.GetJsonSample<Observation>("ObservationWithInvalidDecimalSpecification");
using FhirException exception = await Assert.ThrowsAsync<FhirException>(() => _client.CreateAsync(resource));
Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode);
}

[Fact]
public async Task GivenANewR4ResourceType_WhenCreated_ThenCorrectResourceShouldBeReturned()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace Microsoft.Health.Fhir.Tests.Integration.Persistence
{
/// <summary>
/// Persistence tests for R4
/// </summary>
public partial class FhirStorageTests : IClassFixture<FhirStorageTestsFixture>
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Hl7.Fhir.Model;
using Microsoft.Health.Fhir.Client;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Fhir.Tests.Common.FixtureParameters;
using Xunit;
using Task = System.Threading.Tasks.Task;

Expand All @@ -34,6 +35,15 @@ public async Task GivenAnObservationDefinition_WhenCreating_ThenTheCorrectRespon
Assert.NotNull(actual);
}

[Fact]
[HttpIntegrationFixtureArgumentSets(DataStore.SqlServer)]
public async Task GivenAnObservation_WithInvalidDecimalSpecification_ThenBadRequestShouldBeReturned()
{
var resource = Samples.GetJsonSample<Observation>("ObservationWithInvalidDecimalSpecification");
using FhirException exception = await Assert.ThrowsAsync<FhirException>(() => _client.CreateAsync(resource));
Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode);
}

[Fact]
public async Task GivenANewR5ResourceType_WhenCreated_ThenCorrectResourceShouldBeReturned()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace Microsoft.Health.Fhir.Tests.Integration.Persistence
{
/// <summary>
/// Persistence tests for R5
/// </summary>
public partial class FhirStorageTests : IClassFixture<FhirStorageTestsFixture>
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Net;
using Hl7.Fhir.Model;
using Microsoft.Health.Fhir.Client;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Fhir.Tests.Common.FixtureParameters;
using Xunit;
using Task = System.Threading.Tasks.Task;

Expand All @@ -18,5 +23,14 @@ public async Task GivenStu3Server_WhenCapabilityStatementIsRetrieved_ThenCorrect
{
await TestCapabilityStatementFhirVersion("3.0.2");
}

[Fact]
[HttpIntegrationFixtureArgumentSets(DataStore.SqlServer)]
public async Task GivenAnObservation_WithInvalidDecimalSpecification_ThenBadRequestShouldBeReturned()
{
var resource = Samples.GetJsonSample<Observation>("ObservationWithInvalidDecimalSpecification");
using FhirException exception = await Assert.ThrowsAsync<FhirException>(() => _client.CreateAsync(resource));
Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Microsoft.Health.Fhir.Tests.Integration.Persistence
{
/// <summary>
/// Persistence tests for Stu3
/// </summary>
public partial class FhirStorageTests : IClassFixture<FhirStorageTestsFixture>
{
[Fact]
Expand Down