web stats
Looping through multiple sub-components (MRNs in PID 3.1.x) - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2007, 12:17 PM
rspitz rspitz is offline
Mirth Newb
 
Join Date: Jan 2007
Posts: 8
rspitz
Default Looping through multiple sub-components (MRNs in PID 3.1.x)

I am receiving multiple MRNs in PID 3.1.x within an ADT message.

I'd like to loop through the MRNs and perform the following step:

Insert a separate record for each value (as well as several other fields from the message).

How do I loop through sub-components?
Reply With Quote
  #2  
Old 03-17-2008, 11:06 AM
rspitz rspitz is offline
Mirth Newb
 
Join Date: Jan 2007
Posts: 8
rspitz
Default Re:Looping through multiple sub-components (MRNs in PID 3.1.x)

Did you ever figure this out? I am having the same issue. Thanks!
Reply With Quote
  #3  
Old 03-17-2008, 01:13 PM
afterdark23 afterdark23 is offline
OBX.2 Kenobi
 
Join Date: Oct 2007
Posts: 66
afterdark23
Default Re:Looping through multiple sub-components (MRNs i

I have code that will extract our PN from our PID 3 segment.

Example of PID 3 segment from our HIM:
728825^1^M10^SZB^PN~404417^^^SZB^MR~444665551^^^US GOVT^SS~316611^^^SZB^PI~000024302^^^RHHCS^EE

Code to extract PN:
Code:
var sRepValue = "####";
var sReplace = "";
var mySegment = "";
var myField = "";
var myPID = "";

//Split raw message into segment array
var myRawMessage = messageObject.getRawData().split('\r');
        //Loop through each segment
	for(j = 0; j < myRawMessage.length; j++){
		//Find PID segment
		if (myRawMessage[j].substring(0,3) == 'PID'){		
			//Replace "|" with "####"
			//For some reason I couldn't split by "|"
			sReplace = myRawMessage[j].replace("|", sRepValue);
			mySegment = sReplace.split(sRepValue);
			//Split PID.3 value
			myField = mySegment[3].split('~');
			//Loop through PID.3 values
			for(k = 0; k < myField.length; k++){
				//logger.info("myField: " + myField[k].toString());
				//Split PID.3.k sub values
				sReplace = myField[k].replace("^", sRepValue);
				
				myPID = sReplace.split(sRepValue);
				//Find "PN" value. 
				for(i = 0; i < myPID.length; i++){
					if (myPID[4].toString() == 'PN'){
						//logger.info("myPID: " + myPID[i].toString());
						//$('sPID') = myPID[0];
						channelMap.put('sPID',myPID[0].toString());
						//logger.info("myPID: " + $('sPID'));
					}
				}
			}
		}
	}
There is probably a simpler way to code this, but it works.
__________________
Reid Hospital and Healthcare
Reply With Quote
  #4  
Old 03-17-2008, 01:26 PM
rspitz rspitz is offline
Mirth Newb
 
Join Date: Jan 2007
Posts: 8
rspitz
Default Re:Looping through multiple sub-components (MRNs i

Thanks much!!
Reply With Quote
  #5  
Old 08-11-2017, 04:31 AM
MHAB MHAB is offline
What's HL7?
 
Join Date: Mar 2017
Posts: 2
MHAB is on a distinguished road
Default

Hi,

I'd like to do something similar, so PID3 is repeating but not in all the messages. I'd like to loop PID3 values then map them to the outbound HL7, what do you suggest?
Reply With Quote
  #6  
Old 08-11-2017, 04:35 AM
MHAB MHAB is offline
What's HL7?
 
Join Date: Mar 2017
Posts: 2
MHAB is on a distinguished road
Default

I would like to do the same but map the repeated PID values to the outbound HL7 message?
Reply With Quote
  #7  
Old 11-13-2017, 04:38 PM
jack.downes jack.downes is offline
OBX.2 Kenobi
 
Join Date: Apr 2014
Posts: 59
jack.downes is on a distinguished road
Default

I have a similar issue where I need to remove all the SSN's in the PID segment. One of these is in this PID-3 segment which repeats a bit. Here's my solution which might be of use to people looking at this thread. Obviously, I'm doing something a lot simpler than the OP requested, but... still.

Code:
// Remove the SSN from various locations.

var ssnPattern = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;

msg['PID']['PID.19']['PID.19.1'] = '';
msg['PID']['PID.20']['PID.20.1'] = '';

for (var i = 0; i < 20; i++) {
	try {
		var pid31 = msg['PID']['PID.3'][i]['PID.3.1'].toString();
		if (ssnPattern.test(pid31)) {
			//msg['PID']['PID.3'][i]['PID.3.1'] = '';
			delete msg['PID']['PID.3'][i];
		}
		
	} catch(err) {
		i = 50;
	}
}

// save your changes
hl7_xml = msg;
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through multiple OBX segments, updating SQL database rspitz Support 5 07-27-2012 01:20 PM
Database looping Alexander Support 0 05-08-2008 11:31 PM
Error while looping a single file - SAXParseExcept mac_3785 Support 2 02-26-2008 06:05 AM
Missing components in SVN build of 1.7! andrzej@coalese.com Development 0 02-08-2008 09:40 AM
What are the 'core' components of Mirth? jbartels Development 4 08-09-2007 05:35 AM


All times are GMT -8. The time now is 01:11 AM.


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