Sidebar

Setting nodes within orcGroup

0 votes
478 views
asked Aug 10, 2018 by jonathan-l-4690 (210 points)
Hello,

I am attempting to pick up a message, separate our the ORC segments, and use that data to query our database and insert the appropriate information into a couple of fields (orcGroup.setNode("OBR-5", priority);). Below is what I have put together, but for some odd reason I can't get any information to write to the fields. I know I must be doing something wrong that is likely very simple, but after numerous tries and searching here for an answer I have ran into a wall.

If anyone can assist with this it would be greatly appreciated!

 

var orcGroups = message.getAllNodes('ORC[group=!ORC]');
for (var i = 0; i < orcGroups.length; i++) {
   qie.debug('i: ' + i);
   var orcGroup = qie.parseHL7String(orcGroups[i]);
   
   var ordernum = '\'' + orcGroup.getNode("OBR-2") + '\'';
   var signusridquery = 'select TOP 1 USRID from ORDERS where ordernum =' + ordernum;
   var signusrid = qie.doSelectQuery('Test-DB', signusridquery, true);
   var priorityquery = 'select TOP 1 PRIORITY from ORDERS where ordernum =' + ordernum;
   var priority = qie.doSelectQuery('Test-DB', priorityquery, true);
         
   orcGroup.setNode("OBR-5", priority);
   orcGroup.setNode("OBR-27", signusrid);
   
   }
}

 

Thanks,
Jonathan

1 Answer

0 votes

Might be best to troubleshoot this over a Webex but if you want to dive in a little deeper I have added my code below so that you can debug each variable and see exactly where things are going wrong. Also, I have removed your single quote escape and replaced it with double quotes in the SQL queries.

 

var orcGroups = message.getAllNodes('ORC[group=!ORC]');
for (var i = 0; i < orcGroups.length; i++) {
   qie.debug('i: ' + i);
   var orcGroup = qie.parseHL7String(orcGroups[i]);

   var ordernum = orcGroup.getNode("OBR-2");
   qie.debug('ordernum: ' + ordernum);
   var signusridquery = 'select TOP 1 USRID from ORDERS where ordernum = "' + ordernum + '"';
   var signusrid = qie.doSelectQuery('Test-DB', signusridquery, true);
   qie.debug('signusrid: ' + signusrid);
   var priorityquery = 'select TOP 1 PRIORITY from ORDERS where ordernum = "' + ordernum + '"';
   var priority = qie.doSelectQuery('Test-DB', priorityquery, true);
   qie.debug('priority: ' + priority);

   orcGroup.setNode("OBR-5", priority);
   orcGroup.setNode("OBR-27", signusrid);

}
 

answered Aug 10, 2018 by michael-h-5027 (14,390 points)
commented Aug 10, 2018 by jonathan-l-4690 (210 points)
I am not sure if it is the variables I am creating as I have also tried var priority = "Test"; while failed as well. No errors, it just doesn't insert the information. Also on the single quote escape, it is the only way I have found to run the queries. I tried your version and it wants to error out each time. It wants to treat the ordernum as a column instead of a value in that column.
...