Skip to content

Commit

Permalink
NES-242 - Change screen to filter the questionnaire fields to be expo…
Browse files Browse the repository at this point in the history
…rted
  • Loading branch information
sueli committed Apr 1, 2016
1 parent a7fe16a commit 7665ecf
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 71 deletions.
4 changes: 2 additions & 2 deletions patientregistrationsystem/qdc/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def save_to_csv(complete_filename, rows_to_be_saved):
:param rows_to_be_saved: list of rows that are going to be written on the file
:return:
"""
with open(complete_filename, 'w', newline='') as csv_file:
with open(complete_filename, 'w', newline='', encoding='UTF-8') as csv_file:
export_writer = writer(csv_file)
for row in rows_to_be_saved:
export_writer.writerow(row)
Expand Down Expand Up @@ -126,7 +126,7 @@ def log_message(self, text, param1="", param2=""):

text_message = "%s %s %s %s %s" % (smart_str(current_time), smart_str(self.user),
smart_str(text), smart_str(param1), smart_str(param2))
with open(self.file_name, "a") as f:
with open(self.file_name, "a", encoding='UTF-8') as f:
file_log = File(f)
file_log.write(text_message)

Expand Down
6 changes: 3 additions & 3 deletions patientregistrationsystem/qdc/export/input_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def read(self, input_filename, update_input_data=True):

def write(self, output_filename):
print("write")
with open(output_filename, 'w') as outfile:
with open(output_filename, 'w', encoding='UTF-8') as outfile:
dump(self.data, outfile)

def build_header(self):
Expand All @@ -50,7 +50,7 @@ def build_dynamic_header(self, variable_name, variable_data):
def build_diagnosis_participant(self, strut_name, output_filename, field_header_list):
print("participant or diagnosis")
self.data[strut_name] = []
self.data[strut_name].append({"output_filename": output_filename, "output_list":[]})
self.data[strut_name].append({"output_filename": output_filename, "output_list": []})

# field_header_list[0] -> field
# field_header_list[1] -> header
Expand Down Expand Up @@ -96,4 +96,4 @@ def build_complete_export_structure(export_per_participant, export_per_questionn

json_data.build_questionnaire(questionnaires_list, language)

json_data.write(output_filename)
json_data.write(output_filename)
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h4>{% trans "Questionnaire information" %}</h4>
{% for survey in questionnaires_fields_list %}
<optgroup label='{{ survey.sid }} - {{survey.title }}'>
{% for field in survey.output_list %}
<option value="{{ survey.sid }}*{{survey.title }}*{{ field.field }}*{{ field.header }}"> {{ field.header }} </option>
<option {% for sid1, field1 in selected_ev_quest%} {% if survey.sid == sid1 and field.field == field1 %}selected{% endif %} {% endfor %} value="{{ survey.sid }}*{{survey.title }}*{{ field.field }}*{{ field.header }}"> {{ field.header }} </option>
{% endfor %}
</optgroup>
{% endfor %}
Expand All @@ -136,7 +136,7 @@ <h4>{% trans "Participants" %}</h4>
<label class="control-label">{% trans "Participant fields" %} <b style="color: red;">*</b></label>
<select class="form-control" size="13" required="" id="patient_selected" name="patient_selected" multiple="multiple" data-error={% trans "Please, select a patient field from the list." %}>
{% for field in patient_fields %}
<option value="{{ field.field }}*{{ field.header }}"> {{ field.header }} </option>
<option {% if field.field in selected_participant %}selected{% endif %} value="{{ field.field }}*{{ field.header }}"> {{ field.header }} </option>
{% endfor %}
</select>
</div>
Expand All @@ -151,7 +151,7 @@ <h4>{% trans "Diagnosis" %}</h4>
<label class="control-label">{% trans "Diagnosis fields" %} <b style="color: red;">*</b></label>
<select class="form-control" size="13" required="" id="diagnosis_selected" name="diagnosis_selected" multiple="multiple" data-error={% trans "Please, select a diagnosis field from the list." %}>
{% for field in diagnosis_fields %}
<option value="{{ field.field }}*{{ field.header }}"> {{ field.header }} </option>
<option {% if field.field in selected_diagnosis %}selected{% endif %} value="{{ field.field }}*{{ field.header }}"> {{ field.header }} </option>
{% endfor %}
</select>
</div>
Expand Down
145 changes: 82 additions & 63 deletions patientregistrationsystem/qdc/export/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,49 +410,53 @@ def export_view(request, template_name="export/export_data.html"):

if page == 1:

if request.method == "POST" and export_form.is_valid():
if export_form.is_valid():
selected_ev_quest = []
selected_participant = []
selected_diagnosis = []

print("valid data")
if request.method == "POST":

per_participant = export_form.cleaned_data['per_participant']
per_questionnaire = export_form.cleaned_data['per_questionnaire']
questionnaires_selected_list = request.POST.getlist('questionnaire_selected')

questionnaires_selected_list = request.POST.getlist('questionnaire_selected')
questionnaires_list = []

questionnaires_list = []
previous_questionnaire_id = 0
output_list = []
for questionnaire in questionnaires_selected_list:
sid, title, field, header = questionnaire.split("*")

previous_questionnaire_id = 0
output_list = []
for questionnaire in questionnaires_selected_list:
sid, title, field, header = questionnaire.split("*")
sid = int(sid) # transform to integer
if sid != previous_questionnaire_id:
if previous_questionnaire_id != 0:
output_list = []

sid = int(sid) # transform to integer
if sid != previous_questionnaire_id:
if previous_questionnaire_id != 0:
output_list = []
questionnaires_list.append([sid, title, output_list])

questionnaires_list.append([sid, title, output_list])
previous_questionnaire_id = sid

previous_questionnaire_id = sid
output_list.append((field, header))

output_list.append((field, header))
# get participants list
participant_selected_list = request.POST.getlist('patient_selected')

# get participants list
participant_selected_list = request.POST.getlist('patient_selected')
participants_list = []

participants_list = []
for participant in participant_selected_list:
participants_list.append(participant.split("*"))

for participant in participant_selected_list:
participants_list.append(participant.split("*"))
# get diagnosis list
diagnosis_selected_list = request.POST.getlist('diagnosis_selected')

# get diagnosis list
diagnosis_selected_list = request.POST.getlist('diagnosis_selected')
diagnosis_list = []

diagnosis_list = []
for diagnosis in diagnosis_selected_list:
diagnosis_list.append(diagnosis.split("*"))

for diagnosis in diagnosis_selected_list:
diagnosis_list.append(diagnosis.split("*"))
if export_form.is_valid():
print("valid data")

per_participant = export_form.cleaned_data['per_participant']
per_questionnaire = export_form.cleaned_data['per_questionnaire']

# output_filename = "/Users/sueli/PycharmProjects/nes/patientregistrationsystem/qdc/export/json_export_output2.json"

Expand Down Expand Up @@ -491,60 +495,75 @@ def export_view(request, template_name="export/export_data.html"):
response['Content-Length'] = path.getsize(complete_filename)
return response

else:
# page 1 - list of questionnaires
surveys = Questionnaires()
limesurvey_available = check_limesurvey_access(request, surveys)
else:
for questionnaire in questionnaires_list:
for field in questionnaire[2]: # get output_list
selected_ev_quest.append((questionnaire[0], field[0]))

questionnaires_list = []
for participant in participants_list:
selected_participant.append(participant[0])

if limesurvey_available:
questionnaires_list = surveys.find_all_active_questionnaires()
for diagnosis in diagnosis_list:
selected_diagnosis.append(diagnosis[0])

surveys.release_session_key()
# else:
# page 1 - list of questionnaires
surveys = Questionnaires()
limesurvey_available = check_limesurvey_access(request, surveys)

questionnaires_list_final = []
questionnaires_list = []

# removing surveys that are not entrance evaluation
# entrance_evaluation_questionnaires = QuestionnaireResponse.objects.all()
entrance_evaluation_questionnaire_ids_list = set(QuestionnaireResponse.objects.values_list('survey',
flat=True))
if limesurvey_available:
questionnaires_list = surveys.find_all_active_questionnaires()

# ev_questionnaire_ids_list = entrance_evaluation_questionnaires.values_list("survey")
surveys_with_ev_list = Survey.objects.filter(id__in=entrance_evaluation_questionnaire_ids_list)
surveys.release_session_key()

for survey in surveys_with_ev_list:
for questionnaire in questionnaires_list:
if survey.lime_survey_id == questionnaire['sid']:
questionnaires_list_final.append(questionnaire)
break
questionnaires_list_final = []

# removing surveys that are not entrance evaluation
# entrance_evaluation_questionnaires = QuestionnaireResponse.objects.all()
entrance_evaluation_questionnaire_ids_list = set(QuestionnaireResponse.objects.values_list('survey',
flat=True))

# page 2 fields
# ev_questionnaire_ids_list = entrance_evaluation_questionnaires.values_list("survey")
surveys_with_ev_list = Survey.objects.filter(id__in=entrance_evaluation_questionnaire_ids_list)

# entrance evaluation questionnarie fields
questionnaires_fields_list = get_questionnaire_fields(questionnaires_list_final)
for survey in surveys_with_ev_list:
for questionnaire in questionnaires_list:
if survey.lime_survey_id == questionnaire['sid']:
questionnaires_list_final.append(questionnaire)
break

# for field in questionnaires_fields_list:
# for questionnaire in questionnaires_list_final:
# if field["sid"] == questionnaire['sid']:
# field["title"] = questionnaire["surveyls_title"]
# break
# page 2 fields

# entrance evaluation questionnarie fields
questionnaires_fields_list = get_questionnaire_fields(questionnaires_list_final)

# for field in questionnaires_fields_list:
# for questionnaire in questionnaires_list_final:
# if field["sid"] == questionnaire['sid']:
# field["title"] = questionnaire["surveyls_title"]
# break

# patient fields
# patient_fields = []
#
# "output_list":{}

# patient fields
# patient_fields = []
#
# "output_list":{}
# diagnosis fields

# diagnosis fields
context = {

context = {
"limesurvey_available": limesurvey_available,
"export_form": export_form,
"questionnaires_list": questionnaires_list_final,
# "questionnaires_list": questionnaires_list_final,
"contacts": contacts,
"patient_fields": patient_fields,
"diagnosis_fields": diagnosis_fields,
"questionnaires_fields_list": questionnaires_fields_list,
"selected_ev_quest": selected_ev_quest,
"selected_participant": selected_participant,
"selected_diagnosis":selected_diagnosis,
}

# elif page == 2:
Expand Down

0 comments on commit 7665ecf

Please sign in to comment.