diff --git a/meds/__init__.py b/health/__init__.py similarity index 100% rename from meds/__init__.py rename to health/__init__.py diff --git a/meds/admin.py b/health/admin.py similarity index 100% rename from meds/admin.py rename to health/admin.py diff --git a/health/apps.py b/health/apps.py new file mode 100644 index 0000000..ea5593f --- /dev/null +++ b/health/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class HealthConfig(AppConfig): + name = 'health' diff --git a/health/models.py b/health/models.py new file mode 100644 index 0000000..a6264a0 --- /dev/null +++ b/health/models.py @@ -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) \ No newline at end of file diff --git a/meds/tests.py b/health/tests.py similarity index 100% rename from meds/tests.py rename to health/tests.py diff --git a/meds/views.py b/health/views.py similarity index 100% rename from meds/views.py rename to health/views.py diff --git a/kumify/settings.py b/kumify/settings.py index 34b9f9b..913d198 100644 --- a/kumify/settings.py +++ b/kumify/settings.py @@ -24,7 +24,7 @@ INSTALLED_APPS = [ 'cronhandler', 'cbt', 'dreams', - 'meds', + 'health', 'friends', 'habits', ] diff --git a/meds/apps.py b/meds/apps.py deleted file mode 100644 index cbe212b..0000000 --- a/meds/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class MedsConfig(AppConfig): - name = 'meds' diff --git a/meds/models.py b/meds/models.py deleted file mode 100644 index 759677e..0000000 --- a/meds/models.py +++ /dev/null @@ -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) \ No newline at end of file diff --git a/mood/models.py b/mood/models.py index 7ba28fa..6606b4b 100644 --- a/mood/models.py +++ b/mood/models.py @@ -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 diff --git a/mood/templates/mood/status_edit.html b/mood/templates/mood/status_edit.html index 9c39d1b..c53bb80 100644 --- a/mood/templates/mood/status_edit.html +++ b/mood/templates/mood/status_edit.html @@ -1,4 +1,5 @@ {% extends "frontend/base.html" %} +{% load mood_categories %} {% block "content" %} {% if form.errors %} @@ -33,9 +34,22 @@