Json Parsing in Mirth OR Json in Mirth OR HL7 to JSON in Mirth
Asked Answered
L

4

6

I want to use JSON as input of mirth channel and output like details Save in db or Create HL7 message.

In short Input as JSON Parse it and output as any format.

Leatherback answered 20/2, 2014 at 9:29 Comment(0)
L
6
var object = {};

//Create JSON Object from HL7 Message.
object.mrn = msg['PID']['PID.3']['PID.3.1'].toString();
object.firstName = msg['PID']['PID.5']['PID.5.2'].toString();
object.lastName = msg['PID']['PID.5']['PID.5.1'].toString();
object.dob = msg['PID']['PID.7']['PID.7.1'].toString();
object.ssn = msg['PID']['PID.19']['PID.19.1'].toString();

//Create string from JSON Object.
var objjson = JSON.stringify(object);
logger.info(objjson);

//Create Json Object From JSON string.
var tt = JSON.parse(objjson);

Output

{"mrn":"1001","firstName":"COLLEEN","lastName":"OHALLAHAN","dob":"19850704","ssn":"123456789"}

HL7Message Sample

MSH|^~\&|ADT1|SHM|SHMADT|SHM|200812091126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.5|
EVN|A01|200812091126||
PID|1|1001|1001^5^M11^ADT1^MR^SHM||OHALLAHAN^COLLEEN^^||19850704|F||2106-3|1200 N ELM STREET^^NEWPORT BEACH^CA^92660-1020^US^H|OC|(949) 555-1234|(949) 555-5678||S||PATID1001^2^M10^ADT1^AN^A|123456789|U1234567^CA|
NK1|1|OHALLAHAN^BRITTANY^M|SIS^SISTER||||N^NEXT-OF-KIN
PV1|1|I|2000^2012^01||||001122^ZOIDBERG^JOHN^|||SUR||||1|A0|
Leatherback answered 20/2, 2014 at 9:29 Comment(0)
L
5

I was parsing through this page, and found your code Rikin patel. Actually when You create object and display it, it may appear in the console as a JSON data, when when you look your output it will be the normal XML driven format. But instead of the object when you use msg as below:

msg = JSON.stringify(object); //converting msg into JSON object
logger.info("json data:" + msg); //displaying the JSOn message

You will find the data being modified in the output.

Lamasery answered 17/7, 2015 at 9:16 Comment(1)
Don't set msg variable because this is system variable which is contain XML type format. If you want to use JSON object then create new global/local variable to set JSON object. And one more things your "object" variable should be JSON objectLeatherback
L
2

As Per @Debugger, If some one want json file as input/Source then try this solution.

Mirth channel

  • Inbound Datatype as delimited text

  • Outbound DataType as Javascript

Make JavaScript Type of Destination and Write below code in Transformer:

//Create Json Object From JSON string.
var objJson = JSON.parse(messageObject.getRawData());

logger.info(objJson.propertyName);

Input:

{"mrn":"1001","firstName":"COLLEEN","lastName":"OHALLAHAN","dob":"19850704","ssn":"123456789"}

Output:

logger.info(objJson.firstName);

COLLEEN

Note:

Use connectorMessage.getRawData() instead of messageObject.getRawData() for Mirth 3.0+ version.

Leatherback answered 19/3, 2014 at 10:36 Comment(0)
E
-1

To receive JSON as Input in mirth channel, set inbound datatype as delimited text and in channel pre processor create Json object from received message and return the json object.

use the json object to get the details and store in some variables and use DB writer to save in db. To build hl7 message, mirth provides few functions such as createSegment(seg name, index) to easily build your own hl7 message.

Ecotype answered 14/3, 2014 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.