diff --git a/smash/web/forms.py b/smash/web/forms.py index 2402d689969c532c041c41e6121e01ec9aed391a..7a8458917f0b3970feb56ea71755b2ee3fd5028e 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -146,7 +146,7 @@ def get_new_screening_number(screening_number_prefix): return screening_number_prefix + str(result_number + 1).zfill(3) -class SubjectDetailForm(ModelForm): +class StudySubjectDetailForm(ModelForm): class Meta: model = StudySubject fields = '__all__' @@ -340,7 +340,8 @@ class VisitDetailForm(ModelForm): class VisitAddForm(ModelForm): - subject = forms.ModelChoiceField(queryset=StudySubject.objects.order_by('subject__last_name', 'subject__first_name')) + subject = forms.ModelChoiceField( + queryset=StudySubject.objects.order_by('subject__last_name', 'subject__first_name')) datetime_begin = forms.DateField(label="Visit begins on", widget=forms.TextInput(attrs=DATEPICKER_DATE_ATTRS) ) @@ -565,3 +566,9 @@ class SubjectEditForm(ModelForm): class Meta: model = Subject fields = '__all__' + + +class SubjectDetailForm(ModelForm): + class Meta: + model = Subject + fields = '__all__' diff --git a/smash/web/templates/visits/details.html b/smash/web/templates/visits/details.html index f6c632b961d953120b79982937a94a509a5cde74..ed73408d2e1030b164c7a6e38be41df5b83c9fb8 100644 --- a/smash/web/templates/visits/details.html +++ b/smash/web/templates/visits/details.html @@ -36,7 +36,7 @@ <form method="post" action="" class="form-horizontal"> {% csrf_token %} <div class="box-body"> - {% for field in vform %} + {% for field in visit_form %} {% if not field|is_checkbox %} <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <label for="{# TODO #}" class="col-sm-4 control-label">{{ field.label }}</label> @@ -155,7 +155,32 @@ <form class="form-horizontal"> <div class="box-body"> - {% for field in sform %} + {% for field in subject_form %} + <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> + <label for="{# TODO #}" class="col-sm-4 control-label"> + {{ field.label }} + </label> + + <div class="col-sm-8"> + {{ field|disable|add_class:'form-control' }} + </div> + + {% if field.errors %} + <span class="help-block"> + {{ field.errors }} + </span> + {% endif %} + </div> + {% endfor %} + </div><!-- /.box-body --> + + </form> + <div class="box-header with-border"> + <h3 class="box-title">Subject's study details</h3> + </div> + <form class="form-horizontal"> + <div class="box-body"> + {% for field in study_subject_form %} <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> <label for="{# TODO #}" class="col-sm-4 control-label"> {{ field.label }} @@ -174,11 +199,11 @@ {% endfor %} </div><!-- /.box-body --> - <div class="box-footer"> - <td><a href="{% url 'web.views.subject_edit' visit.subject.id %}" type="button" - class="btn btn-block btn-default">Edit subject</a></td> - </div><!-- /.box-footer --> </form> + <div class="box-footer"> + <td><a href="{% url 'web.views.subject_edit' visit.subject.id %}" type="button" + class="btn btn-block btn-default">Edit subject</a></td> + </div><!-- /.box-footer --> </div> {% include 'includes/mail_templates_box.html' with instance_id=visit.id %} diff --git a/smash/web/tests/view/test_visit.py b/smash/web/tests/view/test_visit.py index d43c5d15e1d32e5a7bba277d6b803c61356a602f..8925d6d8fa8b0be13fba8098c288027c02b071b9 100644 --- a/smash/web/tests/view/test_visit.py +++ b/smash/web/tests/view/test_visit.py @@ -1,4 +1,5 @@ import datetime +import logging from django.urls import reverse @@ -8,14 +9,22 @@ from web.tests import LoggedInTestCase from web.tests.functions import create_study_subject, create_visit, create_appointment, create_appointment_type from web.views.notifications import get_today_midnight_date +logger = logging.getLogger(__name__) + class VisitViewTests(LoggedInTestCase): def test_visit_details_request(self): visit = create_visit() create_appointment(visit) + visit.subject.subject.address = "SUBJECT_ADDRESS_DATA" + visit.subject.subject.save() + visit.subject.comments = "STUDY_SUBJECT_COMMENTS_DATA" + visit.subject.save() - response = self.client.get(reverse('web.views.visit_details', args=[visit.id])) + response = self.client.get(reverse('web.views.visit_details', kwargs={'id': visit.id})) self.assertEqual(response.status_code, 200) + self.assertTrue(visit.subject.comments in response.content, msg="No study subject data in rendered response") + self.assertTrue(visit.subject.subject.address in response.content, msg="No subject data in rendered response") def test_save_visit_details(self): visit = create_visit() diff --git a/smash/web/views/visit.py b/smash/web/views/visit.py index 0de64bba5ce6864b8a0aa0495a4500058ee5ea1a..2dd081106633856fa109d72fdb9db7f7ee57a2d6 100644 --- a/smash/web/views/visit.py +++ b/smash/web/views/visit.py @@ -5,7 +5,7 @@ from notifications import get_active_visits_with_missing_appointments, get_unfin get_approaching_visits_without_appointments, get_approaching_visits_for_mail_contact, get_exceeded_visits, \ waiting_for_appointment from . import wrap_response -from ..forms import VisitDetailForm, SubjectDetailForm, VisitAddForm +from ..forms import VisitDetailForm, StudySubjectDetailForm, VisitAddForm, SubjectDetailForm from ..models import Visit, Appointment, StudySubject, MailTemplate @@ -60,15 +60,17 @@ def visit_details(request, id): if appointment.status == Appointment.APPOINTMENT_STATUS_SCHEDULED: can_finish = False - subject_form = SubjectDetailForm(instance=study_subject) + study_subject_form = StudySubjectDetailForm(instance=study_subject) + subject_form = SubjectDetailForm(instance=study_subject.subject) languages = [] if study_subject.subject.default_written_communication_language: languages.append(study_subject.subject.default_written_communication_language) languages.extend(study_subject.subject.languages.all()) return wrap_response(request, 'visits/details.html', { - 'vform': visit_form, - 'sform': subject_form, + 'visit_form': visit_form, + 'study_subject_form': study_subject_form, + 'subject_form': subject_form, 'loApp': list_of_appointments, 'visFinished': visit_finished, 'canFinish': can_finish,