diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py index 589d19d633efa14f693aff4fbe624ec80c55c1b2..6c9bdcbf30453e4c385bf59da815289ae78c0b08 100644 --- a/smash/web/api_views/subject.py +++ b/smash/web/api_views/subject.py @@ -10,9 +10,10 @@ from web.api_views.serialization_utils import bool_to_yes_no, flying_team_to_str from web.models import StudySubject, Visit, Appointment, Subject, SubjectColumns, StudyColumns, Study, ContactAttempt from web.models.constants import SUBJECT_TYPE_CHOICES, GLOBAL_STUDY_ID from web.models.study_subject_list import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT, \ - StudySubjectList + StudySubjectList, SUBJECT_LIST_VOUCHER_EXPIRY from web.views import e500_error -from web.views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder, get_today_midnight_date +from web.views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder, get_today_midnight_date, \ + get_subjects_with_almost_expired_vouchers logger = logging.getLogger(__name__) @@ -89,6 +90,8 @@ def get_subjects(request, type): return get_subjects_with_no_visit(request.user) elif type == SUBJECT_LIST_REQUIRE_CONTACT: return get_subjects_with_reminder(request.user) + elif type == SUBJECT_LIST_VOUCHER_EXPIRY: + return get_subjects_with_almost_expired_vouchers(request.user) else: raise TypeError("Unknown query type: " + type) diff --git a/smash/web/models/study_subject_list.py b/smash/web/models/study_subject_list.py index cd2f5bbbbfff4142032e0cd68b9624b53e0f7668..de31e3cf04711d7909c80f56019597ef59605cb3 100644 --- a/smash/web/models/study_subject_list.py +++ b/smash/web/models/study_subject_list.py @@ -6,11 +6,13 @@ from web.models import Study, SubjectColumns, StudyColumns SUBJECT_LIST_GENERIC = "GENERIC" SUBJECT_LIST_NO_VISIT = "NO_VISIT" SUBJECT_LIST_REQUIRE_CONTACT = "REQUIRE_CONTACT" +SUBJECT_LIST_VOUCHER_EXPIRY = "VOUCHER_EXPIRY" SUBJECT_LIST_CHOICES = { SUBJECT_LIST_GENERIC: 'Generic', SUBJECT_LIST_NO_VISIT: 'Subjects without visit', SUBJECT_LIST_REQUIRE_CONTACT: 'Subjects required contact', + SUBJECT_LIST_VOUCHER_EXPIRY: 'Subject with vouchers to be expired soon' } diff --git a/smash/web/tests/api_views/test_subject.py b/smash/web/tests/api_views/test_subject.py index 3b4ad50d6f1af4e47c121b1ce4e78f9e7c1a487b..4276b7346901ff26e972498352260bfb8d169f43 100644 --- a/smash/web/tests/api_views/test_subject.py +++ b/smash/web/tests/api_views/test_subject.py @@ -9,7 +9,7 @@ from web.api_views.subject import get_subjects_order, get_subjects_filtered, ser from web.models import StudySubject, Appointment, Study, Worker from web.models.constants import GLOBAL_STUDY_ID, SUBJECT_TYPE_CHOICES_PATIENT, SUBJECT_TYPE_CHOICES_CONTROL from web.models.study_subject_list import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT, \ - StudySubjectList + StudySubjectList, SUBJECT_LIST_VOUCHER_EXPIRY from web.tests import LoggedInWithWorkerTestCase from web.tests.functions import create_study_subject, create_get_suffix, create_visit, \ create_appointment, create_empty_study_columns, create_contact_attempt, create_flying_team, create_worker @@ -104,6 +104,10 @@ class TestSubjectApi(LoggedInWithWorkerTestCase): response = self.client.get(reverse('web.api.subjects', kwargs={'type': SUBJECT_LIST_GENERIC})) self.assertEqual(response.status_code, 200) + def test_subjects_voucher_almost_expired(self): + response = self.client.get(reverse('web.api.subjects', kwargs={'type': SUBJECT_LIST_VOUCHER_EXPIRY})) + self.assertEqual(response.status_code, 200) + def test_subjects_no_visit(self): response = self.client.get(reverse('web.api.subjects', kwargs={'type': SUBJECT_LIST_NO_VISIT})) self.assertEqual(response.status_code, 200) diff --git a/smash/web/urls.py b/smash/web/urls.py index f5da2cb56dd161f3a3f82f2e37d366d25ca9fef4..baa812987f233ae90767d6f5c139e7b33c2a49ff 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -73,6 +73,8 @@ urlpatterns = [ url(r'^subjects$', views.subject.subjects, name='web.views.subjects'), url(r'^subjects/no_visit$', views.subject.subject_no_visits, name='web.views.subject_no_visits'), url(r'^subjects/require_contact$', views.subject.subject_require_contact, name='web.views.subject_require_contact'), + url(r'^subjects/voucher_expiry', views.subject.subject_voucher_expiry, name='web.views.subject_voucher_expiry'), + url(r'^subjects/add$', views.subject.subject_add, name='web.views.subject_add'), url(r'^subjects/subject_visit_details/(?P<id>\d+)$', views.subject.subject_visit_details, name='web.views.subject_visit_details'), diff --git a/smash/web/views/subject.py b/smash/web/views/subject.py index f1c9566a8be16acd252dc146bfcf3c06be5165b9..d891d0d65be6a3c07243f40d4704ee0c071d2103 100644 --- a/smash/web/views/subject.py +++ b/smash/web/views/subject.py @@ -5,11 +5,12 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required from django.shortcuts import redirect, get_object_or_404 -from ..models.study_subject_list import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT from . import wrap_response from ..forms import VisitDetailForm, SubjectAddForm, SubjectEditForm, StudySubjectAddForm, StudySubjectEditForm from ..models import StudySubject, MailTemplate, Worker, Study from ..models.constants import GLOBAL_STUDY_ID +from ..models.study_subject_list import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT, \ + SUBJECT_LIST_VOUCHER_EXPIRY logger = logging.getLogger(__name__) @@ -54,6 +55,13 @@ def subject_no_visits(request): return wrap_response(request, 'subjects/index.html', context) +def subject_voucher_expiry(request): + context = { + 'list_type': SUBJECT_LIST_VOUCHER_EXPIRY, + } + return wrap_response(request, 'subjects/index.html', context) + + def subject_require_contact(request): context = { 'list_type': SUBJECT_LIST_REQUIRE_CONTACT,