-
Notifications
You must be signed in to change notification settings - Fork 345
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
Elements handling during serialization #1653
Elements handling during serialization #1653
Comments
This is a should, not a MUST or SHALL, so is ok if it doesn't return them. |
In our implementation of
So, the client is responsible for listing the mandatory elements. But the specification says also:
This is actually contradictory, so we create an issue for this section at HL7 to make it more clear. When you want to follow the server case, you cannot do that with the SDK at the moment. So, we see that this is a design failure in the SDK. But how to solve it? When you add automatically the mandatory fields when using _elements, then existing users get a larger set in return, which is not backward compatible. We can solve this by adding a flag to the What is your opinion @Ivanidzo4ka and @brianpos ? |
I would personally root for optional flag in
or
Optional flag wouldn't force people to update their codebase, I have suspicion what not many users care about that behavior since I'm the first one who created issue about it, so it would be unfair to force people to update their codebase to provide value in function. I would also argue against setting default to add mandatory elements, that would make stealthy change for users, and since this topic is unclear (see contradictory question) it doesn't sound like best way to handle it. You can argue what change would be described in docs and release, but how many people actually read them if your unit tests works fine after you bump nuget version? :D |
Just filed the change request to provide clearer wording in FHIR spec: |
We plan to include a new boolean option |
Thank you for adding this flag to Serializer. For example Observation from my initial request, or DiagnosticReport with code field. 1..1 seems like required for me, but if I serialize Observation I don't get |
Mmmm.... |
Code is also summary field https://hl7.org/fhir/observation-definitions.html#Observation.code From my glance debugging it looks like for CodeableConcept doesn't have value I've just change observation in IncludeMandatoryInElementsSummaryTest to be
|
The following unit test shows that public void IncludeMandatoryInElementsSummaryTest()
{
Observation obs = new()
{
Status = ObservationStatus.Final,
Issued = DateTimeOffset.Now,
Code = new CodeableConcept("system", "code"),
BodySite = new CodeableConcept("system1", "code")
};
// default behavior
var json = new FhirJsonSerializer().SerializeToDocument(obs, elements: new[] { "issued" }) as IDictionary<string, JToken>;
json.Keys.Should().BeEquivalentTo("resourceType", "issued");
// Adding mandatory elements to the set of elements
json = new FhirJsonSerializer(new SerializerSettings() { IncludeMandatoryInElementsSummary = true })
.SerializeToDocument(obs, elements: new[] { "issued" }) as IDictionary<string, JToken>;
json.Keys.Should().BeEquivalentTo("resourceType", "issued", "status", "code");
} In this case the attribute I was wondering how other sorts of summary types handle this in our serializer. For example [TestMethod]
public void IncludeSummaryTextTest()
{
Observation obs = new()
{
Id = "obs-1",
Status = ObservationStatus.Final,
Issued = DateTimeOffset.Now,
Code = new CodeableConcept("system", "code"),
BodySite = new CodeableConcept("system1", "code")
};
var json = new FhirJsonSerializer().SerializeToDocument(obs, Fhir.Rest.SummaryType.Text) as IDictionary<string, JToken>;
json.Keys.Should().BeEquivalentTo("resourceType", "id", "meta", "status", "code");
} This fails for the same reason described above: fields of CodeableConcepts are not mandatory. How do others servers implement this? I did some tests at:
Both the servers return the mandatory element So I tend to say that our serializer is acting false here. Of course we can correct this, but that will change the behavior of several products. How to deal with that? What would be your opinion @Ivanidzo4ka ? |
The issue here is how far done into children does the call go? |
Exactly @brianpos. How far do we go? Also the extensions of |
Who's to decide on this one? Will we just look at the other servers, sort of reverse-engineer the logic and copy that? Or is this a FHIR-I discussion? |
I've started a discussion on chat.fhir.org |
I also created a ticket on HL7.org: https://jira.hl7.org/browse/FHIR-33002 |
Might also want to check in with Gino Canessa, as he's refining the other JSON serializer that I think you'd likely be using in the MS fhir server too... (once he's done there) |
First off, it seems our issue on including mandatory/modifier elements for The verdict is: "we should **align the advice for clients and servers (e.g., by advising both to pay attention to mandatory elements and modifier elements)." (2020-06-22) To me, "pay attention to" means, that they servers should return mandatory and modifier elements. For the new "4.0" serializers, we should then ENABLE it by default (in contrast to the old serializers), but make it easy to disable - and mention this in the documentation of course. And what about the children of mandatory/modifier elements? As Marco says, I think it's wrong for our serializer to leave them out. I intended for the serializer to include all children of mandatory top-level elements but that does not seem to work correctly. Now I have looked at the in summary part of the discussion (see below), the other alternative is not include all children of mandatory/modifier elements, but just the in summary ones. We could make it work like this:
This way, you get what explicitly listed in HAPI (e.g. http://hapi.fhir.org/baseR4/Observation?_id=1178591&_elements=subject) does currently not include the mandatory top-level elements. |
What about _summary? First http://hl7.org/fhir/elementdefinition-definitions.html#ElementDefinition.isSummary
So, that's almost clear, but incomplete. The spec has indeed made sure that all datatypes have elements marked "in summary" (with exceptions), but see https://jira.hl7.org/browse/FHIR-33148. Most importantly, it does not mention how to handle backbones. I don't think we have to write any additional logic on how to deal with mandatory/modifier elements as the spec itself it responsible for defining a sensible summary set. The only addition is Element.id, we agreed to add it to the summary, even if it is not marked as "in summary". |
Then,
After the discussion on
|
Idem for |
@marcovisserFurore @mmsmits The issues referred to in this issue have been discussed during the last WGM, we need to process the outcomes. |
The resolution of https://jira.hl7.org/browse/FHIR-33002 is that only top level mandatory elements need to be returned, including the children that ensure that the minimal payload is still valid. Our newer PocoSerializers ensure this behavior. The older ITypedElement ones, include all children of the top-level mandatory items. Both are valid, since the spec also states: "servers MAY omit elements within these sub-trees as long as they ensure that the payload is valid)." The spec doesn't says anything about including isModifier elements, this should be a effectuated using "inSummary", modifier elements that aren't specified to be included in the summary are therefor not serialized. |
Describe the bug
https://www.hl7.org/fhir/search.html#elements claims following:
Right now if I use
FhirJsonSerializer
orFhirXmlSerializer
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:
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:
** How to fix:
Change code to :
I would add IncludeMandatory option to
ForElements
constructor.The text was updated successfully, but these errors were encountered: