I am trying to parse a HL7 message by Hapi in map-reduce function i got EncodingNotSupportedException when i run the map task. i tried to add \n or \r to the end of each segment but i am facing the same error. the message is saved in text file and it uploaded to HDFS. should i need to add something this is my code
String v = value.toString();
InputStream is = new StringBufferInputStream(v);
is = new BufferedInputStream(is);
Hl7InputStreamMessageStringIterator iter = new Hl7InputStreamMessageStringIterator(
is);
HapiContext hcontext = new DefaultHapiContext();
Message hapiMsg;
Parser p = hcontext.getGenericParser();
while (iter.hasNext()) {
String msg = iter.next();
try {
hapiMsg = p.parse(msg);
} catch (EncodingNotSupportedException e) {
e.printStackTrace();
return;
} catch (HL7Exception e) {
e.printStackTrace();
return;
}
}
the sample message
MSH|^~\&|HIS|RIH|EKG|EKG|20150121002000||ADT^A01||P|2.5.1
EVN||20150121002000|||||CITY GENL HOSP^0133195934^NPI
PID|1||95101100001^^^^PI^CITY GENL HOSP&0133195934&NPI||SNOW^JOHN^^^MR^^L||19560121002000|M||2054-5^White^CDCREC|470 Ocean Ave^^NEW YORK^^11226^USA^C^^29051||^^^^^513^5551212|||||95101100001||||2186-5^White American^CDCREC|||1
PV1||E||E||||||||||1||||||||||||||||||||||||||||||
OBX|1|NM|21612-7^PATIENT AGE REPORTED^LN||60|a^YEAR^UCUM|||||F|||201601131443
OBX|2|NM|21613-7^Urination^LN||2|a^DAY^UCUM|||||F|||19740514201500
DG1|001||4158^Diabetes^I9CDX||19740514201500|A|5478^Non-infectious
DG1|002||2222^Huntington^I9CDX||19610718121500|A|6958^Genetic
Never store HL7-messages as text file, but as binary. Are you sure, that the segment delimiters are ok?
Just check your HL7 message after reading from HDFS either via printing to the console or via the use of a debugger, if the message contains only \r
as segment delimiter before parsing.
The segment delimiter has to be a \r
, ie x0d, "carriage return" and not a \n
, ie x0a "newline". There are probably some tools, maybe HL7 editors, accepting alternative segment delimiters or writing the wrong delimiter, but this is not standard.