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.
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.
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|
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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.
JSON
object then create new global/local variable to setJSON
object. And one more things your "object" variable should beJSON
object – Leatherback