Skip to main content

fhirstore

Python library to manipulate fhir resources leveraging mongoDB as storage layer.

Installation

pip install fhirstore

Usage

from pymongo import MongoClient
from fhirstore import FHIRStore

client = MongoClient()
store = FHIRStore(client, "<my_database>")

# Dropping collections
store.reset()

# Parse json schema and create collections
store.bootstrap(depth=5)
# OR
# Get existing collections from the database
store.resume(depth=5)

# Create resources
store.create({
    "resourceType": "Patient",
    "id": "pat1",
    "gender": "male"
})

# Read resources
patient = store.read("Patient", "pat1")

# Update resources
updated_patient = store.update("Patient", "pat1", {"gender": "other"})

# Delete resources
deleted_patients_count = store.delete("Patient", "pat1")
deleted_patients_count = store.delete("Patient", resource_id="pyrogResouceId")

Bootstrap the database

  1. Start the database
  2. Drop and re-create all collections based on the provided schema
docker-compose up -d
python main.py

Development setup

  1. Create a virtual environment and enter it
  2. Install python dependncies
virtualenv .
. ./bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt

Test

Test can be run using :

python -m pytest

Make sure dev dependencies are installed.

Benchmark

A benchmark based on example FHIR resources publicly available at can be run using :

python benchmark/benchmark.py

Note that you will need to have a MongoDB up in order for the benchmark to run. You can use the docker-compose file of this repository by running docker-compose up before launching the benchmark.

On a machine with 16GB RAM and an i7 (2.5GHz) processor, the results of the benchamrk were:

--- WRITES ---
insertions per second (on average): 267.17
average: 3.74 milliseconds
median: 1.66 milliseconds
min: 1.07 milliseconds
max: 724.65 milliseconds
spread: 0.00028004697751347234

--- READS ---
reads per second (on average): 378.93
average: 2.63 milliseconds
median: 1.50 milliseconds
min: 0.88 milliseconds
max: 481.18 milliseconds
spread: 0.0002154728657872756

On the same machine, here are the results for the same benchmark using a different library, fhirbase. The latter relies on postgreSQL rather than MongoDB as its storage layer. Also, it only supports FHIR resources 3.3.0 and below.

--- WRITES ---
insertions per second (on average): 152.38
average: 6.56 milliseconds
median: 4.43 milliseconds
min: 3.08 milliseconds
max: 158.88 milliseconds
spread: 7.568139030481407e-05

--- READS ---
reads per second (on average): 261.07
average: 3.83 milliseconds
median: 3.03 milliseconds
min: 2.17 milliseconds
max: 102.06 milliseconds
spread: 1.4565324857334904e-05

Publish

First, you need to have twine installedd

pip install --user --upgrade twine

Make sure you have bumped the version number in setup.py, then run the following:

python setup.py sdist bdist_wheel
python -m twine upload dist/*

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhirstore-0.4.8.tar.gz (309.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fhirstore-0.4.8-py3-none-any.whl (312.3 kB view details)

Uploaded Python 3

File details

Details for the file fhirstore-0.4.8.tar.gz.

File metadata

  • Download URL: fhirstore-0.4.8.tar.gz
  • Upload date:
  • Size: 309.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/42.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for fhirstore-0.4.8.tar.gz
Algorithm Hash digest
SHA256 2b43462e6a4d65e0690ba63ac44479e63bd3be9dff97aa2641568a53044ea0b1
MD5 c298cca2bfc2c9a06194b3f7ec6d5119
BLAKE2b-256 72f3bc5ebb52c1f6851c80469349d49adb3a942048e08f51a11a0c50c944f31c

See more details on using hashes here.

File details

Details for the file fhirstore-0.4.8-py3-none-any.whl.

File metadata

  • Download URL: fhirstore-0.4.8-py3-none-any.whl
  • Upload date:
  • Size: 312.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/42.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for fhirstore-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c3c6f67f043f080f8a6c5d24d958199bb1a4e08f13568c2efa4d35ab2b971f87
MD5 aa0f99998bcca684548f7a50ca728c38
BLAKE2b-256 5f3d34e7c22d8076207170f69a136feb1dba69901d75f713f22a790c3cb20164

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.8 This release

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.11

2 files

0.3.10

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page