FHIR Chat · Expand valueset in Firely .NET SDK · dotnet

Stream: dotnet

Topic: Expand valueset in Firely .NET SDK


view this post on Zulip Stine Johansen (Jan 05 2021 at 13:47):

Hi, I have the following query working in Postman, which I want to do with the Firely .NET SDK, but I can't see any way to define count or offset when using "ExpandValueSet"?

Working query in Postman: {baseUrl}/ValueSet/{valueset-name}/$expand?count=100&offset=10

Anyone have any experience with this?

view this post on Zulip Joe Mundi (Jan 06 2021 at 21:37):

Hi, so I just tried testing this out on HAPI FHIR server R4 from a C# console application using Hl7.Fhir.R4 NuGet package. The valueset can be seen at http://hapi.fhir.org/baseR4/ValueSet/1729316. In the console application, I created a FhirClient using a base Uri of http://hapi.fhir.org/baseR4. To keep it simple, I just called client.get() then checked to see if it had an expansion, and then used the Contains property on the ValueSet’s Expansion property. Since Contains property is an IEnumerable<> you can use Linq on it.

var valSet = (ValueSet)client.Get(“ValueSet/1729316”);

if (valSet.HasExpansion) // it does, with 54 elements
{
var subset = valSet.Expansion.Contains.Skip(5).Take(10);
}

Hope this helps a little. I’m still learning FHIR.

view this post on Zulip Brian Postlethwaite (Jan 07 2021 at 00:14):

I don't k ow the syntax with that routine, but that would grab all the data locally, and then filter client side with linq.

view this post on Zulip Stine Johansen (Jan 07 2021 at 07:09):

Thanks for the tip! I tried your code, and even though there are 1851 expansion, I got HasExpansion == false. However, I see that I can use it like an HttpClient and managed to get all elements with the following, so I think I'll manage to implement some paging as well.

   public ValueSet ExpandValueSet(string valueSetName)
    {
        var valSet = (ValueSet) _client.Get($"ValueSet/{valueSetName}/$expand?count=10000");
        return valSet;
    }

view this post on Zulip Mirjam Baltus (Jan 07 2021 at 07:40):

You can also use the operation methods on the FhirClient, instead of the more low level Get:

   var p = new Parameters();
   p.Parameter.Add(new Parameters.ParameterComponent() { Name = "count", Value = new Integer(10000) });
   p.Parameter.Add(new Parameters.ParameterComponent() { Name = "offset", Value = new Integer(2000) });

  var valSet = (ValueSet) client.InstanceOperation(ResourceIdentity.Build("ValueSet", "{valueSetName}"), "expand", p, useGet:true);

view this post on Zulip Joe Mundi (Jan 07 2021 at 13:13):

Great tip Mirjam, thank you! One question I still have, and it looks like Stine ran into something similar, is that sometimes a ValueSet has an expansion contained within its representation and sometimes it does not. Is that just bad test data in the HAPI server, or is ValueSet going to be unpredictable and should we just call the $expand operation?

Also, is there more documentation about what are the FHIR client capabilities? I would never have known to try the code you listed above without digging deep into the source code.

view this post on Zulip Mirjam Baltus (Jan 11 2021 at 15:28):

A ValueSet does not need to have an expansion element. If the ValueSet is defined by enumerating all the codes with the ValueSet.include part, that would already give you the list of codes you need. ValueSets can also be defined with a filter, in which case you will need the expansion if you need to check a code against the list, or if you want to show the codes that are in the ValueSet. Please do keep in mind that not all servers are capable of performing a $expand, or might only be able to create an expansion for smaller code systems.

The documentation of the FhirClient is still lacking detail, I'm afraid . But the FhirClient has methods for all the interactions listed on the RestFul FHIR page in the specs, and the SDK code has a lot of inline documentation.


Last updated: Apr 12 2022 at 19:14 UTC