web stats
Create new segment RXE, copy existing entire OBR segment to RXE - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 09-12-2018, 04:42 PM
coding_birdie coding_birdie is offline
What's HL7?
Join Date: Aug 2018
Posts: 1
coding_birdie is on a distinguished road
Unhappy Create new segment RXE, copy existing entire OBR segment to RXE

mirth newbie
js newbie

mirth connect 3.5.1 version
java version: 1.8.0_161

request: copy an ORM message to a RDE message. With requirements to copy some OBR fields to the ORC segment. Create an RXE segment that doesn't exist and it should be valued with whatever data is contained in the OBR, so copy OBR segment in entirety to newly created RXE segment.

I searched the forums and did find preprocessor code that would rename all OBR segments to RXE segments, however I actually need to map data from the OBR so the preprocessor would wipe that out I assume. I don't know really ...
//message = message.replace(/\rOBR/g, "\rRXE")
//return message;

desired final output message structure:


current code in destination transformer:

        //	msh 
	//	1.       Transform the MSH.9 to RDE
	msg['MSH']['MSH.9']['MSH.9.1'] = 'RDE';
	msg['MSH']['MSH.9']['MSH.9.2'] = 'O01';
	//	orc 
	//	2.       Update the ORC.1 value to be the HL7 standard abbreviation (i.e. – “Order” would be “NW”)
	msg['ORC']['ORC.1']['ORC.1.1'] = 'NW';

	//	rxe 
	//	3.       Copy entire OBR segment to an RXE segment, remove the OBR segment in last processing line.

	var inputOBRIndex = 0;
	for each (seg in msg.children()) {
    	if (seg.name().toString() == "OBR") {
          if (inputOBRIndex == 0) {
              var outputRXE = <RXE/>;
              outputRXE['RXE'] = msg['OBR'].toString();
           } // end inner if
    	} // end outer if
	} // end for 

	//	4.       Move RXE.4.1(OBR.4.1) to RXE.2.1 (OBR.2.1) and RXE.4.2(OBR.4.2) to RXE.2.1
		msg['RXE']['RXE.2']['RXE.2.1'] = msg['OBR']['OBR.4']['OBR.4.1'].toString();
		msg['RXE']['RXE.2']['RXE.2.2'] = msg['OBR']['OBR.4']['OBR.4.2'].toString(); 
	//	5.       Vendor requires start date/time in ORC.7.4 and end date time in ORC.7.5
	//		    Note: Source sends the start/stop times, are sent in OBR-27.  
	//		    OBR;27.4 has the start time, 27.5 has the end time, and the quantity, interval, and duration are sent in 27.1, 2, and 3, respectively.  

	msg['ORC']['ORC.7']['ORC.7.1'] = msg['OBR']['OBR.27']['OBR.27.1'].toString(); // quantity
	msg['ORC']['ORC.7']['ORC.7.2'] = msg['OBR']['OBR.27']['OBR.27.2'].toString(); // interval
	msg['ORC']['ORC.7']['ORC.7.3'] = msg['OBR']['OBR.27']['OBR.27.3'].toString(); // duration
	msg['ORC']['ORC.7']['ORC.7.4'] = msg['OBR']['OBR.27']['OBR.27.4'].toString(); // start date/time
	msg['ORC']['ORC.7']['ORC.7.5'] = msg['OBR']['OBR.27']['OBR.27.5'].toString(); // end date/time
	msg['ORC']['ORC.7']['ORC.7.6'] = msg['OBR']['OBR.27']['OBR.27.6'].toString(); // priority
	msg['ORC']['ORC.7']['ORC.7.7'] = msg['OBR']['OBR.27']['OBR.27.7'].toString(); // condition
	msg['ORC']['ORC.7']['ORC.7.8'] = msg['OBR']['OBR.27']['OBR.27.8'].toString(); // text
	msg['ORC']['ORC.7']['ORC.7.9'] = msg['OBR']['OBR.27']['OBR.27.9'].toString(); // conjunction
	msg['ORC']['ORC.7']['ORC.7.10'] = msg['OBR']['OBR.27']['OBR.27.10'].toString(); // order seq

// remove unwanted segments
	delete msg['PD1'];		
	delete msg['PV2'];
	delete msg['ZVI'];		
	delete msg['NTE'];
	delete msg['OBR'];
sample input file attached

The code in the current state produced output below, and structure is off the tracks, as well as, all my data is zapped.
Any and all instructions is appreciated, I really don't know what I am doing in trying to cobble this together. Thanks in advance for the review.
Attached Files
File Type: txt sample_incoming_msg.txt (831 Bytes, 5 views)
Reply With Quote
Old 09-13-2018, 12:17 PM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,031
agermano is on a distinguished road

In the pre-processor you're dealing with string data. That's actually going to be the easiest place to rename an entire segment if you don't require the original message with an OBR segment for a different destination.

In your transformer, you are working with e4x xml objects that represent the message. It is difficult to rename a segment in the transformer, because every (repetition of each) field, component, and subcomponent all have the segment name as part of their name. You can't directly assign an xml string to an entire segment, but would have to deserialize it to the appropriate objects first.

Other than section 3 (which you should be able to remove if you do it in the pre-processor) all of your modifications are being made to msg, but section 3 was modifying tmp. Your output is likely reflecting a mostly empty outbound template. If you remove your outbound template, it will pass msg through with your changes.

Assuming you rename OBR to RXE in the pre-processor, those changes will already be in effect at the start of your transformer, so

// this
msg['RXE']['RXE.2']['RXE.2.1'] = msg['OBR']['OBR.4']['OBR.4.1'].toString();
// should be
msg['RXE']['RXE.2']['RXE.2.1'] = msg['RXE']['RXE.4']['RXE.4.1'].toString();

// and this
msg['ORC']['ORC.7']['ORC.7.1'] = msg['OBR']['OBR.27']['OBR.27.1'].toString();
//should be
msg['ORC']['ORC.7']['ORC.7.1'] = msg['RXE']['RXE.27']['RXE.27.1'].toString();
Reply With Quote

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 07:13 PM.

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