Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Show timeline of availability/vaccines on /location/x page, refs #650
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 16, 2021
1 parent 23eb061 commit 1da8ace
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
70 changes: 70 additions & 0 deletions vaccinate/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand Down
30 changes: 30 additions & 0 deletions vaccinate/templates/location.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@ <h2>Derived availability and inventory</h2>

<pre>{{ derived_availability_and_inventory }}</pre>

{% if availability_timeline %}
<p>Availability:</p>
<ul>
{% for item in availability_timeline %}
<li><strong>{{ item.when }}</strong> ({{ item.type }})<br>
{% if item.type == "source_location" %}
{{ item.source_location.import_json.availability }} according to {{ item.source_location.source_uid }}
{% else %}
<em>{{ item.report.availability }}</em> according to {{ item.report }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}

{% if vaccines_offered_timeline %}
<p>Vaccines offered:</p>
<ul>
{% for item in vaccines_offered_timeline %}
<li><strong>{{ item.when }}</strong> ({{ item.type }})<br>
{% if item.type == "source_location" %}
{{ item.source_location.import_json.inventory }} according to {{ item.source_location.source_uid }}
{% else %}
<em>{{ item.report.vaccines_offered }}</em> according to {{ item.report }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}

{% for title, content in api_previews %}
<h2>{{ title }}</h2>
<pre>{{ content }}</pre>
Expand Down

0 comments on commit 1da8ace

Please sign in to comment.