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

Merge branch '186-pdp-study-patient-data' into 'master'

Resolve "PDP study patient data"

Closes #186

See merge request NCER-PD/scheduling-system!116
parents 908deafa 1c6cc1f2
No related branches found
No related tags found
1 merge request!116Resolve "PDP study patient data"
Pipeline #
......@@ -38,7 +38,11 @@ class VoucherForm(ModelForm):
fields = '__all__'
def __init__(self, *args, **kwargs):
voucher_types = kwargs.pop('voucher_types', VoucherType.objects.all())
super(VoucherForm, self).__init__(*args, **kwargs)
self.fields['voucher_type'].queryset = voucher_types
self.fields['number'].widget.attrs['readonly'] = True
self.fields['number'].required = False
......
......@@ -35,7 +35,7 @@
</div>
<div class="box box-info">
<form method="post" action="" enctype="multipart/form-data" class="form-horizontal">
<form method="post" action="" enctype="multipart/form-data" class="form-horizontal">
{% csrf_token %}
<fieldset>
<div class="box-header with-border">
......@@ -136,6 +136,11 @@
</div><!-- /.box-footer -->
</form>
</div>
{% if appointment.visit.subject.study.columns.vouchers %}
{% include 'includes/subject_vouchers_box.html' with subject=appointment.visit.subject %}
{% endif %}
{% include 'includes/mail_templates_box.html' with instance_id=appointment.id %}
{% if appointment.visit %}
{% include 'includes/contact_attempts_box.html' with subject=appointment.visit.subject contact_attempts=contact_attempts appointment_id=appointment.id %}
......
<div class="row">
<div class="col-lg-12">
<div class="box box-success">
<div class="box-header with-border">
<h3>Vouchers <a title="add a new voucher"
id="add-voucher"
href="{% url 'web.views.voucher_add' %}?study_subject_id={{ subject.id }}"
class="text-primary"
><i class="fa fa-plus-circle text-success"></i></a></h3>
</div>
<div class="box-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th class="text-center">Number</th>
<th class="text-center">Type</th>
<th class="text-center">Issue date</th>
<th class="text-center">Expiry date</th>
<th class="text-center">Status</th>
<th class="text-center">Use date</th>
<th class="text-center">Partner</th>
<th class="text-center">Feedback</th>
<th class="text-center">Edit</th>
</tr>
</thead>
<tbody>
{% for voucher in subject.vouchers.all %}
<tr>
<td>{{ voucher.number }}</td>
<td>{{ voucher.voucher_type }}</td>
<td>{{ voucher.issue_date }}</td>
<td>{{ voucher.expiry_date }}</td>
<td>{{ voucher.status }}</td>
<td>{{ voucher.use_date }}</td>
<td>{{ voucher.usage_partner.first_name }} {{ voucher.usage_partner.last_name }}</td>
<td>{{ voucher.feedback }}</td>
<td><a href="{% url 'web.views.voucher_edit' voucher.id %}"><i class="fa fa-edit"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
......@@ -109,11 +109,16 @@
</div><!-- /.col-md-12 -->
</div><!-- /.row -->
{% if study_subject.study.columns.vouchers %}
{% include 'includes/subject_vouchers_box.html' with subject=study_subject %}
{% endif %}
{% include 'includes/mail_templates_box.html' with instance_id=study_subject.id %}
{% include 'includes/contact_attempts_box.html' with subject=study_subject contact_attempts=contact_attempts %}
<div class="modal modal-danger fade" id="confirm-dead-resigned-mark-dialog" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
......
......@@ -16,14 +16,16 @@ class VoucherFormTests(LoggedInWithWorkerTestCase):
super(VoucherFormTests, self).setUp()
def test_auto_generated_use_date(self):
voucher_type = create_voucher_type()
study_subject = create_study_subject()
study_subject.voucher_types.add(voucher_type)
create_voucher(study_subject)
voucher_form = VoucherForm()
form_data = {
"status": VOUCHER_STATUS_USED,
"usage_partner": str(self.worker.id),
"voucher_type": create_voucher_type().id
"voucher_type": voucher_type.id
}
for key, value in voucher_form.initial.items():
form_data[key] = format_form_field(value)
......
......@@ -13,7 +13,9 @@ logger = logging.getLogger(__name__)
class VoucherTypeViewTests(LoggedInTestCase):
def test_render_add_voucher_request(self):
response = self.client.get(reverse('web.views.voucher_add'))
study_subject = create_study_subject()
url = reverse('web.views.voucher_add') + "?study_subject_id=" + str(study_subject.id)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_render_edit_voucher_request(self):
......@@ -22,11 +24,13 @@ class VoucherTypeViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 200)
def test_add_voucher(self):
voucher_type = create_voucher_type()
study_subject = create_study_subject()
study_subject.voucher_types.add(voucher_type)
visit_detail_form = VoucherForm()
form_data = {
"status": VOUCHER_STATUS_NEW,
"voucher_type": create_voucher_type().id
"voucher_type": voucher_type.id
}
for key, value in visit_detail_form.initial.items():
form_data[key] = format_form_field(value)
......
......@@ -139,7 +139,6 @@ def appointment_edit(request, id):
'appointment_form': appointment_form,
'study_subject_form': study_subject_form,
'subject_form': subject_form,
'id': id,
'appointment': the_appointment,
'contact_attempts': contact_attempts,
'mail_templates': MailTemplate.get_appointment_mail_templates(languages)
......
......@@ -8,7 +8,7 @@ from django.views.generic import ListView
from django.views.generic import UpdateView
from web.forms import VoucherForm
from web.models import Voucher
from web.models import Voucher, StudySubject
from web.models.constants import GLOBAL_STUDY_ID
from . import WrappedView
......@@ -21,6 +21,10 @@ class VoucherListView(ListView, WrappedView):
template_name = 'vouchers/list.html'
def voucher_types_for_study_subject(study_subject_id):
return StudySubject.objects.get(id=study_subject_id).voucher_types.all()
class VoucherCreateView(CreateView, WrappedView):
form_class = VoucherForm
model = Voucher
......@@ -39,6 +43,11 @@ class VoucherCreateView(CreateView, WrappedView):
# noinspection PyUnresolvedReferences
return reverse_lazy('web.views.subject_edit', kwargs={'id': self.request.GET.get("study_subject_id", -1)})
def get_form_kwargs(self):
kwargs = super(VoucherCreateView, self).get_form_kwargs()
kwargs['voucher_types'] = voucher_types_for_study_subject(self.request.GET.get("study_subject_id", -1))
return kwargs
class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView):
form_class = VoucherForm
......@@ -51,5 +60,7 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView):
def get_success_url(self, **kwargs):
# noinspection PyUnresolvedReferences
study_subject_id = Voucher.objects.get(id=self.kwargs['pk']).study_subject.id
return reverse_lazy('web.views.subject_edit', kwargs={'id': study_subject_id})
return reverse_lazy('web.views.subject_edit', kwargs={'id': self.get_study_subject_id()})
def get_study_subject_id(self):
return Voucher.objects.get(id=self.kwargs['pk']).study_subject.id
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