This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new f68af36 CAMEL-12736 Create FHIR authorization and transaction quickstart (#2484) f68af36 is described below commit f68af36c00a638fe73b429d62a6b78ac9872af49 Author: Rafal Korytkowski <rafal.korytkow...@gmail.com> AuthorDate: Mon Aug 20 19:27:44 2018 +0200 CAMEL-12736 Create FHIR authorization and transaction quickstart (#2484) --- examples/README.adoc | 6 +- .../camel-example-fhir-auth-tx-spring-boot/pom.xml | 167 +++++++++++++++++++++ .../readme.adoc | 79 ++++++++++ .../src/main/data/patients.csv | 2 + .../main/java/sample/camel/MyCamelApplication.java | 35 +++++ .../src/main/java/sample/camel/MyCamelRouter.java | 48 +++--- .../src/main/resources/application.properties | 56 +++++++ .../java/sample/camel/MyCamelApplicationTest.java | 55 +++++++ .../src/main/java/sample/camel/MyCamelRouter.java | 2 +- examples/pom.xml | 1 + 10 files changed, 421 insertions(+), 30 deletions(-) diff --git a/examples/README.adoc b/examples/README.adoc index 8fbdafb..f242495 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: 107 (8 deprecated) +Number of Examples: 109 (8 deprecated) [width="100%",cols="4,2,4",options="header"] |=== @@ -29,6 +29,8 @@ Number of Examples: 107 (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-auth-tx-spring-boot/readme.adoc[Fhir Auth Tx Spring Boot] (camel-example-fhir-auth-tx-spring-boot) | Beginner | An example showing how to work with Camel, FHIR Authorization, FHIR Transaction and Spring Boot + | 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 @@ -171,6 +173,8 @@ Number of Examples: 107 (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-ehcache-blueprint/README.md[Ehcache Blueprint] (camel-example-ehcache-blueprint) | OSGi | An example using Ehcache with OSGi Blueprint + | 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 diff --git a/examples/camel-example-fhir-auth-tx-spring-boot/pom.xml b/examples/camel-example-fhir-auth-tx-spring-boot/pom.xml new file mode 100644 index 0000000..daf0200 --- /dev/null +++ b/examples/camel-example-fhir-auth-tx-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-auth-tx-spring-boot</artifactId> + <name>Camel :: Example :: Fhir :: Spring Boot</name> + <description>An example showing how to work with Camel, FHIR Authorization, FHIR Transaction 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-csv</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-auth-tx-spring-boot/readme.adoc b/examples/camel-example-fhir-auth-tx-spring-boot/readme.adoc new file mode 100644 index 0000000..37d50bc --- /dev/null +++ b/examples/camel-example-fhir-auth-tx-spring-boot/readme.adoc @@ -0,0 +1,79 @@ +== FHIR Authorization and Transaction 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 patients stored in csv files from a directory and convert them to FHIR dtsu3 patients and upload them to a configured FHIR server. Each file is uploaded in a new transaction. + +The example assumes you have a running FHIR server at your disposal, which is configured for basic authentication. +You may use [hapi-fhir-jpa-server-example](https://github.com/rkorytkowski/hapi-fhir/tree/basic-auth/hapi-fhir-jpaserver-example). You can start it up by running `mvn jetty:run`. + +By default, the example uses `http://localhost:8080/hapi-fhir-jpaserver-example/baseDstu3` as the FHIR server URL, DSTU3 as the FHIR version, BASIC authentication (`admin` as username and `Admin123` as password) and `target/work/fhir/input` +as the directory to look for csv patients. + +However, you can edit the `application.properties` file to change 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: +``` +2018-07-24 11:52:51.615 INFO 30666 --- [work/fhir/input] fhir-example: Converting hl7v2.patient +2018-07-24 11:52:52.700 INFO 30666 --- [work/fhir/input] fhir-example: Inserting Patient: {"resourceType":"Patient","id":"100005056","name":[{"family":"Freeman","given":["Vincent"]}]} +2018-07-24 11:52:56.995 INFO 30666 --- [ #2 - CamelFhir] fhir-example: Patient created successfully: ca.uhn.fhir.rest.api.MethodOutcome@270f03f1 +``` + +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-auth-tx-spring-boot/src/main/data/patients.csv b/examples/camel-example-fhir-auth-tx-spring-boot/src/main/data/patients.csv new file mode 100644 index 0000000..a78f61b --- /dev/null +++ b/examples/camel-example-fhir-auth-tx-spring-boot/src/main/data/patients.csv @@ -0,0 +1,2 @@ +1a,Bob,Smith +2a,Simon,Smith \ No newline at end of file diff --git a/examples/camel-example-fhir-auth-tx-spring-boot/src/main/java/sample/camel/MyCamelApplication.java b/examples/camel-example-fhir-auth-tx-spring-boot/src/main/java/sample/camel/MyCamelApplication.java new file mode 100644 index 0000000..36020f2 --- /dev/null +++ b/examples/camel-example-fhir-auth-tx-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-auth-tx-spring-boot/src/main/java/sample/camel/MyCamelRouter.java similarity index 51% copy from examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelRouter.java copy to examples/camel-example-fhir-auth-tx-spring-boot/src/main/java/sample/camel/MyCamelRouter.java index 1bdf3bb..44313a6 100644 --- a/examples/camel-example-fhir-spring-boot/src/main/java/sample/camel/MyCamelRouter.java +++ b/examples/camel-example-fhir-auth-tx-spring-boot/src/main/java/sample/camel/MyCamelRouter.java @@ -16,19 +16,19 @@ */ package sample.camel; -import ca.uhn.hl7v2.HL7Exception; -import ca.uhn.hl7v2.model.v24.message.ORU_R01; -import ca.uhn.hl7v2.model.v24.segment.PID; +import org.apache.camel.builder.RouteBuilder; + +import java.util.ArrayList; +import java.util.List; 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.springframework.stereotype.Component; + /** - * A simple Camel route that triggers from a timer and calls a bean and prints to system out. + * A simple Camel route that triggers from a file and pushes to a FHIR server. * <p/> * Use <tt>@Component</tt> to make Camel auto detect this route when starting. */ @@ -42,33 +42,25 @@ public class MyCamelRouter extends RouteBuilder { .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 + .unmarshal().csv() .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); + List<Patient> bundle = new ArrayList<>(); + @SuppressWarnings("unchecked") + List<List<String>> patients = (List<List<String>>) exchange.getIn().getBody(); + for (List<String> patient: patients) { + Patient fhirPatient = new Patient(); + fhirPatient.setId(patient.get(0)); + fhirPatient.addName().addGiven(patient.get(1)); + fhirPatient.getNameFirstRep().setFamily(patient.get(2)); + bundle.add(fhirPatient); + } + exchange.getIn().setBody(bundle); }) - // 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}}") + .to("fhir://transaction/withResources?inBody=resources&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}") // log the outcome - .log("Patient created successfully: ${body}"); + .log("Patients created successfully: ${body}"); } } diff --git a/examples/camel-example-fhir-auth-tx-spring-boot/src/main/resources/application.properties b/examples/camel-example-fhir-auth-tx-spring-boot/src/main/resources/application.properties new file mode 100644 index 0000000..34b663b --- /dev/null +++ b/examples/camel-example-fhir-auth-tx-spring-boot/src/main/resources/application.properties @@ -0,0 +1,56 @@ +## --------------------------------------------------------------------------- +## 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/hapi-fhir-jpaserver-example/baseDstu3 +serverUser=admin +serverPassword=Admin123 + +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-auth-tx-spring-boot/src/test/java/sample/camel/MyCamelApplicationTest.java b/examples/camel-example-fhir-auth-tx-spring-boot/src/test/java/sample/camel/MyCamelApplicationTest.java new file mode 100644 index 0000000..470e87e --- /dev/null +++ b/examples/camel-example-fhir-auth-tx-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:transaction/withResources") + 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 shouldPushConvertedCsvtoFhir() throws Exception { + mock.expectedMessageCount(1); + + mock.assertIsSatisfied(); + } + +} 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 index 1bdf3bb..21a7898 100644 --- 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 @@ -28,7 +28,7 @@ import org.hl7.fhir.dstu3.model.Patient; import org.springframework.stereotype.Component; /** - * A simple Camel route that triggers from a timer and calls a bean and prints to system out. + * A simple Camel route that triggers from a file and posts to a FHIR server. * <p/> * Use <tt>@Component</tt> to make Camel auto detect this route when starting. */ diff --git a/examples/pom.xml b/examples/pom.xml index 033f274..80e6e4b 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -46,6 +46,7 @@ <module>camel-example-cdi-aws-s3</module> <module>camel-example-cdi-cassandraql</module> <module>camel-example-fhir</module> + <module>camel-example-fhir-auth-tx-spring-boot</module> <module>camel-example-fhir-osgi</module> <module>camel-example-fhir-spring-boot</module> <module>camel-example-cdi-kubernetes</module>