Skip to content

Commit

Permalink
Merge branch 'release/0.3.26' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Aug 22, 2024
2 parents 265284d + d9cb0bc commit b05c8b1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changes
-------

0.3.26
------
- add signal to recalculate Endpoint record if either model
GlucoseFBG or Glucose is saved.
- queue message on subject dashboard if subject reaches the protocol
glucose / DM endpoint.

0.3.25
------
- refactor GlucoseEndpointsByDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,14 @@ def merge_with_final_endpoints(self):
self.df = self.df.sort_values(by=["subject_identifier", "fbg_datetime"])
self.df = self.df.reset_index(drop=True)

def to_model(self, model: str | None = None, subject_identifiers: list[str] | None = None):
def to_model(self):
"""Write endpoint_only_df to the Endpoints model"""
df = self.endpoint_only_df
model = model or "meta_reports.endpoints"
model = "meta_reports.endpoints"
now = get_utcnow()
model_cls = django_apps.get_model(model)
if subject_identifiers:
model_cls.objects.filter(subject_identifier__in=subject_identifiers).delete()
if self.subject_identifiers:
model_cls.objects.filter(subject_identifier__in=self.subject_identifiers).delete()
else:
model_cls.objects.all().delete()
created = 0
Expand Down
26 changes: 26 additions & 0 deletions meta_dashboard/views/subject/dashboard/dashboard_view.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
from typing import Any

from django.core.checks import messages
from django.core.exceptions import ObjectDoesNotExist
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from edc_subject_dashboard.views import SubjectDashboardView

from meta_reports.models import Endpoints, GlucoseSummary


class DashboardView(SubjectDashboardView):
consent_model = "meta_consent.subjectconsentv1"
navbar_selected_item = "consented_subject"
visit_model = "meta_subject.subjectvisit"
history_button_label = _("Audit")

def get_context_data(self, **kwargs) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
try:
Endpoints.objects.get(subject_identifier=self.subject_identifier)
except ObjectDoesNotExist:
pass
else:
url = reverse("meta_reports_admin:meta_reports_glucosesummary_changelist")
url = f"{url}?q={self.subject_identifier}"
message = _(
format_html(
f"Subject has reached the protocol endpoint. "
f'See <A href="{url}">{GlucoseSummary._meta.verbose_name}</A>'
)
)
self.message_user(message, level=messages.WARNING)
return context
2 changes: 1 addition & 1 deletion meta_reports/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def update_endpoints_table(subject_identifiers: list[str] | None = None):
subject_identifiers = []
cls = GlucoseEndpointsByDate(subject_identifiers=subject_identifiers)
cls.run()
return cls.to_model(subject_identifiers=subject_identifiers)
return cls.to_model()
1 change: 1 addition & 0 deletions meta_subject/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .sf12 import Sf12
from .signals import (
study_medication_on_pre_save,
update_glucose_endpoints_for_subject_on_post_save,
update_pregnancy_notification_on_delivery_post_save,
update_schedule_on_delivery_post_save,
)
Expand Down
19 changes: 19 additions & 0 deletions meta_subject/models/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from meta_pharmacy.constants import METFORMIN
from meta_visit_schedule.constants import SCHEDULE_PREGNANCY

from . import Glucose, GlucoseFbg
from .delivery import Delivery
from .study_medication import StudyMedication
from .subject_visit import SubjectVisit
Expand Down Expand Up @@ -105,3 +106,21 @@ def update_schedule_on_delivery_post_save(sender, instance, raw, **kwargs):
subject_identifier=instance.subject_identifier,
offschedule_datetime=offschedule_datetime,
)


@receiver(
post_save,
weak=False,
dispatch_uid="update_glucose_endpoints_for_subject_on_post_save",
)
def update_glucose_endpoints_for_subject_on_post_save(
sender, instance, raw, update_fields, **kwargs
):
if not raw and not update_fields and sender in [Glucose, GlucoseFbg]:
from meta_analytics.dataframes import GlucoseEndpointsByDate

cls = GlucoseEndpointsByDate(
subject_identifiers=[instance.subject_visit.subject_identifier]
)
cls.run()
cls.to_model()

0 comments on commit b05c8b1

Please sign in to comment.