-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference to Uri Converter, enables custom search parameters with properties of type reference to be indexed as uri type. Refs AB#131463
- Loading branch information
1 parent
bd101b1
commit ea75818
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...crosoft.Health.Fhir.Core/Features/Search/Converters/ReferenceToUriSearchValueConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Hl7.Fhir.ElementModel; | ||
using Hl7.FhirPath; | ||
using Microsoft.Health.Fhir.Core.Features.Search.SearchValues; | ||
|
||
namespace Microsoft.Health.Fhir.Core.Features.Search.Converters | ||
{ | ||
/// <summary> | ||
/// A converter used to convert from <see cref="ReferenceSearchValue"/> to <see cref="Uri"/>. | ||
/// </summary> | ||
public class ReferenceToUriSearchValueConverter() : | ||
FhirTypedElementToSearchValueConverter<UriSearchValue>("Reference") | ||
{ | ||
protected override IEnumerable<ISearchValue> Convert(ITypedElement value) | ||
{ | ||
if (value.Scalar("reference") is not string reference) | ||
{ | ||
yield break; | ||
} | ||
|
||
// Contained resources will not be searchable. | ||
if (reference.StartsWith('#') | ||
|| reference.StartsWith("urn:", StringComparison.Ordinal)) | ||
{ | ||
yield break; | ||
} | ||
|
||
yield return new UriSearchValue(reference, true); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ared.Core.UnitTests/Features/Search/Converters/ReferenceToUriSearchValueConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using Hl7.Fhir.Model; | ||
using Microsoft.Health.Fhir.Core.Features.Search.Converters; | ||
using Microsoft.Health.Fhir.Tests.Common; | ||
using Microsoft.Health.Test.Utilities; | ||
using Xunit; | ||
using static Microsoft.Health.Fhir.Tests.Common.Search.SearchValueValidationHelper; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace Microsoft.Health.Fhir.Core.UnitTests.Features.Search.Converters | ||
{ | ||
[Trait(Traits.OwningTeam, OwningTeam.Fhir)] | ||
[Trait(Traits.Category, Categories.Search)] | ||
public class ReferenceToUriSearchValueConverterTests : FhirTypedElementToSearchValueConverterTests<ReferenceToUriSearchValueConverter, ResourceReference> | ||
{ | ||
[Fact] | ||
public async Task GivenAFhirReferenceWithNoValue_WhenConverted_ThenNoSearchValueShouldBeCreated() | ||
{ | ||
await Test(uri => uri.Reference = null); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAFhirReferenceWithBasicValue_WhenConverted_ThenAUriSearchValueShouldBeCreated() | ||
{ | ||
const string value = "http://uri"; | ||
|
||
await Test( | ||
uri => uri.Reference = value, | ||
ValidateUri, | ||
value); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAFhirReferenceWithReferenceValue_WhenConverted_ThenAUriSearchValueShouldBeCreated() | ||
{ | ||
const string value = "Patient/123ABC"; | ||
|
||
await Test( | ||
uri => uri.Reference = value, | ||
ValidateUri, | ||
value); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAFhirReferenceWithInvalidURL_WhenConverted_ThenSearchValueShouldBeCreated() | ||
{ | ||
const string value = "this is not a valid url"; | ||
|
||
await Test( | ||
uri => uri.Reference = value, | ||
ValidateUri, | ||
value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters