Skip to content

Commit

Permalink
#108 backend: add triage route
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni000 committed Mar 25, 2024
1 parent 7e8c478 commit c7f4fd8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
13 changes: 7 additions & 6 deletions backend/dps_training_k/game/consumers/abstract_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ClosureCodes:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.exercise_code = ""
self.exercise = None
self.REQUESTS_MAP = {}
self.user = None

Expand Down Expand Up @@ -147,27 +148,27 @@ def authenticate(self, token):
token = Token.objects.get(key=token)
self.user = token.user
self.user.set_channel_name(self.channel_name)
return True
return True, self.user.username
except Token.DoesNotExist:
self.close(code=self.ClosureCodes.NOT_AUTHENTICATED)
return False
return False, None

def _send_exercise(self):
exercise = Exercise.createExercise()
patient = Patient.objects.create(
name="Max Mustermann", exercise=exercise, patientId=123456
name="Max Mustermann", exercise=self.exercise, patientId=123456
)
exercise_object = {
"exercise": {
"exerciseId": exercise.exerciseId,
"exerciseId": self.exercise.exerciseId,
"areas": [
{
"areaName": "X",
"patients": [
{
"patientId": patient.patientId,
"patientName": patient.name,
"patientCode": 0
"patientCode": 0,
"triage": patient.triage
}
],
"personnel": [
Expand Down
23 changes: 19 additions & 4 deletions backend/dps_training_k/game/consumers/patient_consumer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from .abstract_consumer import AbstractConsumer
from urllib.parse import parse_qs
from game.models import Patient


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

class PatientOutgoingMessageTypes:
RESPONSE = "response"
Expand All @@ -14,7 +16,8 @@ class PatientOutgoingMessageTypes:

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.patient_code = ""
self.patientId = ""
self.patient = None
self.REQUESTS_MAP = {
self.PatientIncomingMessageTypes.EXAMPLE: (
self.handle_example,
Expand All @@ -24,25 +27,37 @@ def __init__(self, *args, **kwargs):
self.PatientIncomingMessageTypes.TEST_PASSTHROUGH: (
self.handle_test_passthrough,
),
self.PatientIncomingMessageTypes.TRIAGE: (
self.handle_triage,
"triage",
),
}

def connect(self):
query_string = parse_qs(self.scope["query_string"].decode())
token = query_string.get("token", [None])[0]
if self.authenticate(token):
success, patientId = self.authenticate(token)
if success:
self.patient = Patient.objects.filter(patientId=patientId).first()
self.patientId = patientId
self.exercise = self.patient.exercise
self.accept()
self._send_exercise()

def handle_example(self, exercise_code, patient_code):
self.exercise_code = exercise_code
self.patient_code = patient_code
self.patientId = patient_code
self.send_event(
self.PatientOutgoingMessageTypes.RESPONSE,
content=f"exercise_code {self.exercise_code} & patient_code {self.patient_code}",
content=f"exercise_code {self.exercise_code} & patient_code {self.patientId}",
)

def handle_test_passthrough(self):
self.send_event(
self.PatientOutgoingMessageTypes.TEST_PASSTHROUGH,
message="received test event",
)

def handle_triage(self, triage):
self.patient.triage = triage
self._send_exercise()
3 changes: 2 additions & 1 deletion backend/dps_training_k/game/consumers/trainer_consumer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .abstract_consumer import AbstractConsumer

from game.models import Exercise

class TrainerConsumer(AbstractConsumer):
class TrainerIncomingMessageTypes:
Expand Down Expand Up @@ -59,6 +59,7 @@ def handle_example(self, exercise_code):
)

def handle_create_exercise(self):
self.exercise = Exercise.createExercise()
self._send_exercise()

def handle_test_passthrough(self):
Expand Down

0 comments on commit c7f4fd8

Please sign in to comment.