No announcement yet.

Group Multiple ORU Messages

  • Filter
  • Time
  • Show
Clear All
new posts

  • Group Multiple ORU Messages

    Hi Everyone,

    I have a LLP Listener channel(HL7 2.X) that receives multiples ORU messages for the same ORDER #...So say for instance: you have a CHOLESTEROL, GLUCOSE, CBC, for an order.

    The channel will receive a message every time one of the three test is completed. At the end, the channel will have 3 messages. What i am trying to do is write a javascript or transformer that will group those three messages into one.

    The only thing i need out of the three messages is OBR/OBX. Now I am thinking in order for me to do this i have to set a criteria like if OBR-2(PLACER ID) and also the application sending the message to my LLP Listener has to flag each message stating if order is "COMPLETED" Since I don't use OBR-22(FILLER 2) I am thinking of having flag here. So the logic will go like this:

    Last message comes into my LLP Listener:

    If OBR-22 == "Completed" then
    check for every message in the log that equals to OBR-2
    read OBR/OBX
    Group all OBR/OBX.
    end if

    Any help on how I can start or if anyone can point me to the right direction. Please help.

    Thanks in advance.

    Logic is the opposite of the "Deli-Slicer"

  • #2
    I'm not sure how you are receiving these. All at once ? or as each test is completed. If you are receiving these as each test is completed then I am assuming that they are received at different times (Typically the case with Lab Results). If that is the case I would manage these in a seperate DB table. Once order/results are completed set an flag on the rows that indicates that all results are complete. Then use a DB reader channel that polls the DB table for "Completed" results.


    • #3

      How about this suggestion:
      You strip off all the segments you don't need
      Then you write the remaining segments to a file , using the order id as filename (You can additionally combine the name with patient id, admit number or whatever useful).
      As long as you have messages coming for that order, they will concatenate to the same file
      JJ Mouris
      FFE Luxembourg


      • #4
        First of all, thank you for your reply. I like your idea of striping the segments that i do not need and only add the segments that i will require to a file and continue accumulating. The only issue i am having is that this messages will not come in sequence. I'll explain.

        Say you order a CBC and GLUCOSE:
        CBC result message gets completed at 12:00pm, message get sent to Mirth LLP Listener. At this moment Mirth will write the message to a file.

        GLUCOSE oru message gets completed at 4pm,
        message sent to Mirth LLP Listener. I only want to get the OBR/OBX segment. But keep in mind because the message are not in sequence i don't know how to go about writing logic that it will find say the file name that first message was sent to.

        can you provide me an example or snippet of how I can create logic in a channel to write the segments that i require from those 2 messages.


        • #5

          I stunbled into more question about what you are trying to do and the solution I suggested.
          - Do you really not need message headers or other segments? If you need them, my solution won't work.
          - My solution only works if you want files as an output result
          - I don't know if there is a way to flag a message as completed. Perhaps it is possible to rename a file in a postprocessor script once you have received your "completed" flag, but i have never done this before.

          For your other questions:
          - There is a built-in function in the transformer to delete segments. It's very easy:
          delete msg['MSH'];
          and your MSH segment will have gone

          - To have all your remaning segments be gathered in one file (on per placer_id or whatever):
          * put the placer-id (or other unique ID) in a channel map variable
          * use this channel variable as or as part of the filename
          * make sure to select the "Append to file" option in the destination.

          We use this to gather all the items of a pharmacy order in one delivery report, as the robot delivering the items sends one file per item. This works without problems.

          If you need further or more complex processing of your data, I think the database-solution would be the better way, as suggested by rts
          Last edited by mourisj; 05-06-2010, 05:15 AM.
          JJ Mouris
          FFE Luxembourg


          • #6
            Hello again,

            I worked a bit to find a solution for the unanswered question of renaming the file when all data are completed.

            You have to define your output-filename in a variable and put it to channelMap during procesing.
            You use the channel variable as output filename in your destination.

            Also do so for completion flag in your OBR-22.

            Then you do the following in postprocessor-script:

            var path = "/path/for/outputfiles/" + channelMap.get('fn') ;
            var oldfile =;
            var newpath = "/path/for/outputfiles/completed_" + channelMap.get('fn') ;
            You execute this piece of code only if your completed-flag is set.
            Thus, your filename will usually be (e.g.) placer-id.hl7; on completion it will turn to completed_placer-id.hl7

            Hope this helps
            JJ Mouris
            FFE Luxembourg


            • #7
              Thanks So much, I took your advise and in no time i have the basic logic that i am looking for. Now to answer your question; - Do you really not need message headers or other segments? If you need them, my solution won't work.

              Yes i will need them but i will obtain those segments from the first message written to the file: so the logic will be. If placer-id(filename) exist then, delete ['MSH'],['PID'], etc until OBR/OBX and append to the file with the same filename. OBR-21(FLAG to determine if last message)

              1st Message

              MSH|^~\&|HM|HM|AAA|4954|20100422113320||ORU^R01|Q6 31118441T1211841256|P|2.3
              PID|1|4954000001|27688638^^^^LESID~49540000000067^ ^^^VISIT|27688638~4954000001~29170226~4954000001|T EST^ONE||19651125|F|||1313 Mockingbird Lane^^NOWHERE^NOWHERE^12345||(612)719-1100|||||^^^^^CD:472|||||||0
              PV1|1||||||^^^^^^^^^^^OTHER||||||||||^^^^^^^^^^^OT HER|Lab Outreach||-Medicare|||||||||||||||||||4954||Active|||20100422 111800
              ORC|RE|000992010112071119|000992010112071119||CM|| ||20100422113323|||
              OBR|1|000992010112071119|000992010112071119|550029 4^CBC|||20100422112800|||||||20100422112955|WB/Coll list&WB/Coll list|^^^^^^^^^^OTHER||||000992010112071119|P|20100 422113318||General Lab|F||1^^^20100422112800^^RT~^^^^^RT|||||||||2010 0422112800
              NTE|1||Visit Number: 49540000000067

              2nd Message - Will only contain OBR/OBX and any segment associated to OBX

              OBR|1|000992010112071119|000992010112071119|230200 0^METABOLIC|||20100422112800|||||||20100422112955| WB/Coll list|^^^^^^^^^^OTHER||||000992010112071119|P|20100 422113414||General Lab|F||1^^^20100422112800^^RT~^^^^^RT|||||||||2010 0422112800
              NTE|1||Visit Number: 49540000000067
              OBX|14|NM|5300055^Anion Gap||9|mmol/L|5-17||||F|||20100422113400
              OBX|18|NM|5300060^Calcium, Serum||8.8|mg/dL|8.4-10.5||||F|||20100422113400

              ================================================== ==============
              Your logic definitely works, i just have to write logic for the first message to check if file with placer-id exist, however i am running into an obstacle, i am searching online and since Javascript by nature is client side, it does NOT have built functions to search for existing files. Any clues...
              Last edited by jmendezzz; 05-06-2010, 08:19 PM.


              • #8
                Once you have computed your filename (in the channel var. fn), you can check with this code:

                var test =;
                if ( (test.exists()) ){
                <your code to strip headers>
                else {
                <don't strip headers>
                Of course, in this place, fn has to be with the full path.

                I'm not a Java or JavaScript programmer, so I don't know if this is the best way to do, but it works.
                JJ Mouris
                FFE Luxembourg


                • #9
                  Thanks, after further investigation...I realized when i append the 2nd message with OBR/OBX segments, don't know why but it removes the field separator of each field. If i do NOT delete msg['MSH'] then is fine. any clues...


                  • #10
                    Hi mourisj, I figured out the issue with the 2nd message adding with NO field separator. I would like to thank you, because of you i was able to get this going. I found all the issues and now my channels are accumulating all ORU that are part of the same order. Once again, thanks for all your help.


                    • #11
                      I'm glad I could help you.
                      How did you solve the problem?
                      I had tried out various things like dropping the MSH in the destination transformer, but could not find a working solution.
                      The only thing I still thought about was building the message again with manually inserted separators, and output as delimited file, but I had no time to try it.
                      So, what's the solution you found (maybe it could be useful for me or sb else too someday) ?

                      Last edited by mourisj; 05-09-2010, 01:41 AM. Reason: typo
                      JJ Mouris
                      FFE Luxembourg


                      • #12
                        Group Multiple ORU

                        Forgive me for not providing the steps earlier...I created one channel that will append all the results to the same file providing that it is the same placer_id #, remove all segments from EXCEPTION of MSH and OBR/OBX. Have logic that if OBR-35 is flag to "F" that it will be the last message for that placer_id #, move file to a different path.

                        Channel 1: Test_Complete_ORU.xml: does what i explained above.

                        Channel 2: Test_Transform_COMPLETE_ORU.xml: I created a javascript transform, that will iterate through all the MSH segments and delete every MSH starting with element: 1, since we need to keep MSH[0]. Follow by doing some massage of the message like renumbering all the OBR & OBX segments.

                        I took two steps. I am sure there's a way that it can be done in one channel as oppose to two but it is working PERFECT. Once again, I thank you for all your all your help Mourisj. I could have not done it without your advise & code snippets.
                        Attached Files
                        Last edited by jmendezzz; 05-09-2010, 08:03 AM.