Skip to content

Commit

Permalink
Progress on #289
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Oct 23, 2023
1 parent fc2cdf2 commit 2568b98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
24 changes: 19 additions & 5 deletions src/eke.knowledge/src/eke/knowledge/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
<h3>Open Protocols</h3>
{% if opened %}
<table class='table'>
<thead><tr><th>Protocol Name</th><th>Biomarkers</th><th>Datasets</th></tr></thead>
<thead>
<tr>
<th>Protocol Name</th>
<th>Investigatory Role</th>
<th>Biomarkers</th>
<th>Public Data Collections</th>
</tr>
</thead>
<tbody>
{% for protocol in opened %}
<tr>
<td><a href='{{protocol.url}}'>{{protocol.title}}</a></td>
<td>{{protocol.role}}</td>
<td>{% protocol_counts protocol 'biomarkers' %}</td>
<td>{% protocol_counts protocol 'data' %}</td>
</tr>
Expand All @@ -27,11 +35,19 @@ <h3>Open Protocols</h3>
<h3 class='mt-3'>Closed Protocols</h3>
{% if closed %}
<table class='table'>
<thead><tr><th>Protocol Name</th><th>Biomarkers</th><th>Datasets</th></tr></thead>
<thead>
<tr>
<th>Protocol Name</th>
<th>Investigatory Role</th>
<th>Biomarkers</th>
<th>Public Data Collections</th>
</tr>
</thead>
<tbody>
{% for protocol in closed %}
<tr>
<td><a href='{{protocol.url}}'>{{protocol.title}}</a></td>
<td>{{protocol.role}}</td>
<td>{% protocol_counts protocol 'biomarkers' %}</td>
<td>{% protocol_counts protocol 'data' %}</td>
</tr>
Expand Down

0 comments on commit 2568b98

Please sign in to comment.