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

Commit

Permalink
Update derived location fields when source location imported, refs #650
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 22, 2021
1 parent 03d77ee commit 9cb542e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_uid": "vaccinespotter:7382088",
"source_name": "vaccinespotter",
"source_uid": "vaccinespotter_org:7382088",
"source_name": "vaccinespotter_org",
"content_hash": "6cafddd7de8861754ee23c5e4a1f64e1",
"name": "Rite Aid",
"latitude": 33.4962,
Expand All @@ -9,7 +9,7 @@
"action": "new"
},
"import_json": {
"id": "vaccinespotter:7382088",
"id": "vaccinespotter_org:7382088",
"name": "Rite Aid",
"address": {
"street1": "32121 Camino Capistrano",
Expand All @@ -26,8 +26,13 @@
"website": "https://www.riteaid.com/pharmacy/covid-qualifier"
}],
"availability": {
"appointments": false
"appointments": false,
"drop_in": true
},
"inventory": [
{"vaccine": "pfizer_biontech"},
{"vaccine": "johnson_johnson_janssen", "supply_level": "in_stock"}
],
"parent_organization": {
"id": "rite_aid",
"name": "Rite Aid"
Expand All @@ -43,7 +48,7 @@
}
],
"source": {
"source": "vaccinespotter",
"source": "vaccinespotter_org",
"id": "7382088",
"fetched_from_uri": "https://www.vaccinespotter.org/api/v0/states/CA.json",
"fetched_at": "2021-04-06T20:17:55.148+00:00",
Expand Down
22 changes: 22 additions & 0 deletions vaccinate/api/test_import_source_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,25 @@ def test_import_source_location_does_not_overwrite_existing_match(
concordances = set(second_location.concordances.all())
source_concordanes = set(source_location.concordances.all())
assert not source_concordanes.issubset(concordances)


def test_import_source_location_updates_location_fields(client, api_key):
with (tests_dir / "002-new-location.json").open() as fixture_file:
fixture = orjson.loads(fixture_file.read())
import_run_id = client.post(
"/api/startImportRun", HTTP_AUTHORIZATION="Bearer {}".format(api_key)
).json()["import_run_id"]
# Make the API request
client.post(
"/api/importSourceLocations?import_run_id={}".format(import_run_id),
fixture,
content_type="application/json",
HTTP_AUTHORIZATION="Bearer {}".format(api_key),
)
source_location = SourceLocation.objects.first()
location = source_location.matched_location
assert set(location.vaccines_offered) == {"Pfizer", "Johnson & Johnson"}
assert location.accepts_walkins
assert not location.accepts_appointments
assert location.vaccines_offered_provenance_source_location == source_location
assert location.appointments_walkins_provenance_source_location == source_location
6 changes: 6 additions & 0 deletions vaccinate/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ def import_source_locations(request, on_request_logged):
created.append(source_location.pk)
else:
updated.append(source_location.pk)

if source_location.matched_location:
source_location.matched_location.derive_availability_and_inventory(
save=True
)

return JsonResponse({"created": created, "updated": updated})


Expand Down

0 comments on commit 9cb542e

Please sign in to comment.