Sidebar

HL7 to JSON conversion issue

0 votes
1.1K views
asked Apr 2, 2019 by aritra-k-6337 (400 points)
edited Apr 2, 2019 by brandon-w-8204
Hi Team,

I am trying to convert an HL7 message to a JSON format using Qvera. I am using a System variable to perform this task. However, I am stuck on converting multiple segments into JSON Array. For example in the Source HL7 message we may have multiple ORC, consecutive OBR's and OBX's. I want all of them to be maintained in  JSON array.

1 Answer

0 votes

You have 2 options that you will need to add to a mapping after you get your base JSON message using your system variable:

1. Create a second template for the items that go into the array. You will then use a for loop to go through each OBR/OBX segment and use add to array options in the code wizard.

2. Use the JSON functions to create a new JSON message and then push that into the array.

Here are the available JSON array commands

Here is a example channel with sample messages and templates:

https://www.qvera.com/kb/?qa=blob&qa_blobid=12294494307419787154

Here is a sample code with the for loops:

//Get OBR segment count
var obrCount = source.getCount('OBR');

//Loop through each OBR build a JSON object for each using a system variable
for (var obr = 1; obr <= obrCount; obr++) {
   // parse the OBR group as an HL7 message. This instance of obrGroup message will be used in the evealuate template alt tag.
   var obrGroup = qie.parseHL7String(source.getNode('OBR[group=!OBR]', obr));
   var obrJson = qie.parseJSONString(qie.evaluateTemplate(qie.getVariable('obrJsonTemplate'), null, '', true, null, obrGroup));
   
   //Process each obx segment in the OBR group and add a JSON object for each in to the obx array
   var obxCount = obrGroup.getCount('OBX');
   for (var obx = 1; obx <= obxCount; obx++) {
      // parse the OBX segment as an HL7 message.
      // The current instance of obrGroup message will be used in the evealuate template alt-1 tag.
      // This instance of obxSeg message will be used in the evaluate template alt-2 tags.
      var obxSeg = qie.parseHL7String(obrGroup.getNode('OBX', obx));
      var obxJson = qie.parseJSONString(qie.evaluateTemplate(qie.getVariable('obxJsonTemplate'), null, '', true, null, [obrGroup, obxSeg]));

      //Add the complete obx JSON object into the ober JSON object.
      obrJson.addObjectToJSONArray('/obxArray', obxJson);
   }
   
   //add the completed obr Json object in to the message
   message.addObjectToJSONArray('/obrArray', obrJson);
}
 

answered Apr 2, 2019 by brandon-w-8204 (33,270 points)
edited Feb 15, 2023 by michael-h-5027
...