Announcement

Collapse
No announcement yet.

Best way to combine OBX messages?

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

  • Best way to combine OBX messages?

    Hello all:

    I have to take the OBX.5 fields from all of the OBX Message types (within a single MSH), concatenate them together (stripped of whitespace), separate the text between each message they came from with a " ~~ ", and delete the original message.

    I then have to make one OBX message type with this loooooong OBX.5 field.

    I've been at this all day, and I keep getting "<OBX.5><OBX.5.1>" surrounding each field that I read in.

    This is the segment of code that deals with the OBX message types:

    for each (seg in msg.children())
    {
    ...
    (other code dealing with other message types)
    ...

    if (seg.name() == "OBX")
    {
    tempString = msg['OBX']['OBX.5'].toString();
    OBXSegment = OBXSegment + tempString + " ~~ ";
    delete msg.OBX;
    }
    }

    Does anyone know of a better way to do this?
    Again, thank you in advance.

    Robert

  • #2
    There are many examples of this on these forums, but here's another very simple one:

    Code:
    var newOBX = <OBX/>;
    newOBX['OBX.1']['OBX.1.1'] = '1';
    newOBX['OBX.2']['OBX.2.1'] = 'whatever';
    newOBX['OBX.3']['OBX.3.1'] = 'you';
    newOBX['OBX.4']['OBX.4.1'] = 'want';
    newOBX['OBX.5'] = '';
    for each (seg in msg.children())
    	if (seg.name().toString() == 'OBX')
    		for each (obx5 in seg['OBX.5'])
    			newOBX['OBX.5'] = newOBX['OBX.5'].toString() ? newOBX['OBX.5']+obx5 : obx5;
    msg.OBX = newOBX;
    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
      Hmmm... I did a search for "combine OBX" and got nothing. I do try to search first before asking. (The forum members repremand people for not doing that on the AtariAge message board.)

      But - thank you very much for the reply!

      Comment


      • #4
        No problem, sometimes searching online can be somewhat of an art form haha. In any case, it helps out a lot if you include tags!
        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


        • #5
          Thank you for that - I had to move it to concatenate to a variable (because I will need to edit it later), but when I do that I get one of the following issues:

          1 - I get the HTML tags surrounding each message ("<OBX.5><OBX.5.1>History: Cough and congestion. Smoker.</OBX.5.1></OBX.5>") if I initialize the variable to a value ( OBXSegment = ExamName + ' ~~ '; )
          2 - I get a tilde (~) between each message ("History: Cough and congestion. Smoker.~Comparison: None available.~") if I initialize the variable to null ( OBXSegment = ''; ).

          Here is the piece of code:

          ExamName = msg['OBX'][0]['OBX.5']['OBX.5.1'].toString();

          ...
          Some other code here
          ...

          OBXSegment = '';
          for each (seg in msg.children())
          {
          if (seg.name().toString() == 'OBX')
          {
          for each (obx5 in seg['OBX.5'])
          {
          OBXSegment = OBXSegment.toString() ? OBXSegment + obx5 : obx5;
          }
          }
          }

          var newOBX = <OBX/>;
          newOBX['OBX.1']['OBX.1.1'] = '1';
          newOBX['OBX.2']['OBX.2.1'] = 'FT';
          newOBX['OBX.5'] = OBXSegment;
          msg.OBX = newOBX;

          Why does this happen?

          Thank you so much in advance,
          Bob
          Last edited by RobertD; 04-25-2012, 06:00 AM.

          Comment


          • #6
            That's happening because you're trying to mix simple and complex content in a single XML node. If you want to add a special observation value at the beginning, just initialize that OBXSegment variable to an OBX.5 node, and then place your text content in the OBX.5.1 child node. Then that ternary operation in the for loop should handle the rest.
            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


            • #7
              Thank you!... Although even if I do it that way, I still get the tildes between each message.

              I am so sorry to bother you with this

              var newOBX = <OBX/>;
              newOBX['OBX.1']['OBX.1.1'] = '1';
              newOBX['OBX.2']['OBX.2.1'] = 'FT';
              newOBX['OBX.5']['OBX.5.1'] = OBXSegment;

              for each (seg in msg.children())
              {
              if (seg.name().toString() == 'OBX')
              {
              for each (obx5 in seg['OBX.5'])
              {
              newOBX['OBX.5'] = newOBX['OBX.5'].toString() ? newOBX['OBX.5'] + obx5 : obx5;
              }
              }
              }

              msg.OBX = newOBX;

              Comment


              • #8
                I apologize, but I have been trying all day to get rid of these tildes between each message. I can't do it.

                I have to put them in one long string, so I can parse it and separate by a ' ~~ ' on 70-character boundaries (except if it's in the middle of a word, then I have to move the whole word to the next 'line' after the ' ~~ ').

                No matter what I do I cannot get rid of the tildes that Mirth puts in there. Please help!

                Thank you in advance, and again I am sorry
                Robert

                Comment


                • #9
                  So you don't want repeated OBX.5 fields, but instead want a single OBX.5 joined with " ~~ "? In that case, realize that typically the tilde is the repetition character, so you should escape those in your text nodes as "\R\". Here's an example:

                  Code:
                  var newOBX = <OBX/>;
                  newOBX['OBX.1']['OBX.1.1'] = '1';
                  newOBX['OBX.2']['OBX.2.1'] = 'FT';
                  var obs = '';
                  for each (seg in msg.children())
                  	if (seg.name().toString() == 'OBX')
                  		for each (obx5 in seg['OBX.5'])
                  			obs += (obs?' \\R\\\\R\\ ':'') + obx5['OBX.5.1'].toString();
                  newOBX['OBX.5']['OBX.5.1'] = obs;
                  msg.OBX = newOBX;
                  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

                  Working...
                  X