Skip to main content

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 its fhir 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 FROM mimiciii.patients, the sql file should be in models/mimiciii/patients)
  • A fhir model musts have exactly two columns: an unique column id and the fhir object column fhir
  • 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 for id fields
  • The function fhir_ref musts be used for reference fields
  • Use json_build_object, json_build_array and json_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

Screenshot 2021-11-09 at 15 39 06

Highlight DBT references

Screenshot 2021-11-09 at 16 57 16

OMOP

Vocabulary

CDM 5.4

To build the OMOP CDM 5.4 schema in your target database, execute the following files in this order:

  1. OMOPCDM_postgresql_5.4_ddl.sql
  2. OMOPCDM_postgresql_5.4_primary_keys.sql
  3. vocabulary.sql
  4. OMOPCDM_postgresql_5.4_constraints.sql
  5. OMOPCDM_postgresql_5.4_indices.sql

Tests

Unit tests

make unit-tests

End to end tests

make e2e-tests

Implementation

arkhn

Project details


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)

Uploaded Source

Built Distribution

fhir_cli-0.1.0-py3-none-any.whl (13.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page