0

I'm trying to do some math with the PID in a HL7 message in the transform step.

This is the Code i have:

//add 100'000 to PID
var test;
var newPID;
test = parseInt(msg['PID']['PID.3']['PID.3.1'].toString(),10);
newPID = test + 100000;
tmp['PID']['PID.3']['PID.3.1'] = newPID;

The output is:

NaN

Sample of PID Segment:

PID||ABC123|987654|ALT789|PETTY^TOM^^^^||19781218|M||2106-3|10144 MAPLE AVE^^IRVINE^CA^92614||(949)123-1234|||||0053820452|220675537||AME||||1|||||

I always get the PID as a string and i can't convert it.
I'm new to Mirth and JavaScript so I'm glad for any help.

N.R.
  • 230
  • 3
  • 11
  • what is the output referring to? which variable? – erotavlas Mar 21 '18 at 15:58
  • the output refers to: `tmp['PID']['PID.3']['PID.3.1']` – N.R. Mar 21 '18 at 16:09
  • Do you know for sure PID3.1 can always be converted to an integer? Because parseInt will fail if its anything else (gives NaN). -- so NaN + 1000000 = NaN as well – erotavlas Mar 21 '18 at 16:24
  • Yes PID.3.1 is always a number. – N.R. Mar 21 '18 at 17:22
  • well it doesn't appear to be, I would check what this returns - msg['PID']['PID.3']['PID.3.1'], Another possibility is that its an empty string. It will also result in NaN – erotavlas Mar 21 '18 at 17:53
  • Post a sample of your PID segment. It might have repeating patient IDs or something similar. – Shamil Mar 21 '18 at 21:20
  • 1
    @erotavlas You were right the output from msg['PID']['PID.3']['PID.3.1'] ist: `undefined|` – N.R. Mar 22 '18 at 07:43
  • @N.R. If you believe that data is coming, then you may have chosen a strict parsing mode and the actual reference to your PID is different. Other than that your code should work (plus including some additional verification and try-catch block). – Shamil Mar 22 '18 at 16:41

0 Answers0