Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.
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
22 changes: 13 additions & 9 deletions src/Hl7.Fhir.ElementModel/MaskingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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>
private bool _includeAll { get; set;}
private bool _includeAll { get; set; }

public static MaskingNode ForSummary(ITypedElement node) =>
new MaskingNode(node, new MaskingNodeSettings
Expand All @@ -38,9 +38,13 @@ public static MaskingNode ForText(ITypedElement node) =>
});

public static MaskingNode ForElements(ITypedElement node, string[] _elements) =>
ForElements(node, _elements, false);

public static MaskingNode ForElements(ITypedElement node, string[] _elements, bool includeMandatory) =>
new MaskingNode(node, new MaskingNodeSettings
{
IncludeElements = _elements ?? new string[] { },
IncludeMandatory = includeMandatory,
PreserveBundle = MaskingNodeSettings.PreserveBundleMode.All
});

Expand Down Expand Up @@ -103,7 +107,7 @@ private ScopedNode getScope(ITypedElement node) =>
var scope = getScope(node);

// Trivially, we will include the root
if (!scope.Location.Contains(".")) return (true,false);
if (!scope.Location.Contains(".")) return (true, false);

bool atRootBundle() => atBundle() && scope.ParentResource == null;
bool atBundle() => scope.NearestResourceType == "Bundle";
Expand All @@ -112,14 +116,14 @@ private ScopedNode getScope(ITypedElement node) =>
{
case MaskingNodeSettings.PreserveBundleMode.All when atBundle():
case MaskingNodeSettings.PreserveBundleMode.Root when atRootBundle():
return (true,false);
return (true, false);

// fall through...
// fall through...
}

var included = _settings.IncludeAll || _includeAll;

bool mandatory=false; // included because it's required & includeMandatory is on
bool mandatory = false; // included because it's required & includeMandatory is on
var ed = scope.Definition;
if (ed != null)
{
Expand All @@ -133,18 +137,18 @@ private ScopedNode getScope(ITypedElement node) =>
included |= _settings.IncludeElements?.Any(matches) ?? false;

if (_settings.ExcludeElements?.Any(matches) == true)
return (false,false);
return (false, false);

bool matches(string filter)
{
var f = nearest + "." + filter;
return loc == f || loc.StartsWith(f + ".") || loc.StartsWith(f + "["); // include matches + children
}

if (_settings.ExcludeMarkdown && scope.InstanceType == "markdown") return (false,false);
if (_settings.ExcludeNarrative & scope.InstanceType == "Narrative") return (false,false);
if (_settings.ExcludeMarkdown && scope.InstanceType == "markdown") return (false, false);
if (_settings.ExcludeNarrative & scope.InstanceType == "Narrative") return (false, false);

return (included,mandatory);
return (included, mandatory);
}


Expand Down
6 changes: 6 additions & 0 deletions src/Hl7.Fhir.Support.Poco/Serialization/SerializerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class SerializerSettings
/// </summary>
public bool TrimWhiteSpacesInXml { get; set; } = true;

/// <summary>
/// Include mandatory elements when serializing a subset of chosen elements (_elements).
/// </summary>
public bool IncludeMandatoryInElementsSummary { get; set; } = false;

/// <summary>Default constructor. Creates a new <see cref="SerializerSettings"/> instance with default property values.</summary>
public SerializerSettings() { }

Expand All @@ -50,6 +55,7 @@ public void CopyTo(SerializerSettings other)
other.Pretty = Pretty;
other.AppendNewLine = AppendNewLine;
other.TrimWhiteSpacesInXml = TrimWhiteSpacesInXml;
other.IncludeMandatoryInElementsSummary = IncludeMandatoryInElementsSummary;
}

/// <summary>Creates a new <see cref="SerializerSettings"/> object that is a copy of the current instance.</summary>
Expand Down