HL7V2 to JSON in Mirth
Bi-directional Channel (HL7v2-JSON) :
Let’s learn to make the conversion from HL7V2 to JSON in Mith tool. Need for this conversion is high in demand, the end-users may be in need to consume the JSON data for their business use, from the HL7V2 which is basically a pipe-delimiter message.
Pre-requisites :
- MirthConnect : 3.4.1.8057 (latest version)
Channel setup :
- Create a New channel name it as your wish Here I have named HL7V2 to JSON
- Click on Set Data Types button set the source connector inbound to HL7V2.x
- Outbound and Destination 1 to JSON
– that’s it the channel setup is done for it
Source Transformer :
- Go to the source transformer and right click to create a new step
- Name the step as HL7V2 to JSON
- Select the drop-down of the step that you have created and select Javascript
Code :
var hl7V2Array = [];
var hl7V2Obj = {};
hl7V2Obj.messageHeader ={};
hl7V2Obj.messageHeader.fieldSeparator = msg[‘MSH’][‘MSH.1’]
hl7V2Obj.messageHeader.encodingCharacter=msg[‘MSH’][‘MSH.2’]
hl7V2Obj.messageHeader.sendingApplication=msg[‘MSH’][‘MSH.3’][‘MSH.3.1’]
hl7V2Obj.messageHeader.sendingFacility=msg[‘MSH’][‘MSH.4’][‘MSH.4.1’]
hl7V2Obj.messageHeader.receivingApplication=msg[‘MSH’][‘MSH.5’][‘MSH.5.1’]
hl7V2Obj.messageHeader.receivingFacility=msg[‘MSH’][‘MSH.6’][‘MSH.6.1’]
hl7V2Obj.messageHeader.dateTimeMessage=msg[‘MSH’][‘MSH.7’][‘MSH.7.1’]
hl7V2Obj.messageHeader.security=msg[‘MSH’][‘MSH.8’][‘MSH.8.1’]
hl7V2Obj.messageHeader.messageType=msg[‘MSH’][‘MSH.9’][‘MSH.9.1’]
hl7V2Obj.messageHeader.eventType=msg[‘MSH’][‘MSH.9’][‘MSH.9.2’]
hl7V2Obj.messageHeader.controlID=msg[‘MSH’][‘MSH.10’][‘MSH.10.1’]
hl7V2Obj.messageHeader.processingID=msg[‘MSH’][‘MSH.11’][‘MSH.11.1’]
hl7V2Obj.messageHeader.versionID=msg[‘MSH’][‘MSH.12’][‘MSH.12.1’]
hl7V2Obj.messageHeader.sequenceNumber=msg[‘MSH’][‘MSH.13’][‘MSH.13.1’]hl7V2Obj.patientIdentification ={};
hl7V2Obj.patientIdentification.setId=msg[‘PID’][‘PID.1’][‘PID.1.1’]
hl7V2Obj.patientIdentification.patientIdExternal=msg[‘PID’][‘PID.2’][‘PID.2.1’]
hl7V2Obj.patientIdentification.patientIdInternal=msg[‘PID’][‘PID.3’][‘PID.3.1’]
hl7V2Obj.patientIdentification.alternateId=msg[‘PID’][‘PID.4’][‘PID.4.1’]
hl7V2Obj.patientIdentification.patientName={};
hl7V2Obj.patientIdentification.patientName.familyName=msg[‘PID’][‘PID.5’][‘PID.5.1’]
hl7V2Obj.patientIdentification.patientName.givenName=msg[‘PID’][‘PID.5’][‘PID.5.2’]
hl7V2Obj.patientIdentification.motherName=msg[‘PID’][‘PID.6’][‘PID.6.1’]
hl7V2Obj.patientIdentification.dateTimeBirth=msg[‘PID’][‘PID.7’][‘PID.7.1’]
hl7V2Obj.patientIdentification.sex=msg[‘PID’][‘PID.8’][‘PID.8.1’]
hl7V2Obj.patientIdentification.patientAlias=msg[‘PID’][‘PID.9’][‘PID.9.1’]
hl7V2Obj.patientIdentification.race=msg[‘PID’][‘PID.10’][‘PID.10.1’]
hl7V2Obj.patientIdentification.patientAddress=msg[‘PID’][‘PID.11’][‘PID.11.1’]
hl7V2Obj.patientIdentification.countryCode=msg[‘PID’][‘PID.12’][‘PID.12.1’]
hl7V2Obj.patientIdentification.phoneHome=msg[‘PID’][‘PID.13’][‘PID.13.1’]
hl7V2Obj.patientIdentification.phoneBusiness=msg[‘PID’][‘PID.14’][‘PID.14.1’]
hl7V2Obj.patientIdentification.primaryLanguage=msg[‘PID’][‘PID.15’][‘PID.15.1’]
hl7V2Obj.patientIdentification.maritalStatus=msg[‘PID’][‘PID.16’][‘PID.16.1’]
hl7V2Obj.patientIdentification.religion=msg[‘PID’][‘PID.17’][‘PID.17.1’]
hl7V2Obj.patientIdentification.accountNumber=msg[‘PID’][‘PID.18’][‘PID.18.1’]
hl7V2Obj.patientIdentification.ssnNumber=msg[‘PID’][‘PID.19’][‘PID.19.1’]
hl7V2Obj.patientIdentification.driverLicense=msg[‘PID’][‘PID.20’][‘PID.20.1’]hl7V2Array.push(hl7V2Obj);
var output = JSON.stringify(hl7V2Array);
logger.info(output);
channelMap.put(‘JSON’,output);
Consider you send a HL7V2 message like this:
MSH|^~\&|CERNER||PriorityHealth||||ORU^R01|Q479004375T431430612|P|2.3|
PID|||001677980||SMITH^CURTIS||19680219|M||||||||||929645156318|123456789|
PD1||||1234567890^LAST^FIRST^M^^^^^NPI|
OBR|1|341856649^HNAM_ORDERID|000002006326002362|648088^Basic Metabolic Panel|||20061122151600|||||||||1620^Hooker^Robert^L||||||20061122154733|||F|||||||||||20061122140000|
OBX|1|NM|GLU^Glucose Lvl|59|mg/dL|65-99^65^99|L|||F|||20061122154733|
You will get a JSON like this as output:
[{
“messageHeader”: {
“fieldSeparator”: “|”,
“encodingCharacter”: “^~\\&”,
“sendingApplication”: “CERNER”,
“sendingFacility”: “”,
“receivingApplication”: “PriorityHealth”,
“receivingFacility”: “”,
“dateTimeMessage”: “”,
“security”: “”,
“messageType”: “ORU”,
“eventType”: “R01”,
“controlID”: “Q479004375T431430612”,
“processingID”: “P”,
“versionID”: “2.3”,
“sequenceNumber”: “”
},
“patientIdentification”: {
“setId”: “”,
“patientIdExternal”: “”,
“patientIdInternal”: “001677980”,
“alternateId”: “”,
“patientName”: {
“familyName”: “SMITH”,
“givenName”: “CURTIS”
},
“motherName”: “”,
“dateTimeBirth”: “19680219”,
“sex”: “M”,
“patientAlias”: “”,
“race”: “”,
“patientAddress”: “”,
“countryCode”: “”,
“phoneHome”: “”,
“phoneBusiness”: “”,
“primaryLanguage”: “”,
“maritalStatus”: “”,
“religion”: “”,
“accountNumber”: “929645156318”,
“ssnNumber”: “123456789”,
“driverLicense”: “”
}
}]
Thanks, Vibin! Awesome post on nest JSON creation. Really Helpful.