2017-08-21 23:21:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django.views.generic.detail import DetailView
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
from babybuddy.mixins import PermissionRequiredMixin
|
2017-11-10 12:20:34 +00:00
|
|
|
from core import models
|
2017-08-21 23:21:08 +00:00
|
|
|
|
2017-11-10 12:20:34 +00:00
|
|
|
from . import graphs
|
2017-09-25 17:14:14 +00:00
|
|
|
|
|
|
|
|
2022-05-26 04:27:21 +00:00
|
|
|
class BMIChangeChildReport(PermissionRequiredMixin, DetailView):
|
2022-02-26 21:23:43 +00:00
|
|
|
"""
|
2022-05-26 04:27:21 +00:00
|
|
|
Graph of BMI change over time.
|
2022-02-26 21:23:43 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
model = models.Child
|
|
|
|
permission_required = ("core.view_child",)
|
2022-05-26 04:27:21 +00:00
|
|
|
template_name = "reports/bmi_change.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(BMIChangeChildReport, self).get_context_data(**kwargs)
|
|
|
|
child = context["object"]
|
|
|
|
objects = models.BMI.objects.filter(child=child)
|
|
|
|
if objects:
|
|
|
|
context["html"], context["js"] = graphs.bmi_change(objects)
|
|
|
|
return context
|
2022-02-26 21:23:43 +00:00
|
|
|
|
|
|
|
|
2022-05-26 04:27:21 +00:00
|
|
|
class ChildReportList(PermissionRequiredMixin, DetailView):
|
2022-03-03 03:00:56 +00:00
|
|
|
"""
|
2022-05-26 04:27:21 +00:00
|
|
|
Listing of available reports for a child.
|
2022-03-03 03:00:56 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
model = models.Child
|
|
|
|
permission_required = ("core.view_child",)
|
2022-05-26 04:27:21 +00:00
|
|
|
template_name = "reports/report_list.html"
|
2022-03-03 03:00:56 +00:00
|
|
|
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
class DiaperChangeAmounts(PermissionRequiredMixin, DetailView):
|
2020-01-26 22:12:27 +00:00
|
|
|
"""
|
|
|
|
Graph of diaper "amounts" - measurements of urine output.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2020-01-26 22:12:27 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/diaperchange_amounts.html"
|
2020-01-26 22:12:27 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(DiaperChangeAmounts, self).get_context_data(**kwargs)
|
2022-02-10 00:00:30 +00:00
|
|
|
child = context["object"]
|
2020-01-26 22:12:27 +00:00
|
|
|
changes = models.DiaperChange.objects.filter(child=child, amount__gt=0)
|
|
|
|
if changes and changes.count() > 0:
|
2022-02-10 00:00:30 +00:00
|
|
|
context["html"], context["js"] = graphs.diaperchange_amounts(changes)
|
2020-01-26 22:12:27 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
class DiaperChangeLifetimesChildReport(PermissionRequiredMixin, DetailView):
|
2017-10-28 00:46:48 +00:00
|
|
|
"""
|
2017-11-10 12:20:34 +00:00
|
|
|
Graph of diaper "lifetimes" - time between diaper changes.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-11-10 12:20:34 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/diaperchange_lifetimes.html"
|
2017-09-25 17:14:14 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-10 00:00:30 +00:00
|
|
|
context = super(DiaperChangeLifetimesChildReport, self).get_context_data(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
child = context["object"]
|
2017-11-10 12:20:34 +00:00
|
|
|
changes = models.DiaperChange.objects.filter(child=child)
|
2017-10-28 00:46:48 +00:00
|
|
|
if changes and changes.count() > 1:
|
2022-02-10 00:00:30 +00:00
|
|
|
context["html"], context["js"] = graphs.diaperchange_lifetimes(changes)
|
2017-09-25 17:14:14 +00:00
|
|
|
return context
|
2017-08-23 13:04:05 +00:00
|
|
|
|
2017-08-24 18:54:01 +00:00
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
class DiaperChangeTypesChildReport(PermissionRequiredMixin, DetailView):
|
2017-10-28 00:46:48 +00:00
|
|
|
"""
|
2017-11-10 12:20:34 +00:00
|
|
|
Graph of diaper changes by day and type.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-11-10 12:20:34 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/diaperchange_types.html"
|
2017-08-23 01:37:10 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-10 00:00:30 +00:00
|
|
|
context = super(DiaperChangeTypesChildReport, self).get_context_data(**kwargs)
|
|
|
|
child = context["object"]
|
2017-11-10 12:20:34 +00:00
|
|
|
changes = models.DiaperChange.objects.filter(child=child)
|
2017-10-28 00:46:48 +00:00
|
|
|
if changes:
|
2022-02-10 00:00:30 +00:00
|
|
|
context["html"], context["js"] = graphs.diaperchange_types(changes)
|
2017-08-24 18:54:01 +00:00
|
|
|
return context
|
2017-08-23 01:37:10 +00:00
|
|
|
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
class FeedingAmountsChildReport(PermissionRequiredMixin, DetailView):
|
2019-05-29 17:05:30 +00:00
|
|
|
"""
|
|
|
|
Graph of daily feeding amounts over time.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2019-05-29 17:05:30 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/feeding_amounts.html"
|
2019-05-29 17:05:30 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(FeedingAmountsChildReport, self).__init__()
|
2022-02-10 00:00:30 +00:00
|
|
|
self.html = ""
|
|
|
|
self.js = ""
|
2019-05-29 17:05:30 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-10 00:00:30 +00:00
|
|
|
context = super(FeedingAmountsChildReport, self).get_context_data(**kwargs)
|
|
|
|
child = context["object"]
|
2019-05-29 17:05:30 +00:00
|
|
|
instances = models.Feeding.objects.filter(child=child)
|
|
|
|
if instances:
|
2022-02-10 00:00:30 +00:00
|
|
|
context["html"], context["js"] = graphs.feeding_amounts(instances)
|
2019-05-29 17:05:30 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
class FeedingDurationChildReport(PermissionRequiredMixin, DetailView):
|
2017-11-30 02:28:54 +00:00
|
|
|
"""
|
|
|
|
Graph of feeding durations over time.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-11-30 02:28:54 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/feeding_duration.html"
|
2017-11-30 02:28:54 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(FeedingDurationChildReport, self).__init__()
|
2022-02-10 00:00:30 +00:00
|
|
|
self.html = ""
|
|
|
|
self.js = ""
|
2017-11-30 02:28:54 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-10 00:00:30 +00:00
|
|
|
context = super(FeedingDurationChildReport, self).get_context_data(**kwargs)
|
|
|
|
child = context["object"]
|
2017-11-30 02:28:54 +00:00
|
|
|
instances = models.Feeding.objects.filter(child=child)
|
|
|
|
if instances:
|
2022-02-10 00:00:30 +00:00
|
|
|
context["html"], context["js"] = graphs.feeding_duration(instances)
|
2017-11-30 02:28:54 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2022-05-26 04:27:21 +00:00
|
|
|
class HeadCircumferenceChangeChildReport(PermissionRequiredMixin, DetailView):
|
|
|
|
"""
|
|
|
|
Graph of head circumference change over time.
|
|
|
|
"""
|
|
|
|
|
|
|
|
model = models.Child
|
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/head_circumference_change.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(HeadCircumferenceChangeChildReport, self).get_context_data(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
child = context["object"]
|
|
|
|
objects = models.HeadCircumference.objects.filter(child=child)
|
|
|
|
if objects:
|
|
|
|
(
|
|
|
|
context["html"],
|
|
|
|
context["js"],
|
|
|
|
) = graphs.head_circumference_change(objects)
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class HeightChangeChildReport(PermissionRequiredMixin, DetailView):
|
|
|
|
"""
|
|
|
|
Graph of height change over time.
|
|
|
|
"""
|
|
|
|
|
|
|
|
model = models.Child
|
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/height_change.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(HeightChangeChildReport, self).get_context_data(**kwargs)
|
|
|
|
child = context["object"]
|
|
|
|
objects = models.Height.objects.filter(child=child)
|
|
|
|
if objects:
|
|
|
|
context["html"], context["js"] = graphs.height_change(objects)
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class PumpingAmounts(PermissionRequiredMixin, DetailView):
|
|
|
|
"""
|
|
|
|
Graph of pumping milk amounts collected.
|
|
|
|
"""
|
|
|
|
|
|
|
|
model = models.Child
|
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/pumping_amounts.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(PumpingAmounts, self).get_context_data(**kwargs)
|
|
|
|
child = context["object"]
|
|
|
|
changes = models.Pumping.objects.filter(child=child)
|
|
|
|
if changes and changes.count() > 0:
|
|
|
|
context["html"], context["js"] = graphs.pumping_amounts(changes)
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2022-02-26 21:23:43 +00:00
|
|
|
class SleepPatternChildReport(PermissionRequiredMixin, DetailView):
|
2021-10-04 19:37:11 +00:00
|
|
|
"""
|
2022-02-26 21:23:43 +00:00
|
|
|
Graph of sleep pattern comparing sleep to wake times by day.
|
2021-10-04 19:37:11 +00:00
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2021-10-04 19:37:11 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
2022-02-26 21:23:43 +00:00
|
|
|
template_name = "reports/sleep_pattern.html"
|
2021-10-04 19:37:11 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2022-02-26 21:23:43 +00:00
|
|
|
super(SleepPatternChildReport, self).__init__()
|
2022-02-10 00:00:30 +00:00
|
|
|
self.html = ""
|
|
|
|
self.js = ""
|
2021-10-04 19:37:11 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-26 21:23:43 +00:00
|
|
|
context = super(SleepPatternChildReport, self).get_context_data(**kwargs)
|
2022-02-10 00:00:30 +00:00
|
|
|
child = context["object"]
|
2022-02-26 21:23:43 +00:00
|
|
|
instances = models.Sleep.objects.filter(child=child).order_by("start")
|
2021-10-04 19:37:11 +00:00
|
|
|
if instances:
|
2022-02-26 21:23:43 +00:00
|
|
|
context["html"], context["js"] = graphs.sleep_pattern(instances)
|
2021-10-04 19:37:11 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2022-02-26 21:23:43 +00:00
|
|
|
class SleepTotalsChildReport(PermissionRequiredMixin, DetailView):
|
2017-10-28 00:46:48 +00:00
|
|
|
"""
|
2022-02-26 21:23:43 +00:00
|
|
|
Graph of total sleep by day.
|
2017-11-10 12:20:34 +00:00
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-11-10 12:20:34 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
2022-02-26 21:23:43 +00:00
|
|
|
template_name = "reports/sleep_totals.html"
|
2017-08-25 16:19:06 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2022-02-26 21:23:43 +00:00
|
|
|
super(SleepTotalsChildReport, self).__init__()
|
2022-02-10 00:00:30 +00:00
|
|
|
self.html = ""
|
|
|
|
self.js = ""
|
2017-08-25 16:19:06 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-26 21:23:43 +00:00
|
|
|
context = super(SleepTotalsChildReport, self).get_context_data(**kwargs)
|
2022-02-10 00:00:30 +00:00
|
|
|
child = context["object"]
|
|
|
|
instances = models.Sleep.objects.filter(child=child).order_by("start")
|
2017-10-28 00:46:48 +00:00
|
|
|
if instances:
|
2022-02-26 21:23:43 +00:00
|
|
|
context["html"], context["js"] = graphs.sleep_totals(instances)
|
2017-08-25 16:19:06 +00:00
|
|
|
return context
|
2017-09-13 15:53:32 +00:00
|
|
|
|
|
|
|
|
2022-02-26 21:23:43 +00:00
|
|
|
class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView):
|
2017-10-28 00:46:48 +00:00
|
|
|
"""
|
2022-02-26 21:23:43 +00:00
|
|
|
Graph of tummy time durations over time.
|
2017-11-10 12:20:34 +00:00
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-11-10 12:20:34 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
2022-02-26 21:23:43 +00:00
|
|
|
template_name = "reports/tummytime_duration.html"
|
2017-09-13 15:53:32 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2022-02-26 21:23:43 +00:00
|
|
|
super(TummyTimeDurationChildReport, self).__init__()
|
2022-02-10 00:00:30 +00:00
|
|
|
self.html = ""
|
|
|
|
self.js = ""
|
2017-09-13 15:53:32 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-02-26 21:23:43 +00:00
|
|
|
context = super(TummyTimeDurationChildReport, self).get_context_data(**kwargs)
|
2022-02-10 00:00:30 +00:00
|
|
|
child = context["object"]
|
2022-02-26 21:23:43 +00:00
|
|
|
instances = models.TummyTime.objects.filter(child=child)
|
2017-10-28 00:46:48 +00:00
|
|
|
if instances:
|
2022-02-26 21:23:43 +00:00
|
|
|
context["html"], context["js"] = graphs.tummytime_duration(instances)
|
2017-11-10 12:20:34 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2022-05-26 04:27:21 +00:00
|
|
|
class WeightChangeChildReport(PermissionRequiredMixin, DetailView):
|
2017-11-10 12:20:34 +00:00
|
|
|
"""
|
|
|
|
Graph of weight change over time.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-11-10 12:20:34 +00:00
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
permission_required = ("core.view_child",)
|
|
|
|
template_name = "reports/weight_change.html"
|
2017-11-10 12:20:34 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-05-26 04:27:21 +00:00
|
|
|
context = super(WeightChangeChildReport, self).get_context_data(**kwargs)
|
2022-02-10 00:00:30 +00:00
|
|
|
child = context["object"]
|
2017-11-10 12:20:34 +00:00
|
|
|
objects = models.Weight.objects.filter(child=child)
|
|
|
|
if objects:
|
2022-05-26 04:27:21 +00:00
|
|
|
context["html"], context["js"] = graphs.weight_change(objects)
|
2021-12-30 03:32:55 +00:00
|
|
|
return context
|