Skip to content

Commit

Permalink
Revert "Duplicated Search Parameters (#3485)" (#3580)
Browse files Browse the repository at this point in the history
This reverts commit 7359b8b.
  • Loading branch information
abiisnn authored Nov 1, 2023
1 parent dc257d6 commit bacb0e8
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public async Task<IActionResult> Create([FromBody] Resource resource)
[ConditionalConstraint]
[Route(KnownRoutes.ResourceType)]
[AuditEventType(AuditEventSubType.ConditionalCreate)]
[ServiceFilter(typeof(SearchParameterFilterAttribute))]
public async Task<IActionResult> ConditionalCreate([FromBody] Resource resource)
{
StringValues conditionalCreateHeader = HttpContext.Request.Headers[KnownHeaders.IfNoneExist];
Expand Down Expand Up @@ -212,7 +211,6 @@ public async Task<IActionResult> ConditionalCreate([FromBody] Resource resource)
[ValidateResourceIdFilter]
[Route(KnownRoutes.ResourceTypeById)]
[AuditEventType(AuditEventSubType.Update)]
[ServiceFilter(typeof(SearchParameterFilterAttribute))]
public async Task<IActionResult> Update([FromBody] Resource resource, [ModelBinder(typeof(WeakETagBinder))] WeakETag ifMatchHeader)
{
BundleResourceContext bundleResourceContext = GetBundleResourceContext();
Expand All @@ -230,7 +228,6 @@ public async Task<IActionResult> Update([FromBody] Resource resource, [ModelBind
[HttpPut]
[Route(KnownRoutes.ResourceType)]
[AuditEventType(AuditEventSubType.ConditionalUpdate)]
[ServiceFilter(typeof(SearchParameterFilterAttribute))]
public async Task<IActionResult> ConditionalUpdate([FromBody] Resource resource)
{
IReadOnlyList<Tuple<string, string>> conditionalParameters = GetQueriesForSearch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
<EmbeddedResource Include="TestFiles\Normative\SearchParameterUnsupportedType.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterExpressionWrongProperty.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterBadSyntax.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterDuplicatedConditionalCreate.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterDuplicatedConditionalUpdate.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterDuplicatedUpdate.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterMissingExpression.json" />
<EmbeddedResource Include="TestFiles\Normative\SearchParameterMissingBase.json" />
<EmbeddedResource Include="TestFiles\Normative\Specimen.json" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -140,81 +140,5 @@ public async Task GivenAResource_WhenCreatingConditionallyWithEmptyIfNoneHeader_
Assert.Single(exception.OperationOutcome.Issue);
Assert.Equal(exception.Response.Resource.Issue[0].Diagnostics, string.Format(Core.Resources.ConditionalOperationNotSelectiveEnough, "Observation"));
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenCreatingConditionallyANewDuplicatedSearchParameterResourceWithSameUrl_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'code' and base 'Observation' already exists with
* the url http://hl7.org/fhir/SearchParameter/clinical-code */

var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedConditionalCreate");
resourceToCreate.Id = null;
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/clinical-code"; // Same Url than the default one

// For calling a Conditional Create we do need to send a conditionalCreateCriteria which in this case is the url.
using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.CreateAsync(
resourceToCreate,
$"url={resourceToCreate.Url}"));

var expectedSubstring = "A search parameter with the same definition URL 'http://hl7.org/fhir/SearchParameter/clinical-code' already exists.";
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.Contains(expectedSubstring, ex.Message);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenCreatingConditionallyANewDuplicatedSearchParameterResourceWithUrl_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'code' and base 'Observation' already exists with
* the url http://hl7.org/fhir/SearchParameter/clinical-code */

var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedConditionalCreate");
resourceToCreate.Id = null;
resourceToCreate.Url = "http://fhir.medlix.org/SearchParameter/code-observation-test-conditional-create-url";

// For calling a Conditional Create we do need to send a conditionalCreateCriteria which in this case is the url.
using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.CreateAsync(
resourceToCreate,
$"url={resourceToCreate.Url}"));

var expectedSubstring = "A search parameter with the same code value 'code' already exists for base type 'Observation'";
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.Contains(expectedSubstring, ex.Message);

/* If there is a Search parameter alredy defined with the same url, this test will fail because the ex.Message is different,
* in that case we should received (example, URL may change):
* "A search parameter with the same definition URL 'http://fhir.medlix.org/SearchParameter/code-observation-test-conditional-create-url' already exists.
*/
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenCreatingConditionallyANewDuplicatedSearchParameterResourceWithCode_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'code' and base 'Observation' already exists with
* the url http://hl7.org/fhir/SearchParameter/clinical-code */

var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedConditionalCreate");
resourceToCreate.Id = null;
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/code-observation-test-conditional-create-code";

// For calling a Conditional Create we do need to send a conditionalCreateCriteria which in this case is the base.
using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.CreateAsync(
resourceToCreate,
$"code=code"));

var expectedSubstring = "A search parameter with the same code value 'code' already exists for base type 'Observation'";
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.Contains(expectedSubstring, ex.Message);

/* If there is a Search parameter alredy defined with the same url, this test will fail because the ex.Message is different,
* in that case we should received (example, URL may change):
* "A search parameter with the same definition URL 'http://fhir.medlix.org/SearchParameter/code-observation-test-conditional-create-code' already exists.
*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,97 +230,5 @@ public async Task GivenAResource_WhenUpsertingConditionallyWithMultipleMatches_T

Assert.Equal(HttpStatusCode.PreconditionFailed, exception.Response.StatusCode);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenUpdatingConditionallyANewDuplicatedSearchParameterResourceWithSameUrl_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'subject' and base 'Goal' already exists with
* the url http://hl7.org/fhir/SearchParameter/Goal-subject */

var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedConditionalUpdate");
resourceToCreate.Id = null;
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/Goal-subject"; // Same url than the default one

using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.ConditionalUpdateAsync(
resourceToCreate,
$"url={resourceToCreate.Url}"));

var operationOutcome = ex.OperationOutcome;
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.NotNull(operationOutcome);
Assert.NotEmpty(operationOutcome.Issue);
Assert.Single(operationOutcome.Issue);

var expectedError = "A search parameter with the same code value 'subject' already exists for base type 'Goal'.";
Assert.Contains(expectedError, operationOutcome.Issue[0].Diagnostics);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenUpdatingConditionallyANewDuplicatedSearchParameterResourceWithUrl_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'subject' and base 'Goal' already exists with
* the url http://hl7.org/fhir/SearchParameter/Goal-subject */

var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedConditionalUpdate");
resourceToCreate.Id = null;
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/subject-goal-test-conditional-update-url";

using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.ConditionalUpdateAsync(
resourceToCreate,
$"url={resourceToCreate.Url}"));

var operationOutcome = ex.OperationOutcome;
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.NotNull(operationOutcome);
Assert.NotEmpty(operationOutcome.Issue);
Assert.Equal(2, operationOutcome.Issue.Count);

var firstIssue = "A search parameter with Uri 'http://hl7.org/fhir/SearchParameter/subject-goal-test-conditional-update-url' was not found.";
var secondIssue = "A search parameter with the same code value 'subject' already exists for base type 'Goal'.";

Assert.Contains(firstIssue, operationOutcome.Issue[0].Diagnostics);
Assert.Contains(secondIssue, operationOutcome.Issue[1].Diagnostics);

/* If a search parameter with the url http://hl7.org/fhir/SearchParameter/subject-goal-test-conditional-update-url already exists
* this test will fail because the first Issue will not be shown in the OperationOutcome.
*/
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenAResource_WhenUpdatingConditionallyANewDuplicatedSearchParameterResourceWithCode_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'subject' and base 'Goal' already exists with
* the url http://hl7.org/fhir/SearchParameter/Goal-subject */

var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedConditionalUpdate");
resourceToCreate.Id = null;
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/subject-goal-test-conditional-update-code";

using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.ConditionalUpdateAsync(
resourceToCreate,
$"code=subject"));

var operationOutcome = ex.OperationOutcome;
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.NotNull(operationOutcome);
Assert.NotEmpty(operationOutcome.Issue);
Assert.Equal(2, operationOutcome.Issue.Count);

var firstIssue = "A search parameter with Uri 'http://hl7.org/fhir/SearchParameter/subject-goal-test-conditional-update-code' was not found.";
var secondIssue = "A search parameter with the same code value 'subject' already exists for base type 'Goal'.";

Assert.Contains(firstIssue, operationOutcome.Issue[0].Diagnostics);
Assert.Contains(secondIssue, operationOutcome.Issue[1].Diagnostics);

/* If a search parameter with the url http://hl7.org/fhir/SearchParameter/subject-goal-test-conditional-update-code already exists
* this test will fail because the first Issue will not be shown in the OperationOutcome.
*/
}
}
}
61 changes: 0 additions & 61 deletions test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/UpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,67 +261,6 @@ public async Task GivenTheResource_WhenUpdatingAnExistingResourceWithNoDataChang
Assert.Contains(updateResponseAfterMetaUpdated.Resource.Meta.Tag, t => t.Code == "TestCode2");
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenTheResource_WhenUpdatingANewDuplicatedSearchParameterResourceWithSameUrl_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'description' and base 'ResearchDefinition' already exists with
* the url http://hl7.org/fhir/SearchParameter/DocumentReference-relation */

var id = Guid.NewGuid();
var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedUpdate");
resourceToCreate.Id = id.ToString();
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/DocumentReference-relation";

using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.UpdateAsync(
$"SearchParameter/{id}",
resourceToCreate));

var operationOutcome = ex.OperationOutcome;
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.NotNull(operationOutcome);
Assert.NotEmpty(operationOutcome.Issue);
Assert.Single(operationOutcome.Issue);

var expectedError = "A search parameter with the same code value 'relation' already exists for base type 'DocumentReference'.";
Assert.Contains(expectedError, operationOutcome.Issue[0].Diagnostics);
}

[Fact]
[Trait(Traits.Priority, Priority.One)]
public async Task GivenTheResource_WhenUpdatingANewDuplicatedSearchParameterResourceWithUrl_TheServerShouldFail()
{
/* When the server starts, search-parameters.json files are loaded and the default search parameters
* are created. The search parameter with the code 'description' and base 'ResearchDefinition' already exists with
* the url http://hl7.org/fhir/SearchParameter/DocumentReference-relation */

var id = Guid.NewGuid();
var resourceToCreate = Samples.GetJsonSample<SearchParameter>("SearchParameterDuplicatedUpdate");
resourceToCreate.Id = id.ToString();
resourceToCreate.Url = "http://hl7.org/fhir/SearchParameter/relation-DocumentReference-test-update-url";

using FhirClientException ex = await Assert.ThrowsAsync<FhirClientException>(() => _client.UpdateAsync(
$"SearchParameter/{id}",
resourceToCreate));

var operationOutcome = ex.OperationOutcome;
Assert.Equal(HttpStatusCode.BadRequest, ex.StatusCode);
Assert.NotNull(operationOutcome);
Assert.NotEmpty(operationOutcome.Issue);
Assert.Equal(2, operationOutcome.Issue.Count);

var firstIssue = "A search parameter with Uri 'http://hl7.org/fhir/SearchParameter/relation-DocumentReference-test-update-url' was not found.";
var secondIssue = "A search parameter with the same code value 'relation' already exists for base type 'DocumentReference'.";

Assert.Contains(firstIssue, operationOutcome.Issue[0].Diagnostics);
Assert.Contains(secondIssue, operationOutcome.Issue[1].Diagnostics);

/* If a search parameter with the url http://hl7.org/fhir/SearchParameter/relation-DocumentReference-test-update-url already exists
* this test will fail because the first Issue will not be shown in the OperationOutcome.
*/
}

private static void ValidateUpdateResponse(Observation oldResource, FhirResponse<Observation> newResponse, bool same, HttpStatusCode expectedStatusCode)
{
Assert.Equal(expectedStatusCode, newResponse.StatusCode);
Expand Down

0 comments on commit bacb0e8

Please sign in to comment.