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

Merge branch 'fix/avoid_appointments_if_subject_is_marked' into 'devel_0.13.x'

Fix/avoid appointments if subject is marked

See merge request NCER-PD/scheduling-system!222
parents 7d431a90 d0636e54
No related branches found
No related tags found
2 merge requests!224Feature/selectable redcap fields,!222Fix/avoid appointments if subject is marked
Pipeline #10071 passed
......@@ -230,6 +230,23 @@ class StudySubject(models.Model):
return False
return True
def can_schedule(self):
return not any([self.resigned, self.excluded, self.endpoint_reached, self.subject.dead])
@property
def status(self):
if self.subject.dead:
return 'Deceased'
elif self.resigned:
return 'Resigned'
elif self.excluded:
return 'Excluded'
elif self.endpoint_reached:
return 'Endpoint Reached'
else:
return 'Normal'
def __str__(self):
return "%s %s" % (self.subject.first_name, self.subject.last_name)
......
......@@ -91,12 +91,7 @@
</div>
<div>
{%if visFinished%}
<a href="{% url 'web.views.appointment_add' vid %}" class="btn btn-app" disabled>
<i class="fa fa-plus"></i>
Add new appointment
</a>
{% else %}
{%if not visFinished%}
<a href="{% url 'web.views.appointment_add' vid %}" class="btn btn-app">
<i class="fa fa-plus"></i>
Add new appointment
......
......@@ -51,6 +51,12 @@ def appointment_add(request, visit_id=None):
visit = get_object_or_404(Visit, id=visit_id)
visit_start = visit.datetime_begin.strftime("%Y-%m-%d")
visit_end = visit.datetime_end.strftime("%Y-%m-%d")
if visit.is_finished:
messages.error(request, "Appointment cannot be added because the visit is finished")
return redirect('web.views.subject_visit_details', id=visit.subject.id)
if not visit.subject.can_schedule():
messages.error(request, "Appointment cannot be added because the subject status is: {}".format(visit.subject.status))
return redirect('web.views.subject_visit_details', id=visit.subject.id)
else:
visit_start = datetime.datetime.today().strftime("%Y-%m-%d")
visit_end = datetime.datetime.today().strftime("%Y-%m-%d")
......@@ -81,6 +87,11 @@ def appointment_edit(request, id):
contact_attempts = None
study = Study.get_by_id(GLOBAL_STUDY_ID)
if the_appointment.visit is not None and the_appointment.visit.subject is not None:
if not the_appointment.visit.subject.can_schedule():
messages.error(request, "Appointment cannot be edited because the subject status is: {}".format(the_appointment.visit.subject.status))
return redirect('web.views.subject_visit_details', id=the_appointment.visit.subject.id)
if request.method == 'POST':
appointment_form = AppointmentEditForm(request.POST,
request.FILES,
......
......@@ -121,6 +121,8 @@ def subject_visit_details(request, id):
visits_data.append((visit_form, appointments, finished, visit_id, visit_title))
if not visit.is_finished:
allow_add_visit = False
if not study_subject_to_be_viewed.can_schedule():
allow_add_visit = False
return wrap_response(request, 'subjects/visit_details.html',
{'display': visits_data, "id": id, "allow_add_visit": allow_add_visit})
......@@ -103,10 +103,15 @@ def visit_add(request, subject_id=-1):
subject = None
if len(subjects) > 0:
subject = subjects[0]
if Visit.objects.filter(subject=subject, is_finished=False).count() > 0:
messages.add_message(request, messages.WARNING, 'The subject has unfinished visits, please, finish them before adding new visits.')
return redirect('web.views.subject_visit_details', id=subject_id)
if not subject.can_schedule():
messages.error(request, "Visit cannot be added because the subject status is: {}".format(subject.status))
return redirect('web.views.subject_visit_details', id=subject_id)
if request.method == 'POST':
form = VisitAddForm(request.POST, request.FILES)
args = {'form': form}
......
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