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.

A PostgreSQL Interface for FHIR Data



Use the Remoting features of the FHIR JDBC Driver to create a PostgreSQL entry-point for data access.

There are a vast number of PostgreSQL clients available on the Internet. From standard Drivers to BI and Analytics tools, PostgreSQL is a popular interface for data access. Using our JDBC Drivers, you can now create PostgreSQL entry-points that you can connect to from any standard client.

To access FHIR data as a PostgreSQL database, use the CData JDBC Driver for FHIR and a JDBC foreign data wrapper (FDW). In this article, we compile the FDW, install it, and query FHIR data from PostgreSQL Server.

Connect to FHIR Data as a JDBC Data Source

To connect to FHIR as a JDBC data source, you will need the following:

  • Driver JAR path: The JAR is located in the lib subfolder of the installation directory.
  • Driver class: cdata.jdbc.fhir.FHIRDriver

  • JDBC URL: The URL must start with "jdbc:fhir:" and can include any of the connection properties in name-value pairs separated with semicolons.

    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 typical JDBC URL is below:

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

Build the JDBC Foreign Data Wrapper

The Foreign Data Wrapper can be installed as an extension to PostgreSQL, without recompiling PostgreSQL. The jdbc2_fdw extension is used as an example (downloadable here).

  1. Add a symlink from the shared object for your version of the JRE to /usr/lib/libjvm.so. For example: ln -s /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so /usr/lib/libjvm.so
  2. Start the build: make install USE_PGXS=1

Query FHIR Data as a PostgreSQL Database

After you have installed the extension, follow the steps below to start executing queries to FHIR data:

  1. Log into your database.
  2. Load the extension for the database: CREATE EXTENSION jdbc2_fdw;
  3. Create a server object for FHIR: CREATE SERVER FHIR FOREIGN DATA WRAPPER jdbc2_fdw OPTIONS ( drivername 'cdata.jdbc.fhir.FHIRDriver', url 'jdbc:fhir:URL=http://test.fhir.org/r4b/;ConnectionType=Generic;ContentType=JSON;AuthScheme=None;', querytimeout '15', jarfile '/home/MyUser/CData/CData\ JDBC\ Driver\ for\ Salesforce MyDriverEdition/lib/cdata.jdbc.fhir.jar');
  4. Create a user mapping for the username and password of a user known to the MySQL daemon. CREATE USER MAPPING for postgres SERVER FHIR OPTIONS ( username 'admin', password 'test');
  5. Create a foreign table in your local database: postgres=# CREATE FOREIGN TABLE patient ( patient_id text, patient_Id text, patient_[name-use] numeric) SERVER FHIR OPTIONS ( table_name 'patient');
You can now execute SELECT commands to FHIR: postgres=# SELECT * FROM patient;