This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git

commit dc5f21eaec17da562686e3b1fbbcdd23a00bb761
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Mon Oct 21 11:51:40 2024 +0100

    Use build time generated FhirContext in FHIR example
---
 fhir/src/main/java/org/acme/fhir/Routes.java   | 15 ++++++++-------
 fhir/src/main/resources/application.properties |  1 +
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/fhir/src/main/java/org/acme/fhir/Routes.java 
b/fhir/src/main/java/org/acme/fhir/Routes.java
index 72e60f4..2937ff9 100644
--- a/fhir/src/main/java/org/acme/fhir/Routes.java
+++ b/fhir/src/main/java/org/acme/fhir/Routes.java
@@ -23,25 +23,22 @@ import 
ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
 import ca.uhn.hl7v2.HL7Exception;
 import ca.uhn.hl7v2.model.v24.message.ORU_R01;
 import ca.uhn.hl7v2.model.v24.segment.PID;
-import io.quarkus.runtime.annotations.RegisterForReflection;
 import jakarta.enterprise.context.ApplicationScoped;
 import jakarta.inject.Inject;
+import jakarta.inject.Named;
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.fhir.FhirJsonDataFormat;
 import org.apache.http.ProtocolException;
-import org.hl7.fhir.r4.model.CapabilityStatement;
-import org.hl7.fhir.r4.model.HumanName;
 import org.hl7.fhir.r4.model.IdType;
 import org.hl7.fhir.r4.model.Patient;
-import org.hl7.fhir.r4.model.Resource;
 
-@RegisterForReflection(targets = { Patient.class, CapabilityStatement.class, 
MethodOutcome.class, Resource.class,
-        HumanName.class })
 @ApplicationScoped
 public class Routes extends RouteBuilder {
     @Inject
+    @Named("R4")
     FhirContext fhirContext;
 
     @Override
@@ -66,6 +63,10 @@ public class Routes extends RouteBuilder {
                 .end()
                 .setHeader(Exchange.HTTP_RESPONSE_CODE).constant(404);
 
+        // Must set FhirContext to ensure native mode support
+        FhirJsonDataFormat fhirJson = new FhirJsonDataFormat();
+        fhirJson.setFhirContext(fhirContext);
+
         // Simple REST API to create / read patient data
         rest("/api/patients")
                 .post()
@@ -91,7 +92,7 @@ public class Routes extends RouteBuilder {
                     exchange.getIn().setBody(patient);
                 })
                 // marshall to JSON for logging
-                .marshal().fhirJson("{{camel.component.fhir.fhir-version}}")
+                .marshal(fhirJson)
                 .convertBodyTo(String.class)
                 .log("Inserting Patient: ${body}")
                 // create Patient in our FHIR server
diff --git a/fhir/src/main/resources/application.properties 
b/fhir/src/main/resources/application.properties
index 160eece..8808322 100644
--- a/fhir/src/main/resources/application.properties
+++ b/fhir/src/main/resources/application.properties
@@ -22,6 +22,7 @@ fhir.http.server.host = ${FHIR_SERVER_SERVICE_HOST:localhost}
 fhir.http.server.port = ${FHIR_SERVER_SERVICE_PORT:8080}
 
camel.component.fhir.server-url=http://${fhir.http.server.host}:${fhir.http.server.port}/fhir
 camel.component.fhir.fhir-version=R4
+camel.component.fhir.fhir-context=#R4
 
 # Kubernetes configuration
 # Uncomment to trust self signed certificates if they are presented by the 
Kubernetes API server

Reply via email to