Skip to content

Commit

Permalink
fhir: move to test-infra (#134)
Browse files Browse the repository at this point in the history
* fhir: move to test-infra

* fhir: update readme
  • Loading branch information
johnpoth authored Jun 27, 2024
1 parent b931923 commit ebcca60
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 49 deletions.
9 changes: 6 additions & 3 deletions fhir/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<!-- test infra -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers-version}</version>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-fhir</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions fhir/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ This is an example application of the `camel-fhir` component. We'll be using `ca

The Camel route is located in the `MyCamelRouter` class.

This example will read HL7V2 patients from a directory and convert them to FHIR dtsu3 patients and upload them to a configured FHIR server.
This example will read HL7V2 patients from a directory and convert them to FHIR R4 patients and upload them to a configured FHIR server.

The example installs hapiproject/hapi:v4.2.0 docker image as local FHIR server

By default, the example uses `\http://localhost:8081/hapi-fhir-jpaserver/fhir` as the FHIR server URL, DSTU3 as the FHIR version and `target/work/fhir/input`
By default, the example uses `\http://localhost:8081/fhir` as the FHIR server URL, R4 as the FHIR version and `target/work/fhir/input`
as the directory to look for HL7V2 patients.
However, you can edit the `application.properties` file to override the defaults and provide your own configuration.

Expand All @@ -31,7 +31,7 @@ Before running your application execute this command to deploy FHIR server:

[source,bash]
----
docker run -p 8081:8080 -e HAPI_FHIR_VERSION=DSTU3 -e HAPI_REUSE_CACHED_SEARCH_RESULTS_MILLIS=-1 hapiproject/hapi:v4.2.0
docker run -p 8081:8080 -e hapi.fhir.fhir_version=R4 -e hapi.fhir.reuse_cached_search_results_millis=-1 hapiproject/hapi:v6.8.3
----

Then you can run this example using:
Expand Down
2 changes: 1 addition & 1 deletion fhir/src/main/java/sample/camel/MyCamelRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.http.ProtocolException;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.r4.model.Patient;
import org.springframework.stereotype.Component;

/**
Expand Down
4 changes: 2 additions & 2 deletions fhir/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
## limitations under the License.
## ---------------------------------------------------------------------------

serverUrl=http://localhost:8081/hapi-fhir-jpaserver/fhir
serverUrl=http://localhost:8081/fhir

fhirVersion=DSTU3
fhirVersion=R4

input=target/work/fhir/input

Expand Down
67 changes: 27 additions & 40 deletions fhir/src/test/java/sample/camel/MyCamelApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,39 @@
*/
package sample.camel;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.boot.CamelContextConfiguration;
import org.apache.camel.test.infra.fhir.services.FhirService;
import org.apache.camel.test.infra.fhir.services.FhirServiceFactory;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.commons.io.FileUtils;

import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.hl7.fhir.dstu3.model.Patient;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;

import java.io.File;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.springframework.context.annotation.Bean;

@CamelSpringBootTest
@SpringBootTest(classes = MyCamelApplication.class,
@SpringBootTest(classes = {MyCamelApplication.class, MyCamelApplicationTest.class},
properties = "input = target/work/fhir/testinput")
public class MyCamelApplicationTest {

private static final int CONTAINER_PORT = 8080;
private static final int EXPOSED_PORT = 8081;
private static final String CONTAINER_IMAGE = "hapiproject/hapi:v4.2.0";

private static GenericContainer container;
@RegisterExtension
public static FhirService service = FhirServiceFactory.createSingletonService();

@Autowired
private CamelContext camelContext;

@Autowired
private ProducerTemplate producerTemplate;

@BeforeAll
public static void startServer() throws Exception {
Consumer<CreateContainerCmd> cmd = e -> {
e.withPortBindings(new PortBinding(Ports.Binding.bindPort(EXPOSED_PORT),
new ExposedPort(CONTAINER_PORT)));
};

container = new GenericContainer(CONTAINER_IMAGE)
.withNetworkAliases("fhir")
.withExposedPorts(CONTAINER_PORT)
.withCreateContainerCmdModifier(cmd)
.withEnv("HAPI_FHIR_VERSION", "DSTU3")
.withEnv("HAPI_REUSE_CACHED_SEARCH_RESULTS_MILLIS", "-1")
.waitingFor(Wait.forListeningPort())
.waitingFor(Wait.forHttp("/hapi-fhir-jpaserver/fhir/metadata"));
;
container.start();
}

@Test
public void shouldPushConvertedHl7toFhir() throws Exception {
MockEndpoint mock = camelContext.getEndpoint("mock:result", MockEndpoint.class);
Expand All @@ -89,4 +61,19 @@ public void shouldPushConvertedHl7toFhir() throws Exception {
mock.assertIsSatisfied();
Assertions.assertEquals("Freeman", mock.getExchanges().get(0).getIn().getBody(Patient.class).getName().get(0).getFamily());
}

@Bean
CamelContextConfiguration contextConfiguration() {
return new CamelContextConfiguration() {
@Override
public void beforeApplicationStart(CamelContext context) {
context.getPropertiesComponent().addInitialProperty("serverUrl", service.getServiceBaseURL());
}

@Override
public void afterApplicationStart(CamelContext camelContext) {

}
};
}
}

0 comments on commit ebcca60

Please sign in to comment.