Reputation: 2602
I want to get a specific segment hl7, by name of segment for example,
I am using Pipeparser class but i still don't know how to get each segment by structure name (MSH,PID,OBX,...
).
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|||||||||
Upvotes: 3
Views: 1215
Reputation: 9946
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.
Upvotes: 2