diff --git a/vaccinate/core/views.py b/vaccinate/core/views.py index 7c04faa..5fff6a2 100644 --- a/vaccinate/core/views.py +++ b/vaccinate/core/views.py @@ -85,6 +85,74 @@ def location(request, public_id): data = transform(json.loads(content)) api_previews[title] = json.dumps(data, indent=4) + # Come up with a timeline of source locations and reports + availability_reports = ( + location.reports.all() + .exclude(soft_deleted=True) + .prefetch_related("availability_tags") + .exclude(availability_tags__group="skip") + .order_by("-created_at") + ) + + availability_source_locations = ( + location.matched_source_locations.all() + .order_by("-last_imported_at") + .exclude(import_json__availability=None) + ) + + vaccines_offered_reports = ( + location.reports.all() + .exclude(soft_deleted=True) + .prefetch_related("availability_tags") + .exclude(availability_tags__group="skip") + .exclude(vaccines_offered__isnull=True) + .order_by("-created_at") + ) + + vaccines_offered_source_locations = ( + location.matched_source_locations.all() + .order_by("-last_imported_at") + .exclude(import_json__inventory=None) + ) + + availability_timeline = [] + for report in availability_reports: + availability_timeline.append( + { + "type": "report", + "report": report, + "when": report.created_at, + } + ) + for source_location in availability_source_locations: + availability_timeline.append( + { + "type": "source_location", + "source_location": source_location, + "when": source_location.last_imported_at, + } + ) + availability_timeline.sort(key=lambda r: r["when"], reverse=True) + + vaccines_offered_timeline = [] + for report in vaccines_offered_reports: + vaccines_offered_timeline.append( + { + "type": "report", + "report": report, + "when": report.created_at, + } + ) + for source_location in vaccines_offered_source_locations: + vaccines_offered_timeline.append( + { + "type": "source_location", + "source_location": source_location, + "when": source_location.last_imported_at, + } + ) + vaccines_offered_timeline.sort(key=lambda r: r["when"], reverse=True) + return render( request, "location.html", @@ -95,6 +163,8 @@ def location(request, public_id): indent=4, default=lambda v: v.isoformat() if hasattr(v, "isoformat") else repr(v), ), + "availability_timeline": availability_timeline, + "vaccines_offered_timeline": vaccines_offered_timeline, "source_locations": location.matched_source_locations.order_by( "-created_at" ).prefetch_related("concordances"), diff --git a/vaccinate/templates/location.html b/vaccinate/templates/location.html index 1a26289..7440ec3 100644 --- a/vaccinate/templates/location.html +++ b/vaccinate/templates/location.html @@ -13,6 +13,36 @@

Derived availability and inventory

{{ derived_availability_and_inventory }}
+{% if availability_timeline %} +

Availability:

+ +{% endif %} + +{% if vaccines_offered_timeline %} +

Vaccines offered:

+ +{% endif %} + {% for title, content in api_previews %}

{{ title }}

{{ content }}