def _get_normalized_location(site: dict, timestamp: str) -> schema.NormalizedLocation: return schema.NormalizedLocation( id=f"nyc_arcgis:{site['attributes']['LocationID']}", name=site["attributes"]["FacilityName"], address=schema.Address( street1=site["attributes"]["Address"], street2=site["attributes"]["Address2"], city=site["attributes"]["Borough"], state="NY", zip=site["attributes"]["Zipcode"], ), location=schema.LatLng( latitude=site["geometry"]["y"], longitude=site["geometry"]["x"], ), contact=_get_contacts(site), opening_hours=_get_opening_hours(site), availability=_get_availability(site), inventory=_get_inventory(site), access=schema.Access( wheelchair="yes" if site["attributes"]["ADA_Compliant"] == "Yes" else "no"), parent_organization=_get_parent_organization(site), notes=_get_notes(site), source=_get_source(site, timestamp), )
def normalize(site: dict, timestamp: str) -> dict: links = [ schema.Link(authority="ct_gov", id=site["_id"]), schema.Link(authority="ct_gov_network_id", id=site["networkId"]), ] parent_organization = schema.Organization(name=site["networks"][0]["name"]) parsed_provider_link = provider_id_from_name(site["name"]) if parsed_provider_link is not None: links.append( schema.Link(authority=parsed_provider_link[0], id=parsed_provider_link[1]) ) parent_organization.id = parsed_provider_link[0] return schema.NormalizedLocation( id=f"ct_gov:{site['_id']}", name=site["displayName"], address=schema.Address( street1=site["addressLine1"], street2=site["addressLine2"], city=site["city"], state="CT", zip=site["zip"], ), location=_get_lat_lng(site), contact=[ schema.Contact( contact_type="booking", phone=site["phone"], website=site["link"] ), ], languages=None, opening_dates=None, opening_hours=None, availability=schema.Availability( appointments=site["availability"], ), inventory=[ schema.Vaccine(vaccine=vaccine["name"]) for vaccine in site["providerVaccines"] ], access=schema.Access( drive=site["isDriveThru"], ), parent_organization=parent_organization, links=links, notes=None, active=None, source=schema.Source( source="covidvaccinefinder_gov", id=site["_id"], fetched_from_uri="https://covidvaccinefinder.ct.gov/api/HttpTriggerGetProvider", # noqa: E501 fetched_at=timestamp, published_at=site["lastModified"], data=site, ), ).dict()
def _get_access(site: dict) -> Optional[schema.Access]: potentials = { "Yes": True, "No": False, } # TODO: check to see if the arcgis fields really map to Access this way drive = potentials.get(site["attributes"]["drivethru"]) walk = potentials.get(site["attributes"]["pedaccess"]) if (drive, walk) != (None, None): return schema.Access(drive=drive, walk=walk) else: return None
def normalize(site: dict, timestamp: str) -> schema.NormalizedLocation: source_name = SOURCE_NAME # NOTE: we use `get` where the field is optional in our data source, and # ["key'] access where it is not. return schema.NormalizedLocation( id=f"{source_name}:{_get_id(site)}", name=site["locationName"], address=schema.Address( street1=site.get("addressLine1"), street2=site.get("addressLine2"), city=site.get("city"), state=_get_state(site), zip=_get_good_zip(site), ), location=schema.LatLng(latitude=site["latitude"], longitude=site["longitude"]), contact=_get_contacts(site), notes=site.get("description"), # Since this could be nullable we make sure to only provide it if it's True or False availability=schema.Availability(drop_in=site.get("walkIn")) if site.get("walkIn") is not None else None, access=schema.Access( walk=site.get("walkupSite"), drive=site.get("driveupSite"), wheelchair=_get_wheelchair(site), ), # IF supply_level is UNKNOWN, don't say anything about it inventory=[ schema.Vaccine( vaccine=_get_vaccine_type(vaccine), supply_level=_get_supply_level(site) ) for vaccine in site["vaccineTypes"] if _get_vaccine_type(vaccine) is not None ] if _get_supply_level(site) else None, parent_organization=schema.Organization( id=site.get("providerId"), name=site.get("providerName") ), source=schema.Source( source=source_name, id=site["locationId"], fetched_from_uri="https://apim-vaccs-prod.azure-api.net/web/graphql", fetched_at=timestamp, published_at=site["updatedAt"], data=site, ), )
def normalize(site_blob: dict, timestamp: str) -> dict: site = site_blob["properties"] links = [schema.Link(authority="vaccinespotter_org", id=site["id"])] parsed_provider_link = provider_id_from_name( site["provider_brand_name"] # or use site["name"]? ) if parsed_provider_link is not None: links.append( schema.Link(authority=parsed_provider_link[0], id=parsed_provider_link[1])) _strip_source_data(site_blob) return schema.NormalizedLocation( id=f"vaccinespotter_org:{site['id']}", name=site["name"], address=_get_address(site), location=_get_lat_lng(site_blob["geometry"], site["id"]), contact=[ schema.Contact(contact_type=None, phone=None, website=site["url"]), ], languages=None, opening_dates=None, opening_hours=None, availability=schema.Availability( appointments=site["appointments_available"], drop_in=None), inventory=None, access=schema.Access(walk=None, drive=None, wheelchair=None), parent_organization=None, links=links, notes=None, active=None, source=schema.Source( source="vaccinespotter_org", id=site["id"], fetched_from_uri= "https://www.vaccinespotter.org/api/v0/US.json", # noqa: E501 fetched_at=timestamp, published_at=site["appointments_last_fetched"], data=site_blob, ), ).dict()
def _get_access(site: dict) -> Optional[List[str]]: drive = site["attributes"].get("drive_through") drive_bool = drive is not None # walk = site["attributes"].get("drive_through") # walk_bool = drive is not None wheelchair = site["attributes"].get("Wheelchair_Accessible") wheelchair_options = { "Yes": "yes", "Partially": "partial", "Unknown": "no", "Not Applicable": "no", "NA": "no", } wheelchair_bool = try_lookup( wheelchair_options, wheelchair, "no", name="wheelchair access" ) return schema.Access(drive=drive_bool, wheelchair=wheelchair_bool)
def _get_access(site: dict) -> location.Access: if re.search(r"\bdrive[- ](thru|up)\b", site["name"], flags=re.IGNORECASE): return location.Access(drive=True) return None
def _get_access(site: dict) -> Optional[schema.Access]: if "wheelchair" in site["description"].lower(): return schema.Access(wheelchair=schema.WheelchairAccessLevel.YES) return None
def full_location(): return location.NormalizedLocation( id="source:dad13365-2202-4dea-9b37-535288b524fe", name="Rite Aid Pharmacy 5952", address=location.Address( street1="1991 Mountain Boulevard", city="Oakland", state="CA", zip="94611", ), location=location.LatLng( latitude=37.8273167, longitude=-122.2105179, ), contact=[ location.Contact( contact_type=location.ContactType.BOOKING, phone="(916) 445-2841", ), location.Contact( contact_type=location.ContactType.GENERAL, phone="(510) 339-2215", ), ], languages=["en"], opening_dates=[ location.OpenDate( opens="2021-04-01", closes="2021-04-01", ), ], opening_hours=[ location.OpenHour( day=location.DayOfWeek.MONDAY, opens="08:00", closes="14:00", ), ], availability=location.Availability( drop_in=False, appointments=True, ), inventory=[ location.Vaccine( vaccine=location.VaccineType.MODERNA, supply_level=location.VaccineSupply.IN_STOCK, ), ], access=location.Access( walk=True, drive=False, wheelchair=location.WheelchairAccessLevel.PARTIAL, ), parent_organization=location.Organization( id=location.VaccineProvider.RITE_AID, name="Rite Aid Pharmacy", ), links=[ location.Link( authority=location.LocationAuthority.GOOGLE_PLACES, id="ChIJA0MOOYWHj4ARW8M-vrC9yGA", ), ], notes=["long note goes here"], active=True, source=location.Source( source="source", id="dad13365-2202-4dea-9b37-535288b524fe", fetched_from_uri="https://example.org", fetched_at="2020-04-04T04:04:04.4444", published_at="2020-04-04T04:04:04.4444", data={"id": "dad13365-2202-4dea-9b37-535288b524fe"}, ), )
def normalize(site: dict, timestamp: str) -> dict: address = site["location"]["address"] address_parts = [p.strip() for p in address.split(",")] # Remove city from end of address address_parts.pop() street1 = address_parts[0] street2 = None if len(address_parts) > 1: street2 = ", ".join(address_parts[1:]) links = [schema.Link(authority="sf_gov", id=site["id"])] parsed_provider_link = provider_id_from_name(site["name"]) if parsed_provider_link is not None: links.append( schema.Link(authority=parsed_provider_link[0], id=parsed_provider_link[1])) contacts = [] if site["booking"]["phone"] and site["booking"]["phone"].lower() != "none": contacts.append( schema.Contact(contact_type="booking", phone=site["booking"]["phone"])) if site["booking"]["url"] and site["booking"]["url"].lower() != "none": contacts.append( schema.Contact(contact_type="booking", website=site["booking"]["url"])) if site["booking"]["info"] and site["booking"]["info"].lower() != "none": contacts.append( schema.Contact(contact_type="booking", other=site["booking"]["info"])) return schema.NormalizedLocation( id=f"sf_gov:{site['id']}", name=site["name"], address=schema.Address( street1=street1, street2=street2, city=site["location"]["city"], state="CA", zip=(site["location"]["zip"] if site["location"]["zip"] and site["location"]["zip"].lower() != "none" else None), ), location=schema.LatLng( latitude=site["location"]["lat"], longitude=site["location"]["lng"], ), contact=contacts, languages=[k for k, v in site["access"]["languages"].items() if v], opening_dates=None, opening_hours=None, availability=schema.Availability( appointments=site["appointments"]["available"], drop_in=site["booking"]["dropins"], ), inventory=None, access=schema.Access( walk=site["access_mode"]["walk"], drive=site["access_mode"]["drive"], wheelchair="yes" if site["access"]["wheelchair"] else "no", ), parent_organization=None, links=links, notes=None, active=site["active"], source=schema.Source( source="sf_gov", id=site["id"], fetched_from_uri= "https://vaccination-site-microservice.vercel.app/api/v1/appointments", # noqa: E501 fetched_at=timestamp, published_at=site["appointments"]["last_updated"], data=site, ), ).dict()
def test_valid_location(): # Minimal record assert location.NormalizedLocation( id="source:id", source=location.Source( source="source", id="id", data={"id": "id"}, ), ) # Full record with str enums full_loc = location.NormalizedLocation( id="source:id", name="name", address=location.Address( street1="1991 Mountain Boulevard", street2="#1", city="Oakland", state="CA", zip="94611", ), location=location.LatLng( latitude=37.8273167, longitude=-122.2105179, ), contact=[ location.Contact( contact_type="booking", phone="(916) 445-2841", ) ], languages=["en"], opening_dates=[ location.OpenDate( opens="2021-04-01", closes="2021-04-01", ), ], opening_hours=[ location.OpenHour( day="monday", opens="08:00", closes="14:00", ), ], availability=location.Availability( drop_in=False, appointments=True, ), inventory=[ location.Vaccine( vaccine="moderna", supply_level="in_stock", ), ], access=location.Access( walk=True, drive=False, wheelchair="partial", ), parent_organization=location.Organization( id="rite_aid", name="Rite Aid", ), links=[ location.Link( authority="google_places", id="abc123", ), ], notes=["note"], active=True, source=location.Source( source="source", id="id", fetched_from_uri="https://example.org", fetched_at="2020-04-04T04:04:04.4444", published_at="2020-04-04T04:04:04.4444", data={"id": "id"}, ), ) assert full_loc # Verify dict serde full_loc_dict = full_loc.dict() assert full_loc_dict parsed_full_loc = location.NormalizedLocation.parse_obj(full_loc_dict) assert parsed_full_loc assert parsed_full_loc == full_loc # Verify json serde full_loc_json = full_loc.json() assert full_loc_json parsed_full_loc = location.NormalizedLocation.parse_raw(full_loc_json) assert parsed_full_loc assert parsed_full_loc == full_loc # Verify dict->json serde full_loc_json_dumps = json.dumps(full_loc_dict) assert full_loc_json_dumps assert full_loc_json_dumps == full_loc_json parsed_full_loc = location.NormalizedLocation.parse_raw( full_loc_json_dumps) assert parsed_full_loc assert parsed_full_loc == full_loc