def _get_organization(site: dict): if site["Organization Name"] == "": return None if site["Organization Name"] == "Walmart, Inc.": return schema.Organization(name=site["Organization Name"], id="walmart") return schema.Organization(name=site["Organization Name"])
def _get_organization(site: dict) -> Optional[schema.Organization]: if _get_name(site)[0:6] == "Kroger": return schema.Organization(name="Kroger", id="kroger") if _get_name(site)[0:9] == "Walgreens": return schema.Organization(name="Walgreens", id="walgreens") if _get_name(site)[0:7] == "Walmart": return schema.Organization(name="Walmart", id="walmart")
def _get_parent_organization(site: dict) -> Optional[schema.Organization]: # Just the obvious easy cases; Pareto-style name = site["attributes"]["FacilityName"] if name == "Rite Aid Pharmacy": return schema.Organization(name="rite_aid") if name == "Walgreens/Duane Reade": return schema.Organization(name="walgreens") if name == "CVS Pharmacy": return schema.Organization(name="cvs") return None
def _get_organization(site: dict) -> Optional[schema.Organization]: if "Kroger" in site["providerName"]: return schema.Organization(id=schema.VaccineProvider.KROGER) if "Safeway" in site["providerName"]: return schema.Organization(id=schema.VaccineProvider.SAFEWAY) if "Walgreen" in site["providerName"]: return schema.Organization(id=schema.VaccineProvider.WALGREENS) if "Walmart" in site["providerName"]: return schema.Organization(id=schema.VaccineProvider.WALMART) if "CVS" in site["providerName"]: return schema.Organization(id=schema.VaccineProvider.CVS) return None
def _get_parent_organization(name: str) -> Optional[schema.Organization]: if "Costco" in name: return schema.Organization(id=schema.VaccineProvider.COSTCO) if "Sam's Pharmacy" in name: return schema.Organization(id=schema.VaccineProvider.SAMS) if "Walgreen" in name: return schema.Organization(id=schema.VaccineProvider.WALGREENS) if "Walmart" in name: return schema.Organization(id=schema.VaccineProvider.WALMART) if "CVS" in name: return schema.Organization(id=schema.VaccineProvider.CVS) return None
def _get_parent_organization( loc: GMVLocation) -> Optional[location.Organization]: provider = PROVIDER_MAPPING.get(loc.provider) if not provider: return None return location.Organization(id=provider)
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 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 _add_provider_from_name(loc: location.NormalizedLocation) -> None: """Add provider link from name if missing""" if not loc.name: return provider_tuple = normalize.provider_id_from_name(loc.name) if not provider_tuple: return provider_authority, provider_id = provider_tuple existing_links = _generate_link_map(loc) if str(provider_authority) not in existing_links: loc.links = [ *(loc.links or []), location.Link(authority=provider_authority, id=provider_id), ] if not loc.parent_organization: loc.parent_organization = location.Organization(id=provider_authority)
def _get_organization(site: dict) -> Optional[schema.Organization]: emails = [ site["attributes"]["publicEmail"], site["attributes"]["adminEmail"] ] for email in emails: if email and "costco.com" in email: return schema.Organization(id=schema.VaccineProvider.COSTCO) if email and "cvshealth.com" in email: return schema.Organization(id=schema.VaccineProvider.CVS) if email and "fredmeyer.com" in email: return schema.Organization(id=schema.VaccineProvider.FRED_MEYER) if email and "safeway.com" in email: return schema.Organization(id=schema.VaccineProvider.SAFEWAY) if email and "walgreens.com" in email: return schema.Organization(id=schema.VaccineProvider.WALGREENS) if email and "walmart.com" in email: return schema.Organization(id=schema.VaccineProvider.WALMART) return None
def _get_parent_organization(site: dict) -> Optional[schema.Organization]: maybe_provider = provider_id_from_name(site["name"]) if maybe_provider: return schema.Organization(id=maybe_provider[0]) return None
def _lookup_provider(website: schema.Contact) -> Optional[schema.Organization]: """Gets the vaccine provider for the given website, if known.""" url = website.website provider = _URL_HOST_TO_PROVIDER.get(url.host, None) if url else None return schema.Organization(id=provider) if provider else None
def _get_organization(site: dict) -> Optional[schema.Organization]: if _get_name(site) == "Walmart": return schema.Organization(name=_get_name(site), id="walmart") if _get_name(site) == "Walgreens": return schema.Organization(name=_get_name(site), id="walgreens") 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 _get_parent(site: dict) -> Optional[schema.Organization]: if org := site["attributes"].get("agency"): return schema.Organization(id=location_id_from_name(org), name=org)
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