Connect to FHIR Data from a Connection Pool in Jetty



The FHIR JDBC Driver supports connection pooling: This article shows how to connect faster to FHIR data from Web apps in Jetty.

The CData JDBC driver for FHIR is easy to integrate with Java Web applications. This article shows how to efficiently connect to FHIR data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for FHIR in Jetty.

Configure the JDBC Driver for Salesforce as a JNDI Data Source

Follow the steps below to connect to Salesforce from Jetty.

  1. Enable the JNDI module for your Jetty base. The following command enables JNDI from the command-line:

    java -jar ../start.jar --add-to-startd=jndi
  2. Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
  3. Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the FHIR data source at the level of the Web app, in WEB-INF\jetty-env.xml.

    <Configure id='fhirdemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="fhirdemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="fhirdemo"/></Arg> <Arg>jdbc/fhirdb</Arg> <Arg> <New class="cdata.jdbc.fhir.FHIRDriver"> <Set name="url">jdbc:fhir:</Set> <Set name="URL">http://test.fhir.org/r4b/</Set> <Set name="ConnectionType">Generic</Set> <Set name="ContentType">JSON</Set> <Set name="AuthScheme">None</Set> </New> </Arg> </New> </Configure>

    Set URL to the Service Base URL of the FHIR server. This is the address where the resources are defined in the FHIR server you would like to connect to. Set ConnectionType to a supported connection type. Set ContentType to the format of your documents. Set AuthScheme based on the authentication requirements for your FHIR server.

    Generic, Azure-based, AWS-based, and Google-based FHIR server implementations are supported.

    Sample Service Base URLs

    • Generic: http://my_fhir_server/r4b/
    • Azure: https://MY_AZURE_FHIR.azurehealthcareapis.com/
    • AWS: https://healthlake.REGION.amazonaws.com/datastore/DATASTORE_ID/r4/
    • Google: https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/

    Generic FHIR Instances

    The product supports connections to custom instances of FHIR. Authentication to custom FHIR servers is handled via OAuth (read more about OAuth in the Help documentation. Before you can connect to custom FHIR instances, you must set ConnectionType to Generic.

  4. Configure the resource in the Web.xml:

    jdbc/fhirdb javax.sql.DataSource Container
  5. You can then access FHIR with a lookup to java:comp/env/jdbc/fhirdb: InitialContext ctx = new InitialContext(); DataSource myfhir = (DataSource)ctx.lookup("java:comp/env/jdbc/fhirdb");

More Jetty Integration

The steps above show how to configure the driver in a simple connection pooling scenario. For more use cases and information, see the Working with Jetty JNDI chapter in the Jetty documentation.

Ready to get started?

Download a free trial of the FHIR Driver to get started:

 Download Now

Learn more:

FHIR Icon FHIR JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with FHIR.