Skip to content

eugwne/fhirbase-plv8

 
 

Repository files navigation

fhirbase-plv8

Build Status

Slack

For interactive communication about fhirbase we use slack. Please fill this form and get invitation.

Features

This is new version of fhirbase, with support of DSTU-2 and planned support many advanced features:

  • Extended query syntax
  • Terminologies
  • Profile validation
  • References validateion
  • ValueSet validateion

Motivation

While crafting Health IT systems we understand an importance of a properly chosen domain model. FHIR is an open source new generation lightweight standard for health data interoperability, which (we hope) could be used as a foundation for Health IT systems. FHIR is based on a concept of resource.

FHIR® is a next generation standards framework created by HL7. FHIR combines the best features of HL7 Version 2, Version 3 and CDA® product lines while leveraging the latest web standards and applying a tight focus on implementability.

Also we learned that data is a heart of any information system, and should be reliably managed. PostgreSQL is a battle proved open source database which supports structured documents (jsonb) while preserving ACID guaranties and richness of SQL query language.

PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness.

Here is the list of PostgreSQL features that we use:

Installation

To install fhirbase you need postgresql-9.4 and plv8 extension.

sudo apt-get install postgresql-contrib-9.4 postgresql-9.4-plv8  -qq -y
psql -c "CREATE USER user WITH PASSWORD 'password'"
psql -c 'CREATE DATABASE fhirbase;' -U user
psql -c '\dt' -U postgres
export DATABASE_URL=postgres://user:password@localhost:5432/fhirbase

wget https://github.com/fhirbase/fhirbase-plv8/releases/download/v0.0.1-beta.1/fhirbase-0.0.1.sql.zip
unzip fhirbase-0.0.1.sql.zip

cat fhirbase-0.0.1.sql | psql fhirbase

Development Installation

Development installation requires node 0.12 and npm, which could be installed by nvm:

# install node < 0.12 by nvm for example
sudo apt-get install postgresql-contrib-9.4 postgresql-9.4-plv8  -qq -y

git clone https://github.com/fhirbase/fhirbase-plv8
cd fhirbase-plv8
git submodule init && git submodule update

npm install && cd plpl && npm install
npm install -g mocha && npm install -g coffee-script

psql -c "CREATE USER fb WITH PASSWORD 'fb'"
psql -c 'ALTER ROLE fb WITH SUPERUSER'
psql -c 'CREATE DATABASE fhirbase;' -U postgres
psql -c '\dt' -U postgres

export DATABASE_URL=postgres://fb:fb@localhost:5432/fhirbase

# build migrations
coffee  utils/generate_migrations.coffee -n  | psql fhirbase

# change something
# reload schema

plpl/bin/plpl reload
npm run test

# goto: change something

Usage

To make fhirbase-plv8 work you have to just after opening connection to postgresql you have to issue following command (read more here):

SET plv8.start_proc = 'plv8_init';
SET plv8.start_proc = 'plv8_init';

-- work with storage

SELECT fhir_create_storage('{"resourceType": "Patient"}');
SELECT fhir_drop_storage('{"resourceType": "Patient"}');
SELECT fhir_truncate_storage('{"resourceType": "Patient"}');
-- delete all resources of specified type

-- CRUD

SELECT fhir_create_resource('{"resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["Smith"]}]}}');

-- conditional create
SELECT fhir_create_resource('{"ifNotExist": "identifier=007", "resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["Smith"]}]}}');

SELECT fhir_read_resource('{"resourceType": "Patient", "id": "smith"}');

SELECT fhir_vread_resource('{"resourceType": "Patient", "versionId": "????"}');

SELECT fhir_resource_history('{"resourceType": "Patient", "id": "smith"}');

SELECT fhir_resource_type_history('{"resourceType": "Patient", "queryString": "_count=2&_since=2015-11"}');

SELECT fhir_update_resource('{"resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["John"], "family": ["Smith"]}]}}');

-- conditional update
SELECT fhir_update_resource('{"ifNotExist": "identifier=007", "resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["Smith"]}]}}');

-- update with contention guard
SELECT fhir_update_resource('{"ifMatch": "..versionid..", "resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["Smith"]}]}}');

SELECT fhir_search('{"resourceType": "Patient", "queryString": "name=smith"}');

SELECT fhir_index_parameter('{"resourceType": "Patient", "name": "name"}');
SELECT fhir_unindex_parameter('{"resourceType": "Patient", "name": "name"}');

SELECT fhir_search_sql('{"resourceType": "Patient", "queryString": "name=smith"}'); 
-- see generated SQL

SELECT fhir_explain_search('{"resourceType": "Patient", "queryString": "name=smith"}');
-- see execution plan

SELECT fhir_delete_resource('{"resourceType": "Patient", "id": "smith"}');


---

SELECT fhir_conformance('{"default": "values"}');
-- return simple Conformance resource, based on created stores

Contribution

  • Star us on GitHub
  • If you encountered a bug, please make an Issue
  • Contribute to fhirbase

License

Copyright © 2014 health samurai.

fhirbase is released under the terms of the MIT License.

About

fhirbase 2.0

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 99.4%
  • Shell 0.6%