[ https://issues.apache.org/jira/browse/CAMEL-12677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16553851#comment-16553851 ]
ASF GitHub Bot commented on CAMEL-12677: ---------------------------------------- oscerd closed pull request #2435: CAMEL-12677 Create FHIR spring boot quickstart URL: https://github.com/apache/camel/pull/2435 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/examples/README.adoc b/examples/README.adoc index 524be57168b..8fbdafb8403 100644 --- a/examples/README.adoc +++ b/examples/README.adoc @@ -11,7 +11,7 @@ View the individual example READMEs for details. ### Examples // examples: START -Number of Examples: 105 (8 deprecated) +Number of Examples: 107 (8 deprecated) [width="100%",cols="4,2,4",options="header"] |=== @@ -29,6 +29,8 @@ Number of Examples: 105 (8 deprecated) | link:camel-example-console/README.md[Console] (camel-example-console) | Beginner | An example that reads input from the console +| link:camel-example-fhir-spring-boot/readme.adoc[Fhir Spring Boot] (camel-example-fhir-spring-boot) | Beginner | An example showing how to work with Camel, Fhir and Spring Boot + | link:camel-example-ftp/README.md[FTP] (camel-example-ftp) | Beginner | An example for showing Camel FTP integration | link:camel-example-java8/readme.adoc[Java8] (camel-example-java8) | Beginner | An example for showing Camel DSL for Java 8 @@ -169,6 +171,8 @@ Number of Examples: 105 (8 deprecated) | link:camel-example-cxf-blueprint/README.md[CXF Blueprint] (camel-example-cxf-blueprint) | OSGi | An example which use a CXF consumer and the OSGI HTTP Service +| link:camel-example-fhir-osgi/README.md[Fhir Osgi] (camel-example-fhir-osgi) | OSGi | An example running Camel FHIR in Apache Karaf + | link:camel-example-netty-http/README.md[Netty HTTP] (camel-example-netty-http) | OSGi | An example showing how to use a shared Netty HTTP server with multiple Camel applications in OSGi container | link:camel-example-olingo4-blueprint/README.md[Olingo4 Blueprint] (camel-example-olingo4-blueprint) | OSGi | An example which use the Olingo4 component in Blueprint diff --git a/examples/camel-example-fhir-spring-boot/pom.xml b/examples/camel-example-fhir-spring-boot/pom.xml new file mode 100644 index 00000000000..7c3477ee412 --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/pom.xml @@ -0,0 +1,167 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<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/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>examples</artifactId> + <version>2.23.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-fhir-spring-boot</artifactId> + <name>Camel :: Example :: Fhir :: Spring Boot</name> + <description>An example showing how to work with Camel, Fhir and Spring Boot</description> + + <properties> + <category>Beginner</category> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <spring.boot-version>${spring-boot-version}</spring.boot-version> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Spring Boot BOM --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>${spring.boot-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <!-- Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-dependencies</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <!-- Spring Boot --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + + <!-- Camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-fhir</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-hl7</artifactId> + </dependency> + + <dependency> + <groupId>ca.uhn.hapi</groupId> + <artifactId>hapi-structures-v24</artifactId> + </dependency> + + <!-- test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring-boot-version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${project.version}</version> + <!-- allows to fail if not all routes are fully covered during testing --> +<!-- + <configuration> + <failOnError>true</failOnError> + </configuration> +--> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>jdk9+-build</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>--add-modules java.xml.bind --add-opens java.base/java.lang=ALL-UNNAMED</argLine> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/examples/camel-example-fhir-spring-boot/readme.adoc b/examples/camel-example-fhir-spring-boot/readme.adoc new file mode 100644 index 00000000000..d682d9b68e0 --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/readme.adoc @@ -0,0 +1,76 @@ +== FHIR Example - Spring Boot + +=== Introduction + +This is an example application of the `camel-fhir` component. We'll be using `camel-spring-boot` as well for an easy setup. + +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. + +The example assumes you have a running FHIR server at your disposal. +You may use [hapi-fhir-jpa-server-example](https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jpaserver-example) + +By default, the example uses `http://localhost:8080/baseDstu3` as the FHIR server URL, DSTU3 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. + +There is an example of a test in the `MyCamelApplicationTest` class, which mocks out the FHIR server, thus can be run without the FHIR server. + +=== Build + +You can build this example using: + +```sh +$ mvn package +``` + +=== Run + +You can run this example using: + +```sh +$ mvn spring-boot:run +``` + +When the Camel application runs, you should see a folder created under `target/work/fhir/input`. Copy the file `hl7v2.patient` +located in the `src/main/data` folder into it. You should see the following output: +``` + +``` + +The Camel application can be stopped pressing <kbd>ctrl</kbd>+<kbd>c</kbd> in the shell. + +=== To get health check + +To show a summary of spring boot health check + +---- +curl -XGET -s http://localhost:8080/actuator/health +---- + +=== To get info about the routes + +To show a summary of all the routes + +---- +curl -XGET -s http://localhost:8080/actuator/camelroutes +---- + +To show detailed information for a specific route + +---- +curl -XGET -s http://localhost:8080/actuator/camelroutes/{id}/detail +---- + + +=== Forum, Help, etc + +If you hit an problems please let us know on the Camel Forums +<http://camel.apache.org/discussion-forums.html> + +Please help us make Apache Camel better - we appreciate any feedback you may have. Enjoy! + +The Camel riders! + + diff --git a/examples/camel-example-fhir-spring-boot/src/main/data/hl7v2.patient b/examples/camel-example-fhir-spring-boot/src/main/data/hl7v2.patient new file mode 100644 index 00000000000..b5ecbe7103c --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/src/main/data/hl7v2.patient @@ -0,0 +1 @@ +MSH|^~\&|Amalga HIS|BUM|New Tester|MS|20111121103141||ORU^R01|2847970-201111211031|P|2.4|||AL|NE|764|ASCII||| PID||100005056|100005056||Freeman^Vincent^""^^""|""|19810813000000|F||CA|Street 1^""^""^""^34000^SGP^^""~""^""^""^""^Danling Street 5th^THA^^""||326-2275^PRN^PH^^66^675~476-5059^ORN^CP^^66^359~(123)456-7890^ORN^FX^^66^222~^NET^X.400^a@a.a~^NET^X.400^du...@hotmail.com|(123)456-7890^WPN^PH^^66|UNK|S|BUD||BP000111899|D99999^""||CA|Bangkok|||THA||THA|""|N PV1||OPD ||||""^""^""||||CNSLT|||||C|VIP|||6262618|PB1||||||||||||||||||||||||20101208134638 PV2|||^Unknown|""^""||||""|""|0||""|||||||||||||||||||||||||||||HP1 ORC|NW|""|BMC1102771601|""|CM||^^^^^""|||||||||""^""^^^"" OBR|1|""|BMC1102771601|""^Brain (CT)||20111028124215||||||||||||||||||CTSCAN|F||^^^^^ROUTINE|||""||||||""|||||||||||^"" OBX|1|FT|""^Brain (CT)||++++ text of report goes here +++|||REQAT|||FINAL|||20111121103040||75929^Gosselin^Angelina \ No newline at end of file diff --git a/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelApplication.java b/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelApplication.java new file mode 100644 index 00000000000..36020f2e22d --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelApplication.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.camel; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * A sample Spring Boot application that starts the Camel routes. + */ +@SpringBootApplication +public class MyCamelApplication { + + /** + * A main method to start this application. + */ + public static void main(String[] args) { + SpringApplication.run(MyCamelApplication.class, args); + } + +} diff --git a/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelRouter.java b/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelRouter.java new file mode 100644 index 00000000000..25c9aa1ad9d --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelRouter.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.camel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.LoggingLevel; +import org.apache.http.ProtocolException; +import org.hl7.fhir.dstu3.model.Patient; +import org.springframework.stereotype.Component; + +import ca.uhn.hl7v2.HL7Exception; +import ca.uhn.hl7v2.model.v24.message.ORU_R01; +import ca.uhn.hl7v2.model.v24.segment.PID; + + +/** + * A simple Camel route that triggers from a timer and calls a bean and prints to system out. + * <p/> + * Use <tt>@Component</tt> to make Camel auto detect this route when starting. + */ +@Component +public class MyCamelRouter extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("file:{{input}}").routeId("fhir-example") + .onException(ProtocolException.class) + .handled(true) + .log(LoggingLevel.ERROR, "Error connecting to FHIR server with URL:{{serverUrl}}, please check the application.properties file ${exception.message}") + .end() + .onException(HL7Exception.class) + .handled(true) + .log(LoggingLevel.ERROR, "Error unmarshalling ${file:name} ${exception.message}") + .end() + .log("Converting ${file:name}") + // unmarshall file to hl7 message + .unmarshal().hl7() + // very simple mapping from a HLV2 patient to dstu3 patient + .process(exchange -> { + ORU_R01 msg = exchange.getIn().getBody(ORU_R01.class); + final PID pid = msg.getPATIENT_RESULT().getPATIENT().getPID(); + String surname = pid.getPatientName()[0].getFamilyName().getFn1_Surname().getValue(); + String name = pid.getPatientName()[0].getGivenName().getValue(); + String patientId = msg.getPATIENT_RESULT().getPATIENT().getPID().getPatientID().getCx1_ID().getValue(); + Patient patient = new Patient(); + patient.addName().addGiven(name); + patient.getNameFirstRep().setFamily(surname); + patient.setId(patientId); + exchange.getIn().setBody(patient); + }) + // marshall to JSON for logging + .marshal().fhirJson("{{fhirVersion}}") + .log("Inserting Patient: ${body}") + // create Patient in our FHIR server + .to("fhir://create/resource?inBody=resourceAsString&serverUrl={{serverUrl}}&fhirVersion={{fhirVersion}}") + // log the outcome + .log("Patient created successfully: ${body}"); + } + +} diff --git a/examples/camel-example-fhir-spring-boot/src/main/resources/application.properties b/examples/camel-example-fhir-spring-boot/src/main/resources/application.properties new file mode 100644 index 00000000000..ee76e394a38 --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/src/main/resources/application.properties @@ -0,0 +1,54 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +serverUrl=http://localhost:8080/baseDstu3 + +fhirVersion=DSTU3 + +input=target/work/fhir/input + +# the name of Camel +camel.springboot.name = MyCamel + +server.port=0 + +# to automatic shutdown the JVM after a period of time +#camel.springboot.duration-max-seconds=60 +#camel.springboot.duration-max-messages=100 + +# add for example: &repeatCount=5 to the timer endpoint to make Camel idle +#camel.springboot.duration-max-idle-seconds=15 + +# expose actuator endpoint via HTTP +management.endpoints.web.exposure.include=info,health,camelroutes + +# show verbose health details (/actuator/info) so you can see Camel information also +management.endpoint.health.show-details=always + +# to turn off Camel info in (/actuator/info) +management.info.camel.enabled=false + +# allow to obtain basic information about Camel routes (read only mode) +management.endpoint.camelroutes.enabled = true +management.endpoint.camelroutes.read-only = true + +# to configure logging levels +#logging.level.org.springframework = INFO +#logging.level.org.apache.camel.spring.boot = INFO +#logging.level.org.apache.camel.impl = DEBUG +#logging.level.sample.camel = DEBUG + diff --git a/examples/camel-example-fhir-spring-boot/src/test/java/sample/camel/MyCamelApplicationTest.java b/examples/camel-example-fhir-spring-boot/src/test/java/sample/camel/MyCamelApplicationTest.java new file mode 100644 index 00000000000..bd0b251582a --- /dev/null +++ b/examples/camel-example-fhir-spring-boot/src/test/java/sample/camel/MyCamelApplicationTest.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.camel; + +import java.io.File; +import java.io.IOException; + +import org.apache.camel.EndpointInject; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.CamelSpringBootRunner; +import org.apache.camel.test.spring.EnableRouteCoverage; +import org.apache.camel.test.spring.MockEndpointsAndSkip; +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; + +@RunWith(CamelSpringBootRunner.class) +@SpringBootTest(classes = MyCamelApplication.class, + properties = "input = target/work/fhir/testinput") +@EnableRouteCoverage +@MockEndpointsAndSkip("fhir*") +public class MyCamelApplicationTest { + + @EndpointInject(uri = "mock:fhir:create/resource") + private MockEndpoint mock; + + @Before + public void copyData() throws IOException { + FileUtils.copyDirectory(new File("src/main/data"), new File("target/work/fhir/testinput")); + } + + @Test + public void shouldPushConvertedHl7toFhir() throws Exception { + mock.expectedBodiesReceived("{\"resourceType\":\"Patient\",\"id\":\"100005056\",\"name\":[{\"family\":\"Freeman\",\"given\":[\"Vincent\"]}]}"); + + mock.assertIsSatisfied(); + } + +} diff --git a/examples/pom.xml b/examples/pom.xml index bc2ae0fdada..c888bcb8620 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -47,6 +47,7 @@ <module>camel-example-cdi-cassandraql</module> <module>camel-example-fhir</module> <module>camel-example-fhir-osgi</module> + <module>camel-example-fhir-spring-boot</module> <module>camel-example-cdi-kubernetes</module> <module>camel-example-cdi-metrics</module> <module>camel-example-cdi-osgi</module> ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Create FHIR spring boot quickstart > ---------------------------------- > > Key: CAMEL-12677 > URL: https://issues.apache.org/jira/browse/CAMEL-12677 > Project: Camel > Issue Type: Task > Components: examples > Reporter: Rafal Korytkowski > Priority: Major > Fix For: 2.23.0 > > > Base the example onĀ > https://github.com/apache/camel/tree/master/examples/camel-example-fhir -- This message was sent by Atlassian JIRA (v7.6.3#76005)