Json Parsing in Mirth OR Json in Mirth OR HL7 to JSON in Mirth

Rikin Patel picture Rikin Patel · Feb 20, 2014 · Viewed 14k times · Source

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.

Answer

Rikin Patel picture Rikin Patel · Feb 20, 2014
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|