-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#330 backend: add continuousVariable model and data
- Loading branch information
1 parent
66dbdf5
commit 0564c32
Showing
7 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
backend/dps_training_k/template/migrations/0011_continuousvariable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
backend/dps_training_k/template/models/continuous_variable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |