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

Merge branch '169-follow-up-visits-should-be-based-on-visit-one-date' into 'master'

Resolve "follow up visits should be based on visit one date"

Closes #169

See merge request NCER-PD/scheduling-system!86
parents f4777b41 b29b695a
No related branches found
No related tags found
1 merge request!86Resolve "follow up visits should be based on visit one date"
Pipeline #
......@@ -52,11 +52,14 @@ class Visit(models.Model):
self.save()
if (not self.subject.dead) and (not self.subject.resigned):
visit_started = self.datetime_begin
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
time_to_next_visit = datetime.timedelta(days=365)
delta_days = 365
if self.subject.type == SUBJECT_TYPE_CHOICES_CONTROL:
time_to_next_visit = datetime.timedelta(days=365 * 3 + 366)
delta_days = 365 * 3 + 366
time_to_next_visit = datetime.timedelta(days=delta_days * (follow_up_number - 1))
Visit.objects.create(
subject=self.subject,
......
import datetime
from django.test import TestCase
from web.tests.functions import create_subject, create_visit
from web.models.constants import SUBJECT_TYPE_CHOICES_PATIENT
from web.models import Visit
from web.tests.functions import create_subject, create_visit
from web.views.notifications import get_today_midnight_date
class VisitModelTests(TestCase):
......@@ -36,6 +40,33 @@ class VisitModelTests(TestCase):
visit_count = Visit.objects.filter(subject=subject).count()
self.assertEquals(1, visit_count)
def test_mark_as_finished_for_follow_up_visit(self):
subject = create_subject()
subject.type = SUBJECT_TYPE_CHOICES_PATIENT
subject.save()
visit = create_visit(subject)
visit.mark_as_finished()
follow_up_visit = Visit.objects.filter(subject=subject).filter(visit_number=2)[0]
follow_up_visit.datetime_begin = visit.datetime_begin + datetime.timedelta(days=133)
follow_up_visit.datetime_end = visit.datetime_begin + datetime.timedelta(days=170)
follow_up_visit.save()
follow_up_visit.mark_as_finished()
visit_count = Visit.objects.filter(subject=subject).count()
self.assertEquals(3, visit_count)
new_follow_up = Visit.objects.filter(subject=subject).filter(visit_number=3)[0]
# check if follow up date is based on the first visit date
self.assertTrue(visit.datetime_begin + datetime.timedelta(days=365 * 2 - 1) < new_follow_up.datetime_begin)
def test_visit_to_string(self):
visit = create_visit(create_subject())
self.assertIsNotNone(str(visit))
def test_visit_to_unicode(self):
visit = create_visit(create_subject())
self.assertIsNotNone(unicode(visit))
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