diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py index 541af4a22fb8ad8c0a00a52282b40596911eb579..edecdbed43489d00af5c1efff14de80220601d25 100644 --- a/smash/web/api_views/subject.py +++ b/smash/web/api_views/subject.py @@ -1,5 +1,6 @@ import logging import re + from django.db.models import Count, Case, When, Min, Max from django.db.models import Q from django.http import JsonResponse @@ -90,8 +91,8 @@ def get_subject_columns(request, subject_list_type): visit_numbers = range(1, study.visits_to_show_in_subject_list + 1) for one_based_idx, virus_visit_number in enumerate(virus_visit_numbers, 1): - add_column(result, - 'Virus {} RT-PCR'.format(virus_visit_number), + add_column(result, + 'Virus {} RT-PCR'.format(virus_visit_number), 'virus_test_{}'.format(one_based_idx), #always starts in 1 study_subject_columns, 'yes_no_null_inconclusive_filter', study.columns) @@ -118,10 +119,10 @@ def get_subject_columns(request, subject_list_type): add_column(result, "Type", "type", study_subject_columns, "type_filter", study.columns) add_column(result, "Edit", "edit", None, None, sortable=False) - + for one_based_idx, visit_number in enumerate(visit_numbers, 1): visit_key = "visit_{}".format(one_based_idx) #always starts in 1 - add_column(result, "Visit {}".format(visit_number), visit_key, None, + add_column(result, "Visit {}".format(visit_number), visit_key, None, "visit_filter", visible_param=study_subject_list.visits) return JsonResponse({"columns": result}) @@ -215,15 +216,15 @@ def get_subjects_order(subjects_to_be_ordered, order_column, order_direction, co elif str(order_column).startswith("visit_"): visit_number = get_visit_number_from_visit_x_string(order_column) result = order_by_visit(subjects_to_be_ordered, order_direction, visit_number) - elif re.search(r'^virus_test_[1-5]$',order_column): + elif re.search(r'^virus_test_[1-5]$', order_column): result = subjects_to_be_ordered.order_by(order_direction + order_column) - elif re.search(r'^virus_test_[1-5]_updated$',order_column): + elif re.search(r'^virus_test_[1-5]_updated$', order_column): result = subjects_to_be_ordered.order_by(order_direction + order_column) - elif re.search(r'^virus_test_[1-5]_collection_date',order_column): + elif re.search(r'^virus_test_[1-5]_collection_date', order_column): result = subjects_to_be_ordered.order_by(order_direction + order_column) - elif re.search(r'^virus_test_[1-5]_iga_status',order_column): + elif re.search(r'^virus_test_[1-5]_iga_status', order_column): result = subjects_to_be_ordered.order_by(order_direction + order_column) - elif re.search(r'^virus_test_[1-5]_igg_status',order_column): + elif re.search(r'^virus_test_[1-5]_igg_status', order_column): result = subjects_to_be_ordered.order_by(order_direction + order_column) else: logger.warn("Unknown sort column: " + str(order_column)) @@ -360,25 +361,25 @@ def get_subjects_filtered(subjects_to_be_filtered, filters): else: result = result.filter(virus_test_5=(value == "true")) elif column == "virus_test_1_iga_status": - result = result.filter( virus_test_1_iga_status=value) + result = result.filter(virus_test_1_iga_status=value) elif column == "virus_test_1_igg_status": - result = result.filter( virus_test_1_igg_status=value) + result = result.filter(virus_test_1_igg_status=value) elif column == "virus_test_2_iga_status": - result = result.filter( virus_test_2_iga_status=value) + result = result.filter(virus_test_2_iga_status=value) elif column == "virus_test_2_igg_status": - result = result.filter( virus_test_2_igg_status=value) + result = result.filter(virus_test_2_igg_status=value) elif column == "virus_test_3_iga_status": - result = result.filter( virus_test_3_iga_status=value) + result = result.filter(virus_test_3_iga_status=value) elif column == "virus_test_3_igg_status": - result = result.filter( virus_test_3_igg_status=value) + result = result.filter(virus_test_3_igg_status=value) elif column == "virus_test_4_iga_status": - result = result.filter( virus_test_4_iga_status=value) + result = result.filter(virus_test_4_iga_status=value) elif column == "virus_test_4_igg_status": - result = result.filter( virus_test_4_igg_status=value) + result = result.filter(virus_test_4_igg_status=value) elif column == "virus_test_5_iga_status": - result = result.filter( virus_test_5_iga_status=value) + result = result.filter(virus_test_5_iga_status=value) elif column == "virus_test_5_igg_status": - result = result.filter( virus_test_5_igg_status=value) + result = result.filter(virus_test_5_igg_status=value) elif column == "brain_donation_agreement": result = result.filter(brain_donation_agreement=(value == "true")) elif column == "postponed": @@ -544,31 +545,6 @@ def serialize_subject(study_subject): "dead": bool_to_yes_no(study_subject.subject.dead), "resigned": bool_to_yes_no(study_subject.resigned), "endpoint_reached": bool_to_yes_no(study_subject.endpoint_reached), - "virus_test_1": virus_test_to_str(study_subject.virus_test_1, study_subject.virus_test_1_updated), - "virus_test_2": virus_test_to_str(study_subject.virus_test_2, study_subject.virus_test_2_updated), - "virus_test_3": virus_test_to_str(study_subject.virus_test_3, study_subject.virus_test_3_updated), - "virus_test_4": virus_test_to_str(study_subject.virus_test_4, study_subject.virus_test_4_updated), - "virus_test_5": virus_test_to_str(study_subject.virus_test_5, study_subject.virus_test_5_updated), - "virus_test_1_updated": study_subject.virus_test_1_updated, - "virus_test_2_updated": study_subject.virus_test_2_updated, - "virus_test_3_updated": study_subject.virus_test_3_updated, - "virus_test_4_updated": study_subject.virus_test_4_updated, - "virus_test_5_updated": study_subject.virus_test_5_updated, - "virus_test_1_collection_date": study_subject.virus_test_1_collection_date, - "virus_test_2_collection_date": study_subject.virus_test_2_collection_date, - "virus_test_3_collection_date": study_subject.virus_test_3_collection_date, - "virus_test_4_collection_date": study_subject.virus_test_4_collection_date, - "virus_test_5_collection_date": study_subject.virus_test_5_collection_date, - "virus_test_1_iga_status": study_subject.virus_test_1_iga_status, - "virus_test_1_igg_status": study_subject.virus_test_1_igg_status, - "virus_test_2_iga_status": study_subject.virus_test_2_iga_status, - "virus_test_2_igg_status": study_subject.virus_test_2_igg_status, - "virus_test_3_iga_status": study_subject.virus_test_3_iga_status, - "virus_test_3_igg_status": study_subject.virus_test_3_igg_status, - "virus_test_4_iga_status": study_subject.virus_test_4_iga_status, - "virus_test_4_igg_status": study_subject.virus_test_4_igg_status, - "virus_test_5_iga_status": study_subject.virus_test_5_iga_status, - "virus_test_5_igg_status": study_subject.virus_test_5_igg_status, "postponed": bool_to_yes_no(study_subject.postponed), "brain_donation_agreement": bool_to_yes_no(study_subject.brain_donation_agreement), "excluded": bool_to_yes_no(study_subject.excluded), @@ -580,4 +556,12 @@ def serialize_subject(study_subject): "id": study_subject.id, "visits": serialized_visits, } + for i in range(1, 6): + result['virus_test_{}'.format(i)] = virus_test_to_str(getattr(study_subject, "virus_test_{}".format(i)), + getattr(study_subject, "virus_test_{}_updated".format(i))) + result["virus_test_{}_updated".format(i)] = getattr(study_subject, "virus_test_{}_updated".format(i)) + result["virus_test_{}_collection_date".format(i)] = getattr(study_subject, + "virus_test_{}_collection_date".format(i)) + result["virus_test_{}_iga_status".format(i)] = getattr(study_subject, "virus_test_{}_iga_status".format(i)) + result["virus_test_{}_igg_status".format(i)] = getattr(study_subject, "virus_test_{}_igg_status".format(i)) return result