Skip to content

Commit

Permalink
Merge branch 'NES-995' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caco13 committed Aug 15, 2019
2 parents 283d172 + d46eb8c commit 3ff501c
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

{% block header %}
<script type="text/javascript">

$(function(){
$("[data-toggle=tooltip]").tooltip();
});

</script>
<script src="{% static 'quiz/js/subject_questionnaire_response_form.js' %}"></script>
{% endblock %}
Expand Down
4 changes: 2 additions & 2 deletions patientregistrationsystem/qdc/experiment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5276,8 +5276,8 @@ def search_subjects(request, group_id, template_name="experiment/search_subjects
return render(request, template_name, context)


def subject_questionnaire_response_start_fill_questionnaire(request, subject_id, group_id, questionnaire_id,
list_of_path):
def subject_questionnaire_response_start_fill_questionnaire(
request, subject_id, group_id, questionnaire_id, list_of_path):
questionnaire_response_form = QuestionnaireResponseForm(request.POST)

data_configuration_tree_id = list_data_configuration_tree(questionnaire_id, list_of_path)
Expand Down
3 changes: 2 additions & 1 deletion patientregistrationsystem/qdc/plugin/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from solo.admin import SingletonModelAdmin
from .models import RandomForests

from plugin.models import RandomForests

admin.site.register(RandomForests, SingletonModelAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-08-14 17:23
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('plugin', '0003_auto_20190514_1543'),
]

operations = [
migrations.AddField(
model_name='randomforests',
name='plugin_url',
field=models.CharField(default='', max_length=200),
),
]
1 change: 1 addition & 0 deletions patientregistrationsystem/qdc/plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class RandomForests(SingletonModel):
admission_assessment = models.ForeignKey(Survey, related_name='survey_admission', blank=True, null=True)
surgical_evaluation = models.ForeignKey(Survey, related_name='survey_surgical', blank=True, null=True)
plugin_url = models.CharField(max_length=200, default='')

class Meta:
permissions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,10 @@ <h4>{% trans "Additional info" %}</h4>
$("#patient_selected").click(function () {
$("#gender_field").prop('selected', true);
});

{# Open url plugin in new tab #}
{% if plugin_url %}
window.open("{{ plugin_url }}", "_blank");
{% endif %}
</script>
{% endblock %}
10 changes: 10 additions & 0 deletions patientregistrationsystem/qdc/plugin/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.test import TestCase

from plugin.models import RandomForests


class RandomForestsModelTest(TestCase):

def test_default_attributes(self):
random_forests = RandomForests()
self.assertEqual(random_forests.plugin_url, '')
135 changes: 103 additions & 32 deletions patientregistrationsystem/qdc/plugin/tests/test_views.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion patientregistrationsystem/qdc/plugin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from plugin import views

urlpatterns = [
url(r'^$', views.send_to_plugin, name='send_to_plugin'),
url(r'^$', views.send_to_plugin, name='send-to-plugin'),
]
34 changes: 20 additions & 14 deletions patientregistrationsystem/qdc/plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -37,7 +36,7 @@ def participants_dict(survey):


def update_patient_attributes(participants):
"""add item to 'patient_selected POST list to suit to export method
"""Add item to patient_selected POST list to suit to export method
:param participants: list - participants
:return: list - updated participants
"""
Expand Down Expand Up @@ -110,20 +109,20 @@ def build_zip_file(request, participants_plugin, participants_headers, questionn


@login_required
def send_to_plugin(request, template_name="plugin/send_to_plugin.html"):
def send_to_plugin(request, template_name='plugin/send_to_plugin.html'):
if request.method == 'POST':
if not request.POST.getlist('patients_selected[]'):
messages.warning(request, _('Please select at least one patient'))
return redirect(reverse('send_to_plugin'))
return redirect(reverse('send-to-plugin'))
# Export experiment (from export app) requires at least one patient
# attribute selected (patient_selected is the list of attributes).
# This may be changed.
# This may be changed to a better key name
if not request.POST.getlist('patient_selected'):
messages.warning(request, _('Please select at least Gender participant attribute'))
return redirect(reverse('send_to_plugin'))
return redirect(reverse('send-to-plugin'))
if 'gender__name*gender' not in request.POST.getlist('patient_selected'):
messages.warning(request, _('The Floresta Plugin needs to send at least Gender attribute'))
return redirect(reverse('send_to_plugin'))
return redirect(reverse('send-to-plugin'))
participants = request.POST.getlist('patients_selected[]')
participants_headers = update_patient_attributes(request.POST.getlist('patient_selected'))
limesurvey_error, questionnaires = build_questionnaires_list(request.LANGUAGE_CODE)
Expand All @@ -132,23 +131,25 @@ def send_to_plugin(request, template_name="plugin/send_to_plugin.html"):
request,
_('Error: some thing went wrong consuming LimeSurvey API. Please try again. '
'If problem persists please contact System Administrator.'))
return redirect(reverse('send_to_plugin'))
return redirect(reverse('send-to-plugin'))
limesurvey_error, zip_file = build_zip_file(request, participants, participants_headers, questionnaires)
if limesurvey_error:
messages.error(
request,
_('Error: some thing went wrong consuming LimeSurvey API. Please try again. '
'If problem persists please contact System Administrator.'))
return redirect(reverse('send_to_plugin'))
return redirect(reverse('send-to-plugin'))
if zip_file:
# TODO (NES-995): put this below
messages.success(request, _('Data from questionnaires was sent to Forest Plugin'))
with open(zip_file, 'rb') as file:
response = HttpResponse(file, content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename="export.zip"'
response['Content-Lenght'] = path.getsize(zip_file)
return response

export = Export.objects.last()
plugin_url = 'http://plugin_url?user_id=' + str(request.user.id) + '&export_id=' + str(export.id)
request.session['plugin_url'] = plugin_url
return redirect(reverse('send-to-plugin'))
else:
messages.error(request, _('Could not open zip file to send to Forest Plugin'))
# TODO (NES-995): needs test here. Forgeting return statement

try:
random_forests = RandomForests.objects.get()
Expand Down Expand Up @@ -199,4 +200,9 @@ def send_to_plugin(request, template_name="plugin/send_to_plugin.html"):
'surgical_title': surgical_title
}

plugin_url = request.session.get('plugin_url', None)
if plugin_url is not None:
context['plugin_url'] = plugin_url
del request.session['plugin_url']

return render(request, template_name, context)
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
{% endif %}

{% get_solo 'plugin.RandomForests' as random_forests %}
{% if perms.plugin.can_send_data_to_plugin and random_forests.admission_assessment and random_forests.surgical_evaluation %}
{% if perms.plugin.can_send_data_to_plugin and random_forests.admission_assessment and random_forests.surgical_evaluation and random_forests.plugin_url %}
<li {% block activePlugin %}{% endblock %}>
<a href="/plugin/">
<span class="glyphicon glyphicon-cloud-upload"></span>
Expand Down

0 comments on commit 3ff501c

Please sign in to comment.