Data Standards – US Healthcare

Lets take three hospitals, A,B and C which uses different data standards for defining Gender in their hospitals

A uses 0,1 for male and female.
B uses 1,0 for male and female,
C uses M,F,U for male, female and unknown.

The data of A and B are different syntactically while the data standards of A and C are different semantically. To achieve uniformity in these, Data standards are proposed. The simplest data standards are as follows:

National Drug Code System:

National Drug Code System  Maintained by US Food and Drug Administration (FDA)
This is a three segment code, that says “who made it / who labelled it”, “what drug is in it”, “what is the package size of this drug”. There are many commercial databases available which provides the same information.

For Example : Please find the below image which is basically a NDC for some medication called “Prozac”. Prozac tablets are basically anti-depressant tablets that will be used for treating/helping patients with Obsessive-Compulsion-Disorder (OCD), or other depression that includes even Bi-polar disorders.

NDC example

The first 4 digits represents the makers of the product. Here Prozac tablets are made by Dista Products. The next 4 digits represents the type the medication will be used, like Prozac as a medication is consumed as Capsule based tablets, it will come in bottle and with 20 mg of each tablets. Then the last two digits represents the count of the tablets, so the Prozac in general will come with the volume of 100 tablets.

As time progress on, many commercial pharmacy databases also started to use the same kind of information or code standards.


To avoid the complexity of commercial databases who produce same information again and again on the medicines.  Another Standard was initiated by National Library of Medicine (NLM). They created something called RxNorm, which gave much more standard to the medication been used by a particular patient.

These RxNorm codes use a special unique number called RxCUI. which will be unique for different drug. Not all medications will have the same RxCUI code. The RxCUI code for the same drug Prozac and its composition can be found here in this link – RxNorm  Prozac

NLM has also created something called United Medical Language System (UMLS) containing the vast array of multiple healthcare terminologies, vocabularies allows u to download and learn them.


Death certificates played a vital role in the development of ICD International classification of Diseases. Dates back to a fine history. Bertillion in chicago 1893 classified some of the possible causes  of death and diseases with a code, which are still used in ICD.

History ICD codes:

We’re gonna move now to standards for problems, diagnoses, the things that afflict patients. These have a very interesting history beginning in the mid 1400s in Northern Italy, when death certificates were first developed. Of course they specified a cause of the death.
200 years later, the bubonic plague erupted, and for the first time people wanted to look at these death certificates as a source of data for analysis. Trying to understand the dynamics this disastrous plague. A couple of decades later in England. Captain John Graunt got interested in why children die, and again, turned to death certificates as a source of information.
In the United States, as early as 1639, it was recognized in Massachusetts that death certificates were important in that they were a public trust, so they needed to be maintained and made available for research and analysis. In 1839, an important figure called William Farr discovered interoperability. That’s my term. Maybe a bit of an exaggeration, but not too much of one. When he noted that each disease has in fact been described in many ways on different certificates.
In 1851, in London, there was a famous Great Exposition. This is what I think was called the Crystal Hall. Countries demonstrated the latest in science and technology, in agriculture and so on and so forth. And people realized that it was very hard to compare across countries because there was no standard way of representing things.


Logical Observation Identifiers Names and Codes Specifically derived for the lab tests that’s been conducted on the patients and their outcomes.


ICD-10, LOINC and SNOMED-CT include a relationship, but there is a uniqueness in SNOMED-CT. SNOMED-CT is from IHTSDO. refer All SNOMED-CT code are followed by a OID code system, this is maintained and managed by a separate organisation. This code System also provides the mapping for the same SNOMED-CT code.



HTTP sender in Javascript

This blog post is about developing HTTP sender in Mirth, without having to send your data via destination.

Suppose, consider a situation when we need to loop through the incoming message and we have to send/post the message multiple time. Mirth do not have the capability to store the loop content variable and pass that to the destination end. So, if you want to loop through the incoming message and send them to HTTP sender, we need to write the Javascript code in the source transformer.

Imagine, that “output” is the variable that contains the looped contents of information in HL7v2 format, now use the below code to invoke HTTTP sender via javascript.

do {
try {
var data = output;
//Destination URL
destURL = ‘http://localhost:8088/’;
var url = new;
var conn = url.openConnection();
conn.setRequestProperty(“Content-length”, data.length());
conn.setRequestProperty(“Content-type”, “text/plain”);
var outStream = conn.getOutputStream();
var outWriter = new;
// Get response Code (200, 500 etc.)
var respCode = conn.getResponseCode();
// get response body
var response = new XML($(‘RESPONSE’)); // XML response message
var status = response[‘Status’].toString();

if (respCode != 200) {
// Write error to error folder
var stringData = response.toString() + ‘\n’;
FileUtil.write(‘C:/Outbox/Errors/’ + $(‘originalFilename’) + ‘.ERROR_RESPONSE’, false, stringData);
// Return Error to Mirth to move the file to the error folder
return ERROR;
errorCond = ‘false’;
catch(err) {
if(retry > 10) {
channelMap.put(‘RESPONSE’, err);
responseMap.put(‘WEBSVC’, ResponseFactory.getErrorResponse(err))
// Can return ERROR, QUEUED, SENT
// This re-queues the message on a fatal error. I’m doing this since any fatal message may be
// caused by HTTPS connect errors etc. The message will be re-queued
return QUEUED; // Re-queue the message
java.lang.Thread.sleep(6000); // 6 seconds * 10

errorCond = ‘true’;
while (errorCond == ‘true’);

Note : This code should be present inside the for loop or the while loop, so that the specific HL7v2 message will be sent/posted to the destination



Parse SOAP response & send HL7V2 ADT

This channel will explain how to parse the SOAP response which will be received from the webservice endpoint which will be a SOAP XML.

Mirth will fetch this XML, parse the SOAP data and convert it into HL7V2 ADT message and send it to the sender.

Mirth :

Have the below HL7v2 available in the POSTMAN of your system. This message will be received by the Mirth as HTTP listener.

MSH|^~\&|TEST|DH|ADT|DH|201301011226||ADT^A08|HG201001|P|2.3|EVN|A08|201301011223||PID|||MRN04160^7^M12||TEST^JACK^R^||19900903|M||2106-3|No5 AskVAsk Street^^Beta^WH^11136-1020|US|(414)222-9595^^^|(414)123-4597|EN|S||MRN27485987^2^M10|986410430|978974^NC||HIN1|Medicare|CD430677||1|||||||IN2|Medicaid|B025546788||1|||||||PD1|02997173|Data|Data2^20161011^20161111^Enrolled^Other||||02693680|Y|Enrolled|||

We will transform this data to the webservice specified format (XML), and the webservice will send a response like the below:

<S:Envelope xmlns:S=”; xmlns:SOAP-ENV=””&gt;
<ns1:addInformation xmlns:ns2=”http://Getdatawebservice/”&gt;
<ErrorReason>Patient deceased</ErrorReason>

Now, we wanted to take the error reason and send it to the sender as HL7V2 response. To do that, go the the Edit Response tab of this destination, and type as below:

var updateMsg= new XML (msg).toString().replace(/:/g,”)
var newMsg= new XML (updateMsg);

var checkError = newmsg[‘SBody’][‘ns1addInformation ‘][‘send’][‘isError’].toString();
var errorMessage = “Message Sent Successfully”;
var errorMessage = newmsg[‘SBody’][‘ns1addInformation ‘][‘send’][‘ErrorReason’].toString();

Now create another destination and create a MSA segment in the outbound template as follows:


Inside the transformer do the following:

tmp[‘MSH’] = $(‘MSH’);
tmp[‘MSA’][‘MSA.2’][‘MSA.2.1’] = $(‘errorMessage’);

Make the destination as Javascript Writer and copy the following code in the code area part

return connectorMessage.getEncodedData();

Deploy the channel, and send the message from the postman and you will get the response like this

MSA||Patient deceased|||


Happy Integrating !!!!!!!!!!!

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.


  • MirthConnect : (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 =;
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 =;
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

//Generate HL7v2 Message
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;

createSegment(‘PID’, msg);

var nk1Counter=0;
var NK1Segment = createSegment(‘NK1’, msg);

//Convert Mirth based XMl to HL7v2
var output = SerializerFactory.getSerializer(‘HL7V2’).fromXML(msg);“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.


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.


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 : (latest version)

Channel setup :

  1. Create a New channel name it as your wish Here I have named HL7V2 to JSON
  2. Click on Set Data Types button set the source connector inbound to HL7V2.x
  3. 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.patientIdentification ={};


var output = JSON.stringify(hl7V2Array);;

Consider you send a HL7V2 message like this:

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”: “”

Blog at

Up ↑