Skip to content

Elements handling during serialization #1653

@Ivanidzo4ka

Description

@Ivanidzo4ka

Describe the bug
https://www.hl7.org/fhir/search.html#elements claims following:

Servers are not obliged to return just the requested elements. Servers SHOULD always return mandatory elements whether they are requested or not.

Right now if I use FhirJsonSerializer or FhirXmlSerializer and specify elements collection I only get back that collection not including mandatory elements. I probably can expand elements collection by myself, but it doesn't feel right with how serializer is design, considering it already has flag to do that, but it's hidden from public surface.

To Reproduce
Steps to reproduce the behavior:

var observation= new Observation
{
	Id = "observation",
	Status= ObservationStatus.Final,
        Code = new CodeableConcept("A", "B", "C")
};

var serializer = new FhirJsonSerializer();
var jsonText = serializer.SerializeToString(observation, elements: new[] { "id" });

Expected behavior
I would expect string to contain status and code
{"resourceType":"Observation","id":"observation","status":"final","code":{"text":"C"}}
instead I have
{"resourceType":"Observation","id":"observation"}

Screenshots
If applicable, add screenshots to help explain your problem.

Version used:

  • FHIR Version: All of them
  • Version: AFAIK all of them.

** How to fix:
Change code to :

        public static MaskingNode ForElements(ITypedElement node, string[] _elements) =>
            new MaskingNode(node, new MaskingNodeSettings
            {
                IncludeElements = _elements ?? new string[] { },
                IncludeMandatory = (_elements != null && _elements.Length > 0),
                PreserveBundle = MaskingNodeSettings.PreserveBundleMode.All
            });

I would add IncludeMandatory option to ForElements constructor.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions