Setting Up Your Development Environment

Section 6 of 14
43% complete

Maven Dependencies

Maven is the most common build tool for Java HL7 projects. The HAPI library requires both the core module and version-specific structure libraries for each HL7 version you need to support. Apache Camel dependencies enable integration patterns and MLLP transport. Include only the structure versions your project actually uses to minimize dependency size.

Create a pom.xml file with the following dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.healthcare</groupId>
    <artifactId>hl7v2-tutorial</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <hapi.version>2.5.1</hapi.version>
        <camel.version>4.2.0</camel.version>
    </properties>

    <dependencies>
        <!-- HAPI HL7 V2 Core -->
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-base</artifactId>
            <version>${hapi.version}</version>
        </dependency>

        <!-- HAPI HL7 V2 Structures - Include versions you need -->
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v21</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v22</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v23</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v231</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v24</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v25</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v251</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v26</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v27</artifactId>
            <version>${hapi.version}</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v28</artifactId>
            <version>${hapi.version}</version>
        </dependency>

        <!-- Apache Camel Core -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- Camel HL7 Component -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-hl7</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- Camel MINA for MLLP transport -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-mina</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- Camel Netty (alternative to MINA) -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-netty</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- SLF4J Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.9</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.4.14</version>
        </dependency>

        <!-- JUnit for Testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.10.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
            </plugin>
        </plugins>
    </build>
</project>

Gradle Dependencies (Alternative)

If your project uses Gradle instead of Maven, the following configuration provides equivalent functionality. Gradle’s concise syntax makes dependency management straightforward. The key dependencies remain the same: hapi-base for core functionality, version-specific structures, and Camel components for integration.

plugins {
    id 'java'
}

group = 'com.healthcare'
version = '1.0.0'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    // HAPI HL7 V2
    implementation 'ca.uhn.hapi:hapi-base:2.5.1'
    implementation 'ca.uhn.hapi:hapi-structures-v25:2.5.1'
    implementation 'ca.uhn.hapi:hapi-structures-v251:2.5.1'

    // Apache Camel
    implementation 'org.apache.camel:camel-core:4.2.0'
    implementation 'org.apache.camel:camel-hl7:4.2.0'
    implementation 'org.apache.camel:camel-mina:4.2.0'

    // Logging
    implementation 'org.slf4j:slf4j-api:2.0.9'
    implementation 'ch.qos.logback:logback-classic:1.4.14'

    // Testing
    testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
}

test {
    useJUnitPlatform()
}

Quiz: Setting Up Your Development Environment

Question 1 of 4

What is the primary Java library used for HL7 V2 message handling?