Question
Joe Jones · Mar 17

How to read from a JSON File and convert to HL7 message

Hi Community,

I am trying to read a JSON file and convert into HL7 message.Please find the example below

 

Set Jsonobj={"Doctype":"ADT^A01","PatientId":"123","PatientName":"Alex"}

Set Dynjsonobj=##class(%Library.DynamicObject).%FromJSON(Jsonobj)

Error :<THROW>%FromJSON+37^%Library.DynamicAbstractObject.1 *%Exception.General READ error while reading input stream 10 Line 1 Offset 0

I am getting this error while reading the file,Can you please tell me where i am doing wrong in converting the file?

Joe

Product version: Ensemble 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT
0
0 152
Discussion (8)2
Log in or sign up to continue

by using {}  your Jsonobj is already a  %Library.DynamicObject
USER> ZWRITE Jsonobj
Jsonobj=<OBJECT REFERENCE>[1@%Library.DynamicObject]

no need for 
Set Dynjsonobj=##class(%Library.DynamicObject).%FromJSON(Jsonobj)

Hi Robert 

I have tried by giving Set Dynjsonobj={}.%FromJSON(Jsonobj) it is throwing below error 

<THROW>%FromJSON+37^%Library.DynamicAbstractObject.1 *%Exception.General READ error while reading input stream 10 Line 1 Offset 0

Is there any way i can read from the JSON object

if you insist on that line you need

Set Jsonobj="{""Doctype"":""ADT^A01"",""PatientId"":""123"",""PatientName"":""Alex""}"

Thank you Robert, It worked.

Set Jsonobj="{""Doctype"":""ADT^A01"",""PatientId"":""123"",""PatientName"":""Alex""}"

set dynmicobj={}.%FromJSON(Jsonobj)

Set HL7Obj=##Class(EnsLib.HL7.Message).%New(dynmicobj)

---> here i am trying to open an Object trying to Convert JSON to HL7 message

Can you share any ideas how can i proceed from this steps to convert into HL7 message ?

Thank you for giving the example i will look into it

I created a class for the JSON message and then used a data transformation in Ensemble/IRIS to transform the JSON message to an HL7 message.