This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
biomon/src/biomon/forms.py

81 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
'''
biomon - Signs monitoring and patient management application
Copyright (C) 2015 Entr'ouvert
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import simplejson as json
from django import forms
from django.utils.translation import ugettext_lazy as _
from . import models
class MainForm(forms.ModelForm):
class Meta:
model = models.Patient
fields = ['firstname', 'lastname', 'sex', 'birthdate', 'monitoring_place',
'medical_comment', 'enabled']
class SimpleAlertProfileForm(forms.ModelForm):
hr_max_critical = forms.IntegerField(
label=_(u'Maximum critical heartrate'), required=False)
hr_min_critical = forms.IntegerField(
label=_(u'Minimum critical heartrate'), required=False)
hr_max_dangerous = forms.IntegerField(
label=_(u'Maximum dangerous heartrate'), required=False)
hr_min_dangerous = forms.IntegerField(
label=_(u'Minimum dangerous heartrate'), required=False)
t_max_critical = forms.DecimalField(
label=_(u'Maximum critical temperature'),
max_digits=5, decimal_places=2, localize=True, required=False)
t_min_critical = forms.DecimalField(
label=_(u'Minimum critical temperature'),
max_digits=5, decimal_places=2, localize=True, required=False)
t_max_dangerous = forms.DecimalField(
label=_(u'Maximum dangerous temperature'),
max_digits=5, decimal_places=2, localize=True, required=False)
t_min_dangerous = forms.DecimalField(
label=_(u'Minimum dangerous temperature'),
max_digits=5, decimal_places=2, localize=True,required=False)
class Meta:
model = models.Patient
fields = ['simple_alert_profile']
widgets = {'simple_alert_profile': forms.HiddenInput()}
def __init__(self, *args, **kwargs):
super(SimpleAlertProfileForm, self).__init__(*args, **kwargs)
if self.instance and self.instance.get_simple_alert_profile():
for key, value in self.instance.get_simple_alert_profile().items():
if value is not None:
self.fields[key].initial = value
def clean(self):
cleaned_data = super(SimpleAlertProfileForm, self).clean()
sap = {}
for k in self.fields.items():
if cleaned_data.get(k[0]):
sap[k[0]] = cleaned_data.get(k[0])
cleaned_data = dict()
cleaned_data['simple_alert_profile'] = json.dumps(sap)
return cleaned_data