diff --git a/backend/dps_training_k/game/consumers/abstract_consumer.py b/backend/dps_training_k/game/consumers/abstract_consumer.py index 279aaa08..1533589c 100644 --- a/backend/dps_training_k/game/consumers/abstract_consumer.py +++ b/backend/dps_training_k/game/consumers/abstract_consumer.py @@ -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 @@ -147,19 +148,18 @@ 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", @@ -167,7 +167,8 @@ def _send_exercise(self): { "patientId": patient.patientId, "patientName": patient.name, - "patientCode": 0 + "patientCode": 0, + "triage": patient.triage } ], "personnel": [ diff --git a/backend/dps_training_k/game/consumers/patient_consumer.py b/backend/dps_training_k/game/consumers/patient_consumer.py index 67a26b29..418cacde 100644 --- a/backend/dps_training_k/game/consumers/patient_consumer.py +++ b/backend/dps_training_k/game/consumers/patient_consumer.py @@ -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" @@ -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, @@ -24,21 +27,29 @@ 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): @@ -46,3 +57,7 @@ def handle_test_passthrough(self): self.PatientOutgoingMessageTypes.TEST_PASSTHROUGH, message="received test event", ) + + def handle_triage(self, triage): + self.patient.triage = triage + self._send_exercise() diff --git a/backend/dps_training_k/game/consumers/trainer_consumer.py b/backend/dps_training_k/game/consumers/trainer_consumer.py index 8c165f10..d22c954c 100644 --- a/backend/dps_training_k/game/consumers/trainer_consumer.py +++ b/backend/dps_training_k/game/consumers/trainer_consumer.py @@ -1,5 +1,5 @@ from .abstract_consumer import AbstractConsumer - +from game.models import Exercise class TrainerConsumer(AbstractConsumer): class TrainerIncomingMessageTypes: @@ -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):