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

Commit

Permalink
APIv0 now popultes vaccines_offered from location.vaccines_offered, r…
Browse files Browse the repository at this point in the history
…efs #705, refs #650
  • Loading branch information
simonw committed Jun 30, 2021
1 parent d1549fc commit 27bcc4e
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions vaccinate/api/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def location_json_queryset(queryset: QuerySet[Location]) -> QuerySet[Location]:
"google_places_id",
"vaccinefinder_location_id",
"vaccinespotter_location_id",
"vaccines_offered",
"zip_code",
"hours",
"website",
Expand Down Expand Up @@ -177,7 +178,7 @@ def location_v0_json(location: Location) -> Dict[str, object]:
"zip_code": location.zip_code,
"hours": {"unstructured": location.hours},
"website": location.website,
"vaccines_offered": [],
"vaccines_offered": location.vaccines_offered,
"concordances": [str(c) for c in location.concordances.all()],
"last_verified_by_vts": location.dn_latest_non_skip_report.created_at.isoformat()
if location.dn_latest_non_skip_report
Expand All @@ -200,21 +201,8 @@ def split_geojson_by_state(locations_geojson):
}


def location_formats(preload_vaccinefinder=False):
def location_formats():
formats = make_formats(location_json, location_geojson)
expansion = VaccineFinderInventoryExpansion(preload_vaccinefinder)

def transform_batch(batch):
lookups = expansion.expand(batch)
for record in batch:
record["vaccines_offered"] = lookups.get(record["id"]) or []
return batch

def transform_batch_geojson(batch):
lookups = expansion.expand(batch)
for record in batch:
record["properties"]["vaccines_offered"] = lookups.get(record["id"]) or []
return batch

formats["v0preview"] = OutputFormat(
prepare_queryset=lambda qs: qs.select_related("dn_latest_non_skip_report"),
Expand All @@ -228,7 +216,7 @@ def transform_batch_geojson(batch):
b'"content":['
),
transform=lambda l: location_v0_json(l),
transform_batch=transform_batch,
transform_batch=lambda batch: batch,
serialize=orjson.dumps,
separator=b",",
end=lambda qs: b"]}",
Expand All @@ -245,7 +233,7 @@ def transform_batch_geojson(batch):
+ b'"features":['
),
transform=lambda l: to_geojson(location_v0_json(l)),
transform_batch=transform_batch_geojson,
transform_batch=lambda batch: batch,
serialize=orjson.dumps,
separator=b",",
end=lambda qs: b"]}",
Expand Down

0 comments on commit 27bcc4e

Please sign in to comment.