Announcement

Collapse
No announcement yet.

Loop help with multiple OBRs

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

  • Loop help with multiple OBRs

    Each OBR will have a ZSA segment. If I have 1 OBR and 1 ZSA segment below code will work correctly to create two OBX segments under the OBR. But, if there are multiple OBR/ZSA segment pairs in the message it does not work.

    Code:
    if (msg['OBR'].length() >= 1)
    	{
        for (j = 0; j < msg['OBR'].length(); j++)  //loop runs 3 times
    	{
    		for (i = 0; i < msg['ZSA'].length(); i++)
    		{
                    if (msg['ZSA'][i]['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:")
    		{
    		createSegmentAfter('OBX', msg['OBR'])
    		msg['OBX'][j]['OBX.1']['OBX.1.1'] = "1";
    		msg['OBX'][j]['OBX.3']['OBX.3.4'] = "VOLUME";
    		msg['OBX'][j]['OBX.3']['OBX.3.5'] = "Total Volume";
    		msg['OBX'][j]['OBX.5']['OBX.5.1'] = msg['ZSA'][i]['ZSA.15']['ZSA.15.2'].toString();
    				
    		}
    		if (msg['ZSA'][i]['ZSA.16']['ZSA.16.1'].toString() == "Duration:")
    		{
    		createSegmentAfter('OBX', msg['OBR'])
    		msg['OBX'][j]['OBX.1']['OBX.1.1'] = "1";
    		msg['OBX'][j]['OBX.3']['OBX.3.4'] = "DURATION";
    		msg['OBX'][j]['OBX.3']['OBX.3.5'] = "Time Duration";
    		msg['OBX'][j]['OBX.5']['OBX.5.1'] = msg['ZSA'][i]['ZSA.16']['ZSA.16.2'].toString();
    		} 
    		}
    	}
    }
    Sample message with 2 OBR/ZSA segments
    Code:
    
    MSH|^~\&|VENDOR|4984|1100|TESTTTT|201608152308||ORM||P|2.3|48
    PID|1|TESON001|TESON001|TESON001|TESTPATIENT^ONE||19700101|F||B|1234 LabStreet^^Deer Park^NY^11729||5555555555|||S||^^^T|
    PV1|1||||||1184730000^LAST^FIRST^M^^^^L~1184730000^LAST^FIRST^M^^^^U
    IN1|1||CIG00^CIGNH|CIGNA WORLDWIDE INS. CO.|1 Beaver Valley Road^POB 15050^Wilmington^DE^19850-5050|||987654|||||||||2||||||||||||||N|||||123456790|||||||
    IN1|2||AET04^AETNA|AETNA|P O Box 14586^^Lexington^KY^40512-4586|||54321|||||||||2||||||||||||||N|||||A45677789|||||||
    GT1|1||TESTPATIENT^SPOUSE^M||8888 Spouse Street^^Deer Park^NY^11729|1111111111|||||2|
    DG1|1|I10|I10^Essential (primary) hypertension^I10|Essential (primary) hypertension|||||||||||
    ORC|NW|00000596|||||||201608152303|||1184730000^LAST^FIRST^M^^^^L~6312774400^LAST^FIRST^M^^^^U
    OBR|1|00000596||5300710^URIC ACID 24HR NSLIJ^L|||201608152304||||N|||||1184730000^LAST^FIRST^M^^^^L~6312774400^LAST^FIRST^M^^^^U|
    ZSA|Facility ID:^4941|Prep Source:^Prep Src answer|Sources:^Sources answer|Specimen Type:^Polyp|No of Specimens:^2|Initial,Repeat,F/U:^Repeat|LMP Date:^201511110000|ED Date:^201607010000|Gest Age Wks:^13|Gest Age Days:^11|Reflex to HPV ASCUS:^Y|Reflex to HPV 161845:^N|History of NTD:^Y|Clinical History:^Cl History answer|Volume ML:^500|Duration:^24|Weight lbs:^133|Insulin Dependent:^Y|Guardian Name:^Guardian name|Telephone:^555-666-6666|Race:^Race|County:^County
    ORC|NW|00000599|||||||201608152303|||1184730000^LAST^FIRST^M^^^^L~6312774400^LAST^FIRST^M^^^^U
    OBR|2|00000599||5915331^Thin Prep Pap^L|||201608152304||||N||Special Note|||1184730000^LAST^FIRST^M^^^^L~6312774400^LAST^FIRST^M^^^^U|
    ZSA|Facility ID:^4941|Prep Source:^Prep Src answer|Sources:^Sources answer|Specimen Type:^Polyp|No of Specimens:^2|Initial,Repeat,F/U:^Repeat|LMP Date:^201511110000|ED Date:^201607010000|Gest Age Wks:^13|Gest Age Days:^11|Reflex to HPV ASCUS:^Y|Reflex to HPV 161845:^N|History of NTD:^Y|Clinical History:^Cl History answer|Volume ML:^500|Duration:^24|Weight lbs:^133|Insulin Dependent:^Y|Guardian Name:^Guardian name|Telephone:^555-666-6666|Race:^Race|County:^County
    Last edited by jg12345; 08-18-2016, 06:38 AM.

  • #2
    something like this would work

    PHP Code:
    for each(obr in msg.OBR)
    {
        for 
    each(zsa in obr)
        {
            if (
    zsa['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:")
            {
                
    //do something
            
    }
        }

    Comment


    • #3
      Tried below code but the OBX does not get created at all.
      What am I missing?

      Code:
      for each(obr in msg.OBR) 
      {
      	for each(zsa in obr) 
      	{
      		if (zsa['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:") 
      		{
      		createSegmentAfter('OBX', msg['OBR'])
      		msg['OBX']['OBX.1']['OBX.1.1'] = "1";
      		msg['OBX']['OBX.3']['OBX.3.4'] = "VOLUME";
      		msg['OBX']['OBX.3']['OBX.3.5'] = "Total Volume (Amount of mL)";
      		msg['OBX']['OBX.5']['OBX.5.1'] = msg['ZSA']['ZSA.15']['ZSA.15.2'].toString();
      		}
      	}
      }

      Comment


      • #4
        Originally posted by jg12345 View Post
        Tried below code but the OBX does not get created at all.
        What am I missing?

        Code:
        for each(obr in msg.OBR) 
        {
        	for each(zsa in obr) 
        	{
        		if (zsa['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:") 
        		{
        		createSegmentAfter('OBX', msg['OBR'])
        		msg['OBX']['OBX.1']['OBX.1.1'] = "1";
        		msg['OBX']['OBX.3']['OBX.3.4'] = "VOLUME";
        		msg['OBX']['OBX.3']['OBX.3.5'] = "Total Volume (Amount of mL)";
        		msg['OBX']['OBX.5']['OBX.5.1'] = msg['ZSA']['ZSA.15']['ZSA.15.2'].toString();
        		}
        	}
        }

        try something like this...

        Code:
        for each(obr in msg.OBR) 
        {
        	for each(zsa in obr) 
        	{
        		if (zsa['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:") 
        		{
        		var newOBX = createSegmentAfter('OBX', obr);
        		newOBX['OBX.1']['OBX.1.1'] = "1";
        		newOBX['OBX.3']['OBX.3.4'] = "VOLUME";
        		newOBX['OBX.3']['OBX.3.5'] = "Total Volume (Amount of mL)";
        		newOBX['OBX.5']['OBX.5.1'] = zsa['ZSA.15']['ZSA.15.2'].toString();
        		}
        	}
        }

        Comment


        • #5
          Tried it but nothing happens... no OBX segments created. I tried it with a single OBR and ZSA message and I tried it with multiple OBR/ZSA and no change to the output message... no OBX segments created.

          Comment


          • #6
            Originally posted by jg12345 View Post
            Tried it but nothing happens... no OBX segments created. I tried it with a single OBR and ZSA message and I tried it with multiple OBR/ZSA and no change to the output message... no OBX segments created.
            Just tested this...it works...

            PHP Code:
            for each(obr in msg.OBR)
            {
                for 
            each(zsa in getSegmentsAfter(msgobr'ZSA'false))
                {
                    if (
            zsa['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:")
                    {
                        
            logger.info('zsa true');
                        var 
            newOBX createSegmentAfter('OBX'obr);
                        
            newOBX['OBX.1']['OBX.1.1'] = "1";
                        
            newOBX['OBX.3']['OBX.3.4'] = "VOLUME";
                        
            newOBX['OBX.3']['OBX.3.5'] = "Total Volume (Amount of mL)";
                        
            newOBX['OBX.5']['OBX.5.1'] = zsa['ZSA.15']['ZSA.15.2'].toString();        
                    }
                }

            Comment


            • #7
              Yes that is perfect... I was missing the getSegmentsAfter function.

              Thank you!

              Comment


              • #8
                I'm just having a problem getting the OBX count right. I tried different variations, but can't get it right.

                It should show as
                OBR|1|etc
                OBX|1|etc
                OBX|2|etc
                OBR|2|etc
                OBX|1|etc
                OBX|2|etc


                This is my output.. incorrect OBX.1 count
                ORC|NW|00000596|||||||201608152303|||1184730111^LA ST^FIRST^M^^^^L~6312774400^LAST^FIRST^M^^^^U
                OBR|1|00000596||5300710^URIC ACID 24HR NSLIJ^L|||201608152304||||N|||||1184730111^LAST^FI RST^M^^^^L~6312774400^LAST^FIRST^M^^^^U|
                OBX|2||^^^DURATION^Time Duration (Hours)||24
                OBX|1||^^^VOLUME^Total Volume (Amount of mL)||500
                ORC|NW|00000599|||||||201608152303|||1184730111^LA ST^FIRST^M^^^^L~6312774400^LAST^FIRST^M^^^^U
                OBR|2|00000599||5915331^Thin Prep Pap^L|||201608152304||||N||Special Note|||1184730111^LAST^FIRST^M^^^^L~6312774400^LAS T^FIRST^M^^^^U|
                OBX|4||^^^DURATION^Time Duration (Hours)||24
                OBX|3||^^^VOLUME^Total Volume (Amount of mL)||500

                Code I'm currently using
                var obx_index = 0

                for each(obr in msg.OBR)
                {
                for each(zsa in getSegmentsAfter(msg, obr, 'ZSA', true))
                {
                if (zsa['ZSA.15']['ZSA.15.1'].toString() == "Volume ML:") {
                var newOBX1 = createSegmentAfter('OBX', obr, obx_index);
                newOBX1['OBX.1']['OBX.1.1'] = obx_index + 1;
                newOBX1['OBX.3']['OBX.3.4'] = "VOLUME";
                newOBX1['OBX.3']['OBX.3.5'] = "Total Volume (Amount of mL)";
                newOBX1['OBX.5']['OBX.5.1'] = zsa['ZSA.15']['ZSA.15.2'].toString();
                obx_index++; }

                if (zsa['ZSA.16']['ZSA.16.1'].toString() == "Duration:") {
                var newOBX2 = createSegmentAfter('OBX', obr, obx_index);
                newOBX2['OBX.1']['OBX.1.1'] = obx_index + 1;
                newOBX2['OBX.3']['OBX.3.4'] = "DURATION";
                newOBX2['OBX.3']['OBX.3.5'] = "Time Duration (Hours)";
                newOBX2['OBX.5']['OBX.5.1'] = zsa['ZSA.16']['ZSA.16.2'].toString();
                obx_index++; }

                }
                }

                for(var i=0;i<msg['ZSA'].length();i++) {
                delete msg['ZSA'][i];
                i--; }

                Comment


                • #9
                  You could put something like this outside of your OBR loop to clean everything up at the end.

                  PHP Code:
                  for each(obr in msg.OBR){
                      var 
                  newOBXNum 1;
                      for 
                  each (obx in getSegmentsAfter(msg,obr,'OBX')){
                          
                  obx['OBX.1']['OBX.1.1'] = newOBXNum++;
                      }

                  Comment


                  • #10
                    Like magic!
                    I really appreciate your help on this... you're fantastic.

                    Thanks!

                    Comment


                    • #11
                      Missing Functions

                      Originally posted by mcalKno View Post
                      You could put something like this outside of your OBR loop to clean everything up at the end.

                      PHP Code:
                      for each(obr in msg.OBR){
                          var 
                      newOBXNum 1;
                          for 
                      each (obx in getSegmentsAfter(msg,obr,'OBX')){
                              
                      obx['OBX.1']['OBX.1.1'] = newOBXNum++;
                          }

                      What has to be loaded on my MIRTH Connect to gain access to the functions such as getSegmentsAfter() and createSegmentAfter()?

                      I'm new to MIRTH. I don't have a clue.
                      Thanks in advance for your help.

                      Comment

                      Working...
                      X