FHIR Chat · Serializing error · dotnet

Stream: dotnet

Topic: Serializing error


view this post on Zulip Dennis Brox (Feb 21 2022 at 02:04):

When creating a Person resource, I can do the following:

        Period period = new Period()
        {
            Start = DateTime.MinValue.ToString(),
            End = DateTime.MaxValue.ToString()
        };
        var address = new Address()
        {
            . . . ,
            Period = period
        };

to set the Person address. If I then use FHIRserialize to serialize the resource and then use a FhirJsonParser to recreate the patient, I get an
error thrown indicating it can't deserialize the period I set. What's wrong with the period?

view this post on Zulip Dennis Brox (Feb 21 2022 at 07:25):

Forget this. Got it working by just forcing the date format to the FHIR standard. It was confusing when an error doesn't get thrown on the serialize - - not nice to be able to create garbage and not know about it until you try to read it back.

view this post on Zulip Brian Postlethwaite (Feb 21 2022 at 07:51):

There's an extension method .ToFhirDate() that you can use for those conversions.

view this post on Zulip Dennis Brox (Feb 21 2022 at 22:23):

Maybe this is the same type of problem but more severe. Using code:

            var serializer = new FhirJsonSerializer();
            var jo = serializer.SerializeToString(o);

            var parser = new FhirJsonParser();
            o =  parser.Parse<Observation>(jo);

You can see what gets serialized:
jo
"{\"resourceType\":\"Observation\",\"id\":\"f6174e82-f7f5-4ee0-ae61-1c37882bb27d\",\"text\":{\"div\":\"<xml><value>blood pressure</value></xml>\"},\"subject\":{\"reference\":\"52095\"},\"effectiveDateTime\":\"2022-01-16T11:28:16+00:00\",\"component\":[{\"code\":{\"text\":\"Systolic blood pressure\"},\"valueDecimal\":130},{\"code\":{\"text\":\"Diastolic blood pressure\"},\"valueDecimal\":80}]}"

And I get the following error i.e. it won't deserialize, whereas of course it works fine where there are no FHIR types.

Hl7.Fhir.ElementModel.StructuralTypeException
HResult=0x80131537
Message=Type checking the data: Choice element 'valueDecimal' is suffixed with unexpected type 'decimal' (at Observation.component[0].valueDecimal[0])
Source=Hl7.Fhir.Support

view this post on Zulip Michele Mottini (Feb 21 2022 at 22:46):

Yes, decimal is not a valid type for component.value, and the serializer does not check those things, it serializes whatever type it finds in the class (...and there is no easy C# way to prevent the assignment in the first place, that would be the 'right' solution)

view this post on Zulip Brian Postlethwaite (Feb 21 2022 at 22:52):

Yup, in Observation you're meant to use Quantity for numeric data (so that you apply the appropriate units too)

view this post on Zulip Dennis Brox (Feb 22 2022 at 01:45):

But the problem is that in component.value it is valueQuantity that must be used and it is a Quantity. In Quantity, value is decimal and nothing else can be entered except FHIRDecimal ?

view this post on Zulip Brian Postlethwaite (Feb 22 2022 at 03:44):

That's correct.

view this post on Zulip Brian Postlethwaite (Feb 22 2022 at 03:47):

Your example above just had decimal in the component.value, not in component.valueQuantity.valueDecimal


Last updated: Apr 12 2022 at 19:14 UTC