diff --git a/smash/web/admin.py b/smash/web/admin.py index 5fdcc64ec02827b9b594f08b09513dfa6b27b86d..303aa56d09cf241230750c164e8abb6424dedea9 100644 --- a/smash/web/admin.py +++ b/smash/web/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from models import Subject, Item, Room, AppointmentType, Language, Location, Worker, FlyingTeam, Availability, Holiday, \ +from models import StudySubject, Item, Room, AppointmentType, Language, Location, Worker, FlyingTeam, Availability, Holiday, \ Visit, Appointment @@ -9,7 +9,7 @@ class LanguageAdmin(admin.ModelAdmin): # Register your models here. -admin.site.register(Subject) +admin.site.register(StudySubject) admin.site.register(Visit) admin.site.register(Item) admin.site.register(Room) diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py index b84e207c373bdb98fbd3169817c69105df9b3549..2032b605ec28e932be7a882b665ce958279a3803 100644 --- a/smash/web/api_views/subject.py +++ b/smash/web/api_views/subject.py @@ -5,7 +5,7 @@ from django.db.models import Count, Case, When, Min from django.db.models import Q from django.http import JsonResponse -from web.models import Subject, Visit, Appointment +from web.models import StudySubject, Visit, Appointment from web.models.constants import SUBJECT_TYPE_CHOICES from web.views import e500_error from web.views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder, get_today_midnight_date @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) @login_required def cities(request): - result_subjects = Subject.objects.filter(city__isnull=False).values_list('city').distinct() + result_subjects = StudySubject.objects.filter(city__isnull=False).values_list('city').distinct() return JsonResponse({ "cities": [x[0] for x in result_subjects] }) @@ -24,7 +24,7 @@ def cities(request): @login_required def referrals(request): - result_subjects = Subject.objects.filter(referral__isnull=False).values_list('referral').distinct() + result_subjects = StudySubject.objects.filter(referral__isnull=False).values_list('referral').distinct() return JsonResponse({ "referrals": [x[0] for x in result_subjects] }) @@ -33,7 +33,7 @@ def referrals(request): @login_required def get_subjects(request, type): if type == SUBJECT_LIST_GENERIC: - return Subject.objects.all() + return StudySubject.objects.all() elif type == SUBJECT_LIST_NO_VISIT: return get_subjects_with_no_visit(request.user) elif type == SUBJECT_LIST_REQUIRE_CONTACT: diff --git a/smash/web/forms.py b/smash/web/forms.py index 571fd786a5506d785f7aa1107a727ca23cbc88fd..9a30d9e7cc86cdb4cb1d3e81aa73bff23e1ecff2 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -5,7 +5,7 @@ from django import forms from django.forms import ModelForm, Form from django.utils.dates import MONTHS -from web.models import Subject, Worker, Appointment, Visit, AppointmentType, ContactAttempt, AppointmentTypeLink, \ +from web.models import StudySubject, Worker, Appointment, Visit, AppointmentType, ContactAttempt, AppointmentTypeLink, \ Availability, Holiday from web.models.constants import SUBJECT_TYPE_CHOICES, SCREENING_NUMBER_PREFIXES_FOR_TYPE, COUNTRY_OTHER_ID from web.views.notifications import get_filter_locations @@ -38,7 +38,7 @@ APPOINTMENT_TYPES_FIELD_POSITION = 1 def validate_subject_nd_number(self, cleaned_data): if cleaned_data['nd_number'] != "": - subjects_from_db = Subject.objects.filter(nd_number=cleaned_data['nd_number']) + subjects_from_db = StudySubject.objects.filter(nd_number=cleaned_data['nd_number']) if subjects_from_db: if subjects_from_db[0].screening_number != cleaned_data.get('screening_number', ''): self.add_error('nd_number', "ND number already in use") @@ -56,7 +56,7 @@ def validate_subject_resign_reason(self, cleaned_data): def validate_subject_mpower_number(self, cleaned_data): if cleaned_data['mpower_id'] != "": - subjects_from_db = Subject.objects.filter(mpower_id=cleaned_data['mpower_id']) + subjects_from_db = StudySubject.objects.filter(mpower_id=cleaned_data['mpower_id']) if subjects_from_db: if subjects_from_db[0].screening_number != cleaned_data.get('screening_number', ''): self.add_error('mpower_id', "mPower number already in use") @@ -74,7 +74,7 @@ class SubjectAddForm(ModelForm): ) class Meta: - model = Subject + model = StudySubject fields = '__all__' exclude = ['dead', 'resigned', 'resign_reason'] @@ -102,7 +102,7 @@ class SubjectAddForm(ModelForm): screening_number = self.build_screening_number(cleaned_data) if screening_number is not None: cleaned_data['screening_number'] = screening_number - subjects_from_db = Subject.objects.filter(screening_number=screening_number) + subjects_from_db = StudySubject.objects.filter(screening_number=screening_number) if len(subjects_from_db) > 0: self.add_error('screening_number', "Screening number already in use") @@ -128,7 +128,7 @@ class SubjectAddForm(ModelForm): def get_new_screening_number(screening_number_prefix): result_number = 0 - subjects = Subject.objects.filter(screening_number__contains=screening_number_prefix) + subjects = StudySubject.objects.filter(screening_number__contains=screening_number_prefix) for subject in subjects: screening_numbers = subject.screening_number.split(";") for screening_number in screening_numbers: @@ -145,7 +145,7 @@ def get_new_screening_number(screening_number_prefix): class SubjectDetailForm(ModelForm): class Meta: - model = Subject + model = StudySubject fields = '__all__' @@ -182,7 +182,7 @@ class SubjectEditForm(ModelForm): validate_subject_resign_reason(self, self.cleaned_data) class Meta: - model = Subject + model = StudySubject fields = '__all__' @@ -343,7 +343,7 @@ class VisitDetailForm(ModelForm): class VisitAddForm(ModelForm): - subject = forms.ModelChoiceField(queryset=Subject.objects.order_by('last_name', 'first_name')) + subject = forms.ModelChoiceField(queryset=StudySubject.objects.order_by('last_name', 'first_name')) datetime_begin = forms.DateField(label="Visit begins on", widget=forms.TextInput(attrs=DATEPICKER_DATE_ATTRS) ) diff --git a/smash/web/migrations/0063_auto_20171120_1429.py b/smash/web/migrations/0063_auto_20171120_1429.py new file mode 100644 index 0000000000000000000000000000000000000000..7b9c1de9d8c4e5eba269740c479e658a87de8433 --- /dev/null +++ b/smash/web/migrations/0063_auto_20171120_1429.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-11-20 14:29 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0062_subject_resign_reason'), + ] + + operations = [ + migrations.AlterField( + model_name='subject', + name='nd_number', + field=models.CharField(blank=True, max_length=25, validators=[django.core.validators.RegexValidator(b'^(ND[0-9]{4}|)$', message=b'ND number should look as follows: NDxxxx')], verbose_name=b'ND number'), + ), + ] diff --git a/smash/web/migrations/0064_auto_20171127_0954.py b/smash/web/migrations/0064_auto_20171127_0954.py new file mode 100644 index 0000000000000000000000000000000000000000..4fd29798f2f5fa6180904177aa22be5db2c72dcc --- /dev/null +++ b/smash/web/migrations/0064_auto_20171127_0954.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-11-27 09:54 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0063_auto_20171120_1429'), + ] + + operations = [ + migrations.RenameModel('Subject', 'StudySubject') + ] diff --git a/smash/web/migrations/0065_auto_20171127_0957.py b/smash/web/migrations/0065_auto_20171127_0957.py new file mode 100644 index 0000000000000000000000000000000000000000..79e6a2a186804e87b40fb729b72c03247b6561ea --- /dev/null +++ b/smash/web/migrations/0065_auto_20171127_0957.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-11-27 09:57 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0064_auto_20171127_0954'), + ] + + operations = [ + migrations.AlterField( + model_name='studysubject', + name='default_written_communication_language', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='studysubject_written_comunication', to='web.Language', verbose_name=b'Default language for document generation'), + ), + ] diff --git a/smash/web/models/__init__.py b/smash/web/models/__init__.py index 28a4bfa0bbae63229028fc45c83657f1031f9370..5cb87ceccdbf70492b1f66b18b9b2eeba83282d6 100644 --- a/smash/web/models/__init__.py +++ b/smash/web/models/__init__.py @@ -17,13 +17,13 @@ from availability import Availability from holiday import Holiday from item import Item from language import Language -from subject import Subject +from study_subject import StudySubject from contact_attempt import ContactAttempt from mail_template import MailTemplate from missing_subject import MissingSubject from inconsistent_subject import InconsistentSubject, InconsistentField -__all__ = [FlyingTeam, Appointment, AppointmentType, Availability, Holiday, Item, Language, Location, Room, Subject, +__all__ = [FlyingTeam, Appointment, AppointmentType, Availability, Holiday, Item, Language, Location, Room, StudySubject, Visit, Worker, ContactAttempt, ConfigurationItem, MailTemplate, AppointmentTypeLink, MissingSubject, InconsistentSubject, InconsistentField, Country] diff --git a/smash/web/models/contact_attempt.py b/smash/web/models/contact_attempt.py index b21d8d60de852e1588c785cbecfd885554390d68..e8a2608e2b78655add178a3d09de4570137a5545 100644 --- a/smash/web/models/contact_attempt.py +++ b/smash/web/models/contact_attempt.py @@ -7,7 +7,7 @@ __author__ = 'Valentin Grouès' class ContactAttempt(models.Model): - subject = models.ForeignKey("web.Subject", + subject = models.ForeignKey("web.StudySubject", verbose_name='Subject' ) worker = models.ForeignKey("web.Worker", null=True, diff --git a/smash/web/models/inconsistent_subject.py b/smash/web/models/inconsistent_subject.py index b9298c515b5d7dead50cecf5d02c94615be5d8e1..d50564e7e93b5f1aa4d98a152c15bb32bac9c8ed 100644 --- a/smash/web/models/inconsistent_subject.py +++ b/smash/web/models/inconsistent_subject.py @@ -44,7 +44,7 @@ class InconsistentSubject(models.Model): class Meta: app_label = 'web' - subject = models.ForeignKey("web.Subject", + subject = models.ForeignKey("web.StudySubject", verbose_name='Subject', null=True, blank=True diff --git a/smash/web/models/mail_template.py b/smash/web/models/mail_template.py index 9803905cdbd38f69cf579cb622b606563b979068..c899e4935a548d8008d160615b740318c035d1dc 100644 --- a/smash/web/models/mail_template.py +++ b/smash/web/models/mail_template.py @@ -9,7 +9,7 @@ from django.db import models from .constants import MAIL_TEMPLATE_CONTEXT_CHOICES, MAIL_TEMPLATE_CONTEXT_APPOINTMENT, \ MAIL_TEMPLATE_CONTEXT_SUBJECT, MAIL_TEMPLATE_CONTEXT_VISIT from ..docx_helper import process_file -from ..models import Appointment, Visit, Subject, Worker +from ..models import Appointment, Visit, StudySubject, Worker DATE_FORMAT_FULL = "%A %d %B %Y" @@ -132,7 +132,7 @@ class MailTemplate(models.Model): elif isinstance(instance, Visit): visit = instance subject = visit.subject - elif isinstance(instance, Subject): + elif isinstance(instance, StudySubject): subject = instance # set locale to get correct date format locale_name = self.language.locale diff --git a/smash/web/models/missing_subject.py b/smash/web/models/missing_subject.py index ff7353bbfec9910de716a47575fc90a9d0466782..6050dd7e290ee6e10b6edbf059b2d592cc4e3c9d 100644 --- a/smash/web/models/missing_subject.py +++ b/smash/web/models/missing_subject.py @@ -11,7 +11,7 @@ class MissingSubject(models.Model): verbose_name='Ignore missing subject' ) - subject = models.ForeignKey("web.Subject", + subject = models.ForeignKey("web.StudySubject", verbose_name='Subject', null=True, blank=True diff --git a/smash/web/models/subject.py b/smash/web/models/study_subject.py similarity index 99% rename from smash/web/models/subject.py rename to smash/web/models/study_subject.py index ab779e001586776b650fea2bb7f8da0e67e9162b..fa3e65a9c7d3c5352ae4b22e97ab051428976288 100644 --- a/smash/web/models/subject.py +++ b/smash/web/models/study_subject.py @@ -7,7 +7,7 @@ from web.models import Country from . import Appointment, Language, Location, Visit -class Subject(models.Model): +class StudySubject(models.Model): class Meta: app_label = 'web' diff --git a/smash/web/models/visit.py b/smash/web/models/visit.py index 1f491319e8f87585433ee7c1129f1b48c152ef33..a1b4c9acd8aec04963df70995e16250a3aa7019d 100644 --- a/smash/web/models/visit.py +++ b/smash/web/models/visit.py @@ -12,7 +12,7 @@ class Visit(models.Model): class Meta: app_label = 'web' - subject = models.ForeignKey("web.Subject", on_delete=models.CASCADE, + subject = models.ForeignKey("web.StudySubject", on_delete=models.CASCADE, verbose_name='Subject' ) datetime_begin = models.DateTimeField( diff --git a/smash/web/redcap_connector.py b/smash/web/redcap_connector.py index bca70fc0951a5894d2557f83a03f271eb216ce85..de0e9bf9bd1b26d1557dffebe3849b8d88aa6ef9 100644 --- a/smash/web/redcap_connector.py +++ b/smash/web/redcap_connector.py @@ -7,7 +7,7 @@ import pycurl import certifi from django_cron import CronJobBase, Schedule -from web.models import ConfigurationItem, Subject, Language +from web.models import ConfigurationItem, StudySubject, Language from web.models.constants import REDCAP_TOKEN_CONFIGURATION_TYPE, \ REDCAP_BASE_URL_CONFIGURATION_TYPE from web.models.inconsistent_subject import InconsistentField, InconsistentSubject @@ -85,7 +85,7 @@ class RedcapConnector(object): for subject in red_cap_subjects: red_cap_subject_by_nd[subject.nd_number] = subject - smash_subjects = Subject.objects.exclude(nd_number='') + smash_subjects = StudySubject.objects.exclude(nd_number='') smash_subject_by_nd = {} for subject in smash_subjects: smash_subject_by_nd[subject.nd_number] = subject @@ -158,7 +158,7 @@ class RedcapConnector(object): for subject in red_cap_subjects: red_cap_subject_by_nd[subject.nd_number] = subject - smash_subjects = Subject.objects.exclude(nd_number='') + smash_subjects = StudySubject.objects.exclude(nd_number='') result = [] for subject in smash_subjects: diff --git a/smash/web/statistics.py b/smash/web/statistics.py index 63a710dca60acf2a2269e7a27d41ff9318ca2e92..c68c3750542703543a7c06a58609e2932dbad2b4 100644 --- a/smash/web/statistics.py +++ b/smash/web/statistics.py @@ -19,7 +19,7 @@ QUERY_APPOINTMENTS_COUNT = """ SELECT count(*) FROM web_appointment LEFT JOIN (SELECT id, subject_id, rank() OVER (PARTITION BY subject_id ORDER BY datetime_begin) AS rnk FROM web_visit) a ON a.id = web_appointment.visit_id -LEFT JOIN web_subject ON web_subject.id = subject_id +LEFT JOIN web_studysubject ON web_studysubject.id = subject_id WHERE a.rnk = %s AND EXTRACT(MONTH FROM web_appointment.datetime_when) = %s AND EXTRACT(YEAR FROM web_appointment.datetime_when) = %s @@ -28,7 +28,7 @@ AND EXTRACT(YEAR FROM web_appointment.datetime_when) = %s QUERY_VISITS_ENDED_COUNT = """ SELECT count(*) FROM (SELECT id, subject_id, datetime_begin, datetime_end, rank() OVER (PARTITION BY subject_id ORDER BY datetime_begin) AS rnk FROM web_visit) a -LEFT JOIN web_subject ON web_subject.id = subject_id +LEFT JOIN web_studysubject ON web_studysubject.id = subject_id WHERE a.rnk = %s AND EXTRACT(MONTH FROM a.datetime_end) = %s AND EXTRACT(YEAR FROM a.datetime_end) = %s @@ -37,7 +37,7 @@ EXTRACT(YEAR FROM a.datetime_end) = %s QUERY_VISITS_STARTED_COUNT = """ SELECT count(*) FROM (SELECT id, subject_id, datetime_begin, datetime_end, rank() OVER (PARTITION BY subject_id ORDER BY datetime_begin) AS rnk FROM web_visit) a -LEFT JOIN web_subject ON web_subject.id = subject_id +LEFT JOIN web_studysubject ON web_studysubject.id = subject_id WHERE a.rnk = %s AND EXTRACT(MONTH FROM a.datetime_begin) = %s AND EXTRACT(YEAR FROM a.datetime_begin) = %s @@ -48,7 +48,7 @@ SELECT types.appointment_type_id, web_appointment.status, count(*) FROM web_appo LEFT JOIN (SELECT id, subject_id, rank() OVER (PARTITION BY subject_id ORDER BY datetime_begin) AS rnk FROM web_visit) a ON a.id = web_appointment.visit_id LEFT JOIN web_appointmenttypelink types ON types.appointment_id = web_appointment.id -LEFT JOIN web_subject ON web_subject.id = subject_id +LEFT JOIN web_studysubject ON web_studysubject.id = subject_id WHERE a.rnk = %s AND EXTRACT(MONTH FROM web_appointment.datetime_when) = %s AND EXTRACT(YEAR FROM web_appointment.datetime_when) = %s @@ -136,7 +136,7 @@ class StatisticsManager(object): query = QUERY_APPOINTMENTS subject_type_clause = "" if subject_type is not None: - subject_type_clause = " AND web_subject.type = '{}'".format(subject_type) + subject_type_clause = " AND web_studysubject.type = '{}'".format(subject_type) query = query.format(subject_type_clause) with connection.cursor() as cursor: cursor.execute(query, [visit, month, year]) @@ -159,7 +159,7 @@ class StatisticsManager(object): def _get_count_from_filters_or_sql(model, filters, query, visit, month, year, subject_type): if visit: if subject_type is not None: - query += " AND web_subject.type = '{}'".format(subject_type) + query += " AND web_studysubject.type = '{}'".format(subject_type) with connection.cursor() as cursor: cursor.execute( query, @@ -208,7 +208,7 @@ class StatisticsManager(object): def _get_visits_ranks(subject_type=None): query = QUERY_VISITS_RANKS if subject_type is not None: - query += " LEFT JOIN web_subject ON web_subject.id = web_visit.subject_id WHERE web_subject.type = '{}'".format( + query += " LEFT JOIN web_studysubject ON web_studysubject.id = web_visit.subject_id WHERE web_studysubject.type = '{}'".format( subject_type) with connection.cursor() as cursor: cursor.execute( diff --git a/smash/web/tests/api_views/test_subject.py b/smash/web/tests/api_views/test_subject.py index 7fafc2f84a3705ade0f09c9701f60412b022f67d..7ad048d35389de7244db494daeccb39681895304 100644 --- a/smash/web/tests/api_views/test_subject.py +++ b/smash/web/tests/api_views/test_subject.py @@ -10,7 +10,7 @@ from django.urls import reverse from web.views.notifications import get_today_midnight_date from web.api_views.subject import get_subjects_order, get_subjects_filtered, serialize_subject, SUBJECT_LIST_GENERIC, \ SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT -from web.models import Subject, Appointment, Visit +from web.models import StudySubject, Appointment, Visit from web.tests.functions import create_subject, create_worker, create_get_suffix, create_visit, create_appointment @@ -98,18 +98,18 @@ class TestApi(TestCase): self.assertTrue(name in response.content) def check_subject_filtered(self, filters, result): - subjects = get_subjects_filtered(Subject.objects.all(), filters) + subjects = get_subjects_filtered(StudySubject.objects.all(), filters) self.assertEqual(len(result), subjects.count()) for index in range(len(result)): self.assertEqual(result[index], subjects[index]) def check_subject_ordered(self, order, result): - subjects = get_subjects_order(Subject.objects.all(), order, "asc") + subjects = get_subjects_order(StudySubject.objects.all(), order, "asc") self.assertEqual(len(result), subjects.count()) for index in range(len(result)): self.assertEqual(result[index], subjects[index]) - subjects = get_subjects_order(Subject.objects.all(), order, "desc") + subjects = get_subjects_order(StudySubject.objects.all(), order, "desc") length = len(result) self.assertEqual(length, subjects.count()) for index in range(length): diff --git a/smash/web/tests/forms/test_SubjectEditForm.py b/smash/web/tests/forms/test_SubjectEditForm.py index 3de9b95dd970d2aeeb0b029ec32af74c5413b420..f07135c42b9772d45f3735d5b022959fd16d4471 100644 --- a/smash/web/tests/forms/test_SubjectEditForm.py +++ b/smash/web/tests/forms/test_SubjectEditForm.py @@ -1,6 +1,6 @@ from web.forms import SubjectAddForm from web.forms import SubjectEditForm -from web.models import Subject +from web.models import StudySubject from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, COUNTRY_AFGHANISTAN_ID from web.tests import LoggedInWithWorkerTestCase @@ -21,7 +21,7 @@ class SubjectEditFormTests(LoggedInWithWorkerTestCase): } def tearDown(self): - Subject.objects.all().delete() + StudySubject.objects.all().delete() def test_validation(self): add_form = SubjectAddForm(data=self.sample_data, user=self.user) diff --git a/smash/web/tests/functions.py b/smash/web/tests/functions.py index aa6ee1114a859f7df40d03b71f71c5821f22a10f..eb904f6e5bca62b9320d1fd80193f0cb022df803 100644 --- a/smash/web/tests/functions.py +++ b/smash/web/tests/functions.py @@ -3,7 +3,7 @@ import os from django.contrib.auth.models import User -from web.models import Location, AppointmentType, Subject, Worker, Visit, Appointment, ConfigurationItem, Language, \ +from web.models import Location, AppointmentType, StudySubject, Worker, Visit, Appointment, ConfigurationItem, Language, \ ContactAttempt, FlyingTeam, Availability from web.models.constants import REDCAP_TOKEN_CONFIGURATION_TYPE, REDCAP_BASE_URL_CONFIGURATION_TYPE, \ SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, CONTACT_TYPES_PHONE, \ @@ -55,7 +55,7 @@ def create_contact_attempt(subject=None, worker=None): def create_subject(subject_id=1): - return Subject.objects.create( + return StudySubject.objects.create( first_name="Piotr", last_name="Gawron", default_location=get_test_location(), diff --git a/smash/web/tests/models/test_subject.py b/smash/web/tests/models/test_subject.py index 6266ec03e6eb3eeab698a0732d37f42425527ce5..3e3f5e0165564c6b9f0edf80388a5a6bd1399df7 100644 --- a/smash/web/tests/models/test_subject.py +++ b/smash/web/tests/models/test_subject.py @@ -8,7 +8,7 @@ from web.models import Appointment from web.models import Visit -class SubjectModelTests(TestCase): +class SubjectMtodelTests(TestCase): def test_mark_as_dead(self): subject = create_subject() visit = create_visit(subject) diff --git a/smash/web/tests/view/test_appointments.py b/smash/web/tests/view/test_appointments.py index 239fb666b8b039fe5a5c0bc3783fe65105ec23db..37fc2b76fd68cf2ee5b5d4adf69d0a3f275259b3 100644 --- a/smash/web/tests/view/test_appointments.py +++ b/smash/web/tests/view/test_appointments.py @@ -6,7 +6,7 @@ from django.urls import reverse from web.tests.functions import create_subject, create_visit, create_appointment, create_worker, create_flying_team, \ format_form_field from web.forms import AppointmentEditForm, SubjectEditForm -from web.models import Appointment, Subject +from web.models import Appointment, StudySubject from web.views.notifications import get_today_midnight_date from web.tests import LoggedInTestCase @@ -45,7 +45,7 @@ class AppointmentsViewTests(LoggedInTestCase): reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) self.assertEqual(response.status_code, 302) updated_appointment = Appointment.objects.filter(id=appointment.id)[0] - updated_subject = Subject.objects.filter(id=subject.id)[0] + updated_subject = StudySubject.objects.filter(id=subject.id)[0] self.assertEqual(new_comment, updated_appointment.comment) self.assertEqual(new_status, updated_appointment.status) self.assertEqual(new_last_name, updated_subject.last_name) @@ -103,7 +103,7 @@ class AppointmentsViewTests(LoggedInTestCase): self.assertEqual(response.status_code, 200) - updated_subject = Subject.objects.get(id=subject.id) + updated_subject = StudySubject.objects.get(id=subject.id) self.assertFalse(updated_subject.information_sent) def test_save_appointments_edit_with_valid_nd_number(self): @@ -120,7 +120,7 @@ class AppointmentsViewTests(LoggedInTestCase): self.assertEqual(response.status_code, 302) - updated_subject = Subject.objects.get(id=subject.id) + updated_subject = StudySubject.objects.get(id=subject.id) self.assertTrue(updated_subject.information_sent) def prepare_form(self, appointment, subject): @@ -148,7 +148,7 @@ class AppointmentsViewTests(LoggedInTestCase): self.client.post(reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) - updated_subject = Subject.objects.get(id=subject.id) + updated_subject = StudySubject.objects.get(id=subject.id) self.assertIsNotNone(updated_subject.flying_team) def test_delete_appointment(self): diff --git a/smash/web/tests/view/test_subjects.py b/smash/web/tests/view/test_subjects.py index 834ba8d09d950625bd64d32465753c74ce3b2e9f..655c178a42a6830a7f451e5284b22dcd7a3a7b27 100644 --- a/smash/web/tests/view/test_subjects.py +++ b/smash/web/tests/view/test_subjects.py @@ -3,7 +3,7 @@ import datetime from django.urls import reverse from web.forms import SubjectAddForm, SubjectEditForm -from web.models import Subject +from web.models import StudySubject from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL, SUBJECT_TYPE_CHOICES_PATIENT, \ COUNTRY_AFGHANISTAN_ID, COUNTRY_OTHER_ID from web.tests import LoggedInWithWorkerTestCase @@ -74,7 +74,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): reverse('web.views.subject_edit', kwargs={'id': subject.id}), data=form_data) self.assertEqual(response.status_code, 302) - updated_subject = Subject.objects.filter(id=subject.id)[0] + updated_subject = StudySubject.objects.filter(id=subject.id)[0] self.assertTrue(updated_subject.dead) self.assertTrue(updated_subject.resigned) @@ -94,7 +94,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): response = self.client.get(response.url) self.assertContains(response, "Subject created") - subject = Subject.objects.all()[0] + subject = StudySubject.objects.all()[0] self.assertEqual("L-001", subject.screening_number, "prefix should start by L" + " as default location prefix is not defined and subject type is control") @@ -122,7 +122,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): response = self.client.get(response.url) self.assertContains(response, "Subject created") - subject = Subject.objects.all()[0] + subject = StudySubject.objects.all()[0] self.assertEqual("P-001", subject.screening_number, "prefix should start by P" + " as default location prefix is not defined and subject type is patient") @@ -159,7 +159,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): response = self.client.get(response.url) self.assertContains(response, "Subject created") - subject = Subject.objects.all()[0] + subject = StudySubject.objects.all()[0] self.assertEqual("X-001", subject.screening_number, "prefix should start by X as default location prefix is equal to 'X'") diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index 2ec6de2acb48e7232dfe72f5afe13d2d3bf59745..2eca3ad830fc66192548b027693f99bce5a73996 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -8,7 +8,7 @@ from django.shortcuts import get_object_or_404, redirect from . import wrap_response from ..forms import AppointmentDetailForm, AppointmentAddForm, AppointmentEditForm, SubjectEditForm -from ..models import Appointment, Subject, MailTemplate +from ..models import Appointment, StudySubject, MailTemplate APPOINTMENT_LIST_GENERIC = "GENERIC" APPOINTMENT_LIST_UNFINISHED = "UNFINISHED" @@ -89,7 +89,7 @@ def appointment_edit(request, id): the_appointment = get_object_or_404(Appointment, id=id) if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED and the_appointment.visit is not None: - subject = Subject.objects.get(id=the_appointment.visit.subject.id) + subject = StudySubject.objects.get(id=the_appointment.visit.subject.id) subject.information_sent = True if the_appointment.flying_team is not None and subject.flying_team is None: subject.flying_team = the_appointment.flying_team diff --git a/smash/web/views/contact_attempt.py b/smash/web/views/contact_attempt.py index 6246cd03afc6fdea92f4e5f0bd9daea80cd8ed81..6694bc41836623bef0041fe6c7861ee2e4a4c7bc 100644 --- a/smash/web/views/contact_attempt.py +++ b/smash/web/views/contact_attempt.py @@ -2,11 +2,11 @@ from django.shortcuts import redirect, get_object_or_404 from . import wrap_response from ..forms import ContactAttemptForm, ContactAttemptEditForm -from ..models import Subject, ContactAttempt +from ..models import StudySubject, ContactAttempt def contact_add(request, subject_id): - subject = get_object_or_404(Subject, id=subject_id) + subject = get_object_or_404(StudySubject, id=subject_id) if request.method == 'POST': form = ContactAttemptForm(request.POST, user=request.user, subject=subject) form.instance.subject_id = subject_id diff --git a/smash/web/views/export.py b/smash/web/views/export.py index 5279b6b8f302574f0ffaf4f78cdb774256458f21..e99ad38450f3250f50261572dd2b5af65c34299d 100644 --- a/smash/web/views/export.py +++ b/smash/web/views/export.py @@ -7,7 +7,7 @@ from django.http import HttpResponse from notifications import get_today_midnight_date from . import e500_error, wrap_response -from ..models import Subject, Appointment +from ..models import StudySubject, Appointment @login_required @@ -65,7 +65,7 @@ def get_subjects_as_array(): result.append(field_names) - subjects = Subject.objects.order_by('-last_name') + subjects = StudySubject.objects.order_by('-last_name') for subject in subjects: row = subject_to_row_for_fields(subject, subject_fields) result.append([unicode(s).replace("\n", ";").replace("\r", ";") for s in row]) @@ -95,7 +95,7 @@ def subject_to_row_for_fields(subject, subject_fields): def get_default_subject_fields(): subject_fields = [] - for field in Subject._meta.fields: + for field in StudySubject._meta.fields: if field.name != "ID": subject_fields.append(field) subject_fields.append(DROP_OUT_FIELD) diff --git a/smash/web/views/mails.py b/smash/web/views/mails.py index abe5d7f79cf1d12b087d2da1c5b66a9314f4ee1b..8ca773008e269e26c2c9a03010ff25ad5f8df05a 100644 --- a/smash/web/views/mails.py +++ b/smash/web/views/mails.py @@ -13,14 +13,14 @@ from django.views.generic import ListView from django.views.generic import UpdateView from . import wrap_response, WrappedView -from ..models import Subject, Visit, Appointment, MailTemplate +from ..models import StudySubject, Visit, Appointment, MailTemplate from ..models.constants import MAIL_TEMPLATE_CONTEXT_SUBJECT, MAIL_TEMPLATE_CONTEXT_VISIT, \ MAIL_TEMPLATE_CONTEXT_APPOINTMENT MIMETYPE_DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' CONTEXT_TYPES_MAPPING = { - MAIL_TEMPLATE_CONTEXT_SUBJECT: Subject, + MAIL_TEMPLATE_CONTEXT_SUBJECT: StudySubject, MAIL_TEMPLATE_CONTEXT_VISIT: Visit, MAIL_TEMPLATE_CONTEXT_APPOINTMENT: Appointment } diff --git a/smash/web/views/notifications.py b/smash/web/views/notifications.py index 42cbc3e41952d551f53f4d08b99c84a4ba52ecaf..287dc783322647d03f9fa03423aed735b92a0bab 100644 --- a/smash/web/views/notifications.py +++ b/smash/web/views/notifications.py @@ -5,7 +5,7 @@ from django.utils import timezone from django.contrib.auth.models import User, AnonymousUser from django.db.models import Count, Case, When -from ..models import Worker, Subject, Visit, Appointment, Location, MissingSubject, InconsistentSubject +from ..models import Worker, StudySubject, Visit, Appointment, Location, MissingSubject, InconsistentSubject class NotificationCount(object): @@ -132,7 +132,7 @@ def get_notifications(the_user): def get_subjects_with_no_visit(user): - result = Subject.objects.annotate(my_count=Count(Case(When(visit__is_finished=False, then=1)))).filter( + result = StudySubject.objects.annotate(my_count=Count(Case(When(visit__is_finished=False, then=1)))).filter( dead=False, resigned=False, my_count=0, @@ -146,7 +146,7 @@ def get_subjects_with_no_visit(user): def get_subjects_with_reminder(user): tomorrow = datetime.datetime.now() + datetime.timedelta(hours=1) - result = Subject.objects.filter( + result = StudySubject.objects.filter( dead=False, resigned=False, default_location__in=get_filter_locations(user), diff --git a/smash/web/views/subject.py b/smash/web/views/subject.py index dfc0c2bc0cb57991c3f49210e49a38787e3c2136..a8ed57704d22a1f08f36e4313ee742161b4ea296 100644 --- a/smash/web/views/subject.py +++ b/smash/web/views/subject.py @@ -4,7 +4,7 @@ from django.shortcuts import redirect, get_object_or_404 from . import wrap_response from ..forms import SubjectAddForm, SubjectEditForm, VisitDetailForm -from ..models import Subject, MailTemplate, Worker +from ..models import StudySubject, MailTemplate, Worker SUBJECT_LIST_GENERIC = "GENERIC" SUBJECT_LIST_NO_VISIT = "NO_VISIT" @@ -50,7 +50,7 @@ def subject_require_contact(request): def subject_edit(request, id): - the_subject = get_object_or_404(Subject, id=id) + the_subject = get_object_or_404(StudySubject, id=id) contact_attempts = the_subject.contactattempt_set.order_by('-datetime_when').all() was_dead = the_subject.dead was_resigned = the_subject.resigned @@ -87,7 +87,7 @@ def subject_edit(request, id): def subject_visit_details(request, id): - subject_to_be_viewed = get_object_or_404(Subject, id=id) + subject_to_be_viewed = get_object_or_404(StudySubject, id=id) visits = subject_to_be_viewed.visit_set.order_by("-visit_number").all() visits_data = [] allow_add_visit = True diff --git a/smash/web/views/visit.py b/smash/web/views/visit.py index b4f11304a30f1d2417424c1779f98ff5682bac45..5aa0e6d1665517a86c86efe8a5c9d27a60dce518 100644 --- a/smash/web/views/visit.py +++ b/smash/web/views/visit.py @@ -6,7 +6,7 @@ from notifications import get_active_visits_with_missing_appointments, get_unfin waiting_for_appointment from . import wrap_response from ..forms import VisitDetailForm, SubjectDetailForm, VisitAddForm -from ..models import Visit, Appointment, Subject, MailTemplate +from ..models import Visit, Appointment, StudySubject, MailTemplate def visits(request): @@ -92,7 +92,7 @@ def visit_add(request, subject_id=-1): visit = form.save() return redirect('web.views.visit_details', visit.id) else: - subjects = Subject.objects.filter(id=subject_id) + subjects = StudySubject.objects.filter(id=subject_id) subject = None if len(subjects) > 0: subject = subjects[0]