Announcement

Collapse
No announcement yet.

Mapping help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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>

  • #2
    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, 09:22 AM.
    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.

    Comment


    • #3
      Thanks! I'll use that...
      although I realize I need to get my head of of thinking in HL7 Ver 2.x

      Comment

      Working...
      X