FHIR Observation DSTU2 resource

268 views Asked by At

I need some help getting the value and unit of a result from the FHIR Observation DSTU2 resource. I want to map these values to strings but it looks like Observation.value[x] can have different type of data. Any thoughts on how to do this in C#? I tried a few ways but no luck so far because the sandbox I'm using contains results as strings, Quantity and CodeableConcept.

http://hl7.org/fhir/observation-definitions.html#Observation.value_x_

1

There are 1 answers

0
Mirjam Baltus On

For the Observation.value field you indeed have a choice of type, so the data in the FHIR resource can hold any of the choices listed for that field.

If you use the Hl7.Fhir.Dstu2 library - the official C# reference implementation available through NuGet, you can use it to easily retrieve the resources from your sandbox and get them into a POCO. Here's an example:

using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
var client = new FhirClient("<your sandbox url>");
var obs = client.Read<Observation>("Observation/<technical id>");
// now you can access obs.Value regardless of the type in it

if you need to serialize the data to xml or json, you use the serializer:

using Hl7.Fhir.Serialization;
var serializer = new FhirJsonSerializer();
Console.WriteLine(serializer.SerializeToString(obs));