merge experimental #1

Merged
jlobbes merged 25 commits from experimental into master 2023-08-17 15:16:51 +01:00
3 changed files with 114 additions and 1 deletions
Showing only changes of commit 0501977cdf - Show all commits

View File

@ -65,4 +65,57 @@ class MewsRecord(models.Model):
blood_pressure_record = models.ForeignKey(BloodPressureRecord, on_delete=models.CASCADE) blood_pressure_record = models.ForeignKey(BloodPressureRecord, on_delete=models.CASCADE)
body_temp_record = models.ForeignKey(BodyTempRecord, on_delete=models.CASCADE) body_temp_record = models.ForeignKey(BodyTempRecord, on_delete=models.CASCADE)
heart_rate_record = models.ForeignKey(HeartRateRecord, on_delete=models.CASCADE) heart_rate_record = models.ForeignKey(HeartRateRecord, on_delete=models.CASCADE)
respiration_score_record = models.ForeignKey(Spo2LevelRecord, on_delete=models.CASCADE) spo2_level_record = models.ForeignKey(Spo2LevelRecord, on_delete=models.CASCADE)
respiration_score_record = models.ForeignKey(RespirationScoreRecord, on_delete=models.CASCADE)
@staticmethod
def calculate_mews_value(
blood_pressure_systolic_value_mmhg: int,
body_temp_value_celsius: float,
heart_rate_value_bpm: int,
spo2_level_value_percent: int,
respiration_score_value_severity: int,
):
mews_value = 0
if blood_pressure_systolic_value_mmhg <= 70:
mews_value += 3
elif blood_pressure_systolic_value_mmhg <= 80:
mews_value += 2
elif blood_pressure_systolic_value_mmhg <= 100:
mews_value += 1
elif blood_pressure_systolic_value_mmhg < 200:
mews_value += 0
else:
mews_value += 2
if heart_rate_value_bpm < 40:
mews_value += 2
elif heart_rate_value_bpm <= 50:
mews_value += 1
elif heart_rate_value_bpm <= 100:
mews_value += 0
elif heart_rate_value_bpm <= 110:
mews_value += 1
elif heart_rate_value_bpm < 130:
mews_value += 2
else:
mews_value += 3
if respiration_score_value_severity == 1:
mews_value += 1
elif respiration_score_value_severity == 2:
mews_value += 2
if spo2_level_value_percent < 90:
mews_value += 2
elif spo2_level_value_percent < 95:
mews_value += 1
if body_temp_value_celsius < 35:
mews_value += 2
elif body_temp_value_celsius <= 38.4:
mews_value += 0
else:
mews_value += 2

View File

@ -5,4 +5,5 @@ from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="home"), path("", views.index, name="home"),
path("dashboard/", views.dashboard, name="dashboard"), path("dashboard/", views.dashboard, name="dashboard"),
path("mews/status/", views.mews_status, name="mews-status"),
] ]

View File

@ -1,8 +1,67 @@
from datetime import timedelta
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.utils import timezone
from . import models
@require_http_methods(["GET"])
def index(request): def index(request):
return render(request, 'medwings/index.html') return render(request, 'medwings/index.html')
@require_http_methods(["GET"])
def dashboard(request): def dashboard(request):
return render(request, 'medwings/dashboard.html') return render(request, 'medwings/dashboard.html')
@require_http_methods(["GET"])
def mews_status(request):
if not request.user.is_authenticated:
return HttpResponse('Unauthorized', status=401)
request.user.apiaccount.update_records()
ten_minutes_ago = timezone.now() - timedelta(minutes=10)
blood_pressure_record = models.BloodPressureRecord.objects.filter(user=request.user).filter(recorded__gte=ten_minutes_ago).order_by('-recorded').first()
body_temp_record = models.BodyTempRecord.objects.filter(user=request.user).filter(recorded__gte=ten_minutes_ago).order_by('-recorded').first()
heart_rate_record = models.HeartRateRecord.objects.filter(user=request.user).filter(recorded__gte=ten_minutes_ago).order_by('-recorded').first()
spo2_level_record = models.Spo2LevelRecord.objects.filter(user=request.user).filter(recorded__gte=ten_minutes_ago).order_by('-recorded').first()
respiration_score_record = models.RespirationScoreRecord.objects.filter(user=request.user).filter(recorded__gte=ten_minutes_ago).order_by('-recorded').first()
data = {
'blood_pressure_value': blood_pressure_record.value_systolic_mmhg if blood_pressure_record else None,
'body_temp_value': body_temp_record.value_celsius if body_temp_record else None,
'heart_rate_value': heart_rate_record.value_bpm if heart_rate_record else None,
'spo2_level_value': spo2_level_record.value_percent if spo2_level_record else None,
'respiration_score_value': respiration_score_record.value_severity if respiration_score_record else None,
'mews_value': None,
}
if (blood_pressure_record
and body_temp_record
and heart_rate_record
and spo2_level_record
and respiration_score_record
):
mews_record = models.MewsRecord(
user=request.user, recorded=timezone.now(),
value_n=models.MewsRecord.calculate_mews_value(
blood_pressure_record.value_systolic_mmhg,
body_temp_record.value_celsius,
heart_rate_record.value_bpm,
spo2_level_record.value_percent,
respiration_score_record.value_severity
),
blood_pressure_record=blood_pressure_record,
body_temp_record=body_temp_record,
heart_rate_record=heart_rate_record,
respiration_score_record=respiration_score_record,
)
mews_record.save()
data['mews_value'] = mews_record.value_n
return JsonResponse(data)