From daa8f42397a1012a7bb3c2f7defc63014c6b0b6b Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 6 Jun 2018 09:37:39 +0200 Subject: [PATCH] possibility to configure which study subject fields should be available in the system --- smash/web/forms/__init__.py | 4 +-- smash/web/forms/study_forms.py | 12 ++++++- smash/web/models/study_columns.py | 52 ++++++++++++++--------------- smash/web/templates/study/edit.html | 25 ++++++++++++++ smash/web/views/study.py | 20 ++++++----- 5 files changed, 76 insertions(+), 37 deletions(-) diff --git a/smash/web/forms/__init__.py b/smash/web/forms/__init__.py index c89dd25a..d32f7d6c 100644 --- a/smash/web/forms/__init__.py +++ b/smash/web/forms/__init__.py @@ -1,4 +1,4 @@ -from study_forms import StudyEditForm, StudyNotificationParametersEditForm +from study_forms import StudyEditForm, StudyNotificationParametersEditForm, StudyColumnsEditForm from worker_form import WorkerForm from forms import VisitDetailForm, \ VisitAddForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, \ @@ -13,4 +13,4 @@ __all__ = [StudySubjectAddForm, StudySubjectDetailForm, StudySubjectEditForm, Wo AppointmentDetailForm, AppointmentEditForm, AppointmentAddForm, VisitDetailForm, VisitAddForm, ContactAttemptAddForm, ContactAttemptEditForm, KitRequestForm, StatisticsForm, AvailabilityAddForm, AvailabilityEditForm, HolidayAddForm, SubjectAddForm, SubjectEditForm, SubjectDetailForm, VoucherTypeForm, - VoucherTypePriceForm, VoucherForm, StudyEditForm, StudyNotificationParametersEditForm] + VoucherTypePriceForm, VoucherForm, StudyEditForm, StudyNotificationParametersEditForm, StudyColumnsEditForm] diff --git a/smash/web/forms/study_forms.py b/smash/web/forms/study_forms.py index 38910317..76c51a42 100644 --- a/smash/web/forms/study_forms.py +++ b/smash/web/forms/study_forms.py @@ -2,7 +2,7 @@ import logging from django.forms import ModelForm -from web.models import Study, StudyNotificationParameters +from web.models import Study, StudyNotificationParameters, StudyColumns logger = logging.getLogger(__name__) @@ -26,3 +26,13 @@ class StudyNotificationParametersEditForm(ModelForm): class Meta: model = StudyNotificationParameters fields = '__all__' + + +class StudyColumnsEditForm(ModelForm): + + def __init__(self, *args, **kwargs): + super(StudyColumnsEditForm, self).__init__(*args, **kwargs) + + class Meta: + model = StudyColumns + fields = '__all__' diff --git a/smash/web/models/study_columns.py b/smash/web/models/study_columns.py index 7acd12ba..565ad55d 100644 --- a/smash/web/models/study_columns.py +++ b/smash/web/models/study_columns.py @@ -8,107 +8,107 @@ class StudyColumns(models.Model): class Meta: app_label = 'web' - postponed = models.BooleanField(choices=BOOL_CHOICES, - verbose_name='Postponed', - default=True - ) + postponed = models.BooleanField( + verbose_name='Postponed', + default=True + ) - datetime_contact_reminder = models.BooleanField(choices=BOOL_CHOICES, + datetime_contact_reminder = models.BooleanField( default=True, verbose_name='Please make a contact on' ) - type = models.BooleanField(choices=BOOL_CHOICES, + type = models.BooleanField( default=True, verbose_name='Type' ) - default_location = models.BooleanField(choices=BOOL_CHOICES, + default_location = models.BooleanField( default=True, verbose_name='Default appointment location', ) - flying_team = models.BooleanField(choices=BOOL_CHOICES, + flying_team = models.BooleanField( default=True, verbose_name='Default flying team location (if applicable)', ) - screening_number = models.BooleanField(choices=BOOL_CHOICES, + screening_number = models.BooleanField( default=True, verbose_name='Screening number', ) - nd_number = models.BooleanField(choices=BOOL_CHOICES, + nd_number = models.BooleanField( default=True, verbose_name='ND number', ) - mpower_id = models.BooleanField(choices=BOOL_CHOICES, + mpower_id = models.BooleanField( default=True, verbose_name='MPower ID' ) - comments = models.BooleanField(choices=BOOL_CHOICES, + comments = models.BooleanField( default=True, verbose_name='Comments' ) - referral = models.BooleanField(choices=BOOL_CHOICES, + referral = models.BooleanField( default=True, verbose_name='Referred by' ) - diagnosis = models.BooleanField(choices=BOOL_CHOICES, + diagnosis = models.BooleanField( default=True, verbose_name='Diagnosis' ) - year_of_diagnosis = models.BooleanField(choices=BOOL_CHOICES, + year_of_diagnosis = models.BooleanField( default=True, verbose_name='Year of diagnosis (YYYY)' ) - information_sent = models.BooleanField(choices=BOOL_CHOICES, + information_sent = models.BooleanField( default=True, verbose_name='Information sent', ) - pd_in_family = models.BooleanField(choices=BOOL_CHOICES, + pd_in_family = models.BooleanField( default=True, verbose_name='PD in family', ) - resigned = models.BooleanField(choices=BOOL_CHOICES, + resigned = models.BooleanField( default=True, verbose_name='Resigned', ) - resign_reason = models.BooleanField(choices=BOOL_CHOICES, + resign_reason = models.BooleanField( default=True, verbose_name='Resign reason' ) - referral_letter = models.BooleanField(choices=BOOL_CHOICES, + referral_letter = models.BooleanField( default=False, verbose_name='Referral letter' ) - health_partner = models.BooleanField(choices=BOOL_CHOICES, + health_partner = models.BooleanField( default=False, verbose_name='Health partner' ) - health_partner_feedback_agreement = models.BooleanField(choices=BOOL_CHOICES, + health_partner_feedback_agreement = models.BooleanField( default=False, verbose_name='Agrees to give information to referral' ) - screening = models.BooleanField(choices=BOOL_CHOICES, + screening = models.BooleanField( default=False, verbose_name='Screening' ) - previously_in_study = models.BooleanField(choices=BOOL_CHOICES, + previously_in_study = models.BooleanField( default=False, verbose_name='Previously in PDP study', ) - voucher_types = models.BooleanField(choices=BOOL_CHOICES, + voucher_types = models.BooleanField( default=False, verbose_name='Voucher types', ) - vouchers = models.BooleanField(choices=BOOL_CHOICES, + vouchers = models.BooleanField( default=False, verbose_name='Vouchers', ) diff --git a/smash/web/templates/study/edit.html b/smash/web/templates/study/edit.html index 373f6035..54be5ce7 100644 --- a/smash/web/templates/study/edit.html +++ b/smash/web/templates/study/edit.html @@ -85,6 +85,31 @@ </div> </div><!-- /.box-body --> + <div class="box-header with-border"> + <h3>Available subject study data</h3> + </div> + <div class="box-body"> + <div class="col-md-12"> + + {% for field in study_columns_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|add_class:'form-control' }} + </div> + + {% if field.errors %} + <span class="help-block"> {{ field.errors }} </span> + {% endif %} + </div> + {% endfor %} + + </div> + </div><!-- /.box-body --> + <div class="box-footer"> <div class="col-sm-4"> <button type="submit" class="btn btn-block btn-success">Save</button> diff --git a/smash/web/views/study.py b/smash/web/views/study.py index 8a91ed24..75b2d71f 100644 --- a/smash/web/views/study.py +++ b/smash/web/views/study.py @@ -4,9 +4,9 @@ import logging from django.contrib import messages from django.shortcuts import redirect, get_object_or_404 -from . import wrap_response -from ..forms import StudyEditForm, StudyNotificationParametersEditForm -from ..models import Study +from web.forms import StudyColumnsEditForm, StudyEditForm, StudyNotificationParametersEditForm +from web.models import Study +from web.views import wrap_response logger = logging.getLogger(__name__) @@ -18,9 +18,12 @@ def study_edit(request, study_id): notifications_form = StudyNotificationParametersEditForm(request.POST, request.FILES, instance=study.notification_parameters, prefix="notifications") - if study_form.is_valid() and notifications_form.is_valid(): + study_columns_form = StudyColumnsEditForm(request.POST, request.FILES, instance=study.columns, + prefix="columns") + if study_form.is_valid() and notifications_form.is_valid() and study_columns_form.is_valid(): study_form.save() notifications_form.save() + study_columns_form.save() messages.success(request, "Modifications saved") if '_continue' in request.POST: return redirect('web.views.edit_study', study_id=study.id) @@ -29,12 +32,13 @@ def study_edit(request, study_id): messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.') else: study_form = StudyEditForm(instance=study, prefix="study") - notifications_form = StudyNotificationParametersEditForm(instance=study.notification_parameters, prefix="notifications") + notifications_form = StudyNotificationParametersEditForm(instance=study.notification_parameters, + prefix="notifications") + study_columns_form = StudyColumnsEditForm(instance=study.columns, + prefix="columns") return wrap_response(request, 'study/edit.html', { 'study_form': study_form, 'notifications_form': notifications_form, - # 'study_subject': study_subject, - # 'contact_attempts': contact_attempts, - # 'mail_templates': MailTemplate.get_subject_mail_templates(languages) + 'study_columns_form': study_columns_form, }) -- GitLab