Skip to content
Snippets Groups Projects
Commit ef63ec45 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

set of notification types is configurable via db

parent fbb9c70f
No related branches found
No related tags found
1 merge request!104Resolve "Notifications should be customized by study"
Pipeline #
...@@ -52,27 +52,27 @@ def create_study(name="test"): ...@@ -52,27 +52,27 @@ def create_study(name="test"):
return Study.objects.create(name=name, columns=study_columns, notification_parameters=notification_parameters) return Study.objects.create(name=name, columns=study_columns, notification_parameters=notification_parameters)
def create_empty_study(name="test"): def create_empty_notification_parametres():
study_columns = StudyColumns.objects.create( return StudyNotificationParameters.objects.create(
postponed=False, exceeded_visits_visible=False,
datetime_contact_reminder=False, unfinished_visits_visible=False,
type=False, approaching_visits_without_appointments_visible=False,
default_location=False, unfinished_appointments_visible=False,
flying_team=False, visits_with_missing_appointments_visible=False,
screening_number=False, subject_no_visits_visible=False,
nd_number=False, approaching_visits_for_mail_contact_visible=False,
mpower_id=False, subject_require_contact_visible=False,
comments=False, missing_redcap_subject_visible=False,
referral=False, inconsistent_redcap_subject_visible=False,
diagnosis=False,
year_of_diagnosis=False,
information_sent=False,
pd_in_family=False,
resigned=False,
resign_reason=False
) )
result = create_study()
def create_empty_study(name="test"):
study_columns = create_empty_study_columns()
notification_parameters = create_empty_notification_parametres()
result = create_study(name)
result.columns = study_columns result.columns = study_columns
result.notification_parameters = notification_parameters
result.save() result.save()
return result return result
......
...@@ -2,11 +2,11 @@ import datetime ...@@ -2,11 +2,11 @@ import datetime
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from web.models import Appointment, Location, AppointmentTypeLink from web.models import Appointment, Location, AppointmentTypeLink, Study
from web.models.constants import GLOBAL_STUDY_ID
from web.tests import LoggedInTestCase from web.tests import LoggedInTestCase
from web.tests.functions import create_appointment, create_location, create_worker, create_appointment_type from web.tests.functions import create_appointment, create_location, create_worker, create_appointment_type, \
from web.tests.functions import create_study_subject create_empty_notification_parametres, create_study_subject, create_visit
from web.tests.functions import create_visit
from web.views.notifications import \ from web.views.notifications import \
get_approaching_visits_for_mail_contact, \ get_approaching_visits_for_mail_contact, \
get_approaching_visits_for_mail_contact_count, \ get_approaching_visits_for_mail_contact_count, \
...@@ -94,6 +94,17 @@ class NotificationViewTests(LoggedInTestCase): ...@@ -94,6 +94,17 @@ class NotificationViewTests(LoggedInTestCase):
self.assertTrue(isinstance(result[1], list)) self.assertTrue(isinstance(result[1], list))
self.assertTrue(len(result[1]) > 0) self.assertTrue(len(result[1]) > 0)
def test_get_notifications_with_empty_study_notification(self):
study = Study.objects.filter(id=GLOBAL_STUDY_ID)[0]
study.notification_parameters = create_empty_notification_parametres()
study.save()
create_worker(self.user)
result = get_notifications(self.user)
self.assertEquals(0, result[0])
self.assertEquals(0, len(result[1]))
def test_get_visits_without_appointments_count_2(self): def test_get_visits_without_appointments_count_2(self):
appointment_type = create_appointment_type() appointment_type = create_appointment_type()
original_notification = get_visits_without_appointments_count(self.user) original_notification = get_visits_without_appointments_count(self.user)
......
# coding=utf-8 # coding=utf-8
import datetime import datetime
from django.utils import timezone
from django.contrib.auth.models import User, AnonymousUser from django.contrib.auth.models import User, AnonymousUser
from django.db.models import Count, Case, When from django.db.models import Count, Case, When
from django.utils import timezone
from web.models import Study
from web.models.constants import GLOBAL_STUDY_ID
from ..models import Worker, StudySubject, Visit, Appointment, Location, MissingSubject, InconsistentSubject from ..models import Worker, StudySubject, Visit, Appointment, Location, MissingSubject, InconsistentSubject
...@@ -115,16 +117,27 @@ def get_notifications(the_user): ...@@ -115,16 +117,27 @@ def get_notifications(the_user):
notifications = [] notifications = []
count = 0 count = 0
if worker is not None: if worker is not None:
notifications.append(get_exceeded_visit_notifications_count(worker)) study = Study.objects.filter(id=GLOBAL_STUDY_ID)[0]
notifications.append(get_visits_without_appointments_count(worker)) if study.notification_parameters.exceeded_visits_visible:
notifications.append(get_approaching_visits_without_appointments_count(worker)) notifications.append(get_exceeded_visit_notifications_count(worker))
notifications.append(get_unfinished_appointments_count(worker)) if study.notification_parameters.unfinished_visits_visible:
notifications.append(get_visits_with_missing_appointments_count(worker)) notifications.append(get_visits_without_appointments_count(worker))
notifications.append(get_subject_with_no_visit_notifications_count(worker)) if study.notification_parameters.approaching_visits_without_appointments_visible:
notifications.append(get_approaching_visits_for_mail_contact_count(worker)) notifications.append(get_approaching_visits_without_appointments_count(worker))
notifications.append(get_subjects_with_reminder_count(worker)) if study.notification_parameters.unfinished_appointments_visible:
notifications.append(get_missing_redcap_subject_notification_count(worker)) notifications.append(get_unfinished_appointments_count(worker))
notifications.append(get_inconsistent_redcap_subject_notification_count(worker)) if study.notification_parameters.visits_with_missing_appointments_visible:
notifications.append(get_visits_with_missing_appointments_count(worker))
if study.notification_parameters.subject_no_visits_visible:
notifications.append(get_subject_with_no_visit_notifications_count(worker))
if study.notification_parameters.approaching_visits_for_mail_contact_visible:
notifications.append(get_approaching_visits_for_mail_contact_count(worker))
if study.notification_parameters.subject_require_contact_visible:
notifications.append(get_subjects_with_reminder_count(worker))
if study.notification_parameters.missing_redcap_subject_visible:
notifications.append(get_missing_redcap_subject_notification_count(worker))
if study.notification_parameters.inconsistent_redcap_subject_visible:
notifications.append(get_inconsistent_redcap_subject_notification_count(worker))
for notification in notifications: for notification in notifications:
count += notification.count count += notification.count
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment