Getting Started
Step-by-step tutorial to setup PostgreSQL, Fhirbase and perform first data import.
Last updated
Step-by-step tutorial to setup PostgreSQL, Fhirbase and perform first data import.
Last updated
If you have Docker installed, you might want to switch to Docker version of this tutorial.
To start using Fhirbase you have to install PostgreSQL database first. Any version above 9.6 should be fine. Please proceed to the section describing operating system you're running.
If you have Docker installed, you might want to start PostgreSQL as a Docker container:
For Windows the most simple way is to use EnterpriseDB PostgreSQL Installer. Also there is a YouTube video demonstrating the whole installation process.
Most likely that PostgreSQL will be available through your distribution's package manager. On Ubuntu or Debian, it's as easy as
For other Linux distributions, please use search functionality of your package manager or just Google the right command.
You can install PostgreSQL with Homebrew:
Also you'll need to create default user with some password (we advice to use "postgres" as password for simplicity):
As an alternative, there is a Postgres.app project which provides PostgreSQL as a regular MacOS application with common drag-and-drop installation. Please follow instructions at Postgres.app Installation Page and especially make sure you've updated you PATH variable to be able to use psql
command-line tool.
When you finished installing it, open Terminal and execute following command to set password for postgres
user:
After you finished installing Postgres, please check it's running and accepting TCP/IP connections.
You can do this with psql
command-line client or with pgAdmin GUI application. For psql
, use following command:
If you got postgres=#
prompt waiting for your input, your installation is fine. You can quit psql
typing \q
followed by Enter.
If you got an error like this instead:
then it looks like PostgreSQL is either not running or not accepting TCP/IP connections. Please check presence of postgres
process using your operating system's Process Viewer (or Task Manager). If postgres
process is running, please consider updating pg_hba.conf
file as described in this wiki article.
TODO: better troubleshooting guide.
Go to Fhirbase Download page and download most recent release of Fhirbase. Make sure you've picked right file, it should match your operating system and CPU architecture. Nightly-build release is being updated after every commit to master branch, so it might be unstable.
When you downloaded the Fhirbase binary, make it executable (Windows users don't need this):
Then rename it from fhirbase-os-arch
to just fhirbase
and put in some directory listed in you $PATH
environment variable. To check that it was properly installed, type following command:
It should output Fhirbase command-line help.
Note to Windows users: Fhirbase is a terminal application and it's supposed to be run inside Command Prompt window. If you'll just double-click it, Command Prompt window will popup and disappear immediately. To be able to use Fhirbase, do following:
Start Menu => Run... => cmd.exe
type cd C:\Path\To\Fhirbase\Exe
and press Enter (use real path instead of example one)
type fhirbase
and press Enter (make sure you've renamed downloaded exe file to just fhirbase
)
If you don't know what the $PATH
variable is, it's ok, you can skip this step. But you'll have to type full path to the fhirbase
executable every time you'll invoke Fhirbase command. So instead of typing
you'll need to type something like this:
So please remember that if your shell says it cannot find fhirbase
command, most likely fhirbase
binary wasn't correctly placed inside $PATH
.
Next step is to create database where we're going to store FHIR data. Again, we can use psql
command-line client or some GUI client like pgAdmin. Connect to Postgres as you previously did:
To create database there is a CREATE DATABASE
statement:
Do not forget to put semicolon at the end of statement. Of course, you can change "fhirbase" to any database name you want.
If you got CREATE DATABASE
text as a response to your command, your database was succesfully created. Type \q
to quit psql
.
Now we have database, but before loading any FHIR data into it we need to create schema - some tables and stored procedures. This operation is performed with fhirbase init
command:
Let's briefly describe meaning of command-line arguments:
--host localhost
specifies host where Postgres is running
-p 5432
specifies Postgres port
-d fhirbase
specifies name of the database to connect to (don't forget to change it if you named database differently)
-U postgres
name of Postgres user, "postgres" is fine for most cases
-W postgres
user's password
--fhir=3.3.0
FHIR version you're going to use
If you got no error, database was initialized. Most common errors are connection errors (check your Postgres credentials) and SQL errors (you're trying to initialize non-empty database).
We're ready to import data into our newly created database. We can import data from two different sources:
local files (ndjson files)
Bulk Data API endpoints
Let's try to use local file first. Fhirbase GitHub repository contains sample file, go ahead and download it. When this file is on your local filesystem, invoke fhirbase load
command:
Usually it takes from 25 to 45 seconds to import this file. At the end of the input Fhirbase will output statistics about inserted data:
There are two different load modes: insert and copy. Using copy mode in some cases can drastically decrease load time. Also you can load data from Bulk Data API endpoints, FHIR bundles and plain JSON files. To get more information on this, take a look at load command reference.
Fhirbase contains tiny web server to provide basic Web UI for querying database. You can use it instead of desktop Postgres clients for simplicity. Following command will start Fhirbase webserver on http://localhost:3000
Point your browser to http://localhost:3000 and type following query in the editor:
As a result you'll get most popular first names for patients stored in your database.