Announcement

Collapse
No announcement yet.

Converting JSON to HL7

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting JSON to HL7

    I have 2 channels setup in Mirth 1 being HL7 to Json for a rest endpoint and then I need to send the results back from the endpoint HL7. Not all segments of the HL7 message are used so I included a section in the JSON file called "SOURCE HL7" so that I could rebuild the outbound message back. I have attached the file for an example.

    I am looking to convert the inbound JSON message from a REST endpoint to HL7 to be sent out via TCP/IP. I was trying to use "Convert JSON to XML" and then Convert XML to HL7 v2.x but was unable to get it to work.

    I also tried using the map builder setting...

    tmp = msg["Source HL7"] and I get the original raw HL7 message in the transformed section but I get an error. Please see attached.

    I figure if I get the RAW HL7 back I could use the map builder to update the file with the new JSON sections in the source.

    Any help would be appreciated.
    Attached Files
    Last edited by mrando; 01-02-2020, 09:30 AM.

  • #2
    Update

    I now have this converting the "Source HL7" to XML. My next step is to map the new values... I am trying to now take the XML in the source transformation and map it with map builder but get the attached error. Without the Mapping the interface sends an outbound HL7 message which consists of the "Source HL7" values.
    Attached Files

    Comment


    • #3
      One option is, in the channel that converts JSON to HL7, try the following in your transformer code:
      Code:
      hl7Message = msg['HL7'][0]['Source HL7'];
      
      // Convert HL7 to XML, and set it as the message
      msg = SerializerFactory.getSerializer('HL7V2').toXML(hl7Message);
      This assumes that the datatypes for the Source Connector are Inbound:JSON and Outbound:HL7 v2.x.

      Connect will automatically try to do an XML->HL7 conversion when processing the message, post-transformation, so that is why this code is necessary. Also, I realize I responded to an earlier post of yours and gave some misinformation about usage of the "tmp" variable. It is only used when an outbound message template is defined. Otherwise, "msg" should be used.

      Edit: I had not seen your update post, so this is addressing your original question. Hopefully this can solve your issue without needing the map builder.
      Last edited by peterl; 01-02-2020, 10:55 AM. Reason: Didn't see follow up post

      Comment


      • #4
        Slight modification to peterl's response since you are using an outbound template now. The serializer will return a string, which you still need to convert to an XML object before you can modify it.

        Code:
        hl7Message = msg['HL7'][0]['Source HL7'];
        
        // Convert HL7 to XML, and set it as the template
        tmp = new XML(SerializerFactory.getSerializer('HL7V2').toXML(hl7Message));
        Last edited by agermano; 01-02-2020, 12:23 PM.

        Comment


        • #5
          Thanks guys! All is working now except the mapping portion. I could write the mapping in Javascript which I did for PID.5.1, 5.2 and 5.3. I just think it would have a cleaner look if I had it in the message builder. I have uploaded my channel to show what I mean in the transformer for PID.2
          Attached Files

          Comment


          • #6
            Does anyone know if there is a way to do this or should I just stick with the javascript?

            Comment


            • #7
              You should be able to drag-and-drop elements from your inbound template to your outbound template to create the message builder steps automatically. Keep in mind this will use the tmp variable. So, you would either need to assign tmp from the serializer output as in my previous comment, or you'd need to edit all of the message builder steps to change tmp to hl7XML.

              If you end up doing a lot of hand editing of the message builders, I'd just stick with the javascript. What makes the auto-generated message builder steps nice is that you can see from the name of the step what it's going to do. Ultimately, the javascript in the "Generated Script" tab of the message builder is what gets compiled into your channel at deploy time anyway.

              Comment

              Working...
              X