Skip to content

Commit

Permalink
fix epi clones
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Oct 15, 2023
1 parent 4ebaf4a commit beaf966
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 33 deletions.
14 changes: 0 additions & 14 deletions hawc/apps/epi/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,13 @@ class OutcomeAutocomplete(BaseAutocomplete):
filter_fields = ["study_population_id", "study_population__study__assessment_id"]


@register
class ComparisonSetAutocomplete(BaseAutocomplete):
model = models.ComparisonSet
search_fields = ["name"]
filter_fields = ["study_population_id", "outcome_id"]


@register
class AdjustmentFactorAutocomplete(BaseAutocomplete):
model = models.AdjustmentFactor
search_fields = ["description"]
filter_fields = ["assessment_id"]


@register
class ResultAutocomplete(BaseAutocomplete):
model = models.Result
search_fields = ["metric__metric", "comparison_set__name"]
filter_fields = ["outcome_id"]


@register
class CountryAutocomplete(BaseAutocomplete):
model = models.Country
Expand Down
90 changes: 72 additions & 18 deletions hawc/apps/epi/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,18 @@ def clean(self):


class StudyPopulationSelectorForm(CopyForm):
label = "Study Population"
parent_field = "study_id"
autocomplete_class = autocomplete.StudyPopulationAutocomplete
legend_text = "Copy Study Population"
help_text = "Select an existing study population as a template to create a new one."
create_url_pattern = "epi:sp_create"
selector = forms.ModelChoiceField(
queryset=models.StudyPopulation.objects.all(), empty_label=None, label="Select template"
)

def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.fields["selector"].queryset = self.fields["selector"].queryset.filter(
study=self.parent
)


class AdjustmentFactorForm(forms.ModelForm):
Expand Down Expand Up @@ -307,9 +316,18 @@ def helper(self):


class ExposureSelectorForm(CopyForm):
label = "Exposure"
parent_field = "study_population_id"
autocomplete_class = autocomplete.ExposureAutocomplete
legend_text = "Copy Exposure"
help_text = "Select an existing exposure as a template to create a new one."
create_url_pattern = "epi:exp_create"
selector = forms.ModelChoiceField(
queryset=models.Exposure.objects.all(), empty_label=None, label="Select template"
)

def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.fields["selector"].queryset = self.fields["selector"].queryset.filter(
study_population=self.parent
)


class OutcomeForm(forms.ModelForm):
Expand Down Expand Up @@ -387,9 +405,18 @@ def helper(self):


class OutcomeSelectorForm(CopyForm):
label = "Outcome"
parent_field = "study_population_id"
autocomplete_class = autocomplete.OutcomeAutocomplete
legend_text = "Copy Outcome"
help_text = "Select an existing outcome as a template to create a new one."
create_url_pattern = "epi:outcome_create"
selector = forms.ModelChoiceField(
queryset=models.Outcome.objects.all(), empty_label=None, label="Select template"
)

def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.fields["selector"].queryset = self.fields["selector"].queryset.filter(
study_population=self.parent
)


class ComparisonSet(forms.ModelForm):
Expand Down Expand Up @@ -446,15 +473,33 @@ def helper(self):


class ComparisonSetByStudyPopulationSelectorForm(CopyForm):
label = "Comparison set"
parent_field = "study_population_id"
autocomplete_class = autocomplete.ComparisonSetAutocomplete
legend_text = "Copy Comparison Set"
help_text = "Select an existing comparison set as a template to create a new one."
create_url_pattern = "epi:cs_create"
selector = forms.ModelChoiceField(
queryset=models.ComparisonSet.objects.all(), empty_label=None, label="Select template"
)

def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.fields["selector"].queryset = self.fields["selector"].queryset.filter(
study_population=self.parent
)


class ComparisonSetByOutcomeSelectorForm(CopyForm):
label = "Comparison set"
parent_field = "outcome_id"
autocomplete_class = autocomplete.ComparisonSetAutocomplete
legend_text = "Copy Comparison Set"
help_text = "Select an existing comparison set as a template to create a new one."
create_url_pattern = "epi:cs_outcome_create"
selector = forms.ModelChoiceField(
queryset=models.ComparisonSet.objects.all(), empty_label=None, label="Select template"
)

def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.fields["selector"].queryset = self.fields["selector"].queryset.filter(
outcome=self.parent
)


class GroupForm(forms.ModelForm):
Expand Down Expand Up @@ -694,9 +739,18 @@ def helper(self):


class ResultSelectorForm(CopyForm):
label = "Result"
parent_field = "outcome_id"
autocomplete_class = autocomplete.ResultAutocomplete
legend_text = "Copy Result"
help_text = "Select an existing result as a template to create a new one."
create_url_pattern = "epi:result_create"
selector = forms.ModelChoiceField(
queryset=models.Result.objects.all(), empty_label=None, label="Select template"
)

def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.fields["selector"].queryset = self.fields["selector"].queryset.filter(
outcome=self.parent
)


class ResultUpdateForm(ResultForm):
Expand Down
1 change: 0 additions & 1 deletion hawc/apps/lit/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ...services.epa import hero
from ...services.nih import pubmed
from ..assessment.managers import published
from ..assessment.models import Assessment
from ..common.models import BaseManager, replace_null, str_m2m
from ..study.managers import study_df_annotations
from . import constants
Expand Down

0 comments on commit beaf966

Please sign in to comment.