Skip to content

Commit

Permalink
clean use restriction codes
Browse files Browse the repository at this point in the history
The additional infromation in brackets (CC) or [XX] is just a
placeholder. It should be replaced by code/time etc.
  • Loading branch information
vildead committed Sep 11, 2023
1 parent 243d950 commit 7e76a58
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/fixtures/restriction-class.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"description": "No restrictions on data use."
},
{
"code": "GRU(CC)",
"code": "GRU",
"name": "General Research use and Clinical Care",
"description": "For health/medical/biomedical purposes and other biological research, including the study of population origins or ancestry."
},
{
"code": "HMB(CC)",
"code": "HMB",
"name": "Health/medical/biomedical Research and Clinical Care",
"description": "Use of the data is limited to health/medical/biomedical purposes, does not include the study of population origins or ancestry."
},
{
"code": "DS-[XX](CC)",
"code": "DS",
"name": "Disease-specific Research and Clinical Care.",
"description": "Use of the data must be related to [disease]."
},
Expand All @@ -25,7 +25,7 @@
"description": "Use of the data is limited to the study of population origins or ancestry."
},
{
"code": "RS-[XX]",
"code": "RS",
"name": "Other Research-specific restrictions",
"description": "Use of the data is limited to studies of [research type] (e.g., pediatric research)."
},
Expand Down Expand Up @@ -55,7 +55,7 @@
"description": "Requestor agrees to make results of studies using the data available to the larger scientific community."
},
{
"code": "COL-[XX]",
"code": "COL",
"name": "Collaboration Required",
"description": "Requestor must agree to collaboration with the primary study investigator(s)."
},
Expand All @@ -70,17 +70,17 @@
"description": "Requestor must provide documentation of local IRB/REC approval."
},
{
"code": "GS-[XX]",
"code": "GS",
"name": "Geographical Restrictions",
"description": "Use of the data is limited to within [geographic region]."
},
{
"code": "MOR-[XX]",
"code": "MOR",
"name": "Publication Moratorium/Embargo",
"description": "Requestor agrees not to publish results of studies until [date]."
},
{
"code": "TS-[XX]",
"code": "TS",
"name": "Time Limits on use",
"description": "Use of data is approved for [x months]."
},
Expand Down
51 changes: 51 additions & 0 deletions core/migrations/0035_use_restriction_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from django.db import migrations


def apply_code_map(objects, field, reverse=False):
code_map = [
("GRU(CC)", "GRU"),
("HMB(CC)", "HMB"),
("DS-[XX](CC)", "DS"),
("RS-[XX]", "RS"),
("COL-[XX]", "COL"),
("GS-[XX]", "GS"),
("MOR-[XX]", "MOR"),
("TS-[XX]", "TS"),
]
if reverse:
code_map = list(map(tuple, map(reversed, code_map)))

for obj in objects:
for code_mapping in code_map:
if getattr(obj, field) == code_mapping[0]:
setattr(obj, field, code_mapping[1])
obj.save()


class Migration(migrations.Migration):
def restriction_use_code_to_new(apps, schema_editor):
use_restriction_objects = apps.get_model("core", "UseRestriction").objects.all()
apply_code_map(objects=use_restriction_objects, field="restriction_class")

def restriction_use_code_to_old(apps, schema_editor):
use_restriction_objects = apps.get_model("core", "UseRestriction").objects.all()
apply_code_map(use_restriction_objects, field="restriction_class", reverse=True)

def restriction_class_code_to_new(apps, schema_editor):
use_class_objects = apps.get_model("core", "RestrictionClass").objects.all()
apply_code_map(objects=use_class_objects, field="code")

def restriction_class_code_to_old(apps, schema_editor):
use_class_objects = apps.get_model("core", "RestrictionClass").objects.all()
apply_code_map(use_class_objects, field="code", reverse=True)

dependencies = [
("core", "0034_auto_20230515_1353"),
]

operations = [
migrations.RunPython(restriction_use_code_to_new, restriction_use_code_to_old),
migrations.RunPython(
restriction_class_code_to_new, restriction_class_code_to_old
),
]

0 comments on commit 7e76a58

Please sign in to comment.