Announcement

Collapse
No announcement yet.

Split 1 result to multiple based on OBX

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

  • Split 1 result to multiple based on OBX

    I am currently saving my all details from test result into Mirth database and create results manually but i am sure there is better way of doing this. So we receive 1 message which have multiple OBX in it and we want them to be split into multiple result as the current LIS can only support one result per OBX. The no of OBX are not fix nor the sequence. we want to keep the MSH, PID, ORC, PV1 as is but only attach one OBX each time.

    The message we receive is like

    MSH|^~\&|TEST|TEST|||20110529130917-04:00||ORU^R30^ORU-R30|1|P|2.6
    PID|1|12349|123||E^A^B^III||19610615|M|||2222 HOMESTREET^^GREENSBORO^NC^27401-1020|GL|(555) 555-2004|(555)555-2004||S||PATID12345001^2^M10^ADT1^AN^A
    ORC|NW|1234
    PV1|1|I|2000^2012^01||||004777^ATTEND^AARON^A^titl e|||||||1||||||||||||||||||||||||||||||20070110230 0|200701102300
    OBX|1||^HCT^LN||<10|%PCV|||||F|||||APOC3214|||2011 0529130917-04:00|MIX
    OBX|2||41651-1^GLU^LN||28|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|3||^BUN^LN||139|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|4||^CREA^LN||15.5|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|5||^NA^LN||100|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|6||^K^LN||2.1|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    NTE|1|||Sample Type=MIX||20110529130917-04:00
    NTE|2|||CPB=Yes||20110529130917-04:00
    NTE|3|||DSN=314237||20110529130917-04:00
    NTE|4|||HCT=LOW||20110529130917-04:00

    And what we need to send is something like below (this will end up in 6 different results in LIS with same patient ID but different OBX in each)


    MSH|^~\&|TEST|TEST|||20110529130917-04:00||ORU^R30^ORU-R30|1|P|2.6
    PID|1|12349|123||E^A^B^III||19610615|M|||2222 HOMESTREET^^GREENSBORO^NC^27401-1020|GL|(555) 555-2004|(555)555-2004||S||PATID12345001^2^M10^ADT1^AN^A
    ORC|NW|1234
    PV1|1|I|2000^2012^01||||004777^ATTEND^AARON^A^titl e|||||||1||||||||||||||||||||||||||||||20070110230 0|200701102300
    OBX|1||^HCT^LN||<10|%PCV|||||F|||||APOC3214|||2011 0529130917-04:00|MIX
    NTE|1|||Sample Type=MIX||20110529130917-04:00
    NTE|2|||CPB=Yes||20110529130917-04:00
    NTE|3|||DSN=314237||20110529130917-04:00
    NTE|4|||HCT=LOW||20110529130917-04:00

  • #2
    So you want the above message to be converted into 6 different messages based on OBXs?
    HL7v2.7 Certified Control Specialist!

    Comment


    • #3
      Yes thats correct. The way i am doing currently is not the best approach as i am saving all detials first in database and then processing one by one creating manually. plus its also error prompt so trying to see if there is any better way of doing so as i am fairly new to Mirth and still trying to learn basics of it.

      Comment


      • #4
        This is easiest to do in two channels. In my example they are named 'splitter channel' and 'processing channel'.

        Splitter channel has your source connector that receives the hl7 messages. If you don't need to do anything with the message other than split it, you can set your data types to Raw all the way through. The following code is in a javascript writer destination. It returns as a response the number of messages that were forwarded to the second channel.

        Code:
        var msg = new XML(SerializerFactory.getSerializer('HL7V2').toXML(connectorMessage.getEncodedData()));
        
        var top = <HL7Message/>;
        var obxList = [];
        var bottom = new XMLList();
        
        for each (seg in msg.children()) {
        	if (seg.name().toString() == 'OBX') {
        		obxList.push(seg);
        	}
        	else if (obxList.length == 0) {
        		top.appendChild(seg);
        	}
        	else {
        		bottom += seg;
        	}
        }
        
        obxList.forEach(function (obx) {
        	newMsg = top.copy();
        	newMsg.appendChild(obx);
        	newMsg.appendChild(bottom);
        	router.routeMessage('processing channel', SerializerFactory.getSerializer('HL7V2').fromXML(newMsg));
        });
        
        return obxList.length + ' message(s) sent.';
        Processing channel is a channel reader. You may want to turn on the Source Queue to allow faster routing from the splitter channel, which is not capturing a response. This channel has the real destination and transformer that work with the single OBX messages.
        Last edited by agermano; 04-04-2018, 11:35 AM.

        Comment


        • #5
          I tried to use your code and i am getting below error "Wrapped com.mirth.connect.donkey.model.message.MessageSeri alizerException: Error converting ER7 to XML"

          any suggestion ? I am attaching my channel its technically copy paste of your code in destination transformer as javascript.

          Note: For the time being my second channel is called processing channel just to test the code and am only trying to split the result nothing else.
          Attached Files

          Comment


          • #6
            I stated the code that I provided was meant to be run in a javascript writer destination, not a transformer. I think that's why you're getting the error.

            Comment

            Working...
            X