Skip to content

Commit

Permalink
#330 backend: add continuousVariable model and data
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Sep 14, 2024
1 parent 66dbdf5 commit 0564c32
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 5 deletions.
55 changes: 55 additions & 0 deletions backend/dps_training_k/data/continuous_variables_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from template.constants import ActionIDs, MaterialIDs, ContinuousVariableIDs
from template.models.continuous_variable import ContinuousVariable


def update_or_create_continuous_variables():
"""
"name": ContinuousVariable.Variable.SPO2, // name as defined in ContinuousVariable
"function": ContinuousVariable.Function.LINEAR, // function as defined in ContinuousVariable
"exceptions": [{
"actions": ["A1uuid", ["A2uuid", "A3uuid"]], // this means action1 OR (action3 AND action4); can be None
"materials": ["M1uuid", ["M2uuid", "M3uuid"]], // material1 OR material2 OR (material3 AND material4); can be None
"function": ContinuousVariable.Function.LINEAR, // function as defined in ContinuousVariable
}] // exceptions listed according to their priority. If the first exceptions applies, the rest won't be looked at
// actions and materials both need to be true in order for the exception to apply
"""

ContinuousVariable.objects.update_or_create(
uuid=ContinuousVariableIDs.SPO2,
defaults={
"name": ContinuousVariable.Variable.SPO2,
"function": ContinuousVariable.Function.LINEAR,
"exceptions": [
{
"actions": [str(ActionIDs.BEATMUNGSGERAET_ANBRINGEN)],
"materials": [
str(MaterialIDs.BEATMUNGSGERAET_STATIONAER),
str(MaterialIDs.BEATMUNGSGERAET_TRAGBAR),
],
"function": ContinuousVariable.Function.LINEAR,
},
{
"actions": [
[str(ActionIDs.IV_ZUGANG), str(ActionIDs.DRUCKVERBAND)]
],
"materials": [
[str(MaterialIDs.EKG), str(MaterialIDs.BZ_MESSGERAET)]
],
"function": ContinuousVariable.Function.DECREMENT,
},
{
"actions": [str(ActionIDs.IV_ZUGANG)],
"materials": [str(MaterialIDs.EKG)],
"function": ContinuousVariable.Function.INCREMENT,
},
],
},
)
ContinuousVariable.objects.update_or_create(
uuid=ContinuousVariableIDs.HEART_RATE,
defaults={
"name": ContinuousVariable.Variable.HEART_RATE,
"function": ContinuousVariable.Function.LINEAR,
"exceptions": [],
},
)
1 change: 1 addition & 0 deletions backend/dps_training_k/template/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
admin.site.register(StateTransition)
admin.site.register(PatientInformation)
admin.site.register(Material)
admin.site.register(ContinuousVariable)
5 changes: 5 additions & 0 deletions backend/dps_training_k/template/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ class ActionResultIDs:
HB430 = "4a76bb8d-ccd2-4f27-9e08-3131ed3c0178"
BZ920 = "3ddade44-701a-43b9-9670-a8e346a45048"
BZ930 = "c30d670e-c072-4263-9f6a-895d00ef7368"


class ContinuousVariableIDs:
SPO2 = "cb39ff83-6f6a-4dba-9ae1-b2028dbddb35"
HEART_RATE = "862cca82-555e-4f05-bd38-9a6dc9f01f60"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.core.management.base import BaseCommand

from data.continuous_variables_data import update_or_create_continuous_variables
from helpers.triage import Triage
from template.constants import ActionIDs
from template.models import PatientInformation
Expand Down Expand Up @@ -75,7 +76,7 @@ def import_patients(file_path):
"start_status": row["Start-Status"].strip(),
"start_location": row["Start-Ort"].strip(),
"op": row["OP / Interventions-Verlauf"].strip(),
}
},
)
pretreatments_list = [
pt.strip() for pt in patient_information.pretreatment.split(",")
Expand All @@ -102,8 +103,13 @@ def import_patients(file_path):


class Command(BaseCommand):
help = "Imports patient data from a CSV file"
help = "Imports patient data from a CSV file and update continuous variables data"

def handle(self, *args, **options):
import_patients("./data/patient_information.csv") # path to the csv file
self.stdout.write(self.style.SUCCESS("Successfully imported patient data"))
update_or_create_continuous_variables()
self.stdout.write(
self.style.SUCCESS(
"Successfully imported patient data and updated continuous variables data"
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 5.0.1 on 2024-09-12 16:54

import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('template', '0010_merge_20240710_1548'),
]

operations = [
migrations.CreateModel(
name='ContinuousVariable',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.CharField(choices=[('SpO2', 'Spo2'), ('BPM', 'Heart Rate')], unique=True)),
('function', models.CharField(choices=[('linear', 'Linear'), ('increment', 'Increment'), ('decrement', 'Decrement')])),
('exceptions', models.JSONField()),
],
options={
'abstract': False,
},
),
]
5 changes: 3 additions & 2 deletions backend/dps_training_k/template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .action import Action
from .continuous_variable import ContinuousVariable
from .logic_node import LogicNode
from .material import Material
from .patient_information import PatientInformation
from .patient_state import PatientState
from .state_transition import StateTransition
from .subcondition import Subcondition
from .logic_node import LogicNode
from .material import Material
21 changes: 21 additions & 0 deletions backend/dps_training_k/template/models/continuous_variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import models

from helpers.models import UUIDable


class ContinuousVariable(UUIDable, models.Model):
class Variable(models.TextChoices):
SPO2 = "SpO2"
HEART_RATE = "BPM"

class Function(models.TextChoices):
LINEAR = "linear"
INCREMENT = "increment"
DECREMENT = "decrement"

name = models.CharField(choices=Variable.choices, unique=True)
function = models.CharField(choices=Function.choices)
exceptions = models.JSONField()

def __str__(self):
return f"Continuous variable called {self.name}"

0 comments on commit 0564c32

Please sign in to comment.