Skip to content

Commit

Permalink
Merge branch 'main' into 82-n00-implement-personnel
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/dps_training_k/game/consumers/trainer_consumer.py
  • Loading branch information
Wolkenfarmer committed Mar 27, 2024
2 parents 91302f3 + bc258dc commit c6eede8
Show file tree
Hide file tree
Showing 36 changed files with 1,419 additions and 253 deletions.
12 changes: 6 additions & 6 deletions backend/dps_training_k/game/consumers/abstract_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@ def authenticate(self, token):

def _send_exercise(self, exercise):
patient = Patient.objects.create(
name="Max Mustermann", exercise=exercise, patientCode=123456
name="Max Mustermann", exercise=exercise, patientId=123456
)
exercise_object = {
"exercise": {
"exerciseId": exercise.invitation_code,
"exerciseId": exercise.exerciseId,
"areas": [
{
"areaName": "X",
"patients": [
{
"patientId": patient.patientCode,
"patientId": patient.patientId,
"patientName": patient.name,
"patientCode": 0
}
Expand All @@ -176,10 +176,10 @@ def _send_exercise(self, exercise):
"personnelName": "X"
}
],
"devices": [
"material": [
{
"deviceId": 0,
"deviceName": "X"
"materialId": 0,
"materialName": "X"
}
]
}
Expand Down
14 changes: 12 additions & 2 deletions backend/dps_training_k/game/consumers/patient_consumer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from .abstract_consumer import AbstractConsumer
from urllib.parse import parse_qs
from game.models import Exercise, Patient


class PatientConsumer(AbstractConsumer):
class PatientIncomingMessageTypes:
EXAMPLE = "example"
TEST_PASSTHROUGH = "test-passthrough"

class PatientOutgoingMessageTypes:
RESPONSE = "response"
EXERCISE = "exercise"
TEST_PASSTHROUGH = "test-passthrough"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -19,7 +20,10 @@ def __init__(self, *args, **kwargs):
self.handle_example,
"exercise_code",
"patient_code",
)
),
self.PatientIncomingMessageTypes.TEST_PASSTHROUGH: (
self.handle_test_passthrough,
),
}

def connect(self):
Expand All @@ -36,3 +40,9 @@ def handle_example(self, exercise_code, patient_code):
self.PatientOutgoingMessageTypes.RESPONSE,
content=f"exercise_code {self.exercise_code} & patient_code {self.patient_code}",
)

def handle_test_passthrough(self):
self.send_event(
self.PatientOutgoingMessageTypes.TEST_PASSTHROUGH,
message="received test event",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.1 on 2024-03-22 10:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('game', '0004_remove_scheduledevent_owner_owner_event'),
]

operations = [
migrations.RenameField(
model_name='exercise',
old_name='invitation_code',
new_name='exerciseId',
),
migrations.RemoveField(
model_name='patient',
name='patientCode',
),
migrations.AddField(
model_name='patient',
name='patientId',
field=models.IntegerField(default=1, help_text='patientId used to log into patient - therefore part of authentication'),
preserve_default=False,
),
]
4 changes: 2 additions & 2 deletions backend/dps_training_k/game/models/exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ExerciseStateTypes(models.TextChoices):
to="Trainer",
on_delete=models.CASCADE,
) """
invitation_code = models.CharField(
exerciseId = models.CharField(
unique=True,
editable=settings.DEBUG,
max_length=settings.INVITATION_LOGIC.code_length,
Expand All @@ -35,7 +35,7 @@ def createExercise(cls):
new_Exercise = cls.objects.create(
# config=settings.DEFAULT_EXCERCISE_CONFIG,
# trainer=trainer
invitation_code=settings.INVITATION_LOGIC.get_invitation_code(),
exerciseId=settings.INVITATION_LOGIC.get_exerciseId(),
state=cls.ExerciseStateTypes.CONFIGURATION,
)
return new_Exercise
Expand Down
8 changes: 4 additions & 4 deletions backend/dps_training_k/game/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ class Patient(Eventable, models.Model):
name = models.CharField(
max_length=100, default="Max Mustermann"
) # technically patientData but kept here for simplicity for now
# patientID = models.ForeignKey() # currently called "SensenID"
# patientCode = models.ForeignKey() # currently called "SensenID"
exercise = models.ForeignKey("Exercise", on_delete=models.CASCADE)
# stateID = models.ForeignKey()
# measureID = models.ManyToManyField()
patientCode = models.IntegerField(
help_text="patientCode used to log into patient - therefore part of authentication"
patientId = models.IntegerField(
help_text="patientId used to log into patient - therefore part of authentication"
)

def __str__(self):
return f"Patient #{self.id} called {self.name} with code {self.patientCode}"
return f"Patient #{self.id} called {self.name} with ID {self.patientId}"

# ToDo remove when actual method is implemented
def schedule_temporary_event(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_access_success(self):
"""
Test the access with correct credentials.
"""
data = {"exerciseCode": "testuser", "patientCode": "testpassword"}
data = {"exerciseId": "testuser", "patientId": "testpassword"}
response = self.client.post(self.access_url, data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Check if the response contains a token
Expand All @@ -27,7 +27,7 @@ def test_access_fail_wrong_credentials(self):
"""
Test the access with wrong credentials.
"""
data = {"exerciseCode": "wronguser", "patientCode": "wrongpassword"}
data = {"exerciseId": "wronguser", "patientId": "wrongpassword"}
response = self.client.post(self.access_url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
# Check that the response indicates a failure
Expand All @@ -39,8 +39,8 @@ def test_access_fail_missing_fields(self):
Test the access with missing fields.
"""
data = {
"exerciseCode": "testuser"
# Missing "patientCode"
"exerciseId": "testuser"
# Missing "patientId"
}
response = self.client.post(self.access_url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
6 changes: 3 additions & 3 deletions backend/dps_training_k/game/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class PatientAccessView(APIView):
def post(self, request, *args, **kwargs):
if not (request.data.get("exerciseCode") and request.data.get("patientCode")):
if not (request.data.get("exerciseId") and request.data.get("patientId")):
return Response(
status=status.HTTP_400_BAD_REQUEST,
data="Some required fields are missing",
)
exercise_code = request.data.get("exerciseCode")
patient_code = request.data.get("patientCode")
exercise_code = request.data.get("exerciseId")
patient_code = request.data.get("patientId")
user = authenticate(username=exercise_code, password=patient_code)
if user:
token, created = Token.objects.get_or_create(user=user)
Expand Down
6 changes: 3 additions & 3 deletions backend/dps_training_k/helpers/invitation_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def __init__(self, code_length):
self.code_length = code_length
self.codes_taken = []

def get_invitation_code(self):
def get_exerciseId(self):
"""
Generates an unique alphabetic invitation_code of length self.code_length,
Generates an unique alphabetic exerciseId of length self.code_length,
that is also distinctive from other non-finished excercises (levenshtein distance >= 3).
:return: a string, the invitation_code
:return: a string, the exerciseId
"""
new_code = None
letters = string.ascii_lowercase
Expand Down
84 changes: 84 additions & 0 deletions frontend/src/assets/main.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
@import './base.css';

:root {
--red: #ee4035;
--yellow: #e6cf00;
--green: #269f42;
--gray: gray;
}

#app {
height: 100vh;
font-weight: normal;
Expand All @@ -20,4 +27,81 @@ button:hover {
button:active {
cursor: pointer;
filter: brightness(90%);
}

.gray {
background-color: var(--gray);
}

.red {
background-color: var(--red);
}

.yellow {
background-color: var(--yellow);
}

.green {
background-color: var(--green);
}

.popup-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
text-align: center;
z-index: 1;
}

.list {
margin-top: 30px;
margin-left: 30px;
margin-right: 30px;
}

.listItem {
position: relative;
background-color: #FFFFFF;
border: 1px solid rgb(209, 213, 219);
display: flex;
align-items: center;
text-align: left;
margin-top: -1px;
}

.listItemButton {
position: relative;
background-color: #FFFFFF;
border: none;
display: flex;
align-items: center;
font-size: 1.25rem;
padding: .75rem 1rem;
padding-left: 0;
text-align: left;
height: 50px;
width: 100%;
}

.listItemAddButton {
text-align: center;
position: relative;
background-color: #FFFFFF;
border: 1px solid rgb(209, 213, 219);
box-sizing: border-box;
width: 100%;
font-size: 1.25rem;
line-height: 1.25rem;
padding: .75rem 1rem;
margin-top: -1px;
}

.listItemId, .listItemName {
padding: .75rem 1rem;
}
2 changes: 1 addition & 1 deletion frontend/src/components/screensPatient/ScreenInactive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Patient inaktiv
</div>
<div class="inactive-patient-details">
<div>Patient: {{ patientStore.patientName }} | {{ patientStore.patientID }}</div>
<div>Patient: {{ patientStore.patientName }} | {{ patientStore.patientId }}</div>
<div>Bereich: {{ patientStore.areaName }}</div>
</div>
</div>
Expand Down
51 changes: 10 additions & 41 deletions frontend/src/components/screensPatient/ScreenStatus.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
<script setup lang="ts">
import {computed, ref} from 'vue'
import {ref} from 'vue'
import {usePatientStore} from '@/stores/Patient'
import TriagePopup from '@/components/widgets/TriagePopup.vue'
import PatientStatus from '@/components/widgets/PatientStatus.vue'
import { triageToColor } from '@/utils'
const patientStore = usePatientStore()
const triageColor = ref(computed(() => {
switch (patientStore.triage) {
case 'G':
return 'green'
case 'Y':
return 'yellow'
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
return 'red'
default:
return 'gray'
}
}))
const showPopup = ref(false)
</script>

<template>
<nav>
<button id="nav-trainer">
{{ patientStore.patientID }}
{{ patientStore.patientId }}
</button>
<button id="nav-triage" :class="triageColor" @click="showPopup = true">
<button
id="nav-triage"
:style="{backgroundColor: triageToColor(patientStore.triage)}"
@click="showPopup = true"
>
{{ patientStore.triage }}
</button>
<button id="nav-exercise-code">
Expand Down Expand Up @@ -70,30 +58,11 @@
width: 20%;
border-left: 4px solid black;
border-right: 4px solid black;
color: white;
}
#nav-exercise-code {
width: 40%;
border-left: 4px solid black;
}
/*noinspection CssUnusedSymbol*/
.gray {
background-color: lightgray;
}
/*noinspection CssUnusedSymbol*/
.green {
background-color: green;
}
/*noinspection CssUnusedSymbol*/
.yellow {
background-color: yellow;
}
/*noinspection CssUnusedSymbol*/
.red {
background-color: red;
}
</style>
</style>@/utils
Loading

0 comments on commit c6eede8

Please sign in to comment.