Re: Guidance Needed: Parsing HL7v2.7 Segments with HAPI HL7

103 views
Skip to first unread message

James Agnew

unread,
Oct 19, 2024, 12:30:13 PM10/19/24
to Shreeja J, HAPI FHIR
Hi Shreeja,

Note that this mailing list is for HAPI FHIR, the mailing list for HAPI HL7v2 can be found here: https://hapifhir.github.io/hapi-hl7v2/mail-lists.html

Your issue however is that your line endings are incorrect. HL7 v2 uses \r as the segment delimiter, not \n as you are using in your test code.

Cheers,
James

On Sat, Oct 19, 2024 at 12:01 PM Shreeja J <mail2s...@gmail.com> wrote:
Hello Team ,

I am currently working on a project where I am using HAPI HL7 to parse HL7v2.7 segments. I have added the following dependencies in my pom.xml :

<dependency>
    <groupId>ca.uhn.hapi.fhir</groupId>
    <artifactId>hapi-fhir-structures-r4</artifactId>
    <version>7.4.0</version>
</dependency>
<dependency>
    <groupId>ca.uhn.hapi</groupId>
    <artifactId>hapi-structures-v27</artifactId>
    <version>2.4</version>
</dependency>
 
This is the junit I used for testing

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.PipeParser;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

public class PIDSegmentTest {
    @Test
    public void testHl7Parser() throws HL7Exception {
        String hl7Message =
            "MSH|^~\\&|HIS|RIH|EKG|EKG|202310190830||ORU^R01|MSG00001|P|2.7\n" +
            "PID|||12345^^^Hospital^MR||Doe^John||19700101|M";

        // Parse the HL7 message using HAPI HL7v2
        PipeParser parser = new PipeParser();
        Message message = parser.parse(hl7Message);

        assertThat(message).isNotNull();
    }
}

However, I am encountering the following exception when trying to parse a message:

The HL7 version 2.7PID is not recognized
ca.uhn.hl7v2.HL7Exception: The HL7 version 2.7PID is not recognized
    at ca.uhn.hl7v2.parser.Parser.assertVersionExists(Parser.java:527)
    at ca.uhn.hl7v2.parser.Parser.parse(Parser.java:208)
    at ca.uhn.hl7v2.parser.PipeParser.parse(PipeParser.java:1028)

Upon checking the Parser.java file in hapi jar, I noticed that the supported versions listed are only up to 2.6. Could you please guide me on whether HAPI supports HL7v2.7 and, if so, which dependency I should use?

Thank you for your assistance.

Thanks,
Shreeja

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/e541884e-1e10-4d27-88f9-3313ec0db10bn%40googlegroups.com.

Vijay Amirtharaj Xavier

unread,
Oct 19, 2024, 12:55:36 PM10/19/24
to James Agnew, Shreeja J, HAPI FHIR
Hi,
If you want to parse hl7v2 message, try with the below dependency.

   <dependencies>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-base</artifactId>
            <version>2.3</version>

        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v23</artifactId>
            <version>2.3</version>

        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v24</artifactId>
            <version>2.3</version>

        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v25</artifactId>
            <version>2.3</version>

        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v25</artifactId>
            <version>2.5</version>

        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v251</artifactId>
            <version>2.3</version>

        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v26</artifactId>
            <version>2.3</version>
        </dependency>
   </dependencies>

You can add your own version in your case you can just add hapi-structures-v27

The hapi-base must be added as mentioned below:- as 2.3 and structures-v27
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-base</artifactId>
            <version>2.3</version>
        </dependency>


All the best.




--
Thanks & Regards
Vijay Amirtharaj X

+91-7010246798
------------------------
Reply all
Reply to author
Forward
0 new messages