web stats
Copying a field with Iterator function - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2019, 09:33 PM
robertb1 robertb1 is offline
Mirth Newb
 
Join Date: Aug 2019
Posts: 9
robertb1 is on a distinguished road
Default Copying a field with Iterator function

Greetings,
New to Mirth and like to get an expert opinion on this. I like to know if I’m doing something wrong or if this a bug. I am using version 3.8.0 64-bit version.
In the process of learning Mirth and I am trying things out. One of my learning exercises is copying a whole field in its entirety from one location to another. Exp. ORC-12 to PV1-9. I tried using the iterator function. In the message tree I dragged and dropped the inbound ORC-12 to outbound PV1-9 and Mirth generated an Iterator/Message builder for me.
It looks like this:

For each msg[‘ORC’]
For each msg[‘ORC’][i][‘ORC.12’]
Patient Visit - Consulting Doctor (PV1.9) (out) <-- Common Order - Ordering Provider [0] (ORC.12) (in)

This mostly worked. My output in PV1-9 has the expected data but everything is encapsulated with XML tags. Pasted Below.

PV1||I|8A^8A29^A^^R^^^^^^||||01136^ALLENN^PAUL^^^^ ^^DPF^^^^DPF~CMD_601492705^ALLENN^PAUL^^^^^^CMD^^^ ^CMD|07094^GATES^BILL^^^^^^DPF^^^^DPF~AMD_61494300 4^GATES^BILL^^^^^AMD^^^^AMD|<ORC.12><ORC.12.1>04586</ORC.12.1><ORC.12.2>JOBS</ORC.12.2><ORC.12.3>STEVE</ORC.12.3><ORC.12.4/><ORC.12.5/><ORC.12.6/><ORC.12.7/><ORC.12.8/><ORC.12.9>DPF</ORC.12.9><ORC.12.10/><ORC.12.11/><ORC.12.12/><ORC.12.13>DPF</ORC.12.13></ORC.12>~<ORC.12><ORC.12.1>CMD_520402705</ORC.12.1><ORC.12.2>JOBS</ORC.12.2><ORC.12.3>STEVE</ORC.12.3><ORC.12.4/><ORC.12.5/><ORC.12.6/><ORC.12.7/><ORC.12.8/><ORC.12.9>CMD</ORC.12.9><ORC.12.10/><ORC.12.11/><ORC.12.12/><ORC.12.13>CMD</ORC.12.13></ORC.12>|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|||||||01136^PA GE^LARRY^^^^^^DPF^^^^DPF~CMD_601492705^PAGE^LARRY^ ^^^^^CMD^^^^CMD||16335504||||||||||||||||||||||||| 20181210084237|||||| ORC|NW|35570945^EPC|||||^Once&1530^X1^201812121530 00^^Routine^^|35380656^|20181212032201|14025^BEZOS ^JEFF^^||04586^JOBS^STEVE^^^^^^DPF^^^^DPF~CMD_520402705^JOB S^STEVE^^^^^^CMD^^^^CMD||(555)555-5859^^^^^555^5555859||||^1^^^|||HOSPITAL|||THE HOSPITAL FOR GENERAL- 8A - HAEMATOLOGY/ONCOLOGY^111 UNIVERSITY AVENUE^BEVERLY HILLS ^CA^90210^USA|||||I

Is this normal or is this a bug?
In one of my other exercises when I operated on just a specific component such as ORC-12.1 to PV1-9.1 , that worked fine. Pasted below.

PV1||I|8A^8A29^A^^R^^^^^^||||01136^ALLENN^PAUL^^^^ ^^DPF^^^^DPF~CMD_601492705^ALLENN^PAUL^^^^^^CMD^^^ ^CMD|07094^GATES^BILL^^^^^^DPF^^^^DPF~AMD_61494300 4^GATES^BILL^^^^^AMD^^^^AMD|04586~CMD_520402705^^^^^^^^^^^^|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX||| ||||01136^PAGE^LARRY^^^^^^DPF^^^^DPF~CMD_601492705 ^PAGE^LARRY^^^^^^CMD^^^^CMD||16335504||||||||||||| ||||||||||||20181210084237|||||| ORC|NW|35570945^EPC|||||^Once&1530^X1^201812121530 00^^Routine^^|35380656^|20181212032201|14025^BEZOS ^JEFF^^||04586^JOBS^STEVE^^^^^^DPF^^^^DPF~CMD_520402705^JOB S^STEVE^^^^^^CMD^^^^CMD||(555)555-5859^^^^^555^5555859||||^1^^^|||HOSPITAL|||THE HOSPITAL FOR GENERAL- 8A - HAEMATOLOGY/ONCOLOGY^111 UNIVERSITY AVENUE^BEVERLY HILLS ^CA^90210^USA|||||I


This is what I want but for all of ORC-12. How do I do this without doing every single component individually in ORC-12?
Thank you.


If it is needed the javascript code for the Iterator/Message builder is copied below

************************************************** ********************
Level 1: For each msg[‘ORC’]
for (var i = 0; i < getArrayOrXmlLength(msg['ORC']); i++) {

for (var j = 0; j < getArrayOrXmlLength(msg['ORC'][i]['ORC.12']); j++) {

if (typeof(tmp) == 'xml') {
if (typeof(tmp['PV1'][i]) == 'undefined') {
createSegment('PV1', tmp, i);
}
if (typeof(tmp['PV1'][i]['PV1.9'][j]) == 'undefined') {
createSegment('PV1.9', tmp['PV1'][i], j);
}
} else {
if (typeof(tmp) == 'undefined') {
tmp = {};
}
if (typeof(tmp['PV1']) == 'undefined') {
tmp['PV1'] = [];
}
if (typeof(tmp['PV1'][i]) == 'undefined') {
tmp['PV1'][i] = {};
}
if (typeof(tmp['PV1'][i]['PV1.9']) == 'undefined') {
tmp['PV1'][i]['PV1.9'] = [];
}
if (typeof(tmp['PV1'][i]['PV1.9'][j]) == 'undefined') {
tmp['PV1'][i]['PV1.9'][j] = {};
}
}
tmp['PV1'][i]['PV1.9'][j] = validate(msg['ORC'][i]['ORC.12'][j].toString(), '', new Array());

}


}



Level 2: For each msg[‘ORC’][i][‘ORC.12’]

for (var j = 0; j < getArrayOrXmlLength(msg['ORC'][i]['ORC.12']); j++) {

if (typeof(tmp) == 'xml') {
if (typeof(tmp['PV1'][i][0]) == 'undefined') {
createSegment('i', tmp['PV1']);
}
if (typeof(tmp['PV1'][i]['PV1.9'][j]) == 'undefined') {
createSegment('PV1.9', tmp['PV1'][i], j);
}
} else {
if (typeof(tmp) == 'undefined') {
tmp = {};
}
if (typeof(tmp['PV1']) == 'undefined') {
tmp['PV1'] = {};
}
if (typeof(tmp['PV1'][i]) == 'undefined') {
tmp['PV1'][i] = {};
}
if (typeof(tmp['PV1'][i]['PV1.9']) == 'undefined') {
tmp['PV1'][i]['PV1.9'] = [];
}
if (typeof(tmp['PV1'][i]['PV1.9'][j]) == 'undefined') {
tmp['PV1'][i]['PV1.9'][j] = {};
}
}
tmp['PV1'][i]['PV1.9'][j] = validate(msg['ORC'][i]['ORC.12'][j].toString(), '', new Array());

}



Level 3: Patient Visit - Consulting Doctor (PV1.9) (out) <-- Common Order - Ordering Provider [0] (ORC.12) (in)

tmp['PV1'][i]['PV1.9'][j] = validate(msg['ORC'][i]['ORC.12'][j].toString(), '', new Array());
Reply With Quote
  #2  
Old 08-10-2019, 05:21 PM
agermano agermano is online now
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 900
agermano is on a distinguished road
Default

What you're trying to do is not easily accomplished with an Iterator step. This is because you not only have to copy values from child elements, but also rename the elements at the same time. However, here is a code template that should make your task easy: https://github.com/nextgenhealthcare...%20HL7%20Field

Using that template it should be a matter of just doing the following in a javascript transformer step:
Code:
msg['PV1']['PV1.9'] = renameField(msg['ORC']['ORC.12'], 'PV1.9');
Reply With Quote
  #3  
Old 08-11-2019, 07:56 PM
robertb1 robertb1 is offline
Mirth Newb
 
Join Date: Aug 2019
Posts: 9
robertb1 is on a distinguished road
Default

Oh thank you that was brilliant. This code function from narupley was brilliant. Just to clarify I was not head strong on using the iterator. It was a repeating field so I thought I had to use the iterator. But what ever, the goal was to copy the ‘entire’ and this works. I wish I knew about this sooner, I can’t believe how many hours I spent playing with for loops trying to tweak the iterator function.
Cheers
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:52 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation