Add in PatientDetail view context manual and matched automatic checkings.

This commit is contained in:
Mikaël Ates 2016-01-18 18:09:24 +01:00
parent 2f5db7a6c1
commit fb708c2549
1 changed files with 18 additions and 0 deletions

View File

@ -20,6 +20,8 @@
'''
from datetime import datetime
from django.views.generic import (TemplateView, FormView, View, ListView,
CreateView, UpdateView, DeleteView)
from django.contrib.auth import authenticate, login, logout
@ -34,6 +36,8 @@ from django.http import JsonResponse
from . import cbv
from . import models
from . import forms
from . import whisper_backend
from . import time_utils
from medibot import models as medibot_models
LAST_PATIENT_COOKIE = 'last-patient'
@ -148,6 +152,20 @@ class PatientDetail(cbv.MultiUpdateView):
pk=int(self.request.COOKIES.get(LAST_PATIENT_COOKIE)))
except:
pass
def process(subject, metric, values, lookup_range=600):
backend = whisper_backend.WhisperBackend(subject, metric)
l = []
for value in values:
timestamp = time_utils.unix_time(datetime.combine(value.date, value.time))
l.append((value, backend.get_closest(timestamp=timestamp, lookup_range=lookup_range)))
return l
subject = str(self.get_object().id)
metric = settings.WHISPER_HEARTRATE_METRIC
values = models.HeartrateCheck.objects.filter(patient=self.get_object()).order_by('-date').order_by('-time')
context['hr_checks'] = process(subject, metric, values)
metric = settings.WHISPER_TEMPERATURE_METRIC
values = models.TemperatureCheck.objects.filter(patient=self.get_object()).order_by('-date').order_by('-time')
context['t_checks'] = process(subject, metric, values)
context['display_alert_profile'] = settings.DISPLAY_ALERT_PROFILE
context['default_episode_duration'] = settings.DEFAULT_EPISODE_DURATION
return context