Bi-directional Channel (JSON-HL7V2):

Let’s create a channel in Mirth that will consume the incoming JSON message and convert that into an equivalent HL7v2 message in Mirth (i.e) we are converting JSON format of message to the pipe-delimiter format message with Mirth interoperability.

Pre-requisite:

  • MirthConnect : 3.4.1.8057 (latest version)

Channel setup :

  1. Create a New channel name it as your wish Here I have named JSON to HL7V2
  2. Click on Set Data Types button set the source connector inbound to JSON
  3. Outbound and Destination 1 to HL7V2.x
     – 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 JSONto HL7V2 
  • Select the drop-down of  the step that you have created and select Javascript

Code : 

//Get the incoming JSON Data

var input = JSON.parse(connectorMessage.getRawData());

// parse MSH content
var patienId = input.header.patient_id;
var patientName = input.header.patient_name;
var idCard = input.header.id;
var messagetType = input.header.type;
var subType = input.header.subType;
var ctrlNum = input.header.controlNumber;
var pId = input.header.processingId;
var version = input.header.version;

//parse patientInfo
var internalId = input.patientInfo.internalId;
var firstName = input.patientInfo.nameDetails.firstName;
var lastName = input.patientInfo.nameDetails.lastName;
var initial = input.patientInfo.nameDetails.initial;
var suffix = input.patientInfo.nameDetails.suffix;
var motherName = input.patientInfo.motherName;
var DateOfBirth = input.patientInfo.DOB;
var gender = input.patientInfo.sex;
var race = input.patientInfo.race;
var status = input.patientInfo.maritalStatus;
var religion = input.patientInfo.Religion;
var ssn = input.patientInfo.SSN;
var birthPlace = input.patientInfo.birthPlace;
var orderOfBirth = input.patientInfo.birthOrder;
var citizenship =input.patientInfo.citizenship;

//NextOfKin Details
var nk1Len=msg[‘kinDetails’].length;
for(var nk1Counter=0;nk1Counter<nk1Len;nk1Counter++)
{
var kinFirstName=input.kinDetails[nk1Counter].firstName;
var kinLastName=input.kinDetails[nk1Counter].lastName;
var relationShip=input.kinDetails[nk1Counter].relationship;
var phNumber=input.kinDetails[nk1Counter].phoneNumber;
var contactRole=input.kinDetails[nk1Counter].contactRole;
}

//Equal msg=tmp
msg=tmp;

//Generate HL7v2 Message
//MSH
createSegment(‘MSH’, msg);
msg[‘MSH’][‘MSH.1’]= “|”;
msg[‘MSH’][‘MSH.2’]= “^~\\&”;
msg[‘MSH’][‘MSH.3’]= patienId;
msg[‘MSH’][‘MSH.4’]= patientName;
msg[‘MSH’][‘MSH.5’]= idCard;
msg[‘MSH’][‘MSH.9’][‘MSH.9.1’]=messagetType;
msg[‘MSH’][‘MSH.10’][‘MSH.10.1’]=ctrlNum;
msg[‘MSH’][‘MSH.11’][‘MSH.11.1’]=pId;
msg[‘MSH’][‘MSH.12’][‘MSH.12.1’]=version;

//PID
createSegment(‘PID’, msg);
msg[‘PID’][‘PID.3’][‘PID.3.1’]=internalId;
msg[‘PID’][‘PID.5’][‘PID.5.1’]=firstName;
msg[‘PID’][‘PID.5’][‘PID.5.2’]=lastName;
msg[‘PID’][‘PID.5’][‘PID.5.3’]=initial;
msg[‘PID’][‘PID.5’][‘PID.5.4’]=suffix;
msg[‘PID’][‘PID.6’][‘PID.6.1’]=motherName;
msg[‘PID’][‘PID.7’][‘PID.7.1’]=DateOfBirth;
msg[‘PID’][‘PID.8’][‘PID.8.1’]=gender;
msg[‘PID’][‘PID.10’][‘PID.10.1’]=race;
msg[‘PID’][‘PID.16’][‘PID.16.1’]=status;
msg[‘PID’][‘PID.17’][‘PID.17.1’]=religion;
msg[‘PID’][‘PID.19’][‘PID.19.1’]=ssn;
msg[‘PID’][‘PID.23’][‘PID.23.1’]=birthPlace;
msg[‘PID’][‘PID.25’][‘PID.25.1’]=orderOfBirth;
msg[‘PID’][‘PID.26’][‘PID.26.1’]=citizenship;

//NK1
var nk1Counter=0;
var NK1Segment = createSegment(‘NK1’, msg);
msg[‘NK1’][nk1Counter][‘NK1.2’][‘NK1.2.1’]=kinFirstName
msg[‘NK1’][nk1Counter][‘NK1.2’][‘NK1.2.2’]=kinLastName;
msg[‘NK1’][nk1Counter][‘NK1.3’][‘NK1.3.1’]=relationShip;
msg[‘NK1’][nk1Counter][‘NK1.5’][‘NK1.5.1’]=phNumber;
msg[‘NK1’][nk1Counter][‘NK1.7’][‘NK1.7.1’]=contactRole;
nk1Counter++;

//Convert Mirth based XMl to HL7v2
var output = SerializerFactory.getSerializer(‘HL7V2’).fromXML(msg);
logger.info(“output : “+output);

Consider you are sending an JSON message like this provided below:

{
“header”: {
“patient_id”: “XXXX”,
“patient_name”: “John”,
“id”: “454141541”,
“type”: “ADT”,
“subType”: “A04”,
“controlNumber”: “12345678”,
“processingId”: “T”,
“version”: “2.8”
},
“patientInfo”: {
“internalId”: “12345684”,
“nameDetails”: {
“firstName”: “XXXXX”,
“lastName”: “YYYY”,
“initial”: “Z”,
“suffix”: “III”
},
“motherName”: “YYYYYYYY”,
“DOB”: “19940401”,
“sex”: “M”,
“race”: “white”,
“maritalStatus”: “Single”,
“Religion”: “Jew”,
“SSN”: “112-546-878”,
“birthPlace”: “Minnesota”,
“birthOrder”: “test”,
“citizenship”: “US”
},
“kinDetails”: [{
“firstName”: “WWWWWW”,
“lastName”: “ZZZZZ”,
“relationship”: “XXXXX”,
“phoneNumber”: “(216)123-4567”,
“contactRole”: “EC”
}]
}

Note : In the above JSON message you can see that the data being transmitted is primarily a ADT message. specifically an A04 message which is basically a Patient Registration message format.

Here MSH and PID segments are mandatory. That’s why you can see that In the JSON structure I have not used array (‘[]’) for the key values ‘header‘ and ‘patientInfo‘. If there is a possibility that multiple values may occur in future then we will be having a array structure specified there as in kinDetails. That’s why I have looped the kin details in the transformer code.

If everything goes well upon deploying the channel you will get an output message like this show below.

MSH|^~\&|XXXX|John|454141541||||ADT|12345678|T|2.8
PID|||12345684||XXXXX^YYYY^Z^III|YYYYYYYY|19940401|M||white||||||Single|Jew||112-546-878||||Minnesota||test|US
NK1||WWWWWW^ZZZZZ|XXXXX||(216)123-4567||EC

In case of NK1 segment there can be multiple next of kin available then in that case you will have a JSON like this:

“kinDetails”: [{
“firstName”: “WWWWWW”,
“lastName”: “ZZZZZ”,
“relationship”: “XXXXX”,
“phoneNumber”: “(216)123-4567”,
“contactRole”: “EC”
},{
“firstName”: “WWWWWW”,
“lastName”: “ZZZZZ”,
“relationship”: “XXXXX”,
“phoneNumber”: “(216)123-4567”,
“contactRole”: “EC”
}]

If you print the data inside the loop of the transformer code then you can see both the data are logged. Hence the output should also have multiple NK1 segment available in it.

NOTE :  HIPPA policies are strictly followed in this BLOG so I will never reveal any patient name, other relation name etc here. I will only build a dummy data set, don’t look in specific to message logic.

 

Leave a Comment