No announcement yet.

converting HL7v2 to JSON

  • Filter
  • Time
  • Show
Clear All
new posts

  • converting HL7v2 to JSON

    I am new to the Mirth community and have been tasked with working on a channel to convert HL7v2 to JSON. Looking for suggestions on setup ect. So far in my research I have found code on it but keep getting an error trying the conversion. I have attached my Data Types setup as well as the code I am using to transform the MSH. I'm thinking my issue lies in the "source transformation". Any help would be appreciated.
    Attached Files

  • #2
    For Data Types, your Source Connector should have an inbound of HL7 v.2 and outbound of JSON, and your Destination Connectors should have an inbound of JSON.

    In the Javascript step in your Source Transformer, you should use the tmp variable to build your outbound message. It would be something like:
    tmp['msh'] = {}
    tmp['msh']['fieldSeparator'] = msg['MSH']['MSH.1'].toString();
    tmp['msh']['encodingCharacter'] = msg['MSH']['MSH.2'].toString();
    tmp['msh']['sendingApplication'] = msg['MSH']['MSH.3']['MSH.3.1'].toString();
    Also, if you are only doing simple one-to-one mappings from HL7 to JSON, you can consider using Message Builder steps instead of Javascript. See the User Guide at to read more about Transformers and Message Builder steps.

    Edit: "tmp" is only used when an outbound message template is defined. Otherwise, use "msg". For example:
    jsonMessage = {};
    jsonMessage['msh'] = {};
    jsonMessage['msh']['fieldSeparator'] = msg['MSH']['MSH.1'].toString();
    jsonMessage['msh']['encodingCharacter'] = msg['MSH']['MSH.2'].toString();
    jsonMessage['msh']['sendingApplication'] = msg['MSH']['MSH.3']['MSH.3.1'].toString();
    msg = jsonMessage;
    Last edited by peterl; 01-02-2020, 11:06 AM. Reason: Incomplete/incorrect information


    • #3

      Thanks for the response. I changed my data types to HL7 and JSON (see attached). I also added your snip-it of code to the source transformer to tried to get the transformation to work for those fields. However it gets transformed to XML and I get an error which I have attached as well.
      Attached Files