From 2d8b4847e90033aa24c0a882dfc959b20c5699b8 Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Tue, 21 Apr 2020 18:04:13 +0200
Subject: [PATCH] adapted filter and serialization so that the values are
 properly shown

---
 smash/web/api_views/subject.py | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py
index 5652f8bd..c4a0fa3c 100644
--- a/smash/web/api_views/subject.py
+++ b/smash/web/api_views/subject.py
@@ -308,27 +308,37 @@ def get_subjects_filtered(subjects_to_be_filtered, filters):
             result = result.filter(endpoint_reached=(value == "true"))
         elif column == "virus_test_1":
             if value == "null":
-                result = result.filter(virus_test_1__isnull=True)
+                result = result.filter(virus_test_1__isnull=True, virus_test_1_updated__isnull=True)
+            elif value == "inconclusive":
+                result = result.filter(virus_test_1__isnull=True, virus_test_1_updated__isnull=False)
             else:
                 result = result.filter(virus_test_1=(value == "true"))
         elif column == "virus_test_2":
             if value == "null":
-                result = result.filter(virus_test_2__isnull=True)
+                result = result.filter(virus_test_2__isnull=True, virus_test_2_updated__isnull=True)
+            elif value == "inconclusive":
+                result = result.filter(virus_test_2__isnull=True, virus_test_2_updated__isnull=False)
             else:
                 result = result.filter(virus_test_2=(value == "true"))
         elif column == "virus_test_3":
             if value == "null":
-                result = result.filter(virus_test_3__isnull=True)
+                result = result.filter(virus_test_3__isnull=True, virus_test_3_updated__isnull=True)
+            elif value == "inconclusive":
+                result = result.filter(virus_test_3__isnull=True, virus_test_3_updated__isnull=False)
             else:
                 result = result.filter(virus_test_3=(value == "true"))
         elif column == "virus_test_4":
             if value == "null":
-                result = result.filter(virus_test_4__isnull=True)
+                result = result.filter(virus_test_4__isnull=True, virus_test_4_updated__isnull=True)
+            elif value == "inconclusive":
+                result = result.filter(virus_test_4__isnull=True, virus_test_4_updated__isnull=False)
             else:
                 result = result.filter(virus_test_4=(value == "true"))
         elif column == "virus_test_5":
             if value == "null":
-                result = result.filter(virus_test_5__isnull=True)
+                result = result.filter(virus_test_5__isnull=True, virus_test_5_updated__isnull=True)
+            elif value == "inconclusive":
+                result = result.filter(virus_test_5__isnull=True, virus_test_5_updated__isnull=False)
             else:
                 result = result.filter(virus_test_5=(value == "true"))
         elif column == "brain_donation_agreement":
@@ -496,11 +506,11 @@ 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": bool_to_yes_no_null(study_subject.virus_test_1),
-        "virus_test_2": bool_to_yes_no_null(study_subject.virus_test_2),
-        "virus_test_3": bool_to_yes_no_null(study_subject.virus_test_3),
-        "virus_test_4": bool_to_yes_no_null(study_subject.virus_test_4),
-        "virus_test_5": bool_to_yes_no_null(study_subject.virus_test_5),
+        "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,
-- 
GitLab