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.

Connect to FHIR Data in JRuby



Create a simple JRuby app with access to live FHIR data.

JRuby is a high-performance, stable, fully threaded Java implementation of the Ruby programming language. The CData JDBC Driver for FHIR makes it easy to integrate connectivity to live FHIR data in JRuby. This article shows how to create a simple JRuby app that connects to FHIR data, executes a query, and displays the results.

Configure a JDBC Connection to FHIR Data

Before creating the app, note the installation location for the JAR file for the JDBC Driver (typically C:\Program Files\CData\CData JDBC Driver for FHIR\lib).

JRuby natively supports JDBC, so you can easily connect to FHIR and execute SQL queries. Initialize the JDBC connection with the getConnection function of the java.sql.DriverManager class.

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.

Below is a typical JDBC connection string for FHIR:

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

Create a JRuby App with Connectivity to FHIR Data

Create a new Ruby file (for example: FHIRSelect.rb) and open it in a text editor. Copy the following code into your file:

require 'java' require 'rubygems' require 'C:/Program Files/CData/CData JDBC Driver for FHIR 2018/lib/cdata.jdbc.fhir.jar' url = "jdbc:fhir:URL=http://test.fhir.org/r4b/;ConnectionType=Generic;ContentType=JSON;AuthScheme=None;" conn = java.sql.DriverManager.getConnection(url) stmt = conn.createStatement rs = stmt.executeQuery("SELECT Id, [name-use] FROM Patient") while (rs.next) do puts rs.getString(1) + ' ' + rs.getString(2) end

With the file completed, you are ready to display your FHIR data with JRuby. To do so, simply run your file from the command line:

jruby -S FHIRSelect.rb

Writing SQL-92 queries to FHIR allows you to quickly and easily incorporate FHIR data into your own JRuby applications. Download a free trial today!