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_
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));
Related
I'm asking simply out of my favor to the look of its result string and am wondering if the algorithm has some kind of library so that I can use in my own code (C#).
See the answer to this question in the Elasticsearch discuss.
You can find the source code to the method linked there here.
Elasticsearch is written in Java, so you won't be able to import this method into your c# project.
If you don't need the specific optimizations that the Elasticsearch-Team implemented in this method, you can use the build in UUID generator of .NET. Or you can look for other UUID libraries on nuget.
If you just like the format of the Elasticsearch IDs you can also base64 encode your GUIDs/UUIDs to get similar looking IDs:
Guid g = Guid.NewGuid();
var base64GUID = System.Convert.ToBase64String(g.ToByteArray());
Is there a way to convert a fhir bundle from json to xml by means that is independent of the FHIR version used?
I think the .net fhir api by firely can do it, but any given version of the api seems to be specific to a certain release of FHIR.
The problem is that a FHIR Bundle (or any resource) implicitly always has a version. The rationale is that each FHIR version has (or can have) a different underlying data model.
It is possible though, using the .NET FHIR API (specifically package https://www.nuget.org/packages/Hl7.Fhir.Serialization) to do the conversion with minimal version differences.
The following code does the conversion using the version-independent ISourceNode (http://docs.simplifier.net/fhirnetapi/parsing/isourcenode.html)
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Serialization;
var xml = "<Patient xmlns=\"http://hl7.org/fhir\"><identifier><use value=\"official\" /></identifier></Patient>";
var patientNode = FhirXmlNode.Parse(xml);
var typedElement = patientNode.ToTypedElement();
var json = typedElement.ToJson();
The above code has one problem though, as VS will tell you. Using ToTypedElement() without parameters is dangerous because ignoring the version is. It will work in many cases though and if it is good enough for you that may be the way to go.
A safer solution is to use the same code, but to additionally use a so-called IStructureDefinitionSummaryProvider (apologies for the naming ;) to provide the API with specific version information. Implementations for this interface can be found in version-specific API libraries, e.g. https://www.nuget.org/packages/Hl7.Fhir.R4.
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification;
var xml = "<Patient xmlns=\"http://hl7.org/fhir\"><identifier><use value=\"official\" /></identifier></Patient>";
var patientNode = FhirXmlNode.Parse(xml);
var summaryProvider = new PocoStructureDefinitionSummaryProvider();
var typedElement = patientNode.ToTypedElement(summaryProvider);
var json = typedElement.ToJson();
You may be able to inject these PocoStructureDefinitionSummaryProviders based on some property of the input you are reading from. That is how we do it in the Vonk FHIR server for instance.
The FHIR java validator can do this for any version. That might be suitable depending on what you need to use it
I wonder if it is possible to load reference data in the first call. In my case I want to load the patient reference in the Encounter Resource. As I know I always need the patient data I want to avoid to to do an additional call to get the patient data.
The server is HAPI FHIR and the client firely .Net API
Yes, that is possible. Your request will have to be a search, that way you can include any referenced resources.
On REST level it looks like this:
GET <hapi_server>/Encounter?_include=patient
Add any filters you have. For example if you have a specific encounter you would add &_id=<technical_id>.
With the FhirClient from the .Net api, the code looks like this:
var c = new FhirClient("<hapi_server");
var q = new SearchParams().Include("Encounter:patient");
q.Add("_id", "<technical_id>");
var result = c.Search<Encounter>(q);
I'm searching for guidance about how to implement a session-level variable on bot framework.
I've created a class to store global vars that is working fine.
However, these variables are persisted across all bot sessions which is not what I need now.
Thanks in advance,
I'm not sure of you are using the Node or the C# SDK. You can easily store data like this in the Databags provided by the SDK. UserData, ConversationData, and PrivateConversationData
For the purposes of just demonstrating how to use this i'm only going to use UserData but any databag could be used the same way
Node
For node, you would set values as if you were using a dictionary or hashmap in other languages:
You can use either dot notation or bracket notation:
session.userData.SomeProperty = "someValue";
session.userData["SomeProperty"] = "someValue"
And then to use the data later, again you can use either dot notation or bracket notation:
var foo = session.userData.SomeProperty;
var foo = session.userData["SomeProperty"]
C#
To set Data:
context.UserData.SetValue("SomeProperty", "SomeValue");
To get data:
context.UserData.GetValue<string>("SomeProperty");
In C# if you need to do this in a place you do not have access to the context object refer to this SO answer
I'm trying to use an external reference in Postman and validating that with tv4.
This is my code:
var schema = tv4.getSchema('https://schema.getpostman.com/json/collection/v1/');
console.log(tv4.validate(responseBody, schema);
and after testing I get
'TypeError Cannot read property '$ref' of undefined'
.
Does that mean my schema is not valid somehow?
I know it's late, but this could help others
tv4.getSchema(name) is used to retrieve an already loaded schema. tv4.addSchema(name, schema) is used to append a new schema of name with schema value
So, what should you do?
Reading this article I understood that you can't make two requests in a test using Postman. Instead you should store its value in a environment or global variable and don't use tv4's functions as those (I guess) were meant to be used in environments where you can actually download a schema using http module.
Finally, your example should look as this
var schema = JSON.parse(postman.getEnvironmentVariable('myEnvVarName'));
let valid = tv4.validate(pm.response.json(), schema, false, true);