Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Loop through OBRs and OBX's

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

  • Loop through OBRs and OBX's

    Here is the code that I'm trying but it doesn't seem to be deleting the OBX segments and creating a new one or changing the OBR segments. Thanks for helping! Hopefully once I get a good grasp of this I can start contributing and not just asking for help :-).
    -Dave

    What I'm trying to do is loop through this message:
    MSH|^~\&|||||20060814132613||ORU^R01|2006081413261 37727458|D|2.3|
    PID|1||90||Patient^Test^J||19510129000000|F||||||| ||||466-70-4466|
    OBR|1|||x^name|RT||||||||||||||||||||P|||||||||||| |||||
    OBX|1|TX|||Text Here|
    OBX|2|TX|||Text Here|
    OBR|2|||x^name|RT||||||||||||||||||||P|||||||||||| |||||
    OBX|1|TX|||Text Here|
    OBX|2|TX|||Text Here|
    OBR|3|||x^name|RT||||||||||||||||||||P|||||||||||| |||||
    OBX|1|TX|||Text Here|
    OBX|2|TX|||Text Here|

    This is the result I want:
    MSH|^~\&|||||20060814132613||ORU^R01|2006081413261 37727458|D|2.3|
    PID|1||90||Patient^Test^J||19510129000000|F||||||| ||||466-70-4466|
    OBR|1|||x^name|RT||||||||||||||||||||Final 1|||||||||||||||||
    OBX|1|TX|||See Document|
    OBR|2|||x^name|RT||||||||||||||||||||Final 2|||||||||||||||||
    OBX|1|TX|||See Document|
    OBR|3|||x^name|RT||||||||||||||||||||Final 3|||||||||||||||||
    OBX|1|TX|||See Document|

    Code:
    //Loops through the OBRs in the message
    var count = 0;
    for each (obr in tmp..OBR)
    {
    	//Loops through the OBX segments within that OBR
    	for each (obx in obr)
    	{
    		//Deletes the OBX segments it finds
    		delete obx;
    	}
            
            tmp[obr]['OBR.25'] = 'Final' + count.toString();
    
    	//Creates a new OBX segment under the OBR
    	tmp['OBX']['OBX.5']['OBX.5.1'] = 'See Document';
            
            count++;
    }

  • #2
    Re:Loop through OBRs and OBX's

    No one has any ideas on this one?

    Comment


    • #3
      Re:Loop through OBRs and OBX's

      Ok. I sat down and figured out a way to do it. It isn't the best or the cleanest, but it works. I wanted to post it here so other people can see it if needed. If you have any ideas on cleaning this up, let me know.
      Thanks,
      -Dave

      I took this message:
      MSH|^~&|||||20060814132613||ORU^R01|20060814132613 7727458|D|2.3|
      PID|1||90||Test^Patient^J||19880129000000|F||||||| ||||222-11-2222|
      OBR|1||200909090000033895|SIGNALOR^Report 1|RT|200909091011|200909091011||||||||||||||||||P| |1^^^200707091011^200707091011^RT|||||||||||||||
      OBX|1|TX|||Report Line 1|
      OBX|2|TX|||Report Line 2|
      OBX|3|TX|||Report Line 3|
      OBX|4|TX|||Report Line 4|
      OBX|5|TX|||Report Line 5|
      OBR|2||200708080000033894|SIGNALOR^OPERATIVE REPORT|RT|200708081011|200708081011||||||||||||||| |||P||1^^^200707091011^200707091011^RT|||||||||||| |||
      OBX|1|TX|||Report Line 1|
      OBX|2|TX|||Report Line 2|
      OBX|3|TX|||Report Line 3|
      OBX|4|TX|||Report Line 4|
      OBX|5|TX|||Report Line 5|

      I made this message:
      MSH|^~&|||||20060814132613||ORU^R01|20060814132613 7727458|D|2.3|
      PID|1||90||Test^Patient^J||19880129000000|F||||||| ||||222-11-2222|
      OBR|1||200909090000033895|^Report 1|||200909091011|||||||||||||||||
      OBX|1|TX|||See Document
      OBR|2||200708080000033894|^OPERATIVE REPORT|||200708081011|||||||||||||||||
      OBX|1|TX|||See Document

      Using this code:
      Code:
      var count = 0;
      var OBRArray = new Array(); 
      var OBR1, OBR2, OBR3, OBR4, OBR7, OBR16, OBR22, OBR24;
      for each (seg in tmp..OBR)
      {
      	OBR1 = seg['OBR.1']['OBR.1.1'].toString();
      	OBR2 = seg['OBR.2']['OBR.2.1'].toString();
      	OBR3 = seg['OBR.3']['OBR.3.1'].toString();
      	OBR4 = seg['OBR.4']['OBR.4.2'].toString();
      	OBR7 = seg['OBR.7']['OBR.7.1'].toString();
      	OBR16 = seg['OBR.16']['OBR.16.1'].toString();
      	OBR22 = seg['OBR.22']['OBR.22.1'].toString();
      	OBR24 = seg['OBR.24']['OBR.24.1'].toString();
      
      	OBRArray[count] = [OBR1, OBR2, OBR3, OBR4, OBR7, OBR16, OBR22, OBR24];
      	
      	count++;
      }
      delete tmp['OBR'];
      delete tmp['OBX'];
      
      //Loop through the array of allowed values 
      for (var i=0;i<count;i++) 
      { 
      	var obri = <OBR><OBR.1><OBR.1.1></OBR.1.1></OBR.1><OBR.2><OBR.2.1></OBR.2.1></OBR.2><OBR.3><OBR.3.1></OBR.3.1></OBR.3>	<OBR.4><OBR.4.2></OBR.4.2></OBR.4><OBR.7><OBR.7.1></OBR.7.1></OBR.7><OBR.16><OBR.16.1></OBR.16.1></OBR.16><OBR.22><OBR.22.1></OBR.22.1></OBR.22><OBR.24><OBR.24.1></OBR.24.1></OBR.24></OBR>;
      	tmp['OBR'][i] = obri;
      	tmp['OBR']['OBR.1']['OBR.1.1'][i] = OBRArray[i][0];
      	tmp['OBR']['OBR.2']['OBR.2.1'][i] = OBRArray[i][1];
      	tmp['OBR']['OBR.3']['OBR.3.1'][i] = OBRArray[i][2];
      	tmp['OBR']['OBR.4']['OBR.4.2'][i] = OBRArray[i][3];
      	tmp['OBR']['OBR.7']['OBR.7.1'][i] = OBRArray[i][4];
      	tmp['OBR']['OBR.16']['OBR.16.1'][i] = OBRArray[i][5];
      	tmp['OBR']['OBR.22']['OBR.22.1'][i] = OBRArray[i][6];
      	tmp['OBR']['OBR.24']['OBR.24.1'][i] = OBRArray[i][7];
      	
      	var obxi = <OBX><OBX.1><OBX.1.1></OBX.1.1></OBX.1><OBX.2><OBX.2.1></OBX.2.1></OBX.2><OBX.5><OBX.5.1></OBX.5.1></OBX.5></OBX>;
      	tmp['OBX'][i] = obxi;
      	tmp['OBX']['OBX.1']['OBX.1.1'][i] = '1';
      	tmp['OBX']['OBX.2']['OBX.2.1'][i] = 'TX';
      	tmp['OBX']['OBX.5']['OBX.5.1'][i] = 'See Document';
      	
      }
      Post edited by: dvenier, at: 10/08/2007 20:02

      Comment


      • #4
        Originally posted by dvenier View Post
        Re:Loop through OBRs and OBX's

        Ok. I sat down and figured out a way to do it. It isn't the best or the cleanest, but it works. I wanted to post it here so other people can see it if needed. If you have any ideas on cleaning this up, let me know.
        Thanks,
        -Dave

        I took this message:
        MSH|^~&|||||20060814132613||ORU^R01|20060814132613 7727458|D|2.3|
        PID|1||90||Test^Patient^J||19880129000000|F||||||| ||||222-11-2222|
        OBR|1||200909090000033895|SIGNALOR^Report 1|RT|200909091011|200909091011||||||||||||||||||P| |1^^^200707091011^200707091011^RT|||||||||||||||
        OBX|1|TX|||Report Line 1|
        OBX|2|TX|||Report Line 2|
        OBX|3|TX|||Report Line 3|
        OBX|4|TX|||Report Line 4|
        OBX|5|TX|||Report Line 5|
        OBR|2||200708080000033894|SIGNALOR^OPERATIVE REPORT|RT|200708081011|200708081011||||||||||||||| |||P||1^^^200707091011^200707091011^RT|||||||||||| |||
        OBX|1|TX|||Report Line 1|
        OBX|2|TX|||Report Line 2|
        OBX|3|TX|||Report Line 3|
        OBX|4|TX|||Report Line 4|
        OBX|5|TX|||Report Line 5|

        I made this message:
        MSH|^~&|||||20060814132613||ORU^R01|20060814132613 7727458|D|2.3|
        PID|1||90||Test^Patient^J||19880129000000|F||||||| ||||222-11-2222|
        OBR|1||200909090000033895|^Report 1|||200909091011|||||||||||||||||
        OBX|1|TX|||See Document
        OBR|2||200708080000033894|^OPERATIVE REPORT|||200708081011|||||||||||||||||
        OBX|1|TX|||See Document

        Using this code:
        Code:
        var count = 0;
        var OBRArray = new Array();
        var OBR1, OBR2, OBR3, OBR4, OBR7, OBR16, OBR22, OBR24;
        for each (seg in tmp..OBR)
        {
        OBR1 = seg['OBR.1']['OBR.1.1'].toString();
        OBR2 = seg['OBR.2']['OBR.2.1'].toString();
        OBR3 = seg['OBR.3']['OBR.3.1'].toString();
        OBR4 = seg['OBR.4']['OBR.4.2'].toString();
        OBR7 = seg['OBR.7']['OBR.7.1'].toString();
        OBR16 = seg['OBR.16']['OBR.16.1'].toString();
        OBR22 = seg['OBR.22']['OBR.22.1'].toString();
        OBR24 = seg['OBR.24']['OBR.24.1'].toString();
        
        OBRArray[count] = [OBR1, OBR2, OBR3, OBR4, OBR7, OBR16, OBR22, OBR24];
        
        count++;
        }
        delete tmp['OBR'];
        delete tmp['OBX'];
        
        //Loop through the array of allowed values
        for (var i=0;i<count;i++)
        {
        var obri = <OBR><OBR.1><OBR.1.1></OBR.1.1></OBR.1><OBR.2><OBR.2.1></OBR.2.1></OBR.2><OBR.3><OBR.3.1></OBR.3.1></OBR.3> <OBR.4><OBR.4.2></OBR.4.2></OBR.4><OBR.7><OBR.7.1></OBR.7.1></OBR.7><OBR.16><OBR.16.1></OBR.16.1></OBR.16><OBR.22><OBR.22.1></OBR.22.1></OBR.22><OBR.24><OBR.24.1></OBR.24.1></OBR.24></OBR>;
        tmp['OBR'][i] = obri;
        tmp['OBR']['OBR.1']['OBR.1.1'][i] = OBRArray[i][0];
        tmp['OBR']['OBR.2']['OBR.2.1'][i] = OBRArray[i][1];
        tmp['OBR']['OBR.3']['OBR.3.1'][i] = OBRArray[i][2];
        tmp['OBR']['OBR.4']['OBR.4.2'][i] = OBRArray[i][3];
        tmp['OBR']['OBR.7']['OBR.7.1'][i] = OBRArray[i][4];
        tmp['OBR']['OBR.16']['OBR.16.1'][i] = OBRArray[i][5];
        tmp['OBR']['OBR.22']['OBR.22.1'][i] = OBRArray[i][6];
        tmp['OBR']['OBR.24']['OBR.24.1'][i] = OBRArray[i][7];
        
        var obxi = <OBX><OBX.1><OBX.1.1></OBX.1.1></OBX.1><OBX.2><OBX.2.1></OBX.2.1></OBX.2><OBX.5><OBX.5.1></OBX.5.1></OBX.5></OBX>;
        tmp['OBX'][i] = obxi;
        tmp['OBX']['OBX.1']['OBX.1.1'][i] = '1';
        tmp['OBX']['OBX.2']['OBX.2.1'][i] = 'TX';
        tmp['OBX']['OBX.5']['OBX.5.1'][i] = 'See Document';
        
        }
        Post edited by: dvenier, at: 10/08/2007 20:02
        Did you ever find a cleaner way of doing this? How do you overcome the unknown for the number of OBX lines?

        Comment


        • #5
          @notsofast - you responded to an old thread, I'd recommend starting a new one for your specific use case. Otherwise, there's already a bunch of threads on the forum for nesting segment loops.

          Comment


          • #6
            pacmano had just responded to your comment on the other thread to start a new post and not ask new questions on old threads.

            https://forums.mirthproject.io/forum...476#post179476

            As you're searching, I'd recommend looking for posts that include "getSegmentsAfter"

            Comment

            Working...
            X