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.

Create a Data Access Object for FHIR Data using JDBI



A brief overview of creating a SQL Object API for FHIR data in JDBI.

JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for FHIR integrates connectivity to live FHIR data in Java applications. By pairing these technologies, you gain simple, programmatic access to FHIR data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read FHIR data.

Create a DAO for the FHIR Patient Entity

The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.

public interface MyPatientDAO { //request specific data from FHIR (String type is used for simplicity) @SqlQuery("SELECT [name-use] FROM Patient WHERE [address-city] = :[address-city]") String find[name-use]By[address-city](@Bind("[address-city]") String [address-city]); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to FHIR

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to FHIR.

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.

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the FHIR JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.fhir.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for FHIR will typically look like the following:

jdbc:fhir:URL=http://test.fhir.org/r4b/;ConnectionType=Generic;ContentType=JSON;AuthScheme=None;

Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.

DBI dbi = new DBI("jdbc:fhir:URL=http://test.fhir.org/r4b/;ConnectionType=Generic;ContentType=JSON;AuthScheme=None;"); MyPatientDAO dao = dbi.open(MyPatientDAO.class); //do stuff with the DAO dao.close();

Read FHIR Data

With the connection open to FHIR, simply call the previously defined method to retrieve data from the Patient entity in FHIR.

//disply the result of our 'find' method String [name-use] = dao.find[name-use]By[address-city]("New York"); System.out.println([name-use]);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for FHIR by integrating with the CData JDBC Driver for FHIR. Download a free trial and work with live FHIR data in custom Java applications today.