Skip to content

Manual setup

If you prefer to set up a development environment manually, here are the steps. Please note that we do not provide support for developers using a bespoke setup, only the Docker development environment is supported.

This manual approach will require you to have much more familiarity with configuring PostgresQL, Django, and Python to achieve your aims, and is not for beginners.

Install PostgreSQL and create the database with the correct credentials

You will need the Postgresql database, which can be installed natively on your development machine, or (recommended) can be installed using Docker.

Using the command below will create a development database with credentials that match those in our envs/env-template file. You will need Docker to be installed on your local machine. (Please search the web for instructions for installation on your operating system and setup)

docker run --name epilepsy12postgres \
    -e POSTGRES_USER=epilepsy12user \
    -e POSTGRES_PASSWORD=epilepsy12 \
    -e POSTGRES_DB=epilepsy12db \
    -p 5432:5432 \
    -d postgres

Install the correct Python version

If you don't have Python installed already, you will need it. To avoid specifying a specific Python version for the project here in the documentation, please check the Dockerfile in the project root for the version of Python that is currently being used.

We recommend the use of a tool such as pyenv to assist with managing multiple Python versions and their accompanying virtualenvs.

pyenv install <PYTHON_VERSION>

On some platforms, you will get errors at build-time, which indicates you need to install some dependencies which are required for building the Python binaries locally. Rather than listing these here, where they may become out of date, please refer to the pyenv wiki which covers this in detail.

Then create a virtual environment:

pyenv virtualenv <PYTHON_VERSION> rcpch-audit-engine

Clone the repository and cd into the directory:

git clone https://github.com/rcpch/rcpch-audit-engine.git
cd rcpch-audit-engine

Then install all the requirements. Note you can't do this without PostgreSQL already installed first.

pip install -r requirements/development-requirements.txt

Set and initialize the environment variables

You will need to set the environment variables for your local development, using the envs/env-template file as a starting point. This file should not be committed to the repository. You can use real values for the environment variables in this file.

source envs/.env

Danger

The included example environment variables are not secure and must never be used in production.

Prepare the database for use

python manage.py migrate

Create superuser to enable logging into admin section

python manage.py createsuperuser

Then follow the command line prompts to create the first user. Createsuperuser is a Django base feature but there are some custom fields which are mandatory. These include:

  • role: The options are: 1 - Clinical Lead, 2 - Clinician, 3 - E12 Site Administrator, 4 - RCPCH Audit Team. If the integer selected in 1-3 (ie a role within the E12 site) KCH is automatically allocated. If it is an RCPCH user, is_rcpch_staff is automatically set to true, as is is_rcpch_audit_team_member

  • is_rcpch_audit_team_member: True|False.

Further users can subsequently be created in the Admin UI

Running the server

Navigate to the epilepsy12 outer folder and run the server:

python manage.py runserver

Seeding the Database

Migrations will seed the database with the following:

  • Organisations
  • Trusts
  • ICBs (including boundaries)
  • NHS England regions (including boundaries)
  • Countries (including boundaries)
  • KPI aggregations (the tables required to store the results generated by counting up KPIs for individual children at different levels of abstraction eg trust/icb etc)
  • Epilepsy causes, syndromes and comorbidities: these are all pulled from SNOMED and persisted in their own tables
  • Semiology keywords. These are ILAE 2017 keywords to standardise the description of a seizure. It is not an exhaustive list and in time it is hoped through this project that new meaningful words will be identified and add to this lexicon.

By running the migrations there database will therefore be ready to accept new users and children.

In development, it is often necessary to have some seeded children across multiple organisations to test functionality, so in addition there are 2 further seed commands:

python manage.py seed --mode=seed_cases

This accepts the -c or cases attribute followed by the number of children requested. It defaults to 200. Children are given random dates of birth, NHS numbers and postcodes which are all valid.

Once the children have been seeded, they can be scored at random:

python manage.py seed --mode seed_registrations

This accepts the -ct or --cohort attribute followed by the cohort number requested. Note that it is not possible to seed with patients below cohort 4. It defaults to the current actively recruiting cohort.

Both functions accept the --verbose flag also to have a more granular output to the console of the seeding process for debugging purposes.

There are some other functions here also, but these are likely soon to be deprecated:

  • add_permissions_to_existing_groups
  • upload_old_patient_data
  • async_upload_old_patient_data
  • upload_user_data
  • async_upload_user_data

This will seed with the defaults documented above.

Running the tests locally

We have used the coverage package to test our models. It is already in our development requirements, but if you don't have it installed, install it with pip install coverage

Run all the tests

coverage run manage.py test
coverage html

If the htmlcov/index.html is opened in the browser, gaps in outstanding testing of the models can be found.