No announcement yet.

Looping through multiple sub-components (MRNs in PID 3.1.x)

  • Filter
  • Time
  • Show
Clear All
new posts

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

  • #2
    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!


    • #3
      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:
      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++){
      				//"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'){
      						//"myPID: " + myPID[i].toString());
      						//$('sPID') = myPID[0];
      						//"myPID: " + $('sPID'));
      There is probably a simpler way to code this, but it works.
      Reid Hospital and Healthcare


      • #4
        Re:Looping through multiple sub-components (MRNs i

        Thanks much!!


        • #5

          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?


          • #6
            I would like to do the same but map the repeated PID values to the outbound HL7 message?


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

              // 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;