Repository: comic/grand-challenge.org

Issue:
Creators of ground truth cannot answer a reader study
**Describe the bug**
If an editor creates ground truth for a reader study they cannot perform the study.

**To Reproduce**
Create a reader study with cases and questions. Add ground truth. Open CIRRUS. Get told the study is completed.

**Expected behavior**
The editor can read the study.

**Additional context**
The `unanswered_by_user` block in the display set list needs to take into account ground truth answers. 

https://github.com/comic/grand-challenge.org/blob/0a84c04902222c2ca9cec00b5387e6bb3abf7354/app/grandchallenge/reader_studies/views.py#L1109-L1123

Teams discussion https://teams.microsoft.com/l/message/19:cd97152db8544ca1b74c6990e24ec446@thread.tacv2/1654173912687?tenantId=b208fe69-471e-48c4-8d87-025e9b9a157f&groupId=45c973c4-5543-45ad-a8b8-79ea596e6c69&parentMessageId=1654173912687&teamName=Research%20Software%20Engineering&channelName=grand-challenge-dev&createdTime=1654173912687



Discussion:

Resolving patch:
diff --git a/app/grandchallenge/reader_studies/views.py b/app/grandchallenge/reader_studies/views.py
--- a/app/grandchallenge/reader_studies/views.py
+++ b/app/grandchallenge/reader_studies/views.py
@@ -11,7 +11,7 @@
     ValidationError,
 )
 from django.db import transaction
-from django.db.models import Count
+from django.db.models import Count, Q
 from django.forms.utils import ErrorList
 from django.http import (
     Http404,
@@ -1114,7 +1114,11 @@ def list(self, request, *args, **kwargs):
                 )
             answerable_question_count = reader_study.answerable_question_count
             queryset = (
-                queryset.annotate(answer_count=Count("answers"))
+                queryset.annotate(
+                    answer_count=Count(
+                        "answers", filter=Q(answers__is_ground_truth=False)
+                    )
+                )
                 .exclude(
                     answers__creator=user,
                     answer_count__gte=answerable_question_count,


Test patch:
diff --git a/app/tests/reader_studies_tests/test_api.py b/app/tests/reader_studies_tests/test_api.py
--- a/app/tests/reader_studies_tests/test_api.py
+++ b/app/tests/reader_studies_tests/test_api.py
@@ -1146,7 +1146,7 @@ def test_question_accepts_image_type_answers(client, settings):
 
 
 @pytest.mark.django_db
-def test_display_set_endpoints(client, settings):
+def test_display_set_list_filters(client, settings):
     settings.task_eager_propagates = (True,)
     settings.task_always_eager = (True,)
 
@@ -1215,6 +1215,23 @@ def test_display_set_endpoints(client, settings):
 
     assert response.json()["count"] == 2
 
+    AnswerFactory(
+        question=q1, display_set=ds1, creator=r, is_ground_truth=True
+    )
+    AnswerFactory(
+        question=q2, display_set=ds1, creator=r, is_ground_truth=True
+    )
+
+    response = get_view_for_user(
+        viewname="api:reader-studies-display-set-list",
+        data={"reader_study": str(rs1.pk), "unanswered_by_user": True},
+        user=r,
+        client=client,
+        method=client.get,
+    )
+
+    assert response.json()["count"] == 2
+
     AnswerFactory(question=q1, display_set=ds1, creator=r)
 
     response = get_view_for_user(