FHIR Chat · SDK questions · dotnet

Stream: dotnet

Topic: SDK questions


view this post on Zulip Dennis Brox (Jan 24 2022 at 19:20):

10:08 AM

I'm populating SDK classes in C# seemingly the way I expect - - I can see what I am putting into Atlas, but there are some questions. I can't set the humanname.nameuse value to a string so I can test what it is. How do you do that i.e. I have a string that I want to check a nameuse value against? I set value properties but .net puts those in and adds objectvalues. Is there a way to disable that? I put Identifier values in a list but the document result in Mongodb doesn't have them. Is that a .net problem or a Mongo problem because I can see them in the C# class? Sorry to ask such simple questions but search didn't locate anything.

view this post on Zulip Gino Canessa (Jan 24 2022 at 19:45):

Hi Dennis,

The SDK uses enums for values that are bound strictly to a set. This is a convenience when populating to ensure that the value is from the allowed set (e.g., HumanName.Use is bound strictly to HumanName.NameUse).

If you are converting to or from an enum, the class Hl7.Fhir.Utility.EnumUtility has functions to translate. For example: Hl7.Fhir.Utility.EnumUtility.ParseLiteral<HumanName.NameUse>("usual") will return the enum valueHumanName.NameUse.Usual. Make sure to trap errors if you are using unvalidated values.

If you are just checking a value, you can also validate the string of the UseElement. For example:

resource.Name[0].Use = Hl7.Fhir.Utility.EnumUtility.ParseLiteral<HumanName.NameUse>("usual");
if (resource.Name[0].UseElement.ToString() == "usual")
{
    System.Console.WriteLine("Name UseElement is usual");
}

works fine.

It is probably 'better' to use the enum conversion utility to check, but I have not done any performance testing, etc.

If you are trying to use the objects directly (e.g., via an ORM), I am guessing there is some custom work to do. Right now, the internal models have a lot of utility that prevents direct usage in a lot of contexts (e.g., you cannot just serialize/parse them generically). There is work underway which should help this, and I'll make a note to figure out if it actually does.

view this post on Zulip Brian Postlethwaite (Jan 24 2022 at 22:42):

There is also a .GetLiteral() extension method that you should use in place of ToString as there are a few cases where the code isn't a valid dotnet literal and it thus encoded. Subtle, but easy to trip over.


Last updated: Apr 12 2022 at 19:14 UTC