web stats
Mapping help - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2012, 09:10 AM
skip_ppmc skip_ppmc is offline
What's HL7?
 
Join Date: Jan 2008
Posts: 4
skip_ppmc
Default Mapping help

I received many patient identifiers in PID3 and have a utility
to return a set of validated identifiers, but I need the raw content
without the XML tags. Having a tough time mapping the field
without getting all the tags. Is there a simple way?

public static Identifier[] ClinicUtil.getIdentifiers( String str ) { ....


var total_pid3 = msg['PID']['PID.3'].toString();

total_pid3: ( I put in linefeeds )

<PID.3>
<PID.3.1>55464461</PID.3.1>
<PID.3.2/>
<PID.3.3>M10</PID.3.3>
<PID.3.4>380</PID.3.4>
<PID.3.5>PN</PID.3.5></PID.3>
<PID.3>
<PID.3.1>796600</PID.3.1>
<PID.3.2/>
<PID.3.3/>
<PID.3.4>380</PID.3.4>
<PID.3.5>MR</PID.3.5>
</PID.3>
<PID.3>
<PID.3.1>201326232</PID.3.1>
<PID.3.2/>
<PID.3.3/>
<PID.3.4>US GOVT</PID.3.4>
<PID.3.5>SS</PID.3.5>
</PID.3>
<PID.3>
<PID.3.1>276746</PID.3.1>
<PID.3.2/><PID.3.3/>
<PID.3.4>380</PID.3.4>
<PID.3.5>PI</PID.3.5>
</PID.3>
<PID.3>
<PID.3.1>1000233665</PID.3.1>
<PID.3.2/><PID.3.3/><PID.3.4/>
<PID.3.5>EI</PID.3.5>
</PID.3>
Reply With Quote
  #2  
Old 03-26-2012, 10:19 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 want to go through PID.3 and perform logic on each individual identifier, the easiest way is just to use a loop (make sure to check "Parse Field Repetitions" in the appropriate protocol settings, though it looks like you already have):

Code:
for each (pid3 in msg.PID['PID.3']) {
     // Do something
     // For example, access PID.3.1 with pid3['PID.3.1'].toString()
}
If you just want to serialize the entire field, you can use this; it's something I wrote to do just that:

Code:
function XMLtoHL7(node,fieldSeparator,componentSeparator,repetitionMarker,subcomponentSeparator) {
	if (!node) return '';
	String.prototype.replaceAmp = function() {return this.replace(/&amp;/g,'&');};
	if (node.hasSimpleContent()) return node.toString().replaceAmp();
	importPackage(org.apache.commons.lang);
	var fs = fieldSeparator || '|';
	var cs = componentSeparator || '^';
	var rm = repetitionMarker || '~';
	var ss = subcomponentSeparator || '&';
	var cr = '\x0D';
	var output = '';
	var qname = node[0].name().toString();
	var level = StringUtils.countMatches(qname,'.');

	if (qname == 'HL7Message')
		for each (segment in node.children())
			output += XMLtoHL7(segment,fs,cs,rm,ss);
	else if (level == 0) {
		if (node.length() > 1) {
			for each (segment in node)
				output += XMLtoHL7(segment,fs,cs,rm,ss);
		}
		else {
			output += qname;
			var prevName = '';
			for each (field in node.children()) {
				var fieldName = field.name().toString();
				if (fieldName in {'MSH.1':1,'MSH.2':1})
					output += field.toString().replaceAmp();
				else
					output += prevName==fieldName?rm:fs + XMLtoHL7(field,fs,cs,rm,ss);
				prevName = fieldName;
			}
			output += cr;
		}
	}
	else if (level == 1) {
		if (node.length() > 1) {
			for each (field in node)
				output += XMLtoHL7(field,fs,cs,rm,ss) + rm;
			output = StringUtils.chomp(output,rm);
		}
		else {
			for each (component in node.children())
				output += XMLtoHL7(component,fs,cs,rm,ss) + cs;
			output = StringUtils.chomp(output,cs);
		}
	}
	else if (level == 2) {
		for each (subcomponent in node.children())
			output += XMLtoHL7(subcomponent,fs,cs,rm,ss) + ss;
		output = StringUtils.chomp(output,ss);
	}
	else
		output = node.toString().replaceAmp();
	return output;
}
Use it in your code like so:

Code:
logger.info('PID.3: '+XMLtoHL7(msg.PID['PID.3']));

Last edited by narupley; 03-26-2012 at 10:22 AM.
Reply With Quote
  #3  
Old 03-27-2012, 07:26 AM
skip_ppmc skip_ppmc is offline
What's HL7?
 
Join Date: Jan 2008
Posts: 4
skip_ppmc
Default

Thanks! I'll use that...
although I realize I need to get my head of of thinking in HL7 Ver 2.x
Reply With Quote
Reply

Tags
mapping

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:22 AM.


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