JSON.stringify with mapped variables

There are times when I want to create a data structure in Mirth, and output the contents of that data structure while debugging the code. Luckily, JSON.stringify() is available not only in modern browsers but also in Mirth.

var o = {
  mrn: '8675309',
  labs: [
    'blood bank',
    'microbiology',
    'toxicology'
  ]
};

console.log(JSON.stringify(o, null, '\t'));

However, there are any types of Mirth mapped variables, the JSON.stringify() method blows up on itself with a message similar to

DETAILS:    Java class "[B" has no public instance field or method named "toJSON".

This is how we fix it.

[Read More]

Fixing line breaks in HL7 messages in Mirth Connect

Anyone who has worked in the world of healthcare integration or with HL7 knows that if you have seen one HL7 message, you’ve seen one HL7 message.  Now, a common problem with some source systems is that a line break will sneak in the middle of a segment, rendering the whole message invalid.  How many times have you seen this message?

MSH|^~\&|DDTEK LAB|ELAB-1|DDTEK OE|BLDG14|200502150930||ORU^R01^ORU_R01|CTRL-9876|P|2.4
PID|||010-11-1111||Estherhaus^Eva^E^^^^L|Smith|19720520|F|||256 Sherwood Forest Dr.^^Baton Rouge^LA^70809||(225)334-5232|(225)752-1213||||AC010111111||76-B4335^LA^20070520
OBR|1|948642^DDTEK OE|917363^DDTEK LAB|1554-5^GLUCOSE|||200502150730|||||||||020-22-2222^Levin-Epstein^Anna^^^^MD^^Micro-Managed
Health Associates|||||||||F|||||||030-33-3333&Honeywell&Carson&&&&MD
OBX|1|SN|1554-5^GLUCOSE^^^POST 12H CFST:MCNC:PT:SER/PLAS:QN||^175|mg/dl|70_105|H|||F

Notice the “Health Associates” segment? Obviously, this segment invalidates the message.  When this message is sent through a Mirth channel that expects incoming HL7, the message will error out when Mirth tries to parse it.  Here is how we can fix that.

[Read More]