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

appointment doesn't have to be attached to visit

parent ef4af73e
No related branches found
No related tags found
1 merge request!27Resolve "there should be a way to add an appointment with external person (neither a subject nor control)"
...@@ -47,6 +47,8 @@ class Appointment(models.Model): ...@@ -47,6 +47,8 @@ class Appointment(models.Model):
visit = models.ForeignKey(Visit, visit = models.ForeignKey(Visit,
verbose_name='Visit ID', verbose_name='Visit ID',
editable=False, editable=False,
null=True,
blank=True,
) )
comment = models.TextField(max_length=1024, comment = models.TextField(max_length=1024,
verbose_name='Comment', verbose_name='Comment',
...@@ -103,7 +105,7 @@ class Appointment(models.Model): ...@@ -103,7 +105,7 @@ class Appointment(models.Model):
return result return result
def title(self): def title(self):
if self.visit.subject.screening_number == "---": if self.visit is None:
return self.comment.replace("\n", ";").replace("\r", ";") return self.comment.replace("\n", ";").replace("\r", ";")
else: else:
title = self.visit.subject.first_name + " " + self.visit.subject.last_name + " type: " title = self.visit.subject.first_name + " " + self.visit.subject.last_name + " type: "
......
...@@ -59,41 +59,42 @@ ...@@ -59,41 +59,42 @@
</fieldset> </fieldset>
<fieldset>
<div class="box-header with-border">
<h3 class="box-title">Subject's details</h3>
</div>
<div class="box-body"> {% if subject_form %}
{% for field in subject_form %} <fieldset>
<div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> <div class="box-header with-border">
<label for="{# TODO #}" class="col-sm-4 control-label"> <h3 class="box-title">Subject's details</h3>
{{ field.label }} </div>
</label>
<div class="col-sm-8"> <div class="box-body">
{{ field|add_class:'form-control' }} {% for field in subject_form %}
</div> <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>
{% if field.errors %} <div class="col-sm-8">
<span class="help-block"> {{ field|add_class:'form-control' }}
{{ field.errors }} </div>
</span>
{% endif %}
</div>
{% endfor %}
</div><!-- /.box-body -->
<div class="box-footer"> {% if field.errors %}
<div class="col-sm-6"> <span class="help-block"> {{ field.errors }} </span>
<button type="submit" class="btn btn-block btn-success">Save</button> {% endif %}
</div> </div>
<div class="col-sm-6"> {% endfor %}
<a href="{% url 'web.views.appointments' %}" class="btn btn-block btn-default" </div><!-- /.box-body -->
onclick="history.back()">Cancel</a>
</div> </fieldset>
</div><!-- /.box-footer --> {% endif %}
</fieldset> <div class="box-footer">
<div class="col-sm-6">
<button type="submit" class="btn btn-block btn-success">Save</button>
</div>
<div class="col-sm-6">
<a href="{% url 'web.views.appointments' %}" class="btn btn-block btn-default"
onclick="history.back()">Cancel</a>
</div>
</div><!-- /.box-footer -->
</form> </form>
</div> </div>
{% endblock %} {% endblock %}
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
{% for approach in approaching_list %} {% for approach in approaching_list %}
<tr> <tr>
{% if approach.visit.subject.screening_number == "---" %} {% if approach.visit == None %}
<td> <td>
</td> </td>
<td> <td>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
{% for approach in appointment_list %} {% for approach in appointment_list %}
<tr> <tr>
{% if approach.visit.subject.screening_number == "---" %} {% if approach.visit == None %}
<td> <td>
</td> </td>
<td> <td>
......
from django.test import TestCase
from functions import create_subject, create_appointment
from functions import create_visit
from web.models import Appointment
from web.models import Visit
class AppointmentModelTests(TestCase):
def test_title_for_appointment_without_visit(self):
comment = "some comment title"
appointment = create_appointment()
appointment.visit = None
appointment.comment = comment
appointment.save()
self.assertEqual(comment, appointment.title())
...@@ -51,3 +51,31 @@ class AppointmentsViewTests(TestCase): ...@@ -51,3 +51,31 @@ class AppointmentsViewTests(TestCase):
self.assertEqual(new_comment, updated_appointment.comment) self.assertEqual(new_comment, updated_appointment.comment)
self.assertEqual(new_status, updated_appointment.status) self.assertEqual(new_status, updated_appointment.status)
self.assertEqual(new_last_name, updated_subject.last_name) self.assertEqual(new_last_name, updated_subject.last_name)
def test_appointments_edit_without_visit(self):
create_worker(self.user)
appointment = create_appointment()
appointment.visit = None
appointment.save()
response = self.client.get(
reverse('web.views.appointment_edit', kwargs={'id': appointment.id}))
self.assertEqual(response.status_code, 200)
def test_save_appointments_edit_without_visit(self):
create_worker(self.user)
appointment = create_appointment()
appointment.visit = None
appointment.save()
form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment")
form_data = {}
for key, value in form_appointment.initial.items():
if value is not None:
form_data['appointment-{}'.format(key)] = value
response = self.client.post(
reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data)
self.assertEqual(response.status_code, 200)
...@@ -26,9 +26,11 @@ urlpatterns = [ ...@@ -26,9 +26,11 @@ urlpatterns = [
url(r'^appointments/details/(?P<id>\d+)$', views.appointment.appointment_details, url(r'^appointments/details/(?P<id>\d+)$', views.appointment.appointment_details,
name='web.views.appointment_details'), name='web.views.appointment_details'),
url(r'^appointments/add/(?P<visit_id>\d+)$', views.appointment.appointment_add, name='web.views.appointment_add'), url(r'^appointments/add/(?P<visit_id>\d+)$', views.appointment.appointment_add, name='web.views.appointment_add'),
url(r'^appointments/add/general$', views.appointment.appointment_add, name='web.views.appointment_add'),
url(r'^appointments/edit/(?P<id>\d+)$', views.appointment.appointment_edit, name='web.views.appointment_edit'), url(r'^appointments/edit/(?P<id>\d+)$', views.appointment.appointment_edit, name='web.views.appointment_edit'),
url(r'^appointments/edit_datetime/(?P<id>\d+)$', views.appointment.appointment_edit_datetime, url(r'^appointments/edit_datetime/(?P<id>\d+)$', views.appointment.appointment_edit_datetime,
name='web.views.appointment_edit_datetime'), name='web.views.appointment_edit_datetime'),
url(r'^visits$', views.visit.visits, name='web.views.visits'), url(r'^visits$', views.visit.visits, name='web.views.visits'),
url(r'^visits/exceeded$', views.visit.exceeded_visits, name='web.views.exceeded_visits'), url(r'^visits/exceeded$', views.visit.exceeded_visits, name='web.views.exceeded_visits'),
url(r'^visits/unfinished$', views.visit.unfinished_visits, name='web.views.unfinished_visits'), url(r'^visits/unfinished$', views.visit.unfinished_visits, name='web.views.unfinished_visits'),
......
...@@ -42,14 +42,17 @@ def appointment_details(request, id): ...@@ -42,14 +42,17 @@ def appointment_details(request, id):
return wrap_response(request, 'appointments/details.html', {'form': form}) return wrap_response(request, 'appointments/details.html', {'form': form})
def appointment_add(request, visit_id): def appointment_add(request, visit_id=None):
full_list = get_calendar_full_appointments(request.user) full_list = get_calendar_full_appointments(request.user)
if request.method == 'POST': if request.method == 'POST':
form = AppointmentAddForm(request.POST, request.FILES, user=request.user) form = AppointmentAddForm(request.POST, request.FILES, user=request.user)
if form.is_valid(): if form.is_valid():
form.instance.visit_id = visit_id form.instance.visit_id = visit_id
form.save() form.save()
return redirect('web.views.visit_details', id=visit_id) if visit_id is None:
return redirect('web.views.appointments')
else:
return redirect('web.views.visit_details', id=visit_id)
else: else:
form = AppointmentAddForm(user=request.user) form = AppointmentAddForm(user=request.user)
...@@ -59,22 +62,37 @@ def appointment_add(request, visit_id): ...@@ -59,22 +62,37 @@ def appointment_add(request, visit_id):
def appointment_edit(request, id): def appointment_edit(request, id):
the_appointment = get_object_or_404(Appointment, id=id) the_appointment = get_object_or_404(Appointment, id=id)
subject_form = None
if request.method == 'POST': if request.method == 'POST':
appointment_form = AppointmentEditForm(request.POST, appointment_form = AppointmentEditForm(request.POST,
request.FILES, request.FILES,
instance=the_appointment, instance=the_appointment,
user=request.user, user=request.user,
prefix="appointment") prefix="appointment")
subject_form = SubjectEditForm(request.POST, instance=the_appointment.visit.subject, prefix="subject")
if appointment_form.is_valid() and subject_form.is_valid(): is_valid_form = True
if the_appointment.visit is not None:
subject_form = SubjectEditForm(request.POST, instance=the_appointment.visit.subject, prefix="subject")
if not subject_form.is_valid():
is_valid_form = False
if not appointment_form.is_valid():
is_valid_form = False
if is_valid_form:
appointment_form.save() appointment_form.save()
subject_form.save() if subject_form is not None:
return redirect('web.views.appointments') subject_form.save()
the_appointment = get_object_or_404(Appointment, id=id)
if (the_appointment.status != Appointment.APPOINTMENT_STATUS_SCHEDULED) and (the_appointment.visit is not None):
return redirect('web.views.visit_details', id=the_appointment.visit.id)
else:
return redirect('web.views.appointments')
else: else:
appointment_form = AppointmentEditForm(instance=the_appointment, user=request.user, prefix="appointment") appointment_form = AppointmentEditForm(instance=the_appointment, user=request.user, prefix="appointment")
if the_appointment.visit is not None:
subject_form = SubjectEditForm(instance=the_appointment.visit.subject, prefix="subject") subject_form = SubjectEditForm(instance=the_appointment.visit.subject, prefix="subject")
return wrap_response(request, 'appointments/edit.html', { return wrap_response(request, 'appointments/edit.html', {
'form': appointment_form, 'form': appointment_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