Skip to content

Commit 9b31d0f

Browse files
authored
Merge pull request #229 from cmu-delphi/staging
Staging
2 parents ab587b2 + 8aade3a commit 9b31d0f

File tree

22 files changed

+2134
-1513
lines changed

22 files changed

+2134
-1513
lines changed

src/alternative_interface/admin.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
from django.contrib import admin
22

3-
# Register your models here.
3+
from import_export.admin import ImportExportModelAdmin
4+
5+
from alternative_interface.models import ExpressViewIndicator
6+
from alternative_interface.resources import ExpressViewIndicatorResource
7+
8+
9+
@admin.register(ExpressViewIndicator)
10+
class ExpressViewIndicatorAdmin(ImportExportModelAdmin):
11+
resource_class = ExpressViewIndicatorResource
12+
list_display = ["menu_item", "indicator", "display_name"]
13+
search_fields = ["menu_item", "indicator", "display_name"]
14+
list_filter = ["menu_item", "indicator"]
15+
ordering = ["menu_item", "indicator"]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
COVIDCAST_FLUVIEW_LOCATIONS_MAPPING = {
2+
"nation:US": "nat",
3+
"hhs:1": "hhs1",
4+
"hhs:2": "hhs2",
5+
"hhs:3": "hhs3",
6+
"hhs:4": "hhs4",
7+
"hhs:5": "hhs5",
8+
"hhs:6": "hhs6",
9+
"hhs:7": "hhs7",
10+
"hhs:8": "hhs8",
11+
"hhs:9": "hhs9",
12+
"hhs:10": "hhs10",
13+
"state:AK": "AK",
14+
"state:AL": "AL",
15+
"state:AR": "AR",
16+
"state:AZ": "AZ",
17+
"state:CA": "CA",
18+
"state:CO": "CO",
19+
"state:CT": "CT",
20+
"state:DC": "DC",
21+
"state:DE": "DE",
22+
"state:FL": "FL",
23+
"state:GA": "GA",
24+
"state:HI": "HI",
25+
"state:IA": "IA",
26+
"state:ID": "ID",
27+
"state:IL": "IL",
28+
"state:IN": "IN",
29+
"state:KS": "KS",
30+
"state:KY": "KY",
31+
"state:LA": "LA",
32+
"state:MA": "MA",
33+
"state:MD": "MD",
34+
"state:ME": "ME",
35+
"state:MI": "MI",
36+
"state:MN": "MN",
37+
"state:MO": "MO",
38+
"state:MS": "MS",
39+
"state:MT": "MT",
40+
"state:NC": "NC",
41+
"state:ND": "ND",
42+
"state:NE": "NE",
43+
"state:NH": "NH",
44+
"state:NJ": "NJ",
45+
"state:NM": "NM",
46+
"state:NV": "NV",
47+
"state:NY": "NY",
48+
"state:OH": "OH",
49+
"state:OK": "OK",
50+
"state:OR": "OR",
51+
"state:PA": "PA",
52+
"state:RI": "RI",
53+
"state:SC": "SC",
54+
"state:SD": "SD",
55+
"state:TN": "TN",
56+
"state:TX": "TX",
57+
"state:UT": "UT",
58+
"state:VA": "VA",
59+
"state:VT": "VT",
60+
"state:WA": "WA",
61+
"state:WI": "WI",
62+
"state:WV": "WV",
63+
"state:WY": "WY",
64+
}
65+
66+
EXPRESS_VIEW_LABELS_MAPPING = {
67+
"smoothed_pct_ed_visits_influenza": "Influenza emergency department visits (NSSP)",
68+
"confirmed_admissions_flu_ew": "Influenza hospital admissions (NHSN)",
69+
"percent_positive": "Test positivity for influenza (ILINet)",
70+
"percent_a": "Test positivity for influenza A (ILINet)",
71+
"percent_b": "Test positivity for influenza B (ILINet)",
72+
"smoothed_flu_from_claims": "Influenza hospital admissions (from claims)",
73+
"deaths_flu_incidence_num": "Influenza deaths (NCHS)",
74+
"smoothed_cli": "Covid related doctor visits (from claims)",
75+
"smoothed_pct_ed_visits_covid": "Covid emergency department visits (NSSP)",
76+
"confirmed_admissions_covid_ew": "Covid hospital admissions (NHNS)",
77+
"smoothed_covid19_from_claims": "Covid hospital admissions (from claims)",
78+
"deaths_covid_incidence_num": "Covid deaths (NCHS)",
79+
"pct_ed_visits_rsv": "RSV emergency department visits (NSSP)",
80+
"confirmed_admissions_rsv_ew": "RSV hospital admissions (NHSN)",
81+
"pct_ed_visits_combined": "Combined emergency department visits (NSSP)",
82+
"wili": "ILI related doctor visits (ILINet)",
83+
"deaths_pneumonia_or_flu_or_covid_incidence_num": "Deaths from flu, Covid or pneumonia (NCHS)",
84+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Generated by Django 5.2.5 on 2025-11-28 18:20
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
("indicators", "0008_alter_indicator_source_type"),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name="ExpressViewIndicator",
18+
fields=[
19+
(
20+
"id",
21+
models.BigAutoField(
22+
auto_created=True,
23+
primary_key=True,
24+
serialize=False,
25+
verbose_name="ID",
26+
),
27+
),
28+
(
29+
"menu_item",
30+
models.CharField(max_length=255, verbose_name="Menu Item"),
31+
),
32+
(
33+
"display_name",
34+
models.CharField(max_length=255, verbose_name="Display Name"),
35+
),
36+
(
37+
"indicator",
38+
models.ForeignKey(
39+
on_delete=django.db.models.deletion.CASCADE,
40+
to="indicators.indicator",
41+
verbose_name="Indicator",
42+
),
43+
),
44+
],
45+
options={
46+
"verbose_name": "Express View Indicator",
47+
"verbose_name_plural": "Express View Indicators",
48+
"ordering": ["menu_item", "indicator"],
49+
"indexes": [
50+
models.Index(
51+
fields=["menu_item", "indicator"], name="expr_view_ind_menu_idx"
52+
)
53+
],
54+
"constraints": [
55+
models.UniqueConstraint(
56+
fields=("menu_item", "indicator"),
57+
name="uniq_expr_view_menu_ind",
58+
)
59+
],
60+
},
61+
),
62+
]
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
11
from django.db import models
22

3-
# Create your models here.
3+
4+
class ExpressViewIndicator(models.Model):
5+
menu_item = models.CharField(
6+
verbose_name="Menu Item",
7+
max_length=255,
8+
)
9+
indicator = models.ForeignKey(
10+
"indicators.Indicator",
11+
verbose_name="Indicator",
12+
on_delete=models.PROTECT,
13+
)
14+
display_name = models.CharField(
15+
verbose_name="Display Name",
16+
max_length=255,
17+
)
18+
19+
class Meta:
20+
verbose_name = "Express View Indicator"
21+
verbose_name_plural = "Express View Indicators"
22+
ordering = ["menu_item", "indicator"]
23+
indexes = [
24+
models.Index(
25+
fields=["menu_item", "indicator"],
26+
name="expr_view_ind_menu_idx",
27+
),
28+
]
29+
constraints = [
30+
models.UniqueConstraint(
31+
fields=["menu_item", "indicator"],
32+
name="uniq_expr_view_menu_ind",
33+
),
34+
]
35+
36+
def __str__(self):
37+
return self.display_name
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from import_export import resources
2+
from import_export.fields import Field
3+
from import_export.widgets import ForeignKeyWidget
4+
from indicators.models import Indicator
5+
6+
from alternative_interface.models import ExpressViewIndicator
7+
8+
9+
def process_indicator(row):
10+
indicator_source = row.get("Indicator Source")
11+
indicator_name = row.get("Indicator Name")
12+
indicator = None
13+
if indicator_name and indicator_source:
14+
try:
15+
indicator = Indicator.objects.get(
16+
name=indicator_name, source__name=indicator_source
17+
)
18+
except Indicator.DoesNotExist:
19+
indicator = None
20+
if indicator:
21+
row["Indicator Name"] = indicator.id
22+
else:
23+
row["Indicator Name"] = None
24+
25+
26+
class ExpressViewIndicatorResource(resources.ModelResource):
27+
menu_item = Field(attribute="menu_item", column_name="Menu Item")
28+
indicator = Field(
29+
attribute="indicator",
30+
column_name="Indicator Name",
31+
widget=ForeignKeyWidget(Indicator),
32+
)
33+
display_name = Field(
34+
attribute="display_name", column_name="text for display legend"
35+
)
36+
37+
def before_import_row(self, row, **kwargs):
38+
process_indicator(row)
39+
40+
def skip_row(self, instance, original, row, import_validation_errors=None):
41+
if not row["Indicator Name"]:
42+
return True
43+
44+
class Meta:
45+
model = ExpressViewIndicator
46+
fields = (
47+
"menu_item",
48+
"indicator",
49+
"display_name",
50+
)
51+
import_id_fields = ("menu_item", "indicator")
52+
skip_unchanged = True
53+
report_skipped = True
54+
exclude = ("id",)

0 commit comments

Comments
 (0)