web stats
How do you copy "Entire" Feild to another Segment? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2018, 11:51 AM
Rubicon Rubicon is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 98
Rubicon is on a distinguished road
Default How do you copy "Entire" Feild to another Segment?

Hello all,
I'm trying to copy a the "entire' field from one Segment to another.
Here's my code.

//Move ROL.4.1 to PD1.4
//ROL.4.1 becomes null

msg['PD1']['PD1.4']['PD1.4.1']=msg['ROL']['ROL.4']['ROL.4.1'];
msg['ROL']['ROL.4']['ROL.4.1']="";

This will not copy the "entire" field....Only copies PD1.4.1 component and not the rest.

Any ideas?

Thanks,
Rubi
Reply With Quote
  #2  
Old 03-21-2018, 12:08 PM
Kevin Carlin Kevin Carlin is offline
Mirth Newb
 
Join Date: Mar 2012
Posts: 23
Kevin Carlin is on a distinguished road
Default

msg['PD1']['PD1.4']['PD1.4.1']=msg['ROL']['ROL.4']['ROL.4.1'].toString();

Try this to move the data from ROL-4 to PD1-4
Reply With Quote
  #3  
Old 03-21-2018, 12:11 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

You have to do a deep copy of each element and rename them as you go. There's a function already written for this in the User Defined Functions thread.

http://www.mirthproject.org/communit...0&postcount=15
Reply With Quote
  #4  
Old 03-22-2018, 05:52 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

The reason your code isn't changing the "entire" segment is that you are dialing in too far. If you want to make the PD1.4 segment contain the whole ROL.4 then do this...

Code:
msg['PD1']['PD1.4']=msg['ROL']['ROL.4'].copy();
I recommend it in the destination transformer javascript. That way you can see the difference between the raw inbound and the encoded outbound.
Reply With Quote
  #5  
Old 03-22-2018, 06:46 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

appsbyaaron's suggestion won't work either.

You'll end up with elements like msg['PD1']['PD1.4']['ROL.4.1'], and they won't serialize back to hl7 correctly. You have to rename all of the components as you copy them, which is what the function does that I posted a link to.
Reply With Quote
  #6  
Old 03-22-2018, 07:31 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

I'll be the first to admit I'm wrong or don't know something but the results work.

Code:
msg['PV1']['PV1.7'] = msg['PID']['PID.5'].copy();
Before
Quote:
MSH|^~\&|||||20040909150858||ADT^A02|MSG0000000001 |P|2.5
EVN|A02|19850512233959
PID|1||1325327032||EVANS^TOMMY^T|SCHILSKY^SARAH^W| |N|SPALDING^SUMMER^T
PV1|1|U||||||||||||8||||||||xx|xx|||||||||-354.||||||||||||19391013232345
After
Quote:
MSH|^~\&|||||20040909150858||ADT^A02|MSG0000000001 |P|2.5
EVN|A02|19850512233959
PID|1||1325327032||EVANS^TOMMY^T|SCHILSKY^SARAH^W| |N|SPALDING^SUMMER^T
PV1|1|U|||||EVANS^TOMMY^T|||||||||8||||||||xx|xx|| |||||||-354.||||||||||||19391013232345
Edit:
I'm not trying to be obtuse! That function is 6 years old. I'm sure it works and I'll keep it in mind for the future but I've used the built-in 3.2.2.7694 .copy() feature many times and it works fine for my needs. I've never had to go back in and rename a bunch of elements.

Last edited by appsbyaaron; 03-22-2018 at 07:38 AM.
Reply With Quote
  #7  
Old 03-23-2018, 03:37 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

You can also delete entire segments or specific elements.

This will remove the Patient's first name from the outbound message.
Code:
delete msg['PID']['PID.5']['PID.5.2'];
Raw
Quote:
MSH|^~\&|||||19530404203435||ORU^R30|MSG0000000002 |P|2.5
PID|1||460072587|xxTESTxx|RILEY^ALICIA^J|LUGO^ERNE STINE^S||F|GONZALEZ^JAMES^B|||||||||||||||||||||Y
PV1|1|N||||||||||||||||I||||||||||||19561013|xxTES Txx||||||xxTESTxx||||xx
ORC|SR|||||||||||||||||||||||||||||xxTESTxx
OBR|1|||||||||||||||||||||||||||||||||||1906112021 3303|||||N
TQ1|1||||||19400310211632
OBX|1||||clita||||||U
Encoded
Quote:
MSH|^~\&|||||19530404203435||ORU^R30|MSG0000000002 |P|2.5
PID|1||460072587|xxTESTxx|RILEY^^J|LUGO^ERNESTINE^ S||F|GONZALEZ^JAMES^B|||||||||||||||||||||Y
PV1|1|N||||||||||||||||I||||||||||||19561013|xxTES Txx||||||xxTESTxx||||xx
ORC|SR|||||||||||||||||||||||||||||xxTESTxx
OBR|1|||||||||||||||||||||||||||||||||||1906112021 3303|||||N
TQ1|1||||||19400310211632
OBX|1||||clita||||||U

This will remove the entire patient name
Quote:
delete msg['PID']['PID.5'];
Raw
Quote:
MSH|^~\&|||||19530404203435||ORU^R30|MSG0000000002 |P|2.5
PID|1||460072587|xxTESTxx|RILEY^ALICIA^J|LUGO^ERNE STINE^S||F|GONZALEZ^JAMES^B|||||||||||||||||||||Y
PV1|1|N||||||||||||||||I||||||||||||19561013|xxTES Txx||||||xxTESTxx||||xx
ORC|SR|||||||||||||||||||||||||||||xxTESTxx
OBR|1|||||||||||||||||||||||||||||||||||1906112021 3303|||||N
TQ1|1||||||19400310211632
OBX|1||||clita||||||U
Encoded
Quote:
MSH|^~\&|||||19530404203435||ORU^R30|MSG0000000002 |P|2.5
PID|1||460072587|xxTESTxx||LUGO^ERNESTINE^S||F|GON ZALEZ^JAMES^B|||||||||||||||||||||Y
PV1|1|N||||||||||||||||I||||||||||||19561013|xxTES Txx||||||xxTESTxx||||xx
ORC|SR|||||||||||||||||||||||||||||xxTESTxx
OBR|1|||||||||||||||||||||||||||||||||||1906112021 3303|||||N
TQ1|1||||||19400310211632
OBX|1||||clita||||||U
Reply With Quote
  #8  
Old 03-23-2018, 04:12 AM
aTom aTom is offline
OBX.3 Kenobi
 
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 115
aTom is on a distinguished road
Default

Hi,

I was curious to see what really happens when you copy PID-5 to PV1-7.

It's interesting to note that Mirth really replaces PV1-7 by the copy of PID-5 : this is what you can see in the dashboard when your storage mode is set to DEVELOPMENT.
Code:
<PV1>
    <PV1.1/>
    <PV1.2>
        <PV1.2.1>I</PV1.2.1>
    </PV1.2>
    <PV1.3/>
    <PV1.4/>
    <PV1.5/>
    <PV1.6/>
    <PID.5>
        <PID.5.1>NAME</PID.5.1>
        <PID.5.2>FIRSTNAME</PID.5.2>
        <PID.5.3/>
        <PID.5.4/>
        <PID.5.5>MR</PID.5.5>
    </PID.5>
    <PV1.8/>
</PV1>
If you just have to copy a field, it's very easy. And most of the time, you just want to copy! I'll keep it in mind.

You just have to be aware of this, it might get tricky if you have to alter one of the subfields.
__________________
Tom
Reply With Quote
  #9  
Old 03-23-2018, 04:23 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

Here's an example of code we have that uses the .copy() function.

Code:
//MSH
	tmp['MSH']['MSH.4']=msg['MSH']['MSH.4'].copy();	//(C) or PV1.3.4 - Sending Facility
	tmp['MSH']['MSH.7']=msg['MSH']['MSH.7'].copy();	//(R) Date/Time of Message
	tmp['MSH']['MSH.9']['MSH.9.1']=msg['MSH']['MSH.9']['MSH.9.1'].toString(); //Type
	tmp['MSH']['MSH.9']['MSH.9.2']=msg['MSH']['MSH.9']['MSH.9.2'].toString(); //Event
	tmp['MSH']['MSH.10']['MSH.10.1']=msg['MSH']['MSH.10']['MSH.10.1'].toString(); //Message Control ID

//EVN
  	tmp['EVN']=msg['EVN'].copy(); 

//PID
     tmp['PID']['PID.3']=msg['PID']['PID.3'].copy();	//(R) MRN - Patient ID (Internal ID)
 	tmp['PID']['PID.5']['PID.5.1']=msg['PID']['PID.5']['PID.5.1'].toString();	//(R) Patient Last Name 
     tmp['PID']['PID.5']['PID.5.2']=msg['PID']['PID.5']['PID.5.2'].toString();	//(R) Patient First Name
     tmp['PID']['PID.5']['PID.5.3']=msg['PID']['PID.5']['PID.5.3'].toString();	//(O) Patient Middle Name 
     tmp['PID']['PID.7']=msg['PID']['PID.7'].copy();	//(R) Birth Date
     tmp['PID']['PID.8']=msg['PID']['PID.8'].copy();	//(R) Sex
     tmp['PID']['PID.10']=msg['PID']['PID.10'].copy();	//(C) Race
     tmp['PID']['PID.11']['PID.11.1']=msg['PID']['PID.11']['PID.11.1'].toString();	//(O) Address Line 1
     tmp['PID']['PID.11']['PID.11.2']=msg['PID']['PID.11']['PID.11.2'].toString();	//(O) Address Line 2
     tmp['PID']['PID.11']['PID.11.3']=msg['PID']['PID.11']['PID.11.3'].toString();	//(O) City
     tmp['PID']['PID.11']['PID.11.4']=msg['PID']['PID.11']['PID.11.4'].toString();	//(O) State
     tmp['PID']['PID.11']['PID.11.5']=msg['PID']['PID.11']['PID.11.5'].toString();	//(O) Zip/Postal Code
     tmp['PID']['PID.12']=msg['PID']['PID.12'].copy();	//(O) Country
     tmp['PID']['PID.13']=msg['PID']['PID.13'].copy();	//(O) Home Phone Number
     tmp['PID']['PID.14']=msg['PID']['PID.14'].copy();	//(O) Business Phone Number
	tmp['PID']['PID.18']=msg['PID']['PID.18'].copy();	//(R) Patient Visit ID 
     tmp['PID']['PID.22']=msg['PID']['PID.22'].copy();	//(C) Ethinicty
     tmp['PID']['PID.29']=msg['PID']['PID.29'].copy();	//(C) Death Date/Time
     tmp['PID']['PID.30']=msg['PID']['PID.30'].copy();	//(C) Death Inicator

//MRG
  	tmp['MRG']=msg['MRG'].copy();  


//OBX
var v_OBXLoop=0;
for each (OBXLine in msg..OBX) 
   {
      v_OBX_3_2 = msg['OBX'][v_OBXLoop]['OBX.3']['OBX.3.2'].toString();	
      v_OBX_5 = msg['OBX'][v_OBXLoop]['OBX.5'].copy();	 
      v_OBX_6 = msg['OBX'][v_OBXLoop]['OBX.6'].copy();	
      tmp['OBX'][v_OBXLoop] = '';
      tmp['OBX'][v_OBXLoop]['OBX.3']['OBX.3.2'] = v_OBX_3_2;	//(R) Height or Weight Indicator
      tmp['OBX'][v_OBXLoop]['OBX.5'] = v_OBX_5;	//(R) Numberic value of height or weight
      tmp['OBX'][v_OBXLoop]['OBX.6'] = v_OBX_6;	//(R) Units of measurements
      v_OBXLoop++;
   }
Reply With Quote
  #10  
Old 03-23-2018, 04:45 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

Now that latest one I would expect to work, since you are not copying to a differently named field. You're just copying a field and all components from the message to the same spot in the template, and .copy() is how I would suggest doing that as well.
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:46 AM.


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