diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py index 9368d26c2cfbdd89c16876695b29501fc8e26469..4aead296fcda779bf13106b762c0004e436d2699 100644 --- a/smash/web/api_views/subject.py +++ b/smash/web/api_views/subject.py @@ -63,6 +63,8 @@ def get_subjects_order(subjects, order_column, order_direction): result = subjects.order_by(order_direction + 'dead') elif order_column == "resigned": result = subjects.order_by(order_direction + 'resigned') + elif order_column == "information_sent": + result = subjects.order_by(order_direction + 'information_sent') elif order_column == "postponed": result = subjects.order_by(order_direction + 'postponed') return result @@ -87,6 +89,8 @@ def get_subjects_filtered(subjects, filters): result = result.filter(resigned=(value == "true")) elif column == "postponed": result = result.filter(postponed=(value == "true")) + elif column == "information_sent": + result = result.filter(information_sent=(value == "true")) elif column == "default_location": result = result.filter(default_location=value) elif column == "": @@ -165,6 +169,7 @@ def serialize_subject(subject): "dead": get_yes_no(subject.dead), "resigned": get_yes_no(subject.resigned), "postponed": get_yes_no(subject.postponed), + "information_sent": get_yes_no(subject.information_sent), "id": subject.id, } return result diff --git a/smash/web/migrations/0029_auto_20170404_1616.py b/smash/web/migrations/0029_auto_20170404_1616.py new file mode 100644 index 0000000000000000000000000000000000000000..1f24145c9d554209b21b3912e58f62d89cee4862 --- /dev/null +++ b/smash/web/migrations/0029_auto_20170404_1616.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-04-04 14:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0028_location_color_of_flying_team'), + ] + + operations = [ + migrations.AddField( + model_name='subject', + name='information_sent', + field=models.BooleanField(default=False, verbose_name=b'Information sent'), + ), + migrations.AddField( + model_name='subject', + name='pd_in_family', + field=models.BooleanField(default=False, verbose_name=b'PD in family'), + ), + ] diff --git a/smash/web/migrations/0030_subject_information_sent.py b/smash/web/migrations/0030_subject_information_sent.py new file mode 100644 index 0000000000000000000000000000000000000000..ddde585819750b7f56b23195964b7b3874921ac0 --- /dev/null +++ b/smash/web/migrations/0030_subject_information_sent.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-04-04 14:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('web', '0029_auto_20170404_1616'), + ] + + operations = [ + migrations.RunSQL( + "update web_subject set information_sent=true where id in" + + "(select web_subject.id from web_appointment " + + " left join web_visit on visit_id = web_visit.id " + + " left join web_subject on web_visit.subject_id = web_subject.id where status = 'FINISHED');"), + ] diff --git a/smash/web/models/subject.py b/smash/web/models/subject.py index aa7d746cdfe6d43a8b5720a67cba72c0c0cf012c..499b977741cafab600a13ce2a9304f7ad663338b 100644 --- a/smash/web/models/subject.py +++ b/smash/web/models/subject.py @@ -149,6 +149,14 @@ class Subject(models.Model): default=False, editable=True ) + information_sent = models.BooleanField( + verbose_name='Information sent', + default=False + ) + pd_in_family = models.BooleanField( + verbose_name='PD in family', + default=False, + ) resigned = models.BooleanField( verbose_name='Resigned', default=False, diff --git a/smash/web/templates/subjects/edit.html b/smash/web/templates/subjects/edit.html index 9356646e39ad8ec8af3f11885f73cd4a0cb939db..0a0163615c5c195110444c25bf2371fbc13a78a6 100644 --- a/smash/web/templates/subjects/edit.html +++ b/smash/web/templates/subjects/edit.html @@ -42,9 +42,9 @@ <h3>Subject details</h3> </div> - <div class="box-body"> - <div class="col-md-12"> - <form method="post" action="" class="form-horizontal"> + <form method="post" action="" class="form-horizontal"> + <div class="box-body"> + <div class="col-md-12"> {% csrf_token %} {% for field in form %} @@ -64,20 +64,20 @@ {% endfor %} - </form> - </div> - </div><!-- /.box-body --> + </div> + </div><!-- /.box-body --> - <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.subjects' %}" class="btn btn-block btn-default" - onclick="history.back()">Cancel</a> - </div> - </div><!-- /.box-footer --> + <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.subjects' %}" class="btn btn-block btn-default" + onclick="history.back()">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> </div><!-- /.box --> </div><!-- /.col-md-12 --> </div><!-- /.row --> diff --git a/smash/web/templates/subjects/index.html b/smash/web/templates/subjects/index.html index 2b52622dfe6d5e1841bbb89ea2c2390e28c7f803..05229e970349539827b8d9ad19613ec901e47dd4 100644 --- a/smash/web/templates/subjects/index.html +++ b/smash/web/templates/subjects/index.html @@ -39,6 +39,7 @@ <th>Deceased</th> <th>Resigned</th> <th>Postponed</th> + <th>Info sent</th> <th>Edit</th> </tr> </thead> @@ -68,6 +69,9 @@ <th> <div name="yes_no_filter">---</div> </th> + <th> + <div name="yes_no_filter">---</div> + </th> </tr> </tfoot> @@ -117,10 +121,11 @@ {"data": "dead"}, {"data": "resigned"}, {"data": "postponed"}, + {"data": "information_sent"}, {"data": null}, ], columnDefs: [{ - "targets": 8, + "targets": 9, "data": "id", "defaultContent": '<a href="#" type="button" class="btn btn-block btn-default">Edit</a>' }] diff --git a/smash/web/tests/test_view_appointments.py b/smash/web/tests/test_view_appointments.py index 52c7e442009f0b3e8fdbdc00ee8b206a84d3ba8a..b29533c218f459fe6362280e8bfa643fa9be41a3 100644 --- a/smash/web/tests/test_view_appointments.py +++ b/smash/web/tests/test_view_appointments.py @@ -5,6 +5,7 @@ from django.urls import reverse from functions import create_subject, create_visit, create_appointment, create_worker from web.forms import AppointmentEditForm, SubjectEditForm from web.models import Appointment, Subject +from web.views.notifications import get_today_midnight_date from . import LoggedInTestCase @@ -69,3 +70,28 @@ class AppointmentsViewTests(LoggedInTestCase): reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) self.assertEqual(response.status_code, 200) + + def test_save_appointments_edit(self): + subject = create_subject() + create_worker(self.user, True) + visit = create_visit(subject) + appointment = create_appointment(visit, get_today_midnight_date()) + + form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment") + form_subject = SubjectEditForm(instance=subject, prefix="subject") + form_data = {} + for key, value in form_appointment.initial.items(): + if value is not None: + form_data['appointment-{}'.format(key)] = value + for key, value in form_subject.initial.items(): + if value is not None: + form_data['subject-{}'.format(key)] = value + form_data["appointment-status"] = Appointment.APPOINTMENT_STATUS_FINISHED + + response = self.client.post( + reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) + + self.assertEqual(response.status_code, 302) + + updated_subject = Subject.objects.get(id=subject.id) + self.assertTrue(updated_subject.information_sent) \ No newline at end of file diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index 8bc59f0c2d1b637b96abe4c12ba5966c2dea6732..760b83884517ec462f60df31e0dc51ed17bf9b41 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -3,7 +3,7 @@ from django.shortcuts import get_object_or_404, redirect from . import wrap_response from ..forms import AppointmentDetailForm, AppointmentAddForm, AppointmentEditForm, SubjectEditForm -from ..models import Appointment +from ..models import Appointment, Subject APPOINTMENT_LIST_GENERIC = "GENERIC" APPOINTMENT_LIST_UNFINISHED = "UNFINISHED" @@ -75,6 +75,12 @@ def appointment_edit(request, id): if subject_form is not None: subject_form.save() the_appointment = get_object_or_404(Appointment, id=id) + + if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED: + subject = Subject.objects.get(id=the_appointment.visit.subject.id) + subject.information_sent = True + subject.save() + 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)