Native Linux install

Document not ready for translation

This install is based on Ubuntu 22.04 using:

  • Python 3.10 running in a virtualenv

  • Datenbank: PostgreSQL

  • DICOM Store SCP: Orthanc running on port 104

  • Webserver: NGINX with Gunicorn

  • All OpenREM files in /var/dose/ with group owner of openrem

  • Collects any Physics (QA) images and zips them

The instructions should work for Ubuntu 20.04 too, references to jammy will be focal instead.

There are various commands and paths that reference the Python version 3.10 in these instructions. If you are using Python 3.8 or Python 3.9 then these will need to be modified accordingly.

If you are upgrading an existing installation to a new Linux server, go to the Upgrading to a new Linux server docs first.

If you are installing OpenREM on a Linux server with limited internet access, go to the Offline installation or upgrade docs.

If you are installing on a different Linux OS you can adapt these instructions or consider using a Docker install instead.

Initial prep

Install apt packages

Apt sources

We will need the universe repository enabled. Check first:

$ less /etc/apt/sources.list

Suchen nach:

deb http://archive.ubuntu.com/ubuntu/ jammy universe
deb http://archive.ubuntu.com/ubuntu/ jammy-updates universe

If these two lines are not there or are commented out (line starts with a #), add them in or remove the # (sudo nano /etc/apt/sources.list).

$ sudo -- sh -c 'apt update && apt upgrade'
$ sudo apt install acl python3.10 python3.10-dev python3.10-distutils python3.10-venv python3-pip \
postgresql nginx orthanc dcmtk default-jre zip gettext

Redis

Redis is used to temporarily store the background tasks.

$ sudo apt install lsb-release
$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
$ echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
$ sudo apt-get update
$ sudo apt-get install redis

Folders and permissions

Groups

Now create new group openrem and add your user to it ($USER will automatically substitute for the user you are running as):

$ sudo groupadd openrem
$ sudo adduser $USER openrem

Add orthanc and www-data users to openrem group:

$ sudo -- sh -c 'adduser orthanc openrem && adduser www-data openrem'

Bemerkung

Zu einem späteren Zeitpunkt kann ein zweiter Administrator der openrem Gruppe auf die gleiche Weise hinzugefügt werden.

Folders

Create the folders we need, and set the permissions. The ‚sticky‘ group setting and the access control list setting (setfacl) below will enable both orthanc user and www-data user as well as you and your colleagues to write to the logs and access the ‚Physics‘ images etc:

$ sudo -- sh -c 'mkdir /var/dose && chmod 775 /var/dose'
$ sudo chown $USER:openrem /var/dose
$ cd /var/dose
$ mkdir {log,media,pixelmed,static,veopenrem3}
$ mkdir -p orthanc/dicom && mkdir -p orthanc/physics
$ sudo chown -R $USER:openrem /var/dose/*
$ sudo chmod -R g+s /var/dose/*

Find the uid of your user and the gid of the openrem group:

$ id
$ getent group openrem

Take note of the uid number and the gid in the third field of the group information and use it in the next command, replacing 1001 (user uid) and 1002 (openrem group gid) as appropriate:

$ sudo setfacl -PRdm u:1001:rwx,g:1002:rwx,o::r /var/dose/

Pixelmed download

$ cd /var/dose/pixelmed
$ wget http://www.dclunie.com/pixelmed/software/webstart/pixelmed.jar

Create the virtualenv

Eine virtualenv in dem erstellten Ordner erzeugen (lokale Python Umgebung):

$ python3.10 -m venv /var/dose/veopenrem3

Die virtualenv aktivieren

Activate the virtualenv (note the . – you can also use the word source):

$ . /var/dose/veopenrem3/bin/activate

Install Python packages

$ pip install --upgrade pip
$ pip install openrem==1.0.0b2

Konfiguration von Datenbank und OpenREM

Setup PostgreSQL database

Create a postgres user, and create the database. You will be asked to enter a new password (twice). This will be needed when configuring the local_settings.py file later:

$ sudo -u postgres createuser -P openremuser
$ sudo -u postgres createdb -T template1 -O openremuser -E 'UTF8' openremdb

For upgrades use a different template

If this is an upgrade to a new Linux server and not a new install, use template0 instead:

$ sudo -u postgres createdb -T template0 -O openremuser -E 'UTF8' openremdb

Update the PostgreSQL client authentication configuration. Add the following line anywhere near the bottom of the file, for example in the gap before # DO NOT DISABLE or anywhere in the table that follows. The number of spaces between each word is not important (one or more). If you are not using PostgreSQL 14 then substitute the version number in the file path.

$ sudo nano /etc/postgresql/14/main/pg_hba.conf
local   all     openremuser                 md5

Reload postgres:

$ sudo systemctl reload postgresql

OpenREM konfigurieren

Navigate to the Python openrem folder and copy the example local_settings.py and wsgi.py files to remove the .linux and .example suffixes:

$ cd /var/dose/veopenrem3/lib/python3.10/site-packages/openrem/
$ cp openremproject/local_settings.py{.linux,}
$ cp openremproject/wsgi.py{.example,}

Edit local_settings.py as needed - make sure you change the PASSWORD, the SECRET_KEY (to anything, just change it), the ALLOWED_HOSTS list, regionalisation settings and the EMAIL configuration. You can modify the email settings later if necessary. Some settings are not shown here but are documented in the settings file or elsewhere in the docs. For details on the final variable see Systems where Device Observer UID is not static.

Upgrading to a new server

If you are upgrading to a new Linux server, review the local_settings.py file from the old server to copy over the NAME, USER and PASSWORD, ALLOWED_HOSTS list and the EMAIL configuration, and check all the other settings. Change the SECRET_KEY from the default, but it doesn’t have to match the one on the old server. For details on the final variable see Systems where Device Observer UID is not static.

$ nano openremproject/local_settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'openremdb',
        'USER': 'openremuser',
        'PASSWORD': 'mysecretpassword',     # This is the password you set earlier
        'HOST': '',
        'PORT': '',
    }
}

MEDIA_ROOT = '/var/dose/media/'

STATIC_ROOT = '/var/dose/static/'
JS_REVERSE_OUTPUT_PATH = os.path.join(STATIC_ROOT, 'js', 'django_reverse')

# Change secret key
SECRET_KEY = 'hmj#)-$smzqk*=wuz9^a46rex30^$_j$rghp+1#y&i+pys5b@$'

# DEBUG mode: leave the hash in place for now, but remove it and the space (so DEBUG
# is at the start of the line) as soon as something doesn't work. Put it back
# when you get it working again.
# DEBUG = True

ALLOWED_HOSTS = [
    # Add the names and IP address of your host, for example:
    'openrem-server',
    'openrem-server.ad.abc.nhs.uk',
    '10.123.213.22',
]

LOG_ROOT = '/var/dose/log'
LOG_FILENAME = os.path.join(LOG_ROOT, 'openrem.log')
QR_FILENAME = os.path.join(LOG_ROOT, 'openrem_qr.log')
EXTRACTOR_FILENAME = os.path.join(LOG_ROOT, 'openrem_extractor.log')

# Removed comment hashes to enable log file rotation:
LOGGING['handlers']['file']['class'] = 'logging.handlers.RotatingFileHandler'
LOGGING['handlers']['file']['maxBytes'] = 10 * 1024 * 1024  # 10*1024*1024 = 10 MB
LOGGING['handlers']['file']['backupCount'] = 5  # number of log files to keep before deleting the oldest one
LOGGING['handlers']['qr_file']['class'] = 'logging.handlers.RotatingFileHandler'
LOGGING['handlers']['qr_file']['maxBytes'] = 10 * 1024 * 1024  # 10*1024*1024 = 10 MB
LOGGING['handlers']['qr_file']['backupCount'] = 5  # number of log files to keep before deleting the oldest one
LOGGING['handlers']['extractor_file']['class'] = 'logging.handlers.RotatingFileHandler'
LOGGING['handlers']['extractor_file']['maxBytes'] = 10 * 1024 * 1024  # 10*1024*1024 = 10 MB
LOGGING['handlers']['extractor_file']['backupCount'] = 5  # number of log files to keep before deleting the oldest one

# Regionalisation settings
#   Date format for exporting data to Excel xlsx files.
#   Default in OpenREM is dd/mm/yyyy. Override it by uncommenting and customising below; a full list of codes is
#   available at https://msdn.microsoft.com/en-us/library/ee634398.aspx.
# XLSX_DATE = 'mm/dd/yyyy'
#   Local time zone for this installation. Choices can be found here:
#   http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
#   although not all choices may be available on all operating systems.
#   In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Europe/London'
#   Language code for this installation. All choices can be found here:
#   http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

DCMTK_PATH = '/usr/bin'
DCMCONV = os.path.join(DCMTK_PATH, 'dcmconv')
DCMMKDIR = os.path.join(DCMTK_PATH, 'dcmmkdir')
JAVA_EXE = '/usr/bin/java'
JAVA_OPTIONS = '-Xms256m -Xmx512m -Xss1m -cp'
PIXELMED_JAR = '/var/dose/pixelmed/pixelmed.jar'
PIXELMED_JAR_OPTIONS = '-Djava.awt.headless=true com.pixelmed.doseocr.OCR -'

# E-mail server settings - see https://docs.djangoproject.com/en/2.2/topics/email/
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = 0         # Use 0 for False, 1 for True
EMAIL_USE_SSL = 0         # Use 0 for False, 1 for True
EMAIL_DOSE_ALERT_SENDER = 'your.alert@email.address'
EMAIL_OPENREM_URL = 'http://your.openrem.server'

IGNORE_DEVICE_OBSERVER_UID_FOR_THESE_MODELS = ['GE OEC Fluorostar']

Jetzt die Datenbank erzeugen. Stellen Sie sicher, dass Sie sich noch im openrem python Ordner befinden und das virtualenv aktiv ist – die Eingabeaufforderung sieht wie folgt aus

(veopenrem3)username@hostname:/var/dose/veopenrem3/lib/python3.10/site-packages/openrem/$

Otherwise see Die virtualenv aktivieren and navigate back to that folder.

Upgrading to a new server

If you are upgrading to a new Linux server, use these additional commands before continuing with those below:

$ mv remapp/migrations/0001_initial.py{.1-0-upgrade,}

Import the database - update the path to the database backup file you copied from the old server:

$ pg_restore --no-privileges --no-owner -U openremuser -d openremdb /path/to/pre-1-0-upgrade-dump.bak

Migrate the database:

$ python manage.py migrate --fake-initial
$ python manage.py migrate remapp --fake
$ python manage.py makemigrations remapp
$ python manage.py migrate
$ python manage.py loaddata openskin_safelist.json
$ python manage.py collectstatic --no-input --clear
$ python manage.py compilemessages
$ python manage.py createsuperuser

Webserver

Configure NGINX and Gunicorn

Copy in the OpenREM site config file

$ cd /var/dose/veopenrem3/lib/python3.10/site-packages/openrem/
$ sudo cp sample-config/openrem-server /etc/nginx/sites-available/openrem-server

Bemerkung

Content of NGINX config file:

server {
    listen 80;
    server_name openrem-server;

    location /static {
        alias /var/dose/static;
    }

    location / {
        proxy_pass http://unix:/tmp/openrem-server.socket;
        proxy_set_header Host $host;
        proxy_read_timeout 300s;
    }
}

Remove the default config and make ours active:

$ sudo rm /etc/nginx/sites-enabled/default
$ sudo ln -s /etc/nginx/sites-available/openrem-server /etc/nginx/sites-enabled/openrem-server

Copy the Gunicorn systemd service file into place:

$ cd /var/dose/veopenrem3/lib/python3.10/site-packages/openrem/
$ sudo cp sample-config/openrem-gunicorn.service /etc/systemd/system/openrem-gunicorn.service

Bemerkung

Content of systemd file:

[Unit]
Description=Gunicorn server for OpenREM

[Service]
Restart=on-failure
User=www-data
WorkingDirectory=/var/dose/veopenrem3/lib/python3.10/site-packages/openrem

ExecStart=/var/dose/veopenrem3/bin/gunicorn \
    --bind unix:/tmp/openrem-server.socket \
    openremproject.wsgi:application --timeout 300

[Install]
WantedBy=multi-user.target

Copy the task queue consumer systemd service file into place:

$ cd /var/dose/veopenrem3/lib/python3.10/site-packages/openrem/
$ sudo cp sample-config/openrem-consumer.service /etc/systemd/system/openrem-consumer.service

Bemerkung

Content of systemd file:

[Unit]
Description=Huey consumer for OpenREM

[Service]
Restart=on-failure
User=www-data
WorkingDirectory=/var/dose/veopenrem3/lib/python3.10/site-packages/openrem

ExecStart=/var/dose/veopenrem3/bin/python \
    manage.py run_huey

[Install]
WantedBy=multi-user.target

Die neue systemd Konfiguration laden:

$ sudo systemctl daemon-reload

Set the new Gunicorn and consumer services to start on boot:

$ sudo systemctl enable openrem-gunicorn.service
$ sudo systemctl enable redis-server.service
$ sudo systemctl enable openrem-consumer.service

Start the Gunicorn and consumer services, and restart the NGINX service:

$ sudo -- sh -c 'systemctl start openrem-gunicorn.service && systemctl start redis-server.service && systemctl start openrem-consumer.service && systemctl restart nginx.service'

Test the webserver

Jetzt sollte der Zugriff auf den OpenREM Server von anderen Rechner möglich sein.

Ob NGINX und Gunicorn bereit sind kann mit den folgenden zwei Befehlen überprüft werden:

$ sudo systemctl status openrem-gunicorn.service
$ sudo systemctl status nginx.service

DICOM Store SCP

Copy the Lua file to the Orthanc folder. This will control how we process the incoming DICOM objects.

$ cd /var/dose/veopenrem3/lib/python3.10/site-packages/openrem/
$ cp sample-config/openrem_orthanc_config_linux.lua /var/dose/orthanc/

Edit the Orthanc Lua configuration options:

$ nano /var/dose/orthanc/openrem_orthanc_config_linux.lua

Set use_physics_filtering to true if you want Orthanc to keep physics test studies, and have it put them in the /var/dose/orthanc/physics/ folder. Set it to false to disable this feature. Add names or IDs to physics_to_keep as a comma separated list.

-- Set this to true if you want Orthanc to keep physics test studies, and have it
-- put them in the physics_to_keep_folder. Set it to false to disable this feature
local use_physics_filtering = true

-- A list to check against patient name and ID to see if the images should be kept.
-- Orthanc will put anything that matches this in the physics_to_keep_folder.
local physics_to_keep = {'physics'}

Lists of things to ignore. Orthanc will ignore anything matching the content of these comma separated lists; they will not be imported into OpenREM.

-- Lists of things to ignore. Orthanc will ignore anything matching the content of
-- these lists: they will not be imported into OpenREM.
local manufacturers_to_ignore = {'Faxitron X-Ray LLC', 'Gendex-KaVo'}
local model_names_to_ignore = {'CR 85', 'CR 75', 'CR 35', 'CR 25', 'ADC_5146', 'CR975'}
local station_names_to_ignore = {'CR85 Main', 'CR75 Main'}
local software_versions_to_ignore = {'VixWin Platinum v3.3'}
local device_serial_numbers_to_ignore = {'SCB1312016'}

Funktion für das extrahieren der Dosisinformation aus älteren Toshiba und GE Geräte ein- oder ausschalten und für welchen Gerätetyp dies erfolgen soll. Jedes System sollte in der Form {'Manufacturer', 'Model name'} aufgeführt werden, wie das nachstehende Beispiel zeigt:

-- Set this to true if you want to use the OpenREM Toshiba CT extractor. Set it to
-- false to disable this feature.
local use_toshiba_ct_extractor = true

-- A list of CT make and model pairs that are known to have worked with the Toshiba CT extractor.
-- You can add to this list, but you will need to verify that the dose data created matches what you expect.
local toshiba_extractor_systems = {
        {'Toshiba', 'Aquilion'},
        {'GE Medical Systems', 'Discovery STE'},
}

Edit the Orthanc configuration:

$ sudo nano /etc/orthanc/orthanc.json

Dieses Lua Skript zur Othanc Konfiguration hinzufügen:

// List of paths to the custom Lua scripts that are to be loaded
// into this instance of Orthanc
"LuaScripts" : [
"/var/dose/orthanc/openrem_orthanc_config_linux.lua"
],

Set the AE Title and port:

// The DICOM Application Entity Title
"DicomAet" : "OPENREM",

// The DICOM port
"DicomPort" : 104,

Bemerkung

Optionally, you may also like to enable the HTTP server interface for Orthanc (although if the Lua script is removing all the objects as soon as they are processed, you won’t see much!):

// Whether remote hosts can connect to the HTTP server
"RemoteAccessAllowed" : true,

// Whether or not the password protection is enabled
"AuthenticationEnabled" : false,

To see the Orthanc web interface, go to http://openremserver:8042/ – of course change the server name to that of your server!

Allow Orthanc to use DICOM port

By default, Orthanc uses port 4242. If you wish to use a lower port, specifically the DICOM port of 104, you will need to give the Orthanc binary special permission to do so:

$ sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/sbin/Orthanc

Finish off

Restart Orthanc:

$ sudo systemctl restart orthanc.service

Neue Nutzer, und schneller Zugriff auf den Physik-Ordner

This is for new Linux users; for new OpenREM users, refer to Configure the settings

If you left local use_physics_filtering = true in the Orthanc configuration, you might like to give your colleagues a quick method of accessing the physics folder from their home folder. Then if they use a program like WinSCP it is easy to find and copy the QA images to another (Windows) computer on the network. WinSCP can also be run directly from a USB stick if you are unable to install software :-)

Add the new user (replace newusername as appropriate):

$ sudo adduser newusername

Then add the new user to the openrem group (again, replace the user name):

$ sudo adduser newusername openrem

Now add a ‚sym-link‘ to the new users home directory (again, replace the user name):

$ sudo ln -sT /var/dose/orthanc/physics /home/newusername/physicsimages

Der neue Nutzer sollte, sobald er eingeloggt ist, jetzt durch Klicken auf physicsimages Link auf den Physik-Ordner zugreifen können, die ZIP Dateien und Ordner anzeigen, kopieren und löschen können.

Asciinema demo of this install

Link to asciinema demo of this install