You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2024/10/21 13:03:12 UTC
(camel-quarkus) branch main updated (e5dd6b04bc -> 48781876a1)
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
from e5dd6b04bc Mysql testResource instead of devservices
new 6cf7430d11 Document FHIR native mode requirements for FhirContext
new 48781876a1 Improve some test assertions in FHIR tests
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../ROOT/pages/reference/extensions/fhir.adoc | 81 +++++++++++++++++++++-
.../fhir/runtime/src/main/doc/configuration.adoc | 3 +-
extensions/fhir/runtime/src/main/doc/usage.adoc | 73 +++++++++++++++++++
.../fhir/it/AbstractFhirRouteBuilder.java | 7 ++
.../component/fhir/it/FhirDstu2Hl7OrgResource.java | 43 ++++--------
.../component/fhir/it/FhirDstu2Resource.java | 40 ++++-------
.../component/fhir/it/FhirDstu2_1Resource.java | 40 ++++-------
.../component/fhir/it/FhirDstu3Resource.java | 27 +++-----
.../quarkus/component/fhir/it/FhirR4Resource.java | 40 ++++-------
.../quarkus/component/fhir/it/FhirR5Resource.java | 40 ++++-------
.../component/fhir/it/AbstractFhirTest.java | 22 +++++-
11 files changed, 260 insertions(+), 156 deletions(-)
create mode 100644 extensions/fhir/runtime/src/main/doc/usage.adoc
(camel-quarkus) 02/02: Improve some test assertions in FHIR tests
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 48781876a1be1feccf11f14a6c0b36018b6260d0
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Oct 21 11:37:32 2024 +0100
Improve some test assertions in FHIR tests
---
.../fhir/it/AbstractFhirRouteBuilder.java | 7 ++++
.../component/fhir/it/FhirDstu2Hl7OrgResource.java | 43 +++++++---------------
.../component/fhir/it/FhirDstu2Resource.java | 40 +++++++-------------
.../component/fhir/it/FhirDstu2_1Resource.java | 40 +++++++-------------
.../component/fhir/it/FhirDstu3Resource.java | 27 +++++---------
.../quarkus/component/fhir/it/FhirR4Resource.java | 40 +++++++-------------
.../quarkus/component/fhir/it/FhirR5Resource.java | 40 +++++++-------------
.../component/fhir/it/AbstractFhirTest.java | 22 ++++++++++-
8 files changed, 107 insertions(+), 152 deletions(-)
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirRouteBuilder.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirRouteBuilder.java
index 9d9342e760..44f1af2cbe 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirRouteBuilder.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirRouteBuilder.java
@@ -83,6 +83,13 @@ public abstract class AbstractFhirRouteBuilder extends RouteBuilder {
.toF("fhir-%s://create/resource?inBody=resource", sanitizedFhirVersion);
fromF("direct:createResourceAsString-%s", sanitizedFhirVersion)
+ .choice()
+ .when(simple("${header.encodeAs} == 'encodeJson'"))
+ .marshal(fhirJsonDataFormat)
+ .otherwise()
+ .marshal(fhirXmlDataFormat)
+ .end()
+ .convertBodyTo(String.class)
.toF("fhir-%s://create/resource?inBody=resourceAsString", sanitizedFhirVersion);
// Dataformats
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Hl7OrgResource.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Hl7OrgResource.java
index 67b70174f4..c94044b793 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Hl7OrgResource.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Hl7OrgResource.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.quarkus.component.fhir.it;
-import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
@@ -125,18 +124,10 @@ public class FhirDstu2Hl7OrgResource {
patient.addAddress().addLine(address);
patient.addName().addGiven(firstName).addFamily(lastName);
- String patientString = null;
Map<String, Object> headers = new HashMap<>();
- headers.put(encodeAs, Boolean.TRUE);
+ headers.put("encodeAs", encodeAs);
- if (encodeAs.equals("encodeJson")) {
- patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
- } else {
- patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
- }
-
- MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu2-hl7org",
- patientString,
+ MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu2-hl7org", patient,
headers,
MethodOutcome.class);
@@ -177,7 +168,7 @@ public class FhirDstu2Hl7OrgResource {
@Path("/fhir2json")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
public Response fhir2json(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -188,19 +179,16 @@ public class FhirDstu2Hl7OrgResource {
patient.addName().addGiven(firstName).addFamily(lastName);
String patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:json-to-dstu2-hl7org", patientString,
- InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:json-to-dstu2-hl7org", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
@Path("/fhir2xml")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_XML)
public Response fhir2xml(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -211,14 +199,11 @@ public class FhirDstu2Hl7OrgResource {
patient.addName().addGiven(firstName).addFamily(lastName);
String patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:xml-to-dstu2-hl7org", patientString,
- InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:xml-to-dstu2-hl7org", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
/////////////////////
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Resource.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Resource.java
index dddec0e08a..ed09ec21b5 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Resource.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2Resource.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.quarkus.component.fhir.it;
-import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
@@ -130,17 +129,10 @@ public class FhirDstu2Resource {
patient.addAddress().addLine(address);
patient.addName().addGiven(firstName).setFamily(Arrays.asList(new StringDt(lastName)));
- String patientString = null;
Map<String, Object> headers = new HashMap<>();
- headers.put(encodeAs, Boolean.TRUE);
+ headers.put("encodeAs", encodeAs);
- if (encodeAs.equals("encodeJson")) {
- patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
- } else {
- patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
- }
-
- MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu2", patientString,
+ MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu2", patient,
headers,
MethodOutcome.class);
@@ -181,7 +173,7 @@ public class FhirDstu2Resource {
@Path("/fhir2json")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
public Response fhir2json(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -192,18 +184,16 @@ public class FhirDstu2Resource {
patient.addName().addGiven(firstName).setFamily(Arrays.asList(new StringDt(lastName)));
String patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:json-to-dstu2", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:json-to-dstu2", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
@Path("/fhir2xml")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_XML)
public Response fhir2xml(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -214,13 +204,11 @@ public class FhirDstu2Resource {
patient.addName().addGiven(firstName).setFamily(Arrays.asList(new StringDt(lastName)));
String patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:xml-to-dstu2", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:xml-to-dstu2", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
/////////////////////
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2_1Resource.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2_1Resource.java
index af5d2ad2ea..4d0391fe85 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2_1Resource.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu2_1Resource.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.quarkus.component.fhir.it;
-import java.io.InputStream;
import java.net.URI;
import java.net.URLEncoder;
import java.text.ParseException;
@@ -124,17 +123,10 @@ public class FhirDstu2_1Resource {
patient.addAddress().addLine(address);
patient.addName().addGiven(firstName).addFamily(lastName);
- String patientString = null;
Map<String, Object> headers = new HashMap<>();
- headers.put(encodeAs, Boolean.TRUE);
+ headers.put("encodeAs", encodeAs);
- if (encodeAs.equals("encodeJson")) {
- patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
- } else {
- patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
- }
-
- MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu2-1", patientString,
+ MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu2-1", patient,
headers,
MethodOutcome.class);
@@ -175,7 +167,7 @@ public class FhirDstu2_1Resource {
@Path("/fhir2json")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
public Response fhir2json(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -186,18 +178,16 @@ public class FhirDstu2_1Resource {
patient.addName().addGiven(firstName).addFamily(lastName);
String patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:json-to-dstu2-1", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:json-to-dstu2-1", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
@Path("/fhir2xml")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_XML)
public Response fhir2xml(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -208,13 +198,11 @@ public class FhirDstu2_1Resource {
patient.addName().addGiven(firstName).addFamily(lastName);
String patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:xml-to-dstu2-1", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:xml-to-dstu2-1", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
/////////////////////
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu3Resource.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu3Resource.java
index ed89c4310d..684124b912 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu3Resource.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirDstu3Resource.java
@@ -126,17 +126,10 @@ public class FhirDstu3Resource {
patient.addAddress().addLine(address);
patient.addName().addGiven(firstName).setFamily(lastName);
- String patientString = null;
Map<String, Object> headers = new HashMap<>();
- headers.put(encodeAs, Boolean.TRUE);
+ headers.put("encodeAs", encodeAs);
- if (encodeAs.equals("encodeJson")) {
- patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
- } else {
- patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
- }
-
- MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu3", patientString,
+ MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-dstu3", patient,
headers,
MethodOutcome.class);
@@ -177,7 +170,7 @@ public class FhirDstu3Resource {
@Path("/fhir2json")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
public Response fhir2json(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -188,18 +181,16 @@ public class FhirDstu3Resource {
patient.addName().addGiven(firstName).setFamily(lastName);
String patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:json-to-dstu3", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:json-to-dstu3", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
@Path("/fhir2xml")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_XML)
public Response fhir2xml(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR4Resource.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR4Resource.java
index 8ae4d58dae..6534c9eebd 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR4Resource.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR4Resource.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.quarkus.component.fhir.it;
-import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.text.ParseException;
@@ -125,17 +124,10 @@ public class FhirR4Resource {
patient.addAddress().addLine(address);
patient.addName().addGiven(firstName).setFamily(lastName);
- String patientString = null;
Map<String, Object> headers = new HashMap<>();
- headers.put(encodeAs, Boolean.TRUE);
+ headers.put("encodeAs", encodeAs);
- if (encodeAs.equals("encodeJson")) {
- patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
- } else {
- patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
- }
-
- MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-r4", patientString,
+ MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-r4", patient,
headers,
MethodOutcome.class);
@@ -176,7 +168,7 @@ public class FhirR4Resource {
@Path("/fhir2json")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
public Response fhir2json(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -187,18 +179,16 @@ public class FhirR4Resource {
patient.addName().addGiven(firstName).setFamily(lastName);
String patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:json-to-r4", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String result = producerTemplate.requestBody("direct:json-to-r4", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(result)
+ .build();
}
@Path("/fhir2xml")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_XML)
public Response fhir2xml(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -209,13 +199,11 @@ public class FhirR4Resource {
patient.addName().addGiven(firstName).setFamily(lastName);
String patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:xml-to-r4", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String result = producerTemplate.requestBody("direct:xml-to-r4", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(result)
+ .build();
}
/////////////////////
diff --git a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR5Resource.java b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR5Resource.java
index db6269a1c2..83883ab1b1 100644
--- a/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR5Resource.java
+++ b/integration-tests/fhir/src/main/java/org/apache/camel/quarkus/component/fhir/it/FhirR5Resource.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.quarkus.component.fhir.it;
-import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.text.ParseException;
@@ -123,17 +122,10 @@ public class FhirR5Resource {
patient.addAddress().addLine(address);
patient.addName().addGiven(firstName).setFamily(lastName);
- String patientString = null;
Map<String, Object> headers = new HashMap<>();
- headers.put(encodeAs, Boolean.TRUE);
+ headers.put("encodeAs", encodeAs);
- if (encodeAs.equals("encodeJson")) {
- patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
- } else {
- patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
- }
-
- MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-r5", patientString,
+ MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:createResourceAsString-r5", patient,
headers,
MethodOutcome.class);
@@ -174,7 +166,7 @@ public class FhirR5Resource {
@Path("/fhir2json")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
public Response fhir2json(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -185,18 +177,16 @@ public class FhirR5Resource {
patient.addName().addGiven(firstName).setFamily(lastName);
String patientString = fhirContextInstance.get().newJsonParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:json-to-r5", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:json-to-r5", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
@Path("/fhir2xml")
@GET
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_XML)
public Response fhir2xml(
@QueryParam("firstName") String firstName,
@QueryParam("lastName") String lastName,
@@ -207,13 +197,11 @@ public class FhirR5Resource {
patient.addName().addGiven(firstName).setFamily(lastName);
String patientString = fhirContextInstance.get().newXmlParser().encodeResourceToString(patient);
-
- try (InputStream response = producerTemplate.requestBody("direct:xml-to-r5", patientString, InputStream.class)) {
- return Response
- .created(new URI("https:camel.apache.org/"))
- .entity(response)
- .build();
- }
+ String response = producerTemplate.requestBody("direct:xml-to-r5", patientString, String.class);
+ return Response
+ .created(new URI("https:camel.apache.org/"))
+ .entity(response)
+ .build();
}
/////////////////////
diff --git a/integration-tests/fhir/src/test/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirTest.java b/integration-tests/fhir/src/test/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirTest.java
index 357dfd541a..14ba3a20b7 100644
--- a/integration-tests/fhir/src/test/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirTest.java
+++ b/integration-tests/fhir/src/test/java/org/apache/camel/quarkus/component/fhir/it/AbstractFhirTest.java
@@ -23,6 +23,7 @@ import java.util.stream.Stream;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
+import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -45,10 +46,29 @@ abstract class AbstractFhirTest {
@ParameterizedTest
@ValueSource(strings = { "fhir2json", "fhir2xml" })
public void marshalUnmarshal(String path) {
- RestAssured.given()
+ ValidatableResponse response = RestAssured.given()
+ .queryParam("firstName", PATIENT_FIRST_NAME)
+ .queryParam("lastName", PATIENT_LAST_NAME)
+ .queryParam("address", PATIENT_ADDRESS)
.get("/" + path)
.then()
.statusCode(201);
+
+ String familyNameKey = "name[0].family";
+ if (getClass().getSimpleName().matches("FhirDstu2(Hl7Org)?(Test|IT)")) {
+ familyNameKey = "name[0].family[0]";
+ }
+
+ if (path.equals("fhir2json")) {
+ response.body("resourceType", is("Patient"),
+ "name[0].given[0]", is(PATIENT_FIRST_NAME),
+ familyNameKey, is(PATIENT_LAST_NAME),
+ "address[0].line[0]", is(PATIENT_ADDRESS));
+ } else {
+ response.body("Patient.name.given.@value", is(PATIENT_FIRST_NAME),
+ "Patient.name.family.@value", is(PATIENT_LAST_NAME),
+ "Patient.address.line.@value", is(PATIENT_ADDRESS));
+ }
}
@ParameterizedTest
(camel-quarkus) 01/02: Document FHIR native mode requirements for FhirContext
Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 6cf7430d116d5a1be3e46acdfb0ab3949290521d
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Oct 21 11:34:32 2024 +0100
Document FHIR native mode requirements for FhirContext
---
.../ROOT/pages/reference/extensions/fhir.adoc | 81 +++++++++++++++++++++-
.../fhir/runtime/src/main/doc/configuration.adoc | 3 +-
extensions/fhir/runtime/src/main/doc/usage.adoc | 73 +++++++++++++++++++
3 files changed, 153 insertions(+), 4 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/fhir.adoc b/docs/modules/ROOT/pages/reference/extensions/fhir.adoc
index 5103d43e8d..104fe8c4a0 100644
--- a/docs/modules/ROOT/pages/reference/extensions/fhir.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/fhir.adoc
@@ -47,6 +47,84 @@ ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]
+[id="extensions-fhir-usage"]
+== Usage
+[id="extensions-fhir-usage-configuring-the-fhircontext-in-native-mode"]
+=== Configuring the `FhirContext` in native mode
+
+To ensure `camel-quarkus-fhir` operates correctly in native mode, it is important that the FHIR component and data formats use a native mode optimized `FhirContext`.
+Examples of how to achieve this follow below.
+
+NOTE: To use a particular FHIR version in native mode, you must ensure that it is enabled via the configuration options mentioned below.
+
+Endpoint configuration when using the default `R4` FHIR version.
+
+[source,java]
+----
+public class FhirRoutes extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .to("fhir://create/resource?fhirContext=#R4&inBody=resourceAsString");
+ }
+}
+----
+
+Endpoint configuration when using a custom FHIR version (e.g `R5`).
+
+[source,java]
+----
+public class FhirRoutes extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .to("fhir://create/resource?fhirVersion=R5&fhirContext=#R5&inBody=resourceAsString");
+ }
+}
+----
+
+Instead of setting the `fhirContext` option on every endpoint URI, you can instead configure it directly on the FHIR component.
+
+[source,properties]
+----
+camel.component.fhir.fhir-context=#R4
+----
+
+FHIR data format configuration.
+
+[source,java]
+----
+public class FhirRoutes extends RouteBuilder {
+ // Each FHIR version has a corresponding injectable named bean
+ @Inject
+ @Named("R4")
+ FhirContext r4FhirContext;
+
+ @Inject
+ @Named("R5")
+ FhirContext r5FhirContext;
+
+ @Override
+ public void configure() {
+ // Configure FhirJsonDataFormat with the default R4 FhirContext
+ FhirJsonDataFormat fhirJsonDataFormat = new FhirJsonDataFormat();
+ fhirJsonDataFormat.setFhirContext(r4FhirContext);
+
+ // Configure FhirXmlDataFormat with a custom version and the corresponding FhirContext
+ FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
+ fhirXmlDataFormat.setVersion("R5");
+ fhirXmlDataFormat.setFhirContext(r5FhirContext);
+
+ from("direct:marshalFhirJson")
+ .marshal(fhirJsonDataFormat);
+
+ from("direct:marshalFhirXml")
+ .marshal(fhirXmlDataFormat);
+ }
+}
+----
+
+
[id="extensions-fhir-ssl-in-native-mode"]
== SSL in native mode
@@ -57,8 +135,7 @@ https://quarkus.io/guides/native-and-ssl[Quarkus SSL guide].
[id="extensions-fhir-additional-camel-quarkus-configuration"]
== Additional Camel Quarkus configuration
-
-By default, only FHIR versions `R4` & `DSTU3` are enabled in native mode, since they are the default values on the FHIR component and DataFormat.
+By default, only FHIR version `R4` is enabled in native mode, since that is also the default version configured on the FHIR component and data formats.
[width="100%",cols="80,5,15",options="header"]
diff --git a/extensions/fhir/runtime/src/main/doc/configuration.adoc b/extensions/fhir/runtime/src/main/doc/configuration.adoc
index 820a98a5aa..f98ecd15b7 100644
--- a/extensions/fhir/runtime/src/main/doc/configuration.adoc
+++ b/extensions/fhir/runtime/src/main/doc/configuration.adoc
@@ -1,2 +1 @@
-
-By default, only FHIR versions `R4` & `DSTU3` are enabled in native mode, since they are the default values on the FHIR component and DataFormat.
+By default, only FHIR version `R4` is enabled in native mode, since that is also the default version configured on the FHIR component and data formats.
diff --git a/extensions/fhir/runtime/src/main/doc/usage.adoc b/extensions/fhir/runtime/src/main/doc/usage.adoc
new file mode 100644
index 0000000000..d2dc499f3a
--- /dev/null
+++ b/extensions/fhir/runtime/src/main/doc/usage.adoc
@@ -0,0 +1,73 @@
+=== Configuring the `FhirContext` in native mode
+
+To ensure `camel-quarkus-fhir` operates correctly in native mode, it is important that the FHIR component and data formats use a native mode optimized `FhirContext`.
+Examples of how to achieve this follow below.
+
+NOTE: To use a particular FHIR version in native mode, you must ensure that it is enabled via the configuration options mentioned below.
+
+Endpoint configuration when using the default `R4` FHIR version.
+
+[source,java]
+----
+public class FhirRoutes extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .to("fhir://create/resource?fhirContext=#R4&inBody=resourceAsString");
+ }
+}
+----
+
+Endpoint configuration when using a custom FHIR version (e.g `R5`).
+
+[source,java]
+----
+public class FhirRoutes extends RouteBuilder {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .to("fhir://create/resource?fhirVersion=R5&fhirContext=#R5&inBody=resourceAsString");
+ }
+}
+----
+
+Instead of setting the `fhirContext` option on every endpoint URI, you can instead configure it directly on the FHIR component.
+
+[source,properties]
+----
+camel.component.fhir.fhir-context=#R4
+----
+
+FHIR data format configuration.
+
+[source,java]
+----
+public class FhirRoutes extends RouteBuilder {
+ // Each FHIR version has a corresponding injectable named bean
+ @Inject
+ @Named("R4")
+ FhirContext r4FhirContext;
+
+ @Inject
+ @Named("R5")
+ FhirContext r5FhirContext;
+
+ @Override
+ public void configure() {
+ // Configure FhirJsonDataFormat with the default R4 FhirContext
+ FhirJsonDataFormat fhirJsonDataFormat = new FhirJsonDataFormat();
+ fhirJsonDataFormat.setFhirContext(r4FhirContext);
+
+ // Configure FhirXmlDataFormat with a custom version and the corresponding FhirContext
+ FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
+ fhirXmlDataFormat.setVersion("R5");
+ fhirXmlDataFormat.setFhirContext(r5FhirContext);
+
+ from("direct:marshalFhirJson")
+ .marshal(fhirJsonDataFormat);
+
+ from("direct:marshalFhirXml")
+ .marshal(fhirXmlDataFormat);
+ }
+}
+----