diff --git a/smash/web/models/visit.py b/smash/web/models/visit.py index f94d30ddbe876ba539a415f887e62c4848a3d474..bf5c2bb8e9485e4cf03205f83ac5c9f52d19e122 100644 --- a/smash/web/models/visit.py +++ b/smash/web/models/visit.py @@ -9,6 +9,7 @@ from web.models.constants import BOOL_CHOICES, SUBJECT_TYPE_CHOICES_CONTROL class Visit(models.Model): + class Meta: app_label = 'web' @@ -35,7 +36,8 @@ class Visit(models.Model): blank=True, ) - # this value is automatically computed by signal handled by update_visit_number method + # this value is automatically computed by signal handled by + # update_visit_number method visit_number = models.IntegerField( verbose_name='Visit number', default=1 @@ -56,23 +58,29 @@ class Visit(models.Model): create_follow_up = False elif self.subject.resigned: create_follow_up = False + elif self.subject.excluded: + create_follow_up = False elif not self.subject.study.auto_create_follow_up: create_follow_up = False if create_follow_up: - visit_started = Visit.objects.filter(subject=self.subject).filter(visit_number=1)[0].datetime_begin - follow_up_number = Visit.objects.filter(subject=self.subject).count() + 1 + visit_started = Visit.objects.filter( + subject=self.subject).filter(visit_number=1)[0].datetime_begin + follow_up_number = Visit.objects.filter( + subject=self.subject).count() + 1 delta_days = 365 if self.subject.type == SUBJECT_TYPE_CHOICES_CONTROL: delta_days = 365 * 3 + 366 - time_to_next_visit = datetime.timedelta(days=delta_days * (follow_up_number - 1)) + time_to_next_visit = datetime.timedelta( + days=delta_days * (follow_up_number - 1)) Visit.objects.create( subject=self.subject, datetime_begin=visit_started + time_to_next_visit, - datetime_end=visit_started + time_to_next_visit + datetime.timedelta(days=93) + datetime_end=visit_started + time_to_next_visit + + datetime.timedelta(days=93) ) @@ -80,7 +88,8 @@ class Visit(models.Model): def update_visit_number(sender, instance, **kwargs): visit = instance if visit.subject is not None: - count = Visit.objects.filter(subject=visit.subject).filter(datetime_begin__lte=visit.datetime_begin).count() + count = Visit.objects.filter(subject=visit.subject).filter( + datetime_begin__lte=visit.datetime_begin).count() if count != visit.visit_number: visit.visit_number = count visit.save()