web stats
How to create a repeating field (without template) - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2012, 07:13 PM
jchen jchen is offline
What's HL7?
 
Join Date: Jun 2011
Posts: 4
jchen is on a distinguished road
Default How to create a repeating field (without template)

Need helps on how to create the repeating field without using templates.
I need to have the followings:
tmp['PID']['PID.3'][0] = msg['PID']['PID.3']
tmp['PID']['PID.3'][1] = msg['PID']['PID.2']

I cannot use the inbound/outbound templates. Here is what I did:
var tmp = msg.copy();
tmp['PID']['PID.3'][1] = tmp['PID']['PID.3'];
tmp['PID']['PID.3'][1]['PID.3.1'] = msg['PID']['PID.2']['PID.2.1'].toString();
However I got an error message:
TypeError: Cannot set property "PID.3.1" of undefined to "1212121212"

I tried the way indicated in:
http://www.mirthcorp.com/community/f...ead.php?t=4271
It did not really add it as the repeating field. Instead it appends the followings to the end of the entire PID segment:
<PID.3><PID.3.1>......

I struggled whole day without any success. Please help. Thanks.

John Chen
==========
Reply With Quote
  #2  
Old 06-11-2012, 01:52 AM
asulis asulis is offline
Mirth Guru
 
Join Date: Dec 2006
Location: Cagliari, Sardinia, Italy
Posts: 210
asulis is an unknown quantity at this point
Default

Hi john. I had the same problem one year ago and I found no way to do this "directly". The only way that worked for me was this:

Code:
var pid3_template = <PID.3>
            	<PID.3.1></PID.3.1>
            	<PID.3.2></PID.3.2>
				<PID.3.3></PID.3.3>
				<PID.3.4></PID.3.4>
        	</PID.3>
                 
                 pid3_template['PID.3.1'] = 'something'
		 pid3_template['PID.3.4'] = 'something else'

//supposing to have yet instance [0], add the [1] to the message:
 
                 tmp['PID']['PID.3'][1] += pid3_template
I know that it is not the best solution, but I get struggled with this also, so I kept this.
Hope this helps

Alessandro

Last edited by asulis; 06-11-2012 at 03:38 AM.
Reply With Quote
  #3  
Old 06-11-2012, 04:33 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

If you don't want to use an outbound template, you could do this:

Code:
msg.PID['PID.3'] += renameField(msg.PID['PID.2'],'PID.3');
The code for renameField can be found here. Cheers!
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #4  
Old 06-11-2012, 07:12 AM
jchen jchen is offline
What's HL7?
 
Join Date: Jun 2011
Posts: 4
jchen is on a distinguished road
Default

Thanks for your replies.
However each time I use:
tmp['PID']['PID.3'][1] += pid3_template;
It always appends to the end of the PID segment as a value of PID.26.1.
I am using version 2.2.1.5861. Not sure if it is a bug.

John Chen
=======
Reply With Quote
  #5  
Old 02-13-2020, 02:00 PM
StickyBandit's Avatar
StickyBandit StickyBandit is offline
Mirth Guru
 
Join Date: Aug 2013
Location: Home Alone
Posts: 955
StickyBandit is on a distinguished road
Default

I have the same problem, it is putting them at the end.
Mirth Connect Server 3.8.0
Built on May 22, 2019
Java version: 1.8.0_181
Reply With Quote
  #6  
Old 02-14-2020, 12:50 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 95
amble is on a distinguished road
Default

If you're not using templates, how come you have tmp in all your code? We had a system that required very little info so what we did was grab what we wanted from the PID values, delete the PID and just create it again - seemed easier...

Code:
..loop over PID and grab data first (patNum/patVar)


delete msg['PID'];

	createSegmentAfter('PID', msg['MSH']);
	msg['PID']['PID.3']['PID.3.1'] = "001" +patNum;
	msg['PID']['PID.3']['PID.3.4'] = "NAN";
	msg['PID']['PID.3']['PID.3.5'] = "MR";

	if (patVar > 0)
	{
		var newPID = <PID.3/>;
		newPID['PID.3.1'] = "PID";
		msg['PID']['PID.3'] += newPID;
		msg['PID']['PID.3'][1]['PID.3.1'] = patVar;
		msg['PID']['PID.3'][1]['PID.3.4'] = "002";
		msg['PID']['PID.3'][1]['PID.3.5'] = "GB";
	}
Reply With Quote
  #7  
Old 02-14-2020, 12:56 AM
scorpios70 scorpios70 is offline
What's HL7?
 
Join Date: Feb 2014
Posts: 1
scorpios70 is on a distinguished road
Default

Quote:
Originally Posted by jchen View Post
Thanks for your replies.
However each time I use:
tmp['PID']['PID.3'][1] += pid3_template;
It always appends to the end of the PID segment as a value of PID.26.1.
I am using version 2.2.1.5861. Not sure if it is a bug.

John Chen
=======
Something like this should work:

var pid3 = new XML('<PID.3 />');
pid3['PID.3.1']='12345';
pid3['PID.3.4']='A';
pid3['PID.3.5']='MR';

tmp.PID.insertChildBefore(tmp['PID']['PID.3'][0], pid3);
Reply With Quote
  #8  
Old 02-14-2020, 06:16 AM
StickyBandit's Avatar
StickyBandit StickyBandit is offline
Mirth Guru
 
Join Date: Aug 2013
Location: Home Alone
Posts: 955
StickyBandit is on a distinguished road
Default

I got mine to work by doing a function and then calling it....

function getNewPID13() {
var field = new XML();
field = <PID.13><PID.13.1></PID.13.1>
<PID.13.2></PID.13.2>
<PID.13.3></PID.13.3>
<PID.13.5></PID.13.5>
<PID.13.6></PID.13.6>
<PID.13.7></PID.13.7>
<PID.13.8></PID.13.8>
<PID.13.9></PID.13.9>
</PID.13>;
return field;
}

for(i=0;..........{
var pid13=(i>0?getNewPID13():tmp['PID'][0]['PID.13']);

...other assignment code here...
}
if(i>0) { tmp['PID'][0]['PID.13'].appendChild(pid13); }

Last edited by StickyBandit; 02-14-2020 at 06:25 AM.
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 03:09 PM.


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