Skip to content

Blockchain for structured clinical data. Prescrypto's beating heart ❤️

License

Notifications You must be signed in to change notification settings

Prescrypto/RexChain

Repository files navigation

RexChain - a Python - SQL based lightweight, cryptographically enabled, centralised blockchain implementation.

Build Status

Rexchain Coverage Report

Motivation

All the current implementations of blockchains are tightly coupled with the larger context and problems they (e.g. Bitcoin or Ethereum) are trying to solve. This leaves room to implement domain specific solutions. Especially source-code-wisely. This project is an attempt to provide a lightweight concise and simple implementation of a blockchain as possible, completely designed around electronic medical prescriptions and structured medical data.

What is blockchain

From Wikipedia : Blockchain is a new database technology that maintains a continuously-growing list of records called blocks secured from tampering and revision. I encourage the reader to thoroughly understand the different key aspects of Blockchain technology form this article: https://medium.com/@sbmeunier/blockchain-technology-a-very-special-kind-of-distributed-database-e63d00781118

Key concepts of RexChain

RexChain is focused on the specifics of cryptography (which can be linked to electronic identities) and immutability, achieved by Blocks that couple prescription's merkle trees and can verify integrity easily.

  • HTTP interface to control the node
  • At the moment it is a centralised chain of blocks, the block's merkle root can be anchored with Proof of Existence to any particular distributed Blockchain (in a similar way to Factom's white paper) (https://github.com/FactomProject/FactomDocs/blob/master/whitepaper.md)
  • At the moment data is persisted in an SQL implementation
  • Access to the database is enabled by Asymetric Cryptography
  • Proof-of-work thourght Hashcash (http://www.hashcash.org/hashcash.pdf)
  • Transactions: You can transfer data through Prescrypto Wallet [See more over Transactions concept in our wiki].
  • Distributed version: This step will follow.

Quick start

(set up node and mine 1 block)

vagrant up
get server running and start creating stuff
vagrant ssh

$ cd /vagrant/rexchain
$ python3 manage.py migrate
$ python3 manage.py loaddata ./fixtures/initial_data.json
$ python3 manage.py runserver [::]:8000

Wake Up Redis Worker
Open a new window console enter to ssh of vagrant and run these commands
$ cd /vagrant/rexchain
$ python3 manage.py rqworker high default low

HTTP API

Get blockchain
curl http://localhost:8080/api/v1/block
Create block
# The field "public_key" is an binary hexadecimal representation of a Public Key object made by rsa python library
curl -X POST \
  http://127.0.0.1:8000/api/v1/rx-endpoint/ \
  -H 'Content-Type: application/json' \
  -d '{
  "diagnosis": "Diagnostico de Ojo Irritado",
  "location": "México, CDMX",
  "medic_cedula": "465713",
  "medic_hospital": "Privado",
  "medic_name": "Juan Alberto Torres García",
  "medications": [
    {
      "instructions": "Artelac RDules",
      "presentation": "DUSTALOX (KETOROLACO TROMETAMINA 5 mg / ml 1 SOL 5 ml)"
    }
  ],
  "patient_age": 29,
  "patient_name": "Jesus",
  "public_key": "63636f70795f7265670a5f7265636f6e7374727563746f720a70310a28637273612e6b65790a5075626c69634b65790a70320a635f5f6275696c74696e5f5f0a6f626a6563740a70330a4e745270340a284c373435313530383630343332393237323237393336343532383430323735313630383337373839333331383033363932383838383034323630323635393130383336383335353931353533323533343238353732343832333830373537333939343637313337383133363633313537303432363933373330313136353533373433333638333830333634393839383937363238373033343934394c0a4936353533370a74622e",
  "timestamp": "2018-02-01T21:59:19.454752"
}'

Lint the code

Use this to check for adherence to PEP 8 standards

To use the linter on your code, execute the following command on your console, the results will be shown directly on the console:

$ flake8

More documentation about it

If you are interested in collaborate with us please follow the contribution guidelines.

Test for API

cd /vagrant/rexchain/

python3.6 manage.py test api.tests

The test ends successfully when the console shows:

Ran 1 test

OK

Note

The console can ask the following:

Type 'yes' if you would like to try deleting the test database 'test_mydb', or 'no' to cancel:

Enter yes for test continue.

Run Coverage

Python Coverage monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.

To run the coverage follow the next scripts

$ coverage run manage.py test api.tests
$ coverage report -m

## Before commit - Add coverage badge

You must run the following commands in order to add the coverage badge:

$ coverage-badge -o coverage.svg

Note: Run coverage command and coverage report!

About

Blockchain for structured clinical data. Prescrypto's beating heart ❤️

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published