A small example package
Project description
DBTonFHIR
Description
The goal is to be able to map from a given source to a FHIR server without the help of a gui leveraging existing tools such as git and DBT.
Setup and installation
Prerequisites
- Python 3.9+
Base setup
- Create an
.env
file and specify your own configuration (see.env.template
)
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements/base.txt
pre-commit install
Tests setup
pip install -r requirements/tests.txt
Fhir Cli
Install
make install
Usage
fhir --help
Build package
make build
Datawarehouse
Administration
Create a new project database
fhir admin init --database=<target_db>
Create a new project connector
fhir admin conect --database=<target_db>
Create a new project user
fhir admin createuser --database=<target_db> --user=<username>
Postgresql foreign data wrapper
A foreign data wrapper allows to add foreign tables from a distant database into a local schema
CREATE SERVER server_name
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'host', port 'port', dbname 'dbname');
CREATE USER MAPPING FOR local_user
SERVER server_name
OPTIONS (user 'username', password 'password');
CREATE SCHEMA local_schema;
IMPORT FOREIGN SCHEMA foreign_schema
FROM SERVER server_name INTO local_schema;
SET search_path TO local_schema;
-- show foreign tables
\detr
DBT
Usage
Run DBT
To run your models
fhir dbt run
References
To indicate that a FROM clause references a DBT models, use the dbt-ref
keywork in a comment on the same line.
FROM patient -- dbt-ref
After the run, this line will be compiled into
FROM {{ref('patient')}}
Lint your sql files
sqlfluff lint schemas
or
make lint
Validate a fhir model
fhir validate <fhir_model>
Run DBT tests
fhir dbt test
Conventions and good practices
- A mapping model should follow this naming format in snake case
{resource_type}_{profile_name}.sql
and be in itsfhir
folder - In the
models
folder, your sql files should be in their correct directory according to the FROM clause (eg. if the sql statement queries FROMmimiciii.patients
, the sql file should be inmodels/mimiciii/patients
) - A fhir model musts have exactly two columns: an unique column
id
and the fhir object columnfhir
- The
id
column should be ddeclared in the base models as a primary key - A fhir model musts not contain any clause except the FROM clause
- The sql code musts be in full english (thus including aliases)
- The comments should be in english but an exception can be made when some concepts are hard to translate (eg. a pathology)
- The function
fhir_id
musts be used forid
fields - The function
fhir_ref
musts be used forreference
fields - Use
json_build_object
,json_build_array
andjson_agg
to build your fhir object - Add generic DBT tests to your Fhir models (eg. enforce unique and non null constraints on the
id
column)
IntelliJ/Pycharm setup
Configure data source
Highlight DBT references
OMOP
Vocabulary
- Download vocabularies at https://athena.ohdsi.org/
- Create a
vocabulary
folder and extract the files there
CDM 5.4
To build the OMOP CDM 5.4 schema in your target database, execute the following files in this order:
OMOPCDM_postgresql_5.4_ddl.sql
OMOPCDM_postgresql_5.4_primary_keys.sql
vocabulary.sql
OMOPCDM_postgresql_5.4_constraints.sql
OMOPCDM_postgresql_5.4_indices.sql
Tests
Unit tests
make unit-tests
End to end tests
make e2e-tests
Implementation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fhir-cli-0.1.0.tar.gz
(14.0 kB
view hashes)
Built Distribution
fhir_cli-0.1.0-py3-none-any.whl
(13.8 kB
view hashes)