Sidebar

Variable not updating in a loop

0 votes
287 views
asked Jul 12, 2021 by david-g-2503 (170 points)

I've been banging my head against this problem for an hour, and I can't figure it out.

I have a JSON template, called "JSON Treatment Component Template" as follows:

{
  "type": "/*{s:RXC-1}*/",
  "code": "/*{s:RXC-2}*/",
  "amount": "/*{s:RXC-3}*/",
  "units": "/*{s:RXC-4}*/",
  "strength": "/*{s:RXC-5}*/",
  "strength_units": "/*{s:RXC-6}*/"
}

 

I have an HL7 message with the following RXC segments:

RXC|B|NSS250^SOD CHLOR 0.9% INJ|250|ML|250|ML|
RXC|A|VANC500I^VANCOMYCIN|1500|MG|500|MG|

 

When I run the following code, I expect two entries in the JSON, one for the "SOD CHLOR" and another for "VANCOMYCIN"

var rxcSegments = source.getAllNodes('RXC');
template = qie.getVariable('JSON Treatment Component Template');
for (var x = 0; x < rxcSegments.length; x++) {
   var rxcSegment = qie.parseHL7String(rxcSegments[x]);
   var jsonObs;
   jsonObs = qie.evaluateTemplate(template, null, 'JSON', true, null, rxcSegment);
   message.addObjectToJSONArray('/components', jsonObs);
}

 

However, this is the JSON output!

"components": [
   {
      "type": "B",
      "code": "NSS250^SOD CHLOR 0.9% INJ",
      "amount": "250",
      "units": "ML",
      "strength": "250",
      "strength_units": "ML"
   },
   {
      "type": "B",
      "code": "NSS250^SOD CHLOR 0.9% INJ",
      "amount": "250",
      "units": "ML",
      "strength": "250",
      "strength_units": "ML"
   }
]

 

It makes no sense!

1 Answer

0 votes
 
Best answer

In your Evaluate template you are sending the RXC segment as an alternate message but the template is referencing the Source. Update your template to the following:

{
  "type": "/*{alt:RXC-1}*/",
  "code": "/*{alt:RXC-2}*/",
  "amount": "/*{alt:RXC-3}*/",
  "units": "/*{alt:RXC-4}*/",
  "strength": "/*{alt:RXC-5}*/",
  "strength_units": "/*{alt:RXC-6}*/"
}
answered Jul 12, 2021 by brandon-w-8204 (33,270 points)
selected Jul 12, 2021 by david-g-2503
commented Jul 12, 2021 by david-g-2503 (170 points)
It works! Thank you
...