diff --git a/docs/api.md b/docs/api.md index 08f5f3e..734d620 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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. diff --git a/vaccinate/api/serialize.py b/vaccinate/api/serialize.py index 9ec07ca..7df6780 100644 --- a/vaccinate/api/serialize.py +++ b/vaccinate/api/serialize.py @@ -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), @@ -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 " @@ -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) diff --git a/vaccinate/api/test_search.py b/vaccinate/api/test_search.py index 208f3ee..435bad5 100644 --- a/vaccinate/api/test_search.py +++ b/vaccinate/api/test_search.py @@ -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)