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

Adds soft-deleted extension #3412

Merged
merged 1 commit into from
Jul 26, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Features.Persistence;

public static class SoftDeletedFhirPathExtension
{
/// <summary>
/// Return true if this resource contains the Azure 'soft-deleted' extension in meta data
/// </summary>
public static bool IsSoftDeleted(this ResourceElement resourceElement)
{
return resourceElement.Predicate(KnownFhirPaths.IsSoftDeletedExtension);
}
}
4 changes: 4 additions & 0 deletions src/Microsoft.Health.Fhir.Core/Models/KnownFhirPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Microsoft.Health.Fhir.Core.Models
{
public static class KnownFhirPaths
{
internal const string AzureSoftDeletedExtensionUrl = "http://azurehealthcareapis.com/data-extensions/deleted-state";

public const string BundleEntries = "Resource.entry.resource";

public const string BundleNextLink = "Resource.link.where(relation = 'next').url";
Expand All @@ -16,5 +18,7 @@ public static class KnownFhirPaths
public const string BundleType = "Resource.type";

public const string ResourceNarrative = "text.div";

public const string IsSoftDeletedExtension = $"Resource.meta.extension.where(url = '{AzureSoftDeletedExtensionUrl}').where(value='soft-deleted').exists()";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using Microsoft.Health.Fhir.Core.Extensions;
using Microsoft.Health.Fhir.Core.Features.Persistence;
using Microsoft.Health.Fhir.Core.Models;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Test.Utilities;
using Xunit;

namespace Microsoft.Health.Fhir.Shared.Core.UnitTests.Extensions;

[Trait(Traits.OwningTeam, OwningTeam.Fhir)]
[Trait(Traits.Category, Categories.Import)]
public class KnowFhirPathsTests
{
[Fact]
public void GivenAResource_WhenEvaluatingIfSoftDeleted_ThenTheCorrectFlagIsReturned()
{
ResourceElement patient = Samples.GetDefaultPatient();

var isDeleted = patient.IsSoftDeleted();
Assert.False(isDeleted);

ResourceElement withExtension = patient.TryAddSoftDeletedExtension();

isDeleted = withExtension.IsSoftDeleted();
Assert.True(isDeleted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AssemblyValidationsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\KnowFhirPathsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Features\Compartment\CompartmentIndexerTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Features\Compartment\SearchCompartmentHandlerTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Features\Conformance\ConformanceBuilderTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ public static ResourceElement UpdateLastUpdated(this ResourceElement resource, D
return poco.ToResourceElement();
}

public static ResourceElement TryAddSoftDeletedExtension(this ResourceElement resource)
{
EnsureArg.IsNotNull(resource, nameof(resource));

Resource poco = resource.ToPoco();
poco.Meta ??= new Meta();

if (!poco.Meta.Extension.Any(x => string.Equals(x.Url, KnownFhirPaths.AzureSoftDeletedExtensionUrl, StringComparison.OrdinalIgnoreCase)))
{
poco.Meta.Extension.Add(
new Extension
{
Url = KnownFhirPaths.AzureSoftDeletedExtensionUrl,
Value = new FhirString("soft-deleted"),
});
}

return poco.ToResourceElement();
}

public static SearchParameterInfo ToInfo(this SearchParameter searchParam)
{
EnsureArg.IsNotNull(searchParam, nameof(searchParam));
Expand Down