Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Icf cpheapm73 79 add observations #1149

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions hawc/apps/animal/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def get_value_map(self):
"purity": "purity",
"vehicle": "vehicle",
"guideline_compliance": "guideline_compliance",
"guideline": "guideline",
"description": "description",
}

Expand Down
17 changes: 17 additions & 0 deletions hawc/apps/animal/migrations/0032_experiment_guideline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.1 on 2024-10-11 13:26

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("animal", "0031_tre"),
]

operations = [
migrations.AddField(
model_name="experiment",
name="guideline",
field=models.CharField(blank=True, max_length=128, null=True),
),
]
1 change: 1 addition & 0 deletions hawc/apps/animal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Experiment(models.Model):
414 and 412, 1981 versions). If not reported, then use state "not reported."
""",
)
guideline = models.CharField(max_length=128, blank=True, null=True)
description = models.TextField(
blank=True,
verbose_name="Comments",
Expand Down
10 changes: 10 additions & 0 deletions hawc/apps/animal/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools
import json

from django.core.exceptions import ValidationError
from django.db import transaction
from rest_framework import serializers

Expand All @@ -13,6 +14,7 @@
from ..study.models import Study
from ..study.serializers import StudySerializer
from ..vocab.constants import VocabularyTermType
from ..vocab.serializers import GuidelineProfileSerializer
from . import forms, models


Expand Down Expand Up @@ -47,6 +49,14 @@ def validate(self, data):
dict(dtxsid=f"DSSTox {dtxsid} does not exist")
) from exc

# validate guideline profile
guideline = self.initial_data.get("guideline_profile")
if guideline:
valid_guidelines = GuidelineProfileSerializer._load_guideline_data()
names = [guideline["guideline_name"] for guideline in valid_guidelines]
if guideline not in names:
raise ValidationError(f"{guideline} is not a valid guideline")

return data

def create(self, validated_data):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.1 on 2024-10-17 14:16

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("assessment", "0046_assessmentvalue_value_type_qualifier"),
]

operations = [
migrations.AddField(
model_name="assessment",
name="enable_observations",
field=models.BooleanField(
default=True,
help_text="Observations can be used to identify negative effects in animal bioassay studies. The project must use the Toxicity Reference Database Vocabulary to use Observations.",
),
),
]
4 changes: 4 additions & 0 deletions hawc/apps/assessment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def get_rob_name_default():
default=True,
help_text="Show the downloads link on the assessment sidebar.",
)
enable_observations = models.BooleanField(
default=True,
help_text="Observations can be used to identify negative effects in animal bioassay studies. The project must use the Toxicity Reference Database Vocabulary to use Observations.",
)
conflicts_of_interest = models.TextField(
blank=True,
help_text="Describe any conflicts of interest by the assessment-team.",
Expand Down
13 changes: 13 additions & 0 deletions hawc/apps/vocab/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ def get_uid(self, obj):
@admin.display(description="Related terms")
def get_terms(self, obj):
return ul_items(obj.terms.all(), lambda el: f"<a href={el.get_admin_edit_url()}>{el}</a>")


@admin.register(models.GuidelineProfile)
class GuidelineProfileAdmin(admin.ModelAdmin):
list_display = (
"id",
"guideline_id",
"endpoint",
"obs_status",
"description",
)
list_filter = ("guideline_id", "obs_status")
search_fields = ("guideline id", "obs_status")
20 changes: 20 additions & 0 deletions hawc/apps/vocab/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,23 @@ def bulk_update(self, request: Request) -> Response:
def uids(self, request: Request) -> Response:
qs = self.get_queryset().exclude(uid=None)
return Response(qs.values_list("id", "uid"))


class GuidelineProfileViewSet(viewsets.GenericViewSet):
serializer_class = serializers.GuidelineProfileSerializer
filename = "guideline_profiles"

def get_queryset(self, guideline=None) -> QuerySet:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exports guideline profiles for an experiment

guideline_id = models.GuidelineProfile.objects.get_guideline_id(guideline)
qs = models.GuidelineProfile.objects.all()
if guideline_id:
qs = qs.filter(guideline_id=guideline_id)
return qs

def get_df(self, guideline) -> pd.DataFrame:
qs = self.get_queryset(guideline).values()
return pd.DataFrame(list(qs))

@action(detail=True, renderer_classes=PandasRenderers, permission_classes=(AllowAny,))
def export(self, request: Request, pk: str):
return FlatExport.api_response(df=self.get_df(pk), filename=self.filename)
14 changes: 13 additions & 1 deletion hawc/apps/vocab/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models import IntegerChoices
from django.db.models import IntegerChoices, TextChoices
from django.urls import reverse


Expand Down Expand Up @@ -70,3 +70,15 @@ class Ontology(IntegerChoices):
"""

umls = 1, "UMLS"


class ObservationStatus(TextChoices):
"""
Guideline profile observation status
"""

NM = "NM", "NM"
NR = "not required", "not required"
REC = "recommended", "recommended"
REQ = "required", "required"
TR = "triggered", "triggered"
Loading