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

Commit

Permalink
Expose provider in v0preview, refs #705
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 30, 2021
1 parent 3d29ac5 commit b31b11f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ The following output formats are supported:
- `nlgeojson` - Newline-delimited GeoJSON. [Example nl-GeoJSON](https://vial-staging.calltheshots.us/api/searchLocations?q=walgreens&format=nlgeojson)
- `map` - a basic Leaflet map that renders that GeoJSON. [Example map](https://vial-staging.calltheshots.us/api/searchLocations?q=walgreens&format=map)
- `ids` - a JSON array of public location IDs.
- `v0preview` - preview of the v0 API JSON format we publish to `api.vaccinatethestates.com`.
- `v0preview-geojson` - preview of the v0 GeoJSON API format we publish to `api.vaccinatethestates.com`.

You can also add `debug=1` to the JSON output to wrap them in an HTML page. This is primarily useful in development as it enables the Django Debug Toolbar for those results.

Expand Down
14 changes: 12 additions & 2 deletions vaccinate/api/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def location_v0_json(location: Location) -> Dict[str, object]:
return {
"id": location.public_id,
"name": location.name,
"provider": {
"name": location.provider.name,
"vaccine_info_url": location.provider.vaccine_info_url,
}
if location.provider
else None,
"state": location.state.abbreviation,
"latitude": float(location.latitude),
"longitude": float(location.longitude),
Expand Down Expand Up @@ -209,7 +215,9 @@ def transform_batch_geojson(batch):
return batch

formats["v0preview"] = OutputFormat(
prepare_queryset=lambda qs: qs.select_related("dn_latest_non_skip_report"),
prepare_queryset=lambda qs: qs.select_related(
"dn_latest_non_skip_report", "provider"
),
start=(
b'{"usage":{"notice":"Please contact Vaccinate The States and let '
b"us know if you plan to rely on or publish this data. This "
Expand All @@ -227,7 +235,9 @@ def transform_batch_geojson(batch):
content_type="application/json",
)
formats["v0preview-geojson"] = OutputFormat(
prepare_queryset=lambda qs: qs.select_related("dn_latest_non_skip_report"),
prepare_queryset=lambda qs: qs.select_related(
"dn_latest_non_skip_report", "provider"
),
start=(
b'{"type":"FeatureCollection","usage":USAGE,'.replace(
b"USAGE", orjson.dumps(VTS_USAGE)
Expand Down
41 changes: 41 additions & 0 deletions vaccinate/api/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,47 @@ def test_search_locations_format_json(client, api_key, ten_locations):
}


def test_search_locations_format_v0preview(client, api_key, location):
provider_type = ProviderType.objects.get(name="Pharmacy")
location.provider = Provider.objects.get_or_create(
name="Some provider",
defaults={
"provider_type": provider_type,
"vaccine_info_url": "https://example.com/",
},
)[0]
location.save()
result = search_locations(
client, api_key, "id={}&format=v0preview".format(location.public_id)
)
assert set(result.keys()) == {"content", "usage"}
record = result["content"][0]
assert set(record.keys()) == {
"id",
"name",
"provider",
"state",
"latitude",
"longitude",
"location_type",
"phone_number",
"full_address",
"city",
"county",
"zip_code",
"hours",
"website",
"vaccines_offered",
"concordances",
"last_verified_by_vts",
"vts_url",
}
assert record["provider"] == {
"name": "Some provider",
"vaccine_info_url": "https://example.com/",
}


def test_search_locations_format_ids(client, api_key, ten_locations):
result = search_locations(client, api_key, "format=ids")
assert isinstance(result, list)
Expand Down

0 comments on commit b31b11f

Please sign in to comment.