Skip to content

Commit

Permalink
Adds soft-deleted extension (#3412)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankowitz authored Jul 26, 2023
1 parent 940406b commit f4665e3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
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

0 comments on commit f4665e3

Please sign in to comment.