Since FhirParser and FhirJsonParser are obsolete, how do we Parse incoming Json and Serialize to XML now?

752 views
Skip to first unread message

Benson Lott

unread,
Jun 29, 2018, 5:25:34 PM6/29/18
to FHIR DOTNET
I'm trying write a custom BizTalk pipeline that will handle incoming Fhir/Json. Using what is demonstrated on SoapFault: http://soapfault.com/blog/2016/08/hl7-fhir-json-decoding-in-biztalk/ results in everything leading to the following warning

Create a new navigating parser (JsonDomFhirNavigator.Create()), and then use one of the Parse() overloads taking IElementNavigator

 Which I can then do

var fhirNav = JsonDomFhirNavigator.Create(json);

and can then read the type and such. What I really want to do is serialize to XML, so that BizTalk can handle it, but I can't seem to figure out the "right" way now that the old way it obsolete.

Any help?

Thanks. 

Mirjam Baltus

unread,
Jul 4, 2018, 7:20:14 AM7/4/18
to FHIR DOTNET
Hi! 

The FhirParser is obsolete, but FhirJsonParser is not. Here's an example that reads a file as stream, parses it, and serializes to XML:

            JsonTextReader reader = new JsonTextReader(new System.IO.StreamReader(@"MyObservation.json"));

           
var parser = new FhirJsonParser();
           
var obs = parser.Parse<Observation>(reader);

           
var xmlText = new FhirXmlSerializer().SerializeToString(obs);

Hope this helps!

Benson Lott

unread,
Jul 4, 2018, 1:14:30 PM7/4/18
to FHIR DOTNET
Thanks Mirjam, I knew there had to be a way, I just needed a hint. Here's what I ended up doing:

                                                var fhirPArser = new FhirJsonParser();
                        var operation = msgReceived.Context.GetPropertyValue(Constants.ContextProperties.BizTalkSystem.PropertyNames.Operation);
                        Type type;
                        Base fhirObject;
                        switch (operation.ToString())
                        {
                            case "Bundle":
                                fhirObject = fhirPArser.Parse(json, typeof(Bundle));
                                break;
                            default:
                                fhirObject = fhirPArser.Parse(json, typeof(Bundle));
                                break;
                        }
                        
                        //ResourceReader resourceReader = new ResourceReader(fhir, new ParserSettings());
                        

                        //Use FHIR-NET-API to serialize the resource to XML
                        var xmlSerializer = new FhirXmlSerializer();

                        byte[] resourceXmlBytesNew = xmlSerializer.SerializeToBytes(fhirObject);

                        //Create the new BizTalk message
                        var memoryStream = new MemoryStream();
                        memoryStream.Write(resourceXmlBytesNew, 0, resourceXmlBytesNew.Length);
                        memoryStream.Position = 0;
                        msgReceived.BodyPart.Data = memoryStream;

Since BizTalk is really just XML under the hood, I had to convert it all to XML first, THEN serialize to a memory stream, otherwise it doesn't know what to do with the JSON. I'm not sure this is what I'd call a finished product, but it's a good start. Hopefully this helps someone else in the future.
Reply all
Reply to author
Forward
0 new messages