3

I want to get a specific segment hl7, by name of segment for example,

  1. I am using Pipeparser class but i still don't know how to get each segment by structure name (MSH,PID,OBX,...).

  2. Sometimes I have a repeated segments like DG1 or PV1 or OBX(see attached lines) how can I get data fileds from each row segment in Pentaho kettle (do i need java code in kettle, if there is such solution, help please).

OBX|1|TX|PTH_SITE1^Site A|1|left||||||F|||||||
OBX|2|TX|PTH_SPEC1^Specimen A||C-FNA^Fine Needle Aspiration||||||F|||||||

or

DG1|1|I10C|G30.0|Alzheimer's disease with early onset|20160406|W|||||||||
DG1|2|I10C|E87.70|Fluid overload, unspecified|20160406|W|||||||||
Mostav
  • 2,203
  • 15
  • 27

1 Answers1

2

You should use HL7 Parser for proper/accurate parsing of any HL7 formatted message.

With the help of HAPI you can either parse your message as Stream

// Open an InputStream to read from the file
        File file = new File("hl7_messages.txt");
        InputStream is = new FileInputStream(file);

        // It's generally a good idea to buffer file IO
        is = new BufferedInputStream(is);

        // The following class is a HAPI utility that will iterate over
        // the messages which appear over an InputStream
        Hl7InputStreamMessageIterator iter = new Hl7InputStreamMessageIterator(is);

        while (iter.hasNext()) {

            Message next = iter.next();

            // Do something with the message

        }

Or you can read it as String

File file = new File("hl7_messages.txt");
        is = new FileInputStream(file);
        is = new BufferedInputStream(is);
        Hl7InputStreamMessageStringIterator iter2 = new Hl7InputStreamMessageStringIterator(is); 

        while (iter2.hasNext()) {

            String next = iter2.next();

            // Do something with the message

        }

Hope this helps you in right direction.

Sanjeev
  • 9,876
  • 2
  • 22
  • 33
  • Thank you, as i understand, your code can iterate multiple messages HL7 in same time, but my question is about in the same message , how can i get each segment, and how to deal with repeated segments such as DG1|1| and DG1|2| – Mostav Apr 28 '16 at 11:16
  • You can see this [example](http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/ExampleUseTerser.html). You can use Terser to parse and lookup segments – Sanjeev Apr 28 '16 at 11:27
  • Sorry, i am not a kettle user. so i can't really comment. – Sanjeev Apr 28 '16 at 14:45