Skip to content

Commit 77885ab

Browse files
authored
Merge pull request #141 from cmu-delphi/OKRS24-217
Okrs24 217
2 parents cc4b0aa + 32879df commit 77885ab

File tree

8 files changed

+102
-123
lines changed

8 files changed

+102
-123
lines changed

src/datasources/admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SourceSubdivisionAdmin(ImportExportModelAdmin):
1212
"""
1313
Admin interface for managing source subdivision objects.
1414
"""
15-
list_display: tuple[Literal['name'], Literal['db_source']] = ('name', 'db_source')
15+
list_display: tuple[Literal['name'], Literal['db_source'], Literal['external_name']] = ('name', 'db_source', 'external_name')
1616
search_fields: tuple[Literal['name'], Literal['db_source']] = ('name', 'db_source')
1717
resource_classes: list[type[SourceSubdivisionResource]] = [SourceSubdivisionResource]
1818

src/fixtures/available_geography.json

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"pk": 1,
55
"fields": {
66
"name": "county",
7+
"display_name": "L2 division (e.g. U.S. counties)",
78
"created": "2023-08-09T19:23:22.597131",
89
"modified": "2023-08-09T19:23:22.597131"
910
}
@@ -13,6 +14,7 @@
1314
"pk": 2,
1415
"fields": {
1516
"name": "hhs",
17+
"display_name": "HHS Regions",
1618
"created": "2023-08-09T19:23:22.597131",
1719
"modified": "2023-08-09T19:23:22.597131"
1820
}
@@ -22,6 +24,7 @@
2224
"pk": 3,
2325
"fields": {
2426
"name": "hrr",
27+
"display_name": "Hospital Referral Regions (HRAs)",
2528
"created": "2023-08-09T19:23:22.597131",
2629
"modified": "2023-08-09T19:23:22.597131"
2730
}
@@ -31,6 +34,7 @@
3134
"pk": 4,
3235
"fields": {
3336
"name": "msa",
37+
"display_name": "Metropolitan Statistical Areas (MSAs)",
3438
"created": "2023-08-09T19:23:22.597131",
3539
"modified": "2023-08-09T19:23:22.597131"
3640
}
@@ -40,6 +44,7 @@
4044
"pk": 5,
4145
"fields": {
4246
"name": "nation",
47+
"display_name": "National",
4348
"created": "2023-08-09T19:23:22.597131",
4449
"modified": "2023-08-09T19:23:22.597131"
4550
}
@@ -49,6 +54,7 @@
4954
"pk": 6,
5055
"fields": {
5156
"name": "state",
57+
"display_name": "L1 division (e.g. U.S. states)",
5258
"created": "2023-08-09T19:23:22.597131",
5359
"modified": "2023-08-09T19:23:22.597131"
5460
}
@@ -58,6 +64,7 @@
5864
"pk": 7,
5965
"fields": {
6066
"name": "dma",
67+
"display_name": "Designated Market Areas (DMAs)",
6168
"created": "2023-08-09T19:23:22.597131",
6269
"modified": "2023-08-09T19:23:22.597131"
6370
}

src/signals/filters.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
FormatChoices,
1616
Signal,
1717
TimeTypeChoices,
18+
GeographicScope,
19+
SeverityPyramidRungsChoices,
1820
)
1921

2022

@@ -41,10 +43,16 @@ class SignalFilter(django_filters.FilterSet):
4143
)
4244
)
4345
format_type = django_filters.MultipleChoiceFilter(choices=FormatChoices.choices)
46+
severenity_pyramid_rungs = django_filters.MultipleChoiceFilter(choices=SeverityPyramidRungsChoices.choices)
4447
source = django_filters.ModelMultipleChoiceFilter(queryset=SourceSubdivision.objects.all())
4548
time_type = django_filters.MultipleChoiceFilter(choices=TimeTypeChoices.choices)
4649
base_signal = django_filters.BooleanFilter(lookup_expr='isnull', field_name='base_for')
4750

51+
def __init__(self, data, *args, **kwargs):
52+
data = data.copy()
53+
data.setdefault('geographic_scope', GeographicScope.objects.get(name='USA').id)
54+
super().__init__(data, *args, **kwargs)
55+
4856
class Meta:
4957
model = Signal
5058
fields: list[str] = [
@@ -53,9 +61,9 @@ class Meta:
5361
'pathogen',
5462
'active',
5563
'available_geography',
56-
'signal_type',
64+
'severenity_pyramid_rungs',
5765
'category',
58-
'format_type',
66+
'geographic_scope',
5967
'source',
6068
'time_type',
6169
'base_signal',

src/signals/forms.py

+6-20
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
from datasources.models import SourceSubdivision
55
from signals.models import (
66
ActiveChoices,
7-
FormatChoices,
87
Pathogen,
98
Signal,
109
TimeTypeChoices,
10+
GeographicScope,
11+
SeverityPyramidRungsChoices,
1112
)
1213

1314

@@ -27,10 +28,11 @@ class SignalFilterForm(forms.ModelForm):
2728
search = forms.CharField(min_length=3)
2829
pathogen = forms.ModelChoiceField(queryset=Pathogen.objects.all(), widget=forms.CheckboxSelectMultiple())
2930
active = forms.TypedMultipleChoiceField(choices=ActiveChoices.choices, coerce=bool, widget=forms.CheckboxSelectMultiple())
30-
format_type = forms.ChoiceField(choices=FormatChoices.choices, widget=forms.CheckboxSelectMultiple())
3131
source = forms.ModelMultipleChoiceField(queryset=SourceSubdivision.objects.all(), widget=forms.CheckboxSelectMultiple())
3232
time_type = forms.ChoiceField(choices=TimeTypeChoices.choices, widget=forms.CheckboxSelectMultiple())
3333
base_signal = forms.ChoiceField(choices=[('', _('All')), (True, _('Yes')), (False, _('No'))], required=False, widget=forms.RadioSelect())
34+
geographic_scope = forms.ModelMultipleChoiceField(queryset=GeographicScope.objects.all(), widget=forms.CheckboxSelectMultiple())
35+
severenity_pyramid_rungs = forms.ChoiceField(choices=SeverityPyramidRungsChoices.choices, widget=forms.CheckboxSelectMultiple())
3436

3537
class Meta:
3638
model = Signal
@@ -41,11 +43,10 @@ class Meta:
4143
'pathogen',
4244
'active',
4345
'available_geography',
44-
'category',
45-
'format_type',
46-
'signal_type',
46+
'severenity_pyramid_rungs',
4747
'source',
4848
'time_type',
49+
'geographic_scope',
4950
]
5051

5152
widgets = {
@@ -60,21 +61,6 @@ class Meta:
6061
'data-bs-toggle': 'tooltip',
6162
'data-bs-placement': 'bottom',
6263
}),
63-
'signal_type': forms.CheckboxSelectMultiple(attrs={
64-
'class': 'form-select',
65-
'data-bs-toggle': 'tooltip',
66-
'data-bs-placement': 'bottom',
67-
}),
68-
'category': forms.CheckboxSelectMultiple(attrs={
69-
'class': 'form-select',
70-
'data-bs-toggle': 'tooltip',
71-
'data-bs-placement': 'bottom',
72-
}),
73-
'format_type': forms.CheckboxSelectMultiple(attrs={
74-
'class': 'form-select',
75-
'data-bs-toggle': 'tooltip',
76-
'data-bs-placement': 'bottom',
77-
}),
7864
'source': forms.CheckboxSelectMultiple(attrs={
7965
'class': 'form-select',
8066
'data-bs-toggle': 'tooltip',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.10 on 2024-06-11 14:17
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('signals', '0016_remove_signal_geographic_scope_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='geography',
15+
name='display_name',
16+
field=models.CharField(blank=True, help_text='Display Name', max_length=128, null=True),
17+
),
18+
]

src/signals/models.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class ActiveChoices(models.TextChoices):
5353
"""
5454
A class representing choices for active signals.
5555
"""
56-
ACTIVE = True, _('Active')
57-
HISTORICAL = False, _('Historical')
56+
ACTIVE = True, _('Current Surveillance Only')
5857

5958

6059
class SeverityPyramidRungsChoices(models.TextChoices):
@@ -154,6 +153,13 @@ class Geography(TimeStampedModel):
154153
unique=True
155154
)
156155

156+
display_name: models.CharField = models.CharField(
157+
help_text=_('Display Name'),
158+
max_length=128,
159+
null=True,
160+
blank=True
161+
)
162+
157163
class Meta:
158164
verbose_name_plural: str = "geographies"
159165
ordering: list[str] = ["name"]
@@ -165,7 +171,7 @@ def __str__(self) -> str:
165171
:return: The name of the available geography as a string.
166172
:rtype: str
167173
"""
168-
return str(self.name)
174+
return str(self.display_name)
169175

170176

171177
class GeographySignal(models.Model):

src/signals/views.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from signals.filters import SignalFilter
1010
from signals.forms import SignalFilterForm
11-
from signals.models import Signal
11+
from signals.models import Signal, GeographicScope
1212
from signals.serializers import SignalSerializer
1313

1414

@@ -45,13 +45,12 @@ def get_url_params(self):
4545
]
4646
if self.request.GET.get("available_geography")
4747
else None,
48-
"signal_type": [int(el) for el in self.request.GET.getlist("signal_type")]
49-
if self.request.GET.get("signal_type")
48+
"severenity_pyramid_rungs": [el for el in self.request.GET.getlist("severenity_pyramid_rungs")]
49+
if self.request.GET.get("severenity_pyramid_rungs")
5050
else None,
51-
"category": self.request.GET.getlist("category")
52-
if self.request.GET.get("category")
51+
"geographic_scope": [el for el in self.request.GET.getlist("geographic_scope")]
52+
if self.request.GET.get("geographic_scope")
5353
else None,
54-
"format_type": [el for el in self.request.GET.getlist("format_type")],
5554
"source": [int(el) for el in self.request.GET.getlist("source")],
5655
"time_type": [el for el in self.request.GET.getlist("time_type")],
5756
"base_signal": self.request.GET.get("base_signal"),
@@ -76,6 +75,8 @@ def get_context_data(self, **kwargs) -> Dict[str, Any]:
7675

7776
context: Dict[str, Any] = super().get_context_data(**kwargs)
7877
url_params_dict, url_params_str = self.get_url_params()
78+
if not url_params_dict.get("geographic_scope"):
79+
url_params_dict["geographic_scope"] = [GeographicScope.objects.get(name="USA").id]
7980
context["url_params_dict"] = url_params_dict
8081
context["form"] = SignalFilterForm(initial=url_params_dict)
8182
context["url_params_str"] = url_params_str
@@ -120,10 +121,9 @@ class SignalsListApiView(ListAPIView):
120121
"display_name",
121122
"pathogen__name",
122123
"available_geography__name",
123-
"signal_type__name",
124-
"category__name",
125-
"format_type",
124+
"severenity_pyramid_rungs",
126125
"base",
127126
"source__name",
128127
"time_label",
128+
"geographic_scope__name",
129129
)

0 commit comments

Comments
 (0)