Skip to content

Commit

Permalink
Add requires_study_review fields to CDSA tables
Browse files Browse the repository at this point in the history
Add a field to the DataAffiliateAgreementTable and the CDSAWorkspace
Table to indicate whether study review is required.
  • Loading branch information
amstilp committed Mar 19, 2024
1 parent fe08650 commit 4670cc2
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
12 changes: 12 additions & 0 deletions add_cdsa_example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
study=Study.objects.get(short_name="MESA"),
signed_agreement__version=v10,
additional_limitations="This data can only be used for testing the app.",
requires_study_review=True,
)
GroupGroupMembershipFactory.create(
parent_group=cdsa_group, child_group=cdsa_1006.signed_agreement.anvil_access_group
Expand Down Expand Up @@ -229,3 +230,14 @@
additional_limitations="Additional limitations for workspace.",
)
cdsa_workspace_2.data_use_modifiers.add(dum)


# Add a workspace with no primary cdsa.
cdsa_workspace_3 = factories.CDSAWorkspaceFactory.create(
workspace__billing_project__name="demo-primed-cdsa",
workspace__name="DEMO_PRIMED_CDSA_ARIC_1",
study=Study.objects.create(
short_name="ARIC", full_name="Atherosclerosis Risk in Communities"
),
data_use_permission=dup,
)
46 changes: 46 additions & 0 deletions primed/cdsa/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Workspace,
WorkspaceGroupSharing,
)
from django.utils.safestring import mark_safe

from primed.primed_anvil.tables import (
BooleanIconColumn,
Expand Down Expand Up @@ -112,6 +113,12 @@ class DataAffiliateAgreementTable(tables.Table):
signed_agreement__cc_id = tables.Column(linkify=True)
study = tables.Column(linkify=True)
is_primary = BooleanIconColumn(verbose_name="Primary?")
requires_study_review = BooleanIconColumn(
verbose_name="Study review required?",
orderable=False,
true_icon="dash-circle-fill",
true_color="#ffc107",
)
signed_agreement__representative__name = tables.Column(
linkify=lambda record: record.signed_agreement.representative.get_absolute_url(),
verbose_name="Representative",
Expand All @@ -129,6 +136,7 @@ class Meta:
"signed_agreement__cc_id",
"study",
"is_primary",
"requires_study_review",
"signed_agreement__representative__name",
"signed_agreement__representative_role",
"signed_agreement__signing_institution",
Expand Down Expand Up @@ -306,6 +314,12 @@ class CDSAWorkspaceStaffTable(tables.Table):
verbose_name="DUO modifiers",
linkify_item=True,
)
cdsaworkspace_requires_study_review = BooleanIconColumn(
verbose_name="Study review required?",
orderable=False,
true_icon="dash-circle-fill",
true_color="#ffc107",
)
cdsaworkspace__gsr_restricted = BooleanIconColumn(
orderable=False, true_icon="dash-circle-fill", true_color="#ffc107"
)
Expand All @@ -319,10 +333,23 @@ class Meta:
"cdsaworkspace__study",
"cdsaworkspace__data_use_permission__abbreviation",
"cdsaworkspace__data_use_modifiers",
"cdsaworkspace_requires_study_review",
"cdsaworkspace__gsr_restricted",
)
order_by = ("name",)

def render_requires_study_review(self, record):
try:
if record.cdsaworkspace.get_primary_cdsa().requires_study_review:
icon = "dash-circle-fill"
color = "#ffc107"
else:
return ""
except models.DataAffiliateAgreement.DoesNotExist:
icon = "question-circle-fill"
color = "red"
return mark_safe(f'<i class="bi bi-{icon}" style="color: {color}"></i>')


class CDSAWorkspaceUserTable(tables.Table):
"""A table for the CDSAWorkspace model."""
Expand All @@ -337,6 +364,12 @@ class CDSAWorkspaceUserTable(tables.Table):
transform=lambda x: x.abbreviation,
verbose_name="DUO modifiers",
)
cdsaworkspace_requires_study_review = BooleanIconColumn(
verbose_name="Study review required?",
orderable=False,
true_icon="dash-circle-fill",
true_color="#ffc107",
)
cdsaworkspace__gsr_restricted = BooleanIconColumn(orderable=False)
is_shared = WorkspaceSharedWithConsortiumColumn()

Expand All @@ -348,6 +381,19 @@ class Meta:
"cdsaworkspace__study",
"cdsaworkspace__data_use_permission__abbreviation",
"cdsaworkspace__data_use_modifiers",
"cdsaworkspace_requires_study_review",
"cdsaworkspace__gsr_restricted",
)
order_by = ("name",)

def render_requires_study_review(self, record):
try:
if record.cdsaworkspace.get_primary_cdsa().requires_study_review:
icon = "dash-circle-fill"
color = "#ffc107"
else:
return ""
except models.DataAffiliateAgreement.DoesNotExist:
icon = "question-circle-fill"
color = "red"
return mark_safe(f'<i class="bi bi-{icon}" style="color: {color}"></i>')
50 changes: 50 additions & 0 deletions primed/cdsa/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,31 @@ def test_ordering(self):
self.assertEqual(table.data[0], instance_2.workspace)
self.assertEqual(table.data[1], instance_1.workspace)

def test_render_requires_study_review(self):
table = self.table_class(self.model.objects.all())
# CDSA workspace with no data_affiliate_agreement.
cdsa_workspace = factories.CDSAWorkspaceFactory.create()
self.assertIn(
"question-circle-fill",
table.render_requires_study_review(cdsa_workspace.workspace),
)
# With a primary - no review required.
agreement = factories.DataAffiliateAgreementFactory.create(
is_primary=True,
requires_study_review=False,
study=cdsa_workspace.study,
)
self.assertEqual(
"", table.render_requires_study_review(cdsa_workspace.workspace)
)
# With a primary - review required.
agreement.requires_study_review = True
agreement.save()
self.assertIn(
"dash-circle-fill",
table.render_requires_study_review(cdsa_workspace.workspace),
)


class CDSAWorkspaceUserTableTest(TestCase):
"""Tests for the CDSAWorkspaceUserTable class."""
Expand Down Expand Up @@ -501,3 +526,28 @@ def test_ordering(self):
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2.workspace)
self.assertEqual(table.data[1], instance_1.workspace)

def test_render_requires_study_review(self):
table = self.table_class(self.model.objects.all())
# CDSA workspace with no data_affiliate_agreement.
cdsa_workspace = factories.CDSAWorkspaceFactory.create()
self.assertIn(
"question-circle-fill",
table.render_requires_study_review(cdsa_workspace.workspace),
)
# With a primary - no review required.
agreement = factories.DataAffiliateAgreementFactory.create(
is_primary=True,
requires_study_review=False,
study=cdsa_workspace.study,
)
self.assertEqual(
"", table.render_requires_study_review(cdsa_workspace.workspace)
)
# With a primary - review required.
agreement.requires_study_review = True
agreement.save()
self.assertIn(
"dash-circle-fill",
table.render_requires_study_review(cdsa_workspace.workspace),
)

0 comments on commit 4670cc2

Please sign in to comment.