This project is a deployment of JupyterHealth Exchange (JHE) on an Azure VM, then connecting the JHE instance to a JupyterHub instance deployed on the same VM.
The documentation followed for JHE installation is here: https://github.com/the-commons-project/jupyterhealth-exchange/tree/main However, some changes were made to the steps to accomodate the different setup stesp required to launch the project on an VM, which are stated bloew:
JHE setup
(TODO: Add Azure VM setup instructions here.)
git clone https://github.com/the-commons-project/jupyterhealth-exchange.git
cd jupyterhealth-exchange
- Check your Python version (ensure it's between 3.10 and 3.13):
python3 --version`
- Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate
- Install the dependencies from the
requirements.txt
(orPipfile
if using Pipenv):pip install -r requirements.txt
- Install other dependencies not included in 'requirements.text':
pip install python-dotenv pip install django-oauth-toolkit pip install djangorestframework pip install fhirclient pip install fhir.resources pip install humps pip install psycopg2 pip install psycopg2-binary pip install djangorestframework-camel-case pip install whitenoise
- Deactivate from your venv if it is activated
deactivate
- install PostgreSQL:
sudo apt update sudo apt install postgresql postgresql-contrib
- Create a new database and user:
sudo -i -u postgres psql CREATE DATABASE 'your_db'; CREATE USER 'your_username' WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE 'your_db' TO 'your_username'; -U your_database_user -d your_database_name GRANT USAGE ON SCHEMA public TO speziuser; GRANT CREATE ON SCHEMA public TO speziuser; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO speziuser; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO speziuser; \q
- Exit the PostgreSQL shell:
exit
- Check if all prvileges were applied correctly:
\dn+ public
- Make a copy of 'env_example.txt'
cp env_example.txt .env
- Update the 'DB_*' properties to match the your new DB and save it as '.env'
nano .env
openssl genpkey -algorithm RSA -out oidc_private_key.pem -pkeyopt rsa_keygen_bits:2048 2. View the Private Key in PEM Format cat oidc_private_key.pem
Update settings.py with the generated private key
OIDC_RSA_PRIVATE_KEY = """ -----BEGIN PRIVATE KEY----- (your key content) -----END PRIVATE KEY----- """
Run migrations to create the necessary tables: ``` sh python manage.py migrate
psql -U speziuser -d spezi_db -f db/seed.sql
Run the manage.py
file
python manage.py runserver 0.0.0.0:8000
It should load the login page as follows:
Browse to http://localhost:8000/admin and enter the credentials super@example.com
Jhe1234!
- Browse to Applications under Django OAuth Toolkit and create a new application
- Leave User empty
- Set Redirect URLs to include
http://localhost:8000/auth/callback
and any other hosts - ** for HTTPS, add
https://localhost:8000/auth/callback
- ** for virtual machne, localhost will not work. Add
http://<your_vm_ip_address>:8000/auth/callback
- Set Type to Public
- Set Authorization Grant Type to Authorization code
- Leave Secret blank
- Name the app whatever you like
- Check Skip authorization
- Set Algorithm to RSA with SHA-2 256
- Skip Allowed origins for now10.
- Return to the
.env
file and updateOIDC_CLIENT_ID
with the newly created app Client ID and restart the python environment and Django server - Browse to http://localhost:8000/ and log in with the credentials
anna@example.com
Jhe1234!
and you should be directed to the/portal/organizations
path with some example Organizations is the dropdown
When deploying JHE through a VM, establishing a (TODO: Add HTTPS setup instructions here.) ``` sh Install nginx sudo apt update sudo apt install nginx
Generate a self-signed SSL certificate
openssl genrsa -out private_key.pem 2048
``` sh
sudo nano /etc/nginx/sites-available/default # For default server
sudo systemctl restart nginx
Step 4: Configure Django for Proxy Headers (Optional)
In your settings.py
file, add the following settings:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 31536000 # 1 year
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
Update your /etc/nginx/sites-available/jhe-site
for both HTTP (port 8080) and HTTPS (port 443)
Update application settings in django server Double check static files location
If the static files do not have the necessary permissions, run
sudo chmod -R 755 /home/speziuser/jupyterhealth-exchange/jhe/staticfiles/
sudo chown -R www-data:www-data /home/speziuser/jupyterhealth-exchange/jhe/staticfiles/
``` sh
python manage.py runserver 0.0.0.0:8000