diff --git a/smash/web/tests/functions.py b/smash/web/tests/functions.py index b9cd6189814fe60d3e56fb9bf2255f9f36e34359..b7089c3b332d4ad18a560b6ab15645b02517e5a4 100644 --- a/smash/web/tests/functions.py +++ b/smash/web/tests/functions.py @@ -52,27 +52,27 @@ def create_study(name="test"): return Study.objects.create(name=name, columns=study_columns, notification_parameters=notification_parameters) -def create_empty_study(name="test"): - study_columns = StudyColumns.objects.create( - postponed=False, - datetime_contact_reminder=False, - type=False, - default_location=False, - flying_team=False, - screening_number=False, - nd_number=False, - mpower_id=False, - comments=False, - referral=False, - diagnosis=False, - year_of_diagnosis=False, - information_sent=False, - pd_in_family=False, - resigned=False, - resign_reason=False +def create_empty_notification_parametres(): + return StudyNotificationParameters.objects.create( + exceeded_visits_visible=False, + unfinished_visits_visible=False, + approaching_visits_without_appointments_visible=False, + unfinished_appointments_visible=False, + visits_with_missing_appointments_visible=False, + subject_no_visits_visible=False, + approaching_visits_for_mail_contact_visible=False, + subject_require_contact_visible=False, + missing_redcap_subject_visible=False, + inconsistent_redcap_subject_visible=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.notification_parameters = notification_parameters result.save() return result diff --git a/smash/web/tests/view/test_notifications.py b/smash/web/tests/view/test_notifications.py index 031a225c754c4a41bb50bc81a3f8fe93f1c2b3fd..d25525fa92f0d4d459b39ea8a174c8f129154221 100644 --- a/smash/web/tests/view/test_notifications.py +++ b/smash/web/tests/view/test_notifications.py @@ -2,11 +2,11 @@ import datetime 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.functions import create_appointment, create_location, create_worker, create_appointment_type -from web.tests.functions import create_study_subject -from web.tests.functions import create_visit +from web.tests.functions import create_appointment, create_location, create_worker, create_appointment_type, \ + create_empty_notification_parametres, create_study_subject, create_visit from web.views.notifications import \ get_approaching_visits_for_mail_contact, \ get_approaching_visits_for_mail_contact_count, \ @@ -94,6 +94,17 @@ class NotificationViewTests(LoggedInTestCase): self.assertTrue(isinstance(result[1], list)) 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): appointment_type = create_appointment_type() original_notification = get_visits_without_appointments_count(self.user) diff --git a/smash/web/views/notifications.py b/smash/web/views/notifications.py index 53680ebc08c7953123dfdbf25b5b7bc037f26020..d6e8d62ff461acfbe5b7be0d758bb757adb75962 100644 --- a/smash/web/views/notifications.py +++ b/smash/web/views/notifications.py @@ -1,10 +1,12 @@ # coding=utf-8 import datetime -from django.utils import timezone from django.contrib.auth.models import User, AnonymousUser 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 @@ -115,16 +117,27 @@ def get_notifications(the_user): notifications = [] count = 0 if worker is not None: - notifications.append(get_exceeded_visit_notifications_count(worker)) - notifications.append(get_visits_without_appointments_count(worker)) - notifications.append(get_approaching_visits_without_appointments_count(worker)) - notifications.append(get_unfinished_appointments_count(worker)) - notifications.append(get_visits_with_missing_appointments_count(worker)) - notifications.append(get_subject_with_no_visit_notifications_count(worker)) - notifications.append(get_approaching_visits_for_mail_contact_count(worker)) - notifications.append(get_subjects_with_reminder_count(worker)) - notifications.append(get_missing_redcap_subject_notification_count(worker)) - notifications.append(get_inconsistent_redcap_subject_notification_count(worker)) + study = Study.objects.filter(id=GLOBAL_STUDY_ID)[0] + if study.notification_parameters.exceeded_visits_visible: + notifications.append(get_exceeded_visit_notifications_count(worker)) + if study.notification_parameters.unfinished_visits_visible: + notifications.append(get_visits_without_appointments_count(worker)) + if study.notification_parameters.approaching_visits_without_appointments_visible: + notifications.append(get_approaching_visits_without_appointments_count(worker)) + if study.notification_parameters.unfinished_appointments_visible: + notifications.append(get_unfinished_appointments_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: count += notification.count