Rename meds to health
Add more health related models Add activity categories
This commit is contained in:
parent
1d3251d886
commit
431f7acba2
12 changed files with 139 additions and 44 deletions
5
health/apps.py
Normal file
5
health/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class HealthConfig(AppConfig):
|
||||
name = 'health'
|
101
health/models.py
Normal file
101
health/models.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils import timezone
|
||||
|
||||
from datetime import time, date
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
class MedicationSettings(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
|
||||
morning_from = models.TimeField(default=time(6))
|
||||
morning_till = models.TimeField(default=time(10))
|
||||
|
||||
noon_from = models.TimeField(default=time(12))
|
||||
noon_till = models.TimeField(default=time(14))
|
||||
|
||||
evening_from = models.TimeField(default=time(19))
|
||||
evening_till = models.TimeField(default=time(21))
|
||||
|
||||
night_from = models.TimeField(default=time(22))
|
||||
night_till = models.TimeField(default=time(23))
|
||||
|
||||
notifications = models.BooleanField(default=True)
|
||||
refill_reminder = models.PositiveSmallIntegerField(default=7)
|
||||
|
||||
class Medication(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
name = models.CharField(max_length=128)
|
||||
icon = models.CharField(max_length=64, default="fas fa-tablets")
|
||||
|
||||
supply = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
default_refill = models.PositiveSmallIntegerField(default=1)
|
||||
|
||||
prn = models.BooleanField(default=False)
|
||||
remarks = models.TextField(null=True, blank=True)
|
||||
|
||||
class MedicationSchedule(models.Model):
|
||||
class ScheduleChoices(models.IntegerChoices):
|
||||
DAYS = 0
|
||||
WEEKS = 1
|
||||
MONTHS = 2
|
||||
|
||||
medication = models.ForeignKey(Medication, models.CASCADE)
|
||||
|
||||
cycle_type = models.IntegerField(choices=ScheduleChoices.choices)
|
||||
cycle_count = models.IntegerField(default=1)
|
||||
|
||||
first = models.DateField(default=date.today)
|
||||
last = models.DateField(null=True, blank=True)
|
||||
|
||||
morning = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
noon = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
evening = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
night = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
|
||||
def next(self, today=True):
|
||||
if timezone.now().date() > self.last:
|
||||
return False
|
||||
|
||||
cur = self.first
|
||||
|
||||
while True:
|
||||
if (timezone.now().date() < cur) or (today and timezone.now().date() == cur):
|
||||
return cur
|
||||
|
||||
cur += relativedelta(
|
||||
days=self.cycle_count if self.cycle_type == ScheduleChoices.DAYS else 0,
|
||||
weeks=self.cycle_count if self.cycle_type == ScheduleChoices.WEEKS else 0,
|
||||
months=self.cycle_count if self.cycle_type == ScheduleChoices.MONTHS else 0
|
||||
)
|
||||
|
||||
if cur > self.last:
|
||||
return False
|
||||
|
||||
class MedicationCalendar(models.Model):
|
||||
class TimeChoices(models.IntegerChoices):
|
||||
MORNING = 0
|
||||
NOON = 1
|
||||
EVENING = 2
|
||||
NIGHT = 3
|
||||
|
||||
date = models.DateField(default=date.today)
|
||||
time = models.IntegerField(choices=TimeChoices.choices)
|
||||
|
||||
medication = models.ForeignKey(Medication, models.CASCADE)
|
||||
schedule = models.ForeignKey(MedicationSchedule, models.SET_NULL, null=True)
|
||||
|
||||
count = models.DecimalField(max_digits=5, decimal_places=2)
|
||||
taken = models.BooleanField(default=False)
|
||||
|
||||
class HealthParameter(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
name = models.CharField(max_length=128)
|
||||
icon = models.CharField(max_length=64, default="fas fa-heart")
|
||||
unit = models.CharField(max_length=12, null=True, blank=True)
|
||||
|
||||
class HealthRecord(models.Model):
|
||||
parameter = models.ForeignKey(HealthParameter, models.CASCADE)
|
||||
value = models.DecimalField(max_digits=12, decimal_places=6, null=True, blank=True)
|
||||
comment = models.TextField(null=True, blank=True)
|
|
@ -24,7 +24,7 @@ INSTALLED_APPS = [
|
|||
'cronhandler',
|
||||
'cbt',
|
||||
'dreams',
|
||||
'meds',
|
||||
'health',
|
||||
'friends',
|
||||
'habits',
|
||||
]
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MedsConfig(AppConfig):
|
||||
name = 'meds'
|
|
@ -1,37 +0,0 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from datetime import time
|
||||
|
||||
class MedicationSettings(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
|
||||
morning_from = models.TimeField(default=time(6))
|
||||
morning_till = models.TimeField(default=time(10))
|
||||
|
||||
noon_from = models.TimeField(default=time(12))
|
||||
noon_till = models.TimeField(default=time(14))
|
||||
|
||||
evening_from = models.TimeField(default=time(19))
|
||||
evening_till = models.TimeField(default=time(21))
|
||||
|
||||
night_from = models.TimeField(default=time(22))
|
||||
night_till = models.TimeField(default=time(23))
|
||||
|
||||
notifications = models.BooleanField(default=True)
|
||||
refill_reminder = models.PositiveSmallIntegerField(default=7)
|
||||
|
||||
class Medication(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
name = models.CharField(max_length=128)
|
||||
icon = models.CharField(max_length=64, default="fas fa-tablets")
|
||||
|
||||
supply = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
default_refill = models.PositiveSmallIntegerField(null=True, blank=True)
|
||||
|
||||
morning = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
noon = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
evening = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
night = models.DecimalField(null=True, blank=True, max_digits=5, decimal_places=2)
|
||||
|
||||
remarks = models.TextField(null=True, blank=True)
|
|
@ -37,11 +37,21 @@ class Status(models.Model):
|
|||
def __str__(self):
|
||||
return self.short_text
|
||||
|
||||
class ActivityCategory(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
name = models.CharField(max_length=64)
|
||||
icon = models.CharField(default="fas fa-check", max_length=64)
|
||||
color = ColorField(default="#000000")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Activity(models.Model):
|
||||
user = models.ForeignKey(get_user_model(), models.CASCADE)
|
||||
name = models.CharField(max_length=64)
|
||||
icon = models.CharField(default="fas fa-check", max_length=64)
|
||||
color = ColorField(default="#000000")
|
||||
category = models.ForeignKey(ActivityCategory, models.SET_NULL, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% extends "frontend/base.html" %}
|
||||
{% load mood_categories %}
|
||||
{% block "content" %}
|
||||
|
||||
{% if form.errors %}
|
||||
|
@ -33,9 +34,22 @@
|
|||
</select></td></tr>
|
||||
|
||||
<tr><th><label for="activities">Activities:</label></th><td>
|
||||
{% for activity in request.user.activity_set.all %}
|
||||
{% for activitycategory in request.user.activitycategory_set.all %}
|
||||
|
||||
<b>{{ activitycategory.name }}</b>
|
||||
|
||||
{% for activity in activitycategory.activity_set.all %}
|
||||
<input type="checkbox" {% if activity in object.activity_set %}checked{% endif %} value="{{ activity.id }}" name="activities"> <i class="{{ activity.icon }}" style="color:{{ activity.color }};"></i> {{ activity }}<br>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
<b>Uncategorized activities</b>
|
||||
|
||||
{% for activitycategory in request.user.activitycategory_set.all %}
|
||||
{% for activity in activitycategory.activity_set.all %}
|
||||
<input type="checkbox" {% if activity in object.activity_set %}checked{% endif %} value="{{ activity.id }}" name="activities"> <i class="{{ activity.icon }}" style="color:{{ activity.color }};"></i> {{ activity }}<br>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</td></tr>
|
||||
|
||||
<tr><th><label for="id_uploads">Uploads:</label></th><td><input type="file" name="uploads" id="id_uploads" multiple="multiple"></td></tr>
|
||||
|
|
7
mood/templatetags/mood_categories.py
Normal file
7
mood/templatetags/mood_categories.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def other_activities(context):
|
||||
return context["user"].activity_set.filter(category=None)
|
Loading…
Reference in a new issue