def _get_availability(site: dict) -> schema.Availability: avail_field = site["attributes"]["flu_walkins"] potentials = { "no_please_make_an_appointment": schema.Availability(appointments=True), "yes": schema.Availability(drop_in=True), } try: return potentials[avail_field] except KeyError as e: logger.error("Unexpected availability code: %s", e) return None
def normalize(site_blob: dict, timestamp: str) -> dict: """ sample entry: {"providerId": 1013, "providerName": "\u1d42**York College - Health and Physical Education Complex - Queens", "vaccineBrand": "Pfizer", "address": "Jamaica, NY", "availableAppointments": "Y", "isShowable": true, "lastUpdated": "2021-04-23T20:04:24"} # noqa: E501 """ name = NAME_CLEAN_RE.sub("", site_blob["providerName"]).strip() city = CITY_RE.search(site_blob["address"]).group(1) appts_available = True if site_blob[ "availableAppointments"] == "Y" else False return schema.NormalizedLocation( id=f"am_i_eligible_covid19vaccine_gov:{site_blob['providerId']}", name=name, address=schema.Address( city=city, state="NY", ), availability=schema.Availability(appointments=appts_available), inventory=_get_inventory(site_blob["vaccineBrand"]), links=[ schema.Link(authority="am_i_eligible_covid19vaccine_gov", id=site_blob["providerId"]), ], source=_get_source(site_blob, timestamp), ).dict()
def _get_normalized_site(site: dict, timestamp: str) -> schema.NormalizedLocation: name = site["attributes"]["f3"] lat_lng = _get_lat_lng(site) id = _id("d1a799c7f98e41fb8c6b4386ca6fe014", lat_lng, name, None) return schema.NormalizedLocation( id=f"{SOURCE_NAME}:{id}", name=name, address=None, location=lat_lng, contact=_get_contact(site), availability=schema.Availability( drop_in=False, appointments=True, ), notes=[site["attributes"]["f5"]], source=schema.Source( source=SOURCE_NAME, id=id, fetched_from_uri=FETCHED_FROM_URI, fetched_at=timestamp, data=site, ), )
def _get_availability(loc: GMVLocation) -> Optional[location.Availability]: if not loc.availability: return None if loc.availability.available == "UNKNOWN": return None return location.Availability(appointments=True)
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_availability(site: dict) -> schema.Availability: for field in VACCINES_FIELD.keys(): try: if site["attributes"][field] > 0: return schema.Availability(appointments=True) except KeyError: pass return None
def _get_availability(site: dict) -> schema.Availability: appointment_required = site["attributes"]["Intake_ApptRequired"] == "Yes" drop_ins_allowed = site["attributes"]["Intake_WalkIn"] == "Yes" return schema.Availability( drop_in=(True if drop_ins_allowed else (False if appointment_required else None)), appointments=(True if appointment_required else None), )
def _get_availability(site: dict) -> Optional[schema.Availability]: if not site["attributes"]["TestingRequirements"]: return None requirements = site["attributes"]["TestingRequirements"].split("|") return schema.Availability( appointments=True if "Appointment" in requirements else None, drop_in=True if "No appointment necessary" in requirements else None, )
def add_availability( self, drop_in: Optional[bool] = None, appointments: Optional[bool] = None, ) -> None: """Adds the given availability information to the current site.""" site = self._current_site site.availability = site.availability or schema.Availability() if drop_in is not None: site.availability.drop_in = drop_in if appointments is not None: site.availability.appointments = appointments
def normalize(site: dict, timestamp: str) -> dict: normalized = schema.NormalizedLocation( id=("tx_memorialhermann:" + _get_id(site)), name=_get_name(site), address=_get_address(site), opening_hours=_get_hours(site), inventory=_get_vaccine(site), notes=_get_notes(site), availability=schema.Availability( drop_in=True), # The webpage is for walk-in clinics source=_get_source(site, timestamp), ).dict() return normalized
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 _get_availability(site: dict) -> schema.Availability: appt_only = site["attributes"]["appt_only"] appt_options = { "Yes": True, "No": False, "Vax only": True, "Test only": False, } avail = try_lookup(appt_options, appt_only, None, name="availability lookup") if avail is not None: return schema.Availability(appointments=avail) # there seems to be no walk-in data unless you want to parse "drive_in" = yes and "vehiche_required" = no into a "walk-in = yes" return None
def _get_availability(site: dict) -> Optional[schema.Availability]: drop_in, appointments = None, None for field in ("description", "application_process", "hours_of_operation"): if not site.get(field): continue value = site[field].lower() if "appointment" in value: appointments = True if re.search("walk[ |-]in", value): drop_in = True if drop_in or appointments: return schema.Availability(drop_in=drop_in, appointments=appointments) else: return None
def normalize(site: dict, timestamp: str) -> str: """ sample: {"name": "Rebel Med NW - COVID Vaccine Clinic", "date": "04/30/2021", "address": "5401 Leary Ave NW, Seattle WA, 98107", "vaccines": "Moderna COVID-19 Vaccine", "ages": "Adults, Seniors", "info": "truncated", "hours": "09:00 am - 05:00 pm", "available": "14", "special": "If you are signing up for a second dose, you must get the same vaccine brand as your first dose.", "clinic_id": "2731"} # noqa: E501 """ normalized = schema.NormalizedLocation( id=f"wa_prepmod:{site['clinic_id']}", name=site["name"], address=_get_address(site), availability=schema.Availability(appointments=True), contact=_get_contact(site), inventory=_get_inventory(site), opening_dates=_get_opening_dates(site), opening_hours=_get_opening_hours(site), notes=_get_notes(site), source=_get_source(site, timestamp), ).dict() return normalized
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 normalize(site: dict, timestamp: str) -> schema.NormalizedLocation: source_id = "il_sfsites" name = site["Testing_Center__c"] notes = [] loc = schema.LatLng( latitude=site["Geolocation__Latitude__s"], longitude=site["Geolocation__Longitude__s"], ) addr = _get_address(site) location_id = _id(loc, name, addr) if "Location_Type__c" in site: notes.append(site["Location_Type__c"]) return schema.NormalizedLocation( id=f"{source_id}:{location_id}", name=name, address=addr, location=loc, contact=_get_contact(site), languages=None, opening_dates=None, opening_hours=None, availability=schema.Availability(appointments=True), inventory=None, access=None, parent_organization=_get_parent_organization(name), links=None, notes=notes, active=None, source=schema.Source( source=source_id, id=location_id, fetched_from_uri= "https://coronavirus.illinois.gov/s/vaccination-location", # noqa: E501 fetched_at=timestamp, published_at=None, data=site, ), )
def normalize(site: dict, timestamp: str) -> schema.NormalizedLocation: id_ = _get_id(site) return schema.NormalizedLocation( id=id_, name=site["Walk-Up Site"], address=_get_address(site), opening_dates=_get_opening_dates(site), opening_hours=_get_opening_hours(site), availability=schema.Availability(appointments=False, drop_in=True), inventory=_get_inventory(site), notes=_get_notes(site), source=schema.Source( source="dc_district", id=id_.split(":")[-1], fetched_from_uri="https://coronavirus.dc.gov/vaccinatedc", fetched_at=timestamp, data=site, ), )
def normalize(site: dict, timestamp: str) -> str: """ input keys: - "organizer": Always "IL-IDPH". - "slug": Unique ID, may be a UUID or something like "7vbvl-29-31". Used in URLs. - "name": Name, often includes dates and vaccine type but no consistent format. - "location": Street address, no consistent format. - "dateFrom": Start time, always formatted like "4/24/2021, 9:30 AM". - "dateTo": End time, may be null, otherwise always formatted like "4/24/2021, 4:30 PM". - "lat": Latitude, may be null. - "lon": Longitude, may be null. - "search": Not interesting, just a bunch of the other fields joined together. """ building, address = _get_building_and_address(site) if site["lat"] and site["lon"]: latlng: Optional[location.LatLng] = location.LatLng( latitude=site["lat"], longitude=site["lon"]) else: latlng = None normalized = location.NormalizedLocation( id=f"il_juvare:{site['slug'].replace('-','_')}", name=_filter_name(building, site), address=address, location=latlng, contact=_get_contact(site), opening_dates=_get_opening_dates(site), opening_hours=_get_opening_hours(site), availability=location.Availability(appointments=True), inventory=_get_inventory(site), access=_get_access(site), active=True, source=_get_source(site, timestamp), ).dict() return normalized
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_availability(site: dict) -> Optional[schema.Availability]: potentials = { "Yes": schema.Availability(drop_in=True), "No": schema.Availability(drop_in=False), } return potentials.get(site["attributes"]["WalkUpAvailable"])
def _get_availability(site: dict) -> Optional[schema.Availability]: if site["attributes"]["flu_walkins"] == "no_please_make_an_appointment": return schema.Availability(drop_in=False) return None
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
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()