1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
672 views
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);

 

by ben-s-7515 (13.0k points)
selected by jon-t-7005
...