|
1 | 1 | import logging |
| 2 | +import ast |
2 | 3 |
|
3 | 4 |
|
4 | 5 | import django_filters |
|
13 | 14 | ) |
14 | 15 | from indicators.models import Indicator |
15 | 16 | from base.models import Pathogen, Geography, SeverityPyramidRung |
| 17 | +from alternative_interface.helper import COVIDCAST_FLUVIEW_LOCATIONS_MAPPING |
16 | 18 |
|
17 | 19 |
|
18 | 20 | logger = logging.getLogger(__name__) |
@@ -123,18 +125,27 @@ def hosted_by_delphi_filter(self, queryset, name, value): |
123 | 125 |
|
124 | 126 | return queryset |
125 | 127 |
|
| 128 | + @staticmethod |
| 129 | + def include_fluview(values): |
| 130 | + include_fluview = False |
| 131 | + for value in ast.literal_eval(values): |
| 132 | + if COVIDCAST_FLUVIEW_LOCATIONS_MAPPING.get(value): |
| 133 | + include_fluview = True |
| 134 | + break |
| 135 | + return include_fluview |
| 136 | + |
126 | 137 | def location_search_filter(self, queryset, name, value): |
127 | 138 | if not value: |
128 | 139 | return queryset |
| 140 | + indicator_sets = [] |
129 | 141 | filtered_indicators = get_list_of_indicators_filtered_by_geo(value) |
| 142 | + include_fluview = self.include_fluview(value) |
| 143 | + query = Q() |
130 | 144 | if filtered_indicators["epidata"]: |
131 | | - query = Q() |
132 | 145 | for item in filtered_indicators["epidata"]: |
133 | 146 | query |= Q(source__name=item["source"], name=item["signal"]) |
134 | | - self.indicators_qs = self.indicators_qs.filter(query) |
135 | | - indicator_sets = self.indicators_qs.values_list( |
136 | | - "indicator_set_id", flat=True |
137 | | - ).distinct() |
138 | | - return queryset.filter(id__in=indicator_sets) |
139 | | - else: |
140 | | - return IndicatorSet.objects.none() |
| 147 | + if include_fluview: |
| 148 | + query |= Q(indicator_set__epidata_endpoint="fluview") |
| 149 | + self.indicators_qs = self.indicators_qs.filter(query) |
| 150 | + indicator_sets = list(self.indicators_qs.values_list("indicator_set_id", flat=True).order_by("indicator_set_id").distinct()) |
| 151 | + return queryset.filter(id__in=indicator_sets) |
0 commit comments