Solved

# How to split, re-arrange in order HL7 message

Posted on 2014-07-31

I receive an HL7 message which looks like:

MSH|fdsas43423|fdsfs|432423|fdfads|423423|

PID|43243|fdfds|654|HGDF|76554|HGDS

PV1|5434|gfsd|543534|hgdfz|

ORC||||F|RE

OBR|20140709|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

ORC||||p|RE

OBR|20140706|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

ORC||||F|RE

OBR|20140710|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

ORC||||F|RE

OBR|20140711|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

I need to split the message into sections which start at ORC and end at the next one. the field next to OBR is a timestamp which is alwasy unique and once the message is split into sections it needs to be rebuilt in order of the time stamp from latest to earliest.

So it should look like:

MSH|fdsas43423|fdsfs|432423|fdfads|423423|

PID|43243|fdfds|654|HGDF|76554|HGDS

PV1|5434|gfsd|543534|hgdfz|

ORC||||p|RE

OBR|20140706|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

ORC||||F|RE

OBR|20140709|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

ORC||||F|RE

OBR|20140710|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

ORC||||F|RE

OBR|20140711|gffsd|425643|hgd|543

OBX|65465|GFFSD|7664|aHGFF|4654

NTE|GHFDSGF|543|GFSFD|654|HGDF

OBX|423|FDSAD|432423|FDAS|423423

Thanks.