Convert fhir between XML and Json - hl7-fhir

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

Related

How Elasticsearch generate the unique _id value?

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());

FHIR Observation DSTU2 resource

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));

Eager loading for reference

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);

What are the capabilities of .NET in AutoCad

Can anyone describe what you can create in C # in Autocad?
I would like to improve the work in the design office, but I do not know what my options are.
Can I create new objects?
Overlays forming an aomomatically drawing based on the given data
other
On the net I found only two blogs with posts from a few years earlier. There is nothing new.
Can anyone recommend any interesting articles, guides?
Any help will be helpful to get started. I know there is documentation but I will need some explanation step by step how everything works.
What you mentioned is possible. The API basics are the same since version 2007 (with incremental updated since and a couple binary breaks, but the code remains similar). For a new development, use the oldest version you plan to support (the last binary break release was 2013)
Visit the AutoCAD DevCenter and check:
Wizard for Visual Studio
Developer Guide
Training material
Webinars (Sessions 1-8)
You can definitely create new objects with the AutoCAD .Net API, below is an example I wrote a while ago, that creates a MLeader.
The .Net API is a managed wrapper around the C++ ObjectARX API, so it covers most of what the C++ API is capable of. The one thing that it cannot do is to derive custom classes from native ones, for Example AcDbLine cannot be extended through .Net. To achieve that you need to use the C++ API and can write a custom .Net wrapper in C++/CLI to expose it to .Net, then you will be able to instantiate your custom classes from .Net similarly to the built-in ones.
Modifying the behaviour of built-in entities can however be achieved directly in .Net by using overrules.
If your plugin is supposed to work only on Windows, then .Net is a more convenient choice than C++ and more flexible to implement UI's.
[CommandMethod("netTextMLeader")]
public static void netTextMLeader() {
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction Tx = db.TransactionManager.StartTransaction()) {
BlockTable table = Tx.GetObject(
db.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord model = Tx.GetObject(
table[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
MLeader leader = new MLeader();
leader.SetDatabaseDefaults();
leader.ContentType = ContentType.MTextContent;
MText mText = new MText();
mText.SetDatabaseDefaults();
mText.Width = 100;
mText.Height = 50;
mText.SetContentsRtf("MLeader");
mText.Location = new Point3d(4, 2, 0);
leader.MText = mText;
int idx = leader.AddLeaderLine(new Point3d(1, 1, 0));
leader.AddFirstVertex(idx, new Point3d(0, 0, 0));
model.AppendEntity(leader);
Tx.AddNewlyCreatedDBObject(leader, true);
Tx.Commit();
}
}
With .Net can you create a new Object?
The answer is No. You need to use ObjectArx for that. However, with .Net you can modify how an object looks like. For example you can modify a line to look like an arrow. Not only how it looks but also how it behaves. So there is enough flexibility in .Net that is enough to compensate for the need to create new objects. Basically with .Net you have the power of windows and autocad.
A good resource of .Net samples is through the interface by Kean Walmsley. Try to go through this blog and you will learn more about .Net capabilities in AutoCAD than what I would ever be able to describe.

Data abstraction in API Blueprint + Aglio?

Reading the API Blueprint specification, it seems set up to allow one to specify 'Data Structures' like:
Address
street: 100 Main Str. (string) - street address
zip: 77777-7777 (string) - zip / postal code
...
Customer:
handle: mrchirpy (string)
address: (address)
And then in the model, make a reference to the data structure:
Model
[Customer][]
It seems all set up that by referencing the data structure it should generate documentation and examples in-line with the end points.
However, I can't seem to get it to work, nor can I find examples using "fully normalized data abstraction". I want to define my data structures once, and then reference everywhere. It seems like it might be a problem with the tooling, specifically I'm using aglio as the rendering agent.
It seems like all this would be top of the fold type stuff so I'm confused and wondering if I'm missing something or making the wrong assumptions about what's possible here.
#zanerock, I'm the author of Aglio. The data structure support that you mention is a part of MSON, which was recently added as a feature to API Blueprint to describe data structures / schemas. Aglio has not yet been updated to support this, but I do plan on adding the feature.

Resources