Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into 325-add-project-licensing
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
Wolkenfarmer committed Jul 11, 2024
2 parents f513da6 + 6433e44 commit 51a3e8f
Show file tree
Hide file tree
Showing 35 changed files with 647 additions and 405 deletions.
2 changes: 0 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=dps

FRONTEND_URL=localhost
2 changes: 0 additions & 2 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=ozuCk0rrF6nzkzcR1TQMR93m3iYUzMBG

FRONTEND_URL=klinik-dps.de
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:

- name: Run docker containers with deploy dev configuration
run: |
docker-compose --env-file .env.dev up -d
docker-compose -f docker-compose.dev.yml up -d
- name: Run integration tests
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ jobs:
- name: Prepare deployment files
run: |
mkdir deployment_files
cp docker-compose.yml deployment_files/
cp docker-compose.prod.yml deployment_files/docker-compose.yml
cp ./.env.prod deployment_files/
cp ./.env.dev deployment_files/
cp backend/dps_training_k/deployment/nginx/nginx_deploy_prod.conf deployment_files/nginx.conf
- name: Archive deployment files
uses: actions/upload-artifact@v2
Expand Down
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# ![img.png](./frontend/public/favicon-32x32.png) K-dPS
# ![img.png](./frontend/public/favicon-32x32.png) Klinik-dPS
The K-dPS (the clinic variant of the dynamic patient simulation) simulation software for training medical personnel on how to act during medical
surges / during mass casualty incidents.

It is currently only available in German at http://139.162.170.6:5173/.
It is currently only available in German at https://klinik-dps.de/.

The software is developed as part of a project at the Hasso Plattner Institute in Potsdam, Germany:
[Project Website](https://hpi.de/giese/teaching/bachelor-projects/digitale-simulationsuebungen-fuer-krankenhaeuser.html).

## Features
The K-dPS offers the following features:
- **Create Exercises**: Trainers can quickly create exercises by adding areas, patients, personnel and material to them and customize names.
- **Dynamic Patients**: Patients dynamically change their state based on the material assigned and actions applied to them.
- **Dynamic Patients**: Patients dynamically change their state based on the current state as well as the material assigned and actions applied to them.
- **Real-time Interaction**: Trainees can interact with the patients in real-time by applying treatments, conducting examinations and more.
- **Resource Management**: Trainees can assign personnel and material to different patients and manage the resources effectively.
- **Triaging**: Trainees can triage patients based on their state and assign them different triage categories and move them to different areas.
Expand Down Expand Up @@ -51,3 +51,26 @@ some components are licensed differently:
[backend/dps_training_k/data/LICENSE](./backend/dps_training_k/data/LICENSE) file. This license prohibits the use of the data for commercial use.
Consequently, the data needs to be removed or replaced or licensing addendums have to be negotiated if the project should be used commercially. For
more details, see the [backend/dps_training_k/data/README.md](./backend/dps_training_k/data/README.md) file.


## Thank you
First and foremost, we would like to thank the [Hasso Plattner Institute](https://hpi.de/) for giving us the opportunity to work on this project as well as our
supervisors Christian Schäffer and Matthias Barkowsky for their guidance and organization of the project.

Right after that come our official project partners, the [ZaNowi](https://zanowi.de/) ("Zentrum für angewandte Notfallwissenschaft") and the
[Johanniter](https://www.johanniter.de/bildungseinrichtungen/johanniter-akademie/johanniter-akademie-nordrhein-westfalen/standorte-der-akademie-in-nordrhein-westfalen/campus-muenster/)
("Johanniter Akademie NRW, Campus Münster"), for making the project possible by providing the necessary data and insights.

And last but not least, we would like to thank our supporters:
- [BABZ](https://www.bbk.bund.de/DE/Themen/Akademie-BABZ/akademie-babz_node.html) ("Bundesakademie für Bevölkerungsschutz und Zivile Verteidigung")
of the [BBK](https://www.bbk.bund.de/DE/Home/home_node.html) ("Bundesamtes für Bevölkerungsschutz und Katastrophenhilfe")
- [Evangelisches Krankenhaus Hubertus](https://www.johannesstift-diakonie.de/medizinische-versorgung/evangelisches-krankenhaus-hubertus)
Berlin-Zehlendorf
- [Universitätsklinikum Düsseldorf](https://www.uniklinik-duesseldorf.de/)

Special thanks to the following people for being directly available to us and providing us with valuable insights and feedback: Frank Sensen
(ZaNowi), Philipp Rocker (Johanniter) and Daniel Schmitz (Evangelisches Krankenhaus Hubertus).

![](./docs/hpi_logo.png)
![](./docs/johanniter_logo.png)
![](./docs/zanowi_logo.png)
92 changes: 40 additions & 52 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,67 @@
# K-dPS Backend
# Klinik-dPS Backend
The simulation logic and database management for the K-dPS project. For the interactive website see the [frontend folder](../frontend/README.md).

## Running the project using Docker

For more information on the difference between `prod` and `dev`, see the project README.
Note that the `prod` env file here still assumes this is running locally -
meaning it will expect the frontend to run on localhost.

- inside dps_training_k folder, run `docker-compose --env-file .env.<prod/dev> up -d`
- create superuser account: `docker exec -it K-dPS-django python manage.py createsuperuser`
For general information on the project like e.g. licensing information or future plans, see the [Project README](../README.md).

## Running the project locally (NOT UP TO DATE)
## Setup
### Install Python
- install from official [python website](https://www.python.org/downloads/)
- version should be at least 3.12

### Setup a virtual environment for python
#### Linux

- navigate to backend folder
- `python3 -m venv env`
- `source env/bin/activate`

#### Windows

- navigate to backend folder
- `python -m venv env`
- `env/Scripts/Activate.ps1`
- in case the previous command failed due to execution policy, run: `powershell.exe -exec bypass`

### install requirements

### Install requirements
- navigate into backend folder
- `pip install -r requirements.txt`

## Setup Black Formatter
### Linux (for this project only)

- make sure python extension is installed
- type "Python: Select Interpreter" in command palette and set newest interpreter for virtual environment
- neavigate to venv in terminal
- pip install black
- create .vscode file in venv
- create settings.json file in .vscode folder
- paste:
```json
{
"python.formatting.blackPath": "path/to/bin/of black/formatter/in/venv",
"python.formatting.blackArgs": [
"-l 150"
],
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
}
```

### Windows (for all python files open with VS Code)

### Setup Black Formatter
We are using black as a biased formatter for the whole project. For more information about black see: [Black](https://black.readthedocs.io/en/stable/)
- make sure you have python extension installed
- download "Black Formatter" from marketplace
- right click on a python file
- right-click on a python file
- select "Format Document with"
- select "Configure Default formatter"
- select "Black"
- head to VS Code settings
- search for "format on save"
- enable "Editor: Format on Save"

## Running the project using Docker
Running the project without docker is currently not tested/supported.
For more information on the difference between `prod` and `dev`, see the [docs file](../docs/deployment-process.md).
Note that the `prod` env file here still assumes this is running locally -
meaning it will expect the frontend to run on localhost.

Build and run:
```bash
docker compose --env-file .env.<prod/dev> up
```

Optionally, to access the database, create a superuser account:
```bash
docker exec -it K-dPS-django python manage.py createsuperuser
```
Afterwards, you can log into the admin interface at e.g. `http://localhost:80/admin/`<br/>
Note: this is only available if DEBUG = true, which is the case in the dev environment.


## Development

- to run tests: `docker exec -it K-dPS-django python manage.py test`
### Migrations
When changing models, you need to create migrations in order to update existing databases.
- Create new migrations: `docker exec -it K-dPS-django python manage.py makemigrations`
- Optionally, if you have conflicting migrations: `docker exec -it K-dPS-django python manage.py migrate --merge`
- Execute these migrations to update the database: `docker exec -it K-dPS-django python manage.py migrate`

### Running Tests
- start docker container with docker compose(see Running the project using Docker)
- wait until Application Startup is Completed
- run: `docker exec -it K-dPS-django python manage.py test`

### Working with Fixtures
- (clear database)
- fill database with data you want to export as fixture (e.g. `docker exec -it K-dPS-django python manage.py import_patient_states`)
- in this example, make PatientState.transition null=True and blank=True, migrate that
- if updating a fixture that is used by a model that doesn't allow null fields, make them nullable, migrate and discard the migration file
afterwards.
- create fixture:
- `docker exec -it K-dPS-django bash`
- `export PYTHONIOENCODING=utf8`
Expand Down
2 changes: 0 additions & 2 deletions backend/dps_training_k/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=dps

FRONTEND_URL=localhost
2 changes: 0 additions & 2 deletions backend/dps_training_k/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ CHANNEL_REDIS=True
POSTGRES_DB=dps
POSTGRES_USER=dps
POSTGRES_PASSWORD=ozuCk0rrF6nzkzcR1TQMR93m3iYUzMBG

FRONTEND_URL=localhost
3 changes: 1 addition & 2 deletions backend/dps_training_k/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG")
CORS_ORIGIN_ALLOW_ALL = DEBUG
CORS_ALLOWED_ORIGINS = ["http://" + env.str("FRONTEND_URL") + ":5173"]
CORS_ALLOWED_ORIGINS = ["https://klinik-dps.de", "https://www.klinik-dps.de", "http://localhost"]
RUN_CONFIG = env.str("RUN_CONFIG", default="dev")

CSRF_TRUSTED_ORIGINS = ["http://localhost:8000"]
Expand Down Expand Up @@ -134,7 +134,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

Expand Down
3 changes: 1 addition & 2 deletions backend/dps_training_k/deployment/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
RUN rm /etc/nginx/conf.d/default.conf
37 changes: 22 additions & 15 deletions backend/dps_training_k/deployment/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
upstream configuration {
server django:8000;
}

server {

listen 80;

location / {
proxy_pass http://configuration;
location /api {
proxy_pass http://django:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /ws {
proxy_pass http://django:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}


# For the admin interface
location /admin {
proxy_pass http://django:8000/admin;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static/ {
alias /app/staticfiles/;
}

location /media/ {
alias /app/mediafiles/;
}

}
42 changes: 42 additions & 0 deletions backend/dps_training_k/deployment/nginx/nginx_deploy_dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
server {
listen 80;

location / {
proxy_pass http://frontend:5173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /api {
proxy_pass http://django:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /ws {
proxy_pass http://django:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# For the admin interface
location /admin {
proxy_pass http://django:8000/admin;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static/ {
alias /app/staticfiles/;
}
}
39 changes: 39 additions & 0 deletions backend/dps_training_k/deployment/nginx/nginx_deploy_prod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
server {
listen 80;
server_name klinik-dps.de www.klinik-dps.de;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name klinik-dps.de www.klinik-dps.de;

ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;

location / {
proxy_pass http://frontend:5173;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api {
proxy_pass http://django:8000/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws {
proxy_pass http://django:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
7 changes: 4 additions & 3 deletions backend/dps_training_k/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ services:
volumes:
- static_volume:/app/staticfiles
- .:/app:z
expose:
- 8000
ports:
- 8000:8000
command: uvicorn configuration.asgi:application --host 0.0.0.0 --reload
stdin_open: true
tty: true
Expand Down Expand Up @@ -82,8 +82,9 @@ services:
container_name: K-dPS-nginx
volumes:
- static_volume:/app/staticfiles
- ./deployment/nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf
ports:
- "8000:80"
- "80:80"
depends_on:
- django

Expand Down
Loading

0 comments on commit 51a3e8f

Please sign in to comment.