Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 30-m03-implement-pati…
Browse files Browse the repository at this point in the history
…ent-phase-change
  • Loading branch information
claasga committed Mar 25, 2024
1 parent c5755a1 commit 27253f9
Show file tree
Hide file tree
Showing 35 changed files with 1,012 additions and 122 deletions.
1 change: 1 addition & 0 deletions backend/dps_training_k/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
CODE_LENGTH = 6
INVITATION_LOGIC = LevenshteinCode(CODE_LENGTH)
CURRENT_TIME = lambda: timezone.now()
DEFAULT_STATE_ID = 101
2 changes: 1 addition & 1 deletion backend/dps_training_k/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"corsheaders",
"game.apps.GameConfig",
"helpers.apps.GameConfig",
"templates.apps.GameConfig",
"template.apps.TemplateConfig",
"rest_framework",
"rest_framework.authtoken",
"django_celery_beat",
Expand Down
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 = Exercise.createExercise()
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):
"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",
)
2 changes: 0 additions & 2 deletions backend/dps_training_k/game/consumers/trainer_consumer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .abstract_consumer import AbstractConsumer
from game.models import Exercise, Patient
from django.conf import settings


class TrainerConsumer(AbstractConsumer):
Expand Down
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,
),
]
14 changes: 14 additions & 0 deletions backend/dps_training_k/game/migrations/0007_merge_20240325_1625.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 5.0.1 on 2024-03-25 16:25

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('game', '0005_rename_invitation_code_exercise_exerciseid_and_more'),
('game', '0006_patient_stateid_delete_patientstate'),
]

operations = [
]
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 @@ -10,7 +10,7 @@ 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.OneToOneField(
"template.PatientState",
Expand All @@ -19,12 +19,12 @@ class Patient(Eventable, models.Model):
default=settings.DEFAULT_STATE_ID,
)
# 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
26 changes: 25 additions & 1 deletion 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,21 @@ 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);
}

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 27253f9

Please sign in to comment.