FHIR Chat · HL7v2 Parsing · hapi

Stream: hapi

Topic: HL7v2 Parsing


view this post on Zulip Vibin_chander (Feb 16 2021 at 18:32):

I'm using the HAPI V25structures to parse HL7v2 message & convert that into FHIR resources. I'm facing a strange issue while receiving and parsing the HL7V2 message using HAPI via TCP listener.

"Determine encoding for message. The following is the first 50 chars of the message for reference, although this may not be where the issue is: MSH|^~\\&|OPENEMR|DrJhonDoe|TEST|UNKNOWN|20210216190432||ADT^A01^ADT_A01|60b647d4-b5a5-4fae-a928-d4a3849de3c8|T|2.5"

Strange that I'm not getting this error when I'm trying to send this message as a string in main function. I'm getting this error only when I send the data over TCP to my Java function.

Here is my Java pgm:

public static String getPv1SegmentData(String hl7Message) throws HL7Exception {
        String hl7RoomConfiguration = "";
        try {
// Im just reading the mapping from another config json
        String getHl7ConfigFromFile     = HL7HelperFunction.readHl7ConfigFromFile("Config.json");
        String getGqlPath               = getHl7ConfigFromFile.split(",")[3].toString();
        HapiContext context             = new DefaultHapiContext();
        context.getParserConfiguration().setValidating(false);
        CanonicalModelClassFactory mcf  = new CanonicalModelClassFactory("2.5");
        context.setModelClassFactory(mcf);
        PipeParser parser               = context.getPipeParser();
// Till this it works fine

// this is the portion where its causing error
        ADT_A01 v25Message              = (ADT_A01) parser.parse(hl7Message);
        Terser t25                      = new Terser(v25Message);
        String getPid                   = t25.get("/."+getHl7ConfigFromFile.split(",")[0]);
        String getBed                   = t25.get("/."+getHl7ConfigFromFile.split(",")[1]);
        String getRoom                  = t25.get("/."+getHl7ConfigFromFile.split(",")[2]);
        String getBuilding              = t25.get("/."+getGqlPath.split("/")[1]);
        String getFloor                 = t25.get("/."+getGqlPath.split("/")[2]);
        String getFacility              = t25.get("/."+getGqlPath.split("/")[0]);
        // Parse HL7 and create String
        hl7RoomConfiguration = "Bed:"+getBed+"@"+"Room:"+getRoom+"@"+"Building:"+getBuilding+"@"+"Floor:"+getFloor+"@"+"Facility:"+getFacility+"@"+"PID:"+getPid;

        System.out.println(hl7RoomConfiguration);

        }catch(Exception e) {
            System.out.println("get Exception -->"+e);
        }
        return hl7RoomConfiguration;
    }

view this post on Zulip Vibin_chander (Feb 17 2021 at 03:10):

While receiving the message from the tcp source. Im converting it to string using the UTF-8 character

view this post on Zulip Vibin_chander (Feb 17 2021 at 03:11):

InputStream in = connection.getInputStream();
OutputStream out = connection.getOutputStream();
receivedMessageSize = in.read(receivedByeBuffer);
String incomingHl7Message = new String(receivedByeBuffer, StandardCharsets.UTF_8);

view this post on Zulip Lin Zhang (Feb 17 2021 at 04:36):

MSH|^~\\...

I'm a totally a newbie for this. Are the duplicate slash right? Ignore my response if yes.

view this post on Zulip Vibin_chander (Feb 17 2021 at 04:37):

yes. java throws error with single \

view this post on Zulip Lin Zhang (Feb 17 2021 at 04:38):

OK

view this post on Zulip Vibin_chander (Feb 17 2021 at 04:39):

i ve posted in stackoverflow too. got 4 upvotes seems like many people problem

https://stackoverflow.com/questions/66230745/hl7v2-hapi-parser-exception-while-receiving-data-via-tcp-ip

view this post on Zulip Lin Zhang (Feb 17 2021 at 05:22):

What if you use other people's example message(s), e.g.: http://www.ringholm.com/docs/04300_en.htm

view this post on Zulip Vibin_chander (Feb 17 2021 at 06:01):

Same error for all messages

view this post on Zulip Vibin_chander (Feb 18 2021 at 04:22):

I identified the issue. it is because of getting <VT> and <FS> only. When receiving data via normal Basic TCP I am not getting this issue. But this issue I am getting only when receiving the data through MLLP & I couldn't find a better way to handle this characters in the incoming Bytes on JAVA.

view this post on Zulip Lin Zhang (Feb 18 2021 at 13:46):

A related page:

These headers and trailers are usually non-printable characters that would not typically be in the content of HL7 messages. The header is a vertical tab character <VT> its hex value is 0x0b. The trailer is a file separator character <FS> (hex 0x1c) immediately followed by a carriage return <CR> (hex 0x0d)...

http://healthstandards.com/blog/2007/05/02/hl7-mlp-minimum-layer-protocol-defined/

view this post on Zulip Lin Zhang (Feb 18 2021 at 13:51):

Another one:

https://www.c-sharpcorner.com/article/sending-an-hl7-message-receiving-it-using-a-listener-and-sending-an-acknowledge/

view this post on Zulip Lin Zhang (Feb 18 2021 at 13:56):

A Java based Tutorial:

Step 4&5&6 of 8 - transmit/parse a dummy MLLP-wrapped HL7 message

https://saravanansubramanian.com/hl72xjavaprogramming/

view this post on Zulip Vibin_chander (Mar 10 2021 at 10:10):

This is more complicated than we thought. One can definitely understand that HL7v2 over tcp dont behave same as MLLP.MLLP is a frame level protocol You can also see in the last link that he is trying to read as input stream. Which is not possible. We need to read MLLP message special way. Wondering if there is a HAPI code of Version 2 that allows to read input stream

view this post on Zulip Vibin_chander (Mar 15 2021 at 03:20):

One way of handling this is using the MLLPMinLowLayer() from HAPI

view this post on Zulip Vibin_chander (Mar 15 2021 at 03:21):

But if the connection is kept open on the sender side you will still face issue


Last updated: Apr 12 2022 at 19:14 UTC