Sidebar
0 votes
33 views
ago by jayaprakash-r-2523 (120 points)
How to read, iterate as an array the Json below and attach the AIG segments in a HL7 SIU message?

"AIG": [

    {

      "setId": "111",

      "resourceId": "111222",

      "resourceName": {

        "id": "111222333",

        "lastName": "TLN-1",

        "firstName": "TFN-1"

      }

    },

    {

      "setId": "222",

      "resourceId": "222333",

      "resourceName": {

        "id": "222333444",

        "lastName": "TLN-2",

        "firstName": "TFN-2"

      }

    }

  ]

1 Answer

0 votes

You can loop through the JSON array and add the elements to your HL7 like this:

First we set up the HL7 message object:

message = qie.createHL7Message();

Then we loop through the AIG array, adding each element to the HL7 (in the example below, I've only added the "setId" element, but you can extrapolate how to add additional fields)

for (var i = 1; i <= source.getCount('/AIG/[]'); i++) {
   message.addChild('/', 'AIG', 'AIG|', i);
   message.setNode('AIG-1', source.getNode('/AIG/[' + i + ']/setId'), i);
}
ago by jon-t-7005 (8.3k points)
...