Skip to content

Commit

Permalink
Merge pull request #2755 from FirelyTeam/feature/summary-count-selflinks
Browse files Browse the repository at this point in the history
Preserve self links when a count summary is conducted
  • Loading branch information
mmsmits committed Apr 3, 2024
2 parents d33ed77 + 929072d commit 69efc6f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/Hl7.Fhir.Base/ElementModel/MaskingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Hl7.Fhir.ElementModel
{
public class MaskingNode : ITypedElement, IAnnotated, IExceptionSource
{

/// <summary>
/// Set to true when a complex type property is mandatory so all its children need to be included
/// </summary>
Expand Down Expand Up @@ -59,7 +58,7 @@ public class MaskingNode : ITypedElement, IAnnotated, IExceptionSource
new MaskingNode(node, new MaskingNodeSettings
{
IncludeMandatory = true,
IncludeElements = new[] { "id", "total" },
IncludeElements = new[] { "id", "total", "link" },
});

public MaskingNode(ITypedElement source, MaskingNodeSettings settings = null)
Expand Down
7 changes: 7 additions & 0 deletions src/Hl7.Fhir.Base/Serialization/SerializationFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public abstract class SerializationFilter
IncludeMandatory = true
}));

public static SerializationFilter ForCount() => new BundleFilter(new TopLevelFilter(
new ElementMetadataFilter()
{
IncludeMandatory = true,
IncludeNames = new[] { "id", "total", "link" }
}));

/// <summary>
/// Construct a new filter that conforms to the `_summary=data` summarized form.
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion src/Hl7.Fhir.Serialization.Shared.Tests/SummaryTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hl7.Fhir.ElementModel;
using FluentAssertions;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Specification;
using Hl7.Fhir.Specification.Source;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -74,5 +75,16 @@ public void SummaryCountUsingStructureDefinitionSummaryProvider()
ITypedElement getXmlNodeSDSP(string xml, FhirXmlParsingSettings s = null) =>
XmlParsingHelpers.ParseToTypedElement(xml, new StructureDefinitionSummaryProvider(ZipSource.CreateValidationSource()), s);
}

[TestMethod]
public void TestSummaryCountSelfLinks()
{
var tpXml = File.ReadAllText(Path.Combine("TestData", "no-namespace.xml"));

var nav = new ScopedNode(getXmlNode(tpXml));
var masker = MaskingNode.ForCount(nav);

masker.Children("link").Children("relation").First().Value.Should().BeEquivalentTo("self");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<meta>
<lastUpdated value="2014-08-18T01:43:30Z"/>
</meta>
<link>
<relation value="self"/>
<url value="https://example.com/base/Observation?subject=Patient/347"/>
</link>
<type value="searchset"/>
<total value="3"/>
<entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public void SummaryElements()
traverse(full.StatusElement).Count());
}

[TestMethod]
public void SummaryCount()
{
var (full, summarized) = runSummarize<Bundle>("simple-bundle.xml", SerializationFilter.ForCount());

// check if result contains the link
traverse(summarized).Should().ContainKey("link");
}

private (T full, T summarized) runSummarize<T>(string filename, SerializationFilter filter) where T : Resource
{
var fullXml = File.ReadAllText(Path.Combine("TestData", filename));
Expand Down
12 changes: 12 additions & 0 deletions src/Hl7.Fhir.Support.Poco.Tests/TestData/simple-bundle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Bundle xmlns="http:https://hl7.org/fhir">
<id value="bundle-example"/>
<meta>
<lastUpdated value="2014-08-18T01:43:30Z"/>
</meta>
<type value="searchset"/>
<total value="0"/>
<link>
<relation value="self"/>
<url value="https://example.com/base/Observation?subject=Patient/347"/>
</link>
</Bundle>

0 comments on commit 69efc6f

Please sign in to comment.