Sidebar

Unable to get proper JSON output from HL7 message

0 votes
416 views
asked Apr 21, 2021 by manoj-m-7223 (210 points)
HI Team,

Below Javascript not successfully getting executed while converting HL7 message to JSON format and result not showing properly in JSON format. Please help at earliests.

var jsonObsTemplate = '' +
   '{\n' +
   '   "InsuranceID":" /*{alt:IN1-1}*/",\n' +
   '   "InsuranceCompanID": "/*{alt:IN1-3}*/",\n' +
   '   "InsuranceCompanyName": "/*{alt:IN1-4}*/",\n' +
   '   "InsuranceCompanyAddress": "/*{alt:IN1-5}*/",\n' +
   '      }';

var insurances = source.getAllNodes('IN1');
for (var i = 0; i < insurances.length; i++) {
   var insurance = qie.parseHL7String(insurances[i]);
   var jsonins = qie.evaluateTemplate(jsonObsTemplate, null, 'JSON', true, null, insurance);
   message.addObjectToJSONArray('/Insurance', jsonins);
}

// Format the message for readability
message.formatJSON(3);
====================

Output getting as below

"Insurance": [
      "{\n   \"InsuranceID\":\" 1\",\n   \"InsuranceCompanID\": \"80\",\n   \"InsuranceCompanyName\": \"AETNA US HEALTHCARE\",\n   \"InsuranceCompanyAddress\": \"PO BOX 981114^\\\"\\\"^EL PASO^TX^79998^\\\"\\\"\",\n      }",
      "{\n   \"InsuranceID\":\" 2\",\n   \"InsuranceCompanID\": \"90\",\n   \"InsuranceCompanyName\": \"REF US HEALTHCARE\",\n   \"InsuranceCompanyAddress\": \"PO BOX 819439^\\\"\\\"^LP PASO^TX^23400^\\\"\\\"\",\n      }"
   ]

1 Answer

0 votes
 
Best answer

You have an extra comma after the "InsuranceCompanyAddress" element in your JSON template.  If you remove the comma, the template works correctly.

var jsonObsTemplate = '' +
   '{\n' +
   '   "InsuranceID":" /*{alt:IN1-1}*/",\n' +
   '   "InsuranceCompanID": "/*{alt:IN1-3}*/",\n' +
   '   "InsuranceCompanyName": "/*{alt:IN1-4}*/",\n' +
   '   "InsuranceCompanyAddress": "/*{alt:IN1-5}*/"\n' +
   '      }';

var insurances = source.getAllNodes('IN1');
for (var i = 0; i < insurances.length; i++) {
   var insurance = qie.parseHL7String(insurances[i]);
   var jsonins = qie.evaluateTemplate(jsonObsTemplate, null, 'JSON', true, null, insurance);
   message.addObjectToJSONArray('/Insurance', jsonins);
}

// Format the message for readability
message.formatJSON(3);

 

answered Apr 21, 2021 by ben-s-7515 (12,640 points)
selected Apr 21, 2021 by jon-t-7005
...