diff --git a/src/eke.knowledge/src/eke/knowledge/sites.py b/src/eke.knowledge/src/eke/knowledge/sites.py
index bc169af7..f0a50715 100644
--- a/src/eke.knowledge/src/eke/knowledge/sites.py
+++ b/src/eke.knowledge/src/eke/knowledge/sites.py
@@ -12,6 +12,7 @@
from django.core.exceptions import ValidationError
from django.core.files.images import ImageFile
from django.db import models
+from django.db.models import Q, Case, When, Value, BooleanField
from django.db.models.fields import Field
from django.db.models.functions import Lower
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
@@ -311,11 +312,24 @@ def get_context(self, request: HttpRequest, *args, **kwargs) -> dict:
context['has_interests'] = self.interests.count() > 0
if my_site:
from eke.knowledge.protocols import Protocol
- opened, closed = [], []
- protocols = Protocol.objects.filter(involvedInvestigatorSites=my_site).order_by(Lower('title'))
- for protocol in protocols:
- if protocol.finish_date: closed.append(protocol)
- else: opened.append(protocol)
+
+ # Whew, this was "fun"
+ q = Q(coordinatingInvestigatorSite=my_site)
+ q |= Q(leadInvestigatorSite=my_site)
+ q |= Q(involvedInvestigatorSites=my_site)
+ protocols = Protocol.objects.filter(q).distinct().annotate(role=Case(
+ When(coordinatingInvestigatorSite=my_site, then=Value('Coordinating')),
+ When(leadInvestigatorSite=my_site, then=Value('Leading')),
+ When(involvedInvestigatorSites=my_site, then=Value('Involved')),
+ default=Value('unknown'),
+ output_field=models.CharField()
+ )).annotate(finish_blank=Case(
+ When(finish_date='', then=Value(True)),
+ default=Value(False),
+ output_field=BooleanField()
+ )).order_by(Lower('title'))
+
+ opened, closed = protocols.filter(finish_blank=True), protocols.filter(finish_blank=False)
context['opened'], context['closed'] = opened, closed
context['publications'] = my_site.publications.order_by(Lower('title'))
return context
diff --git a/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html b/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html
index 64db1ff1..e936f819 100644
--- a/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html
+++ b/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/person.html
@@ -9,11 +9,19 @@
Open Protocols
{% if opened %}
- Protocol Name | Biomarkers | Datasets |
+
+
+ Protocol Name |
+ Investigatory Role |
+ Biomarkers |
+ Public Data Collections |
+
+
{% for protocol in opened %}
{{protocol.title}} |
+ {{protocol.role}} |
{% protocol_counts protocol 'biomarkers' %} |
{% protocol_counts protocol 'data' %} |
@@ -27,11 +35,19 @@ Open Protocols
Closed Protocols
{% if closed %}
- Protocol Name | Biomarkers | Datasets |
+
+
+ Protocol Name |
+ Investigatory Role |
+ Biomarkers |
+ Public Data Collections |
+
+
{% for protocol in closed %}
{{protocol.title}} |
+ {{protocol.role}} |
{% protocol_counts protocol 'biomarkers' %} |
{% protocol_counts protocol 'data' %} |