Skip to main content

Introduction

This read me identifies a set of microservices that implement a range of functionality that allows for the handling of clinical trial data in an automated manner. The use cases addressed are

  1. Import of data held in a variety of data formats into study designs
  2. Export of data in a number of formats

The microservices within the system are:

  1. Registration Authority
  2. Clinical Recording Model
  3. Controlled Terminology
  4. Biomedical Concepts
  5. SDTM
  6. Forms
  7. Study

The services are all python services running on FastAPI and uvicorn. They can be run locally using a single shared Neo4j instance or deployed. When deployed each micorservices requires a separate Aura Neo4j instance.

Running Locally

Use a single Neo4 instance will all databases for the microservices setup within one instance. Typical names for a devlepoment environment are

  • ra-service-dev
  • crm-service-dev
  • bc-service-dev
  • sdtm-service-dev
  • study-service-dev
  • form-service-dev

Note: there are no separate data bases for Study Import service or the Study Data Import service

Port Numbers

User Interface Services

Microservice Port
CT 8000
BC 8001
Study 8002
Form 8003
SDTM 8004

Data Services

Microservice Port
RA 8010
CRM 8011
CT 8012
BC 8013
Study 8014
Study Import 8015
Form 8016
SDTM 8017
Study Data Import 8018

To Run

Use the microservice.command file to run. Note this file is mac specific. This will start all of the services and the UIs. There is also a dev_server.sh file in each git repo to run each element individually.

Deployed

Overview

To deploy each microservice the following actions should be followed.

  1. Create Aura Neo4j instance.
  2. Load the data using the data prep utility
  3. Deploy the microservice
  4. Check all running

Neo4j Aura

Use the Aura console to create the database as per the site instructions. Download the file holding the credentials (username and password) for the instance

Data Load

Overview

From the appropriate data prep project

  1. Setup the virtual environment
  2. Set the environment variables for the credentials of the neo4j instance
  3. Set production
  4. Run the load python file

Virtual Environment

Run . ./setup_env.sh

Environment Variables

Modify the .production_env file. The file will need to contain the following lines

NEO4J_URI=<database uri>
NEO4J_DB_NAME=neo4j
NEO4J_USERNAME=<username>
NEO4J_PASSWORD=<password>
GITHUB=<URL of the github repo main page>

The database URI will look something like neo4j+s://a1bc23d4.databases.neo4j.io The githb repo URL will look something like https://raw.githubusercontent.com/data4knowledge/ra_prep/main/

Set Production

We need to tell the load utility to use the production database rather than the local (development) one. This is done via setting the PYTHON_ENVIRONMENTenvironment variable. To so this run . ./set_production.sh

Load Data

There will be a python rpogram to load the data. It will be named stage_<n>_load.py. Run this program by entering python stage_2_load.py, here n is 2.

The output from the program should look somethig like

Deleting database ...
Database deleted. Load new data ...
https://raw.githubusercontent.com/data4knowledge/ra_prep/main/load_data/node-namespace-1.csv
https://raw.githubusercontent.com/data4knowledge/ra_prep/main/load_data/relationship-manages-1.csv
https://raw.githubusercontent.com/data4knowledge/ra_prep/main/load_data/node-registration_authority-1.csv
<Record file='progress.csv' source='file' format='csv' nodes=9 relationships=7 properties=58 time=4294 rows=0 batchSize=-1 batches=0 done=True data=None>
Load complete. 9 nodes and 7 relationships loaded in 4294 milliseconds.

Deploy Microservice

The microservices are deployed using the fly.io cloud service.

  1. General python instructions are available here https://fly.io/docs/languages-and-frameworks/python/
  2. Installing the fly command line tool is detailed here https://fly.io/docs/hands-on/install-flyctl/
  3. deploy the app
  4. Set environment variables

Environment Variables

Setting environment variables on the server is achieved by using th ecommand line program, either one at a time

fly secrets set SUPER_SECRET_KEY=password1234

or multiple values, note space delimited

fly secrets set NEO4J_URI=xxx NEO4J_PASSWORD=yyy

Using Auth0 by Okta

Environment Keys

AUTH0_SESSION_SECRET=<session secret key>
AUTH0_DOMAIN=<from the Auth0 configuation>
AUTH0_CLIENT_ID=<from the Auth0 configuation>
AUTH0_CLIENT_SECRET=<from the Auth0 configuation>
AUTH0_AUDIENCE=<from the Auth0 configuation>
AUTH0_MNGT_CLIENT_ID=<Management API client ID>
AUTH0_MNGT_CLIENT_SECRET=<Management API client secret>
ROOT_URL=<base URL for the app>

For the session secret run cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 50 | head -n 1to generate a 50 character randon string

For the root URL use http:\\localhost:8000or similar for a locally running app or https:\\xxx.fly.devfor a deployed app

Code in Main Program

Use this initialisation code

authorisation = Auth0Service(app)
authorisation.register()

Need a local method to protect an endpoint

def protect_endpoint(request: Request) -> None:
  authorisation.protect_route(request, "/login")

and then protect an endpoint by using

@app.get("/index", dependencies=[Depends(protect_endpoint)])
def index(request: Request):
  ...code...

Loading Studies & Data

To be defined.

Building package

Build and Upload

Use pip to install build and twine. Use the following commands to build

python -m build

and upload to pypi.org using the command

twine upload dist/*

Upload requires a token.

Token

Generate an API token on pypi.org. Then, to use the API token:

Set your username to __token__
Set your password to the token value, including the pypi- prefix

Metadata

Release files for d4kms 0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for d4kms 0.14
File Size Uploaded Provenance Actions
d4kms-0.14.tar.gz 23.2 kB Without provenance Details for d4kms-0.14.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for d4kms 0.14
File Interpreter ABI Platform Actions
d4kms-0.14-py3-none-any.whl Python 3 none any Details for d4kms-0.14-py3-none-any.whl

Total release size: 49.4 kB

Release files / d4kms-0.14.tar.gz

Download URL d4kms-0.14.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5e065750fc9f5238c8720812b641d11ac1d2128c1c18d7b3462a4e8663e6ab48
BLAKE2b-256 checksum
How to use checksums
0ef38aaa77d9169cfd5f1604c1c2fcb87eabbbfdf45e9905f36accfcac2ae9a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / d4kms-0.14-py3-none-any.whl

Download URL d4kms-0.14-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b58282f845c18e693acebd295df25549944391fddfa2d9af6f16cde637c683d3
BLAKE2b-256 checksum
How to use checksums
7dcfbd044f4c48cdcec92d1c7a60e5220ce75d12108d71cc2d0a13d145573478
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for d4kms 0.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page