Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Using the CData ODBC Driver for FHIR in PyCharm
Connect to FHIR as an ODBC data source in PyCharm using the CData ODBC Driver for FHIR.
The CData ODBC Drivers can be used in any environment that supports loading an ODBC Driver. In this tutorial we will explore using the CData ODBC Driver for FHIR from within PyCharm. Included are steps for adding the CData ODBC Driver as a data source, as well as basic PyCharm code to query the data source and display results.
To begin, this tutorial will assume that you have already installed the CData ODBC Driver for FHIR as well as PyCharm.
Add Pyodbc to the Project
Follow the steps below to add the pyodbc module to your project.
- Click File -> Settings to open the project settings window.
- Click Project Interpreter from the Project: YourProjectName menu.
- To add pyodbc, click the + button and enter pyodbc.
- Click Install Package to install pyodbc.

Connect to FHIR
You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.
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.
Below is the syntax for a DSN:
[CData FHIR Source]
Driver = CData ODBC Driver for FHIR
Description = My Description
URL = http://test.fhir.org/r4b/
ConnectionType = Generic
ContentType = JSON
AuthScheme = None
Execute SQL to FHIR
Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.
import pyodbc
cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for FHIR};URL = http://test.fhir.org/r4b/;ConnectionType = Generic;ContentType = JSON;AuthScheme = None;')
cursor = cnxn.cursor()
cursor.execute("SELECT Id, [name-use] FROM Patient WHERE [address-city] = 'New York'")
rows = cursor.fetchall()
for row in rows:
print(row.Id, row.[name-use])
After connecting to FHIR in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to FHIR data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.