def test_insee_to_departement_code(): right_insee_code = "01001" short_insee_code = "1001" DOM_TOM_insee_code = "97234" passed_linked_to_Guadeloupe_insee_code = "97801" corse_insee_code = "2A004" monaco_insee_code = "99138" wrong_insee_code = "123" not_in_insee_code_table_insee_code = "12345" assert departementUtils.to_departement_number( right_insee_code) == right_insee_code[:2] assert departementUtils.to_departement_number( short_insee_code) == short_insee_code.zfill(5)[:2] assert departementUtils.to_departement_number( DOM_TOM_insee_code) == DOM_TOM_insee_code[:3] assert departementUtils.to_departement_number( passed_linked_to_Guadeloupe_insee_code) == "971" assert departementUtils.to_departement_number(corse_insee_code) == "2A" assert departementUtils.to_departement_number(monaco_insee_code) == "98" with pytest.raises(ValueError): departementUtils.to_departement_number(wrong_insee_code) with pytest.raises(ValueError): departementUtils.to_departement_number( not_in_insee_code_table_insee_code)
def organization_to_center(organization) -> Optional[CenterInfo]: if organization is None: return None url = AVECMONDOC_CONF.get("patient_url", "").format(slug=organization.get("slug")) id = organization["id"] zip = organization["zipCode"] dept = departementUtils.to_departement_number(departementUtils.cp_to_insee(zip)) reasons = organization["consultationReasons"] if reasons is None: logger.warning(f"no reasons found in organization") return None if get_valid_reasons(reasons) == []: return None center = CenterInfo(dept, organization["name"], url) location = CenterLocation(0, 0, organization["city"], organization["zipCode"]) if organization.get("coordinates") is not None: location.longitude = organization["coordinates"].get("lng", 0.0) location.latitude = organization["coordinates"].get("lat", 0.0) center.metadata = { "address": organization["address"], "phone_number": organization["phone"], } center.location = location center.internal_id = f"amd{id}" if "schedules" not in organization: return center business_hours = {} for day, day_name in AVECMONDOC_SCRAPER.get("business_days", {}).items(): value = "" if organization["schedules"][day]["enabled"]: value = " ".join(f'{sc["start"]}-{sc["end"]}' for sc in organization["schedules"][day]["schedules"]) business_hours[day_name] = value center.metadata["business_hours"] = business_hours return center
def campagne_to_centre(pharmacy: dict, campagne: dict) -> dict: if not pharmacy.get("code_postal"): raise ValueError("Absence de code postal") insee = departementUtils.cp_to_insee(pharmacy.get("code_postal")) departement = departementUtils.to_departement_number(insee) centre = dict() centre["nom"] = pharmacy.get("nom") centre["type"] = DRUG_STORE centre["long_coor1"] = pharmacy.get("longitude") centre["lat_coor1"] = pharmacy.get("latitude") centre["com_nom"] = pharmacy.get("ville") adr_voie = pharmacy.get("adresse") adr_cp = pharmacy.get("code_postal") adr_nom = pharmacy.get("ville") centre["address"] = f"{adr_voie}, {adr_cp} {adr_nom}" business_hours = dict() horaires = pharmacy.get("horaires", "") days = [ "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche" ] for day in days: for line in horaires.splitlines(): if day not in line: continue business_hours[day] = line.replace(f"{day}: ", "") centre["business_hours"] = business_hours centre["phone_number"] = pharmacy.get("telephone", "") centre["rdv_site_web"] = campagne.get("url") centre["com_insee"] = insee centre["gid"] = campagne.get("url").encode("utf8").hex()[52:][:23] return centre
def convert_csv_data_to_center_info(data: dict) -> CenterInfo: name = data.get('nom', None) departement = '' ville = '' url = data.get('rdv_site_web', None) try: departement = departementUtils.to_departement_number( data.get('com_insee', None)) except ValueError as e: logger.error( f"erreur lors du traitement de la ligne avec le gid {data['gid']}, com_insee={data['com_insee']} : {e}" ) center = CenterInfo(departement, name, url) if data.get('iterator', '') == 'ordoclic': return convert_ordoclic_to_center_info(data, center) center.fill_localization(convert_csv_data_to_location(data)) center.metadata = dict() center.metadata['address'] = convert_csv_address(data) if data.get('rdv_tel'): center.metadata['phone_number'] = format_phone_number( data.get('rdv_tel')) if data.get('phone_number'): center.metadata['phone_number'] = format_phone_number( data.get('phone_number')) center.metadata['business_hours'] = convert_csv_business_hours(data) return center
def campagne_to_centre(pharmacy: dict, campagne: dict) -> dict: if not pharmacy.get('code_postal'): raise ValueError('Absence de code postal') insee = departementUtils.cp_to_insee(pharmacy.get('code_postal')) departement = departementUtils.to_departement_number(insee) centre = dict() centre['nom'] = pharmacy.get('nom') centre['type'] = DRUG_STORE centre['long_coor1'] = pharmacy.get('longitude') centre['lat_coor1'] = pharmacy.get('latitude') centre['com_nom'] = pharmacy.get('ville') adr_voie = pharmacy.get('adresse') adr_cp = pharmacy.get('code_postal') adr_nom = pharmacy.get('ville') centre['address'] = f'{adr_voie}, {adr_cp} {adr_nom}' business_hours = dict() horaires = pharmacy.get('horaires', '') days = ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'] for day in days: for line in horaires.splitlines(): if day not in line: continue business_hours[day] = line.replace(f'{day}: ', '') centre['business_hours'] = business_hours centre['phone_number'] = pharmacy.get('telephone', '') centre['rdv_site_web'] = campagne.get('url') centre['com_insee'] = insee centre['gid'] = campagne.get('url').encode('utf8').hex()[40:][:8] centre['internal_id'] = campagne.get('url').encode('utf8').hex()[40:][:8] return centre
def convert_csv_data_to_center_info(data: dict) -> CenterInfo: name = data.get("nom", None) departement = "" ville = "" url = data.get("rdv_site_web", None) try: departement = departementUtils.to_departement_number( data.get("com_insee", None)) except ValueError as e: logger.error( f"erreur lors du traitement de la ligne avec le gid {data['gid']}, com_insee={data['com_insee']} : {e}" ) center = CenterInfo(departement, name, url) if data.get("iterator", "") == "ordoclic": return convert_ordoclic_to_center_info(data, center) center.fill_localization(convert_csv_data_to_location(data)) center.metadata = dict() center.metadata["address"] = convert_csv_address(data) if data.get("rdv_tel"): center.metadata["phone_number"] = format_phone_number( data.get("rdv_tel")) if data.get("phone_number"): center.metadata["phone_number"] = format_phone_number( data.get("phone_number")) center.metadata["business_hours"] = convert_csv_business_hours(data) return center
def from_csv_data(cls, data: dict) -> CenterInfo: departement = "" try: departement = departementUtils.to_departement_number( data.get("com_insee")) except ValueError as e: logger.error( f"erreur lors du traitement de la ligne avec le gid {data['gid']}, com_insee={data['com_insee']} : {e}" ) center = CenterInfo( departement, data.get("nom"), data.get("rdv_site_web"), location=CenterLocation.from_csv_data(data), metadata=cls._metadata_from_csv_data(data), ) # TODO: Behaviour about particular implementations shouldln’t bubble up to the pattern. if data.get("iterator") == "ordoclic": return convert_ordoclic_to_center_info(data, center) return center
def test_insee_to_departement_code(): right_insee_code = "01001" short_insee_code = "1001" DOM_TOM_insee_code = "97234" passed_linked_to_Guadeloupe_insee_code = "97120" corse_insee_code = "2A004" monaco_insee_code = "99138" wrong_insee_code = "123" not_in_insee_code_table_insee_code = "12345" saint_barthelemy_insee_code = "97701" miquelon_laglande_insee_code = "97501" saint_pierre_insee_code = "97502" saint_martin_insee_code = "97801" assert departementUtils.to_departement_number(right_insee_code) == right_insee_code[:2] assert departementUtils.to_departement_number(short_insee_code) == short_insee_code.zfill(5)[:2] assert departementUtils.to_departement_number(DOM_TOM_insee_code) == DOM_TOM_insee_code[:3] assert departementUtils.to_departement_number(passed_linked_to_Guadeloupe_insee_code) == "971" assert departementUtils.to_departement_number(corse_insee_code) == "2A" assert departementUtils.to_departement_number(monaco_insee_code) == "98" with pytest.raises(ValueError): departementUtils.to_departement_number(wrong_insee_code) with pytest.raises(ValueError): departementUtils.to_departement_number(not_in_insee_code_table_insee_code) assert departementUtils.to_departement_number(saint_barthelemy_insee_code) == "om" assert departementUtils.to_departement_number(miquelon_laglande_insee_code) == "om" assert departementUtils.to_departement_number(saint_pierre_insee_code) == "om" assert departementUtils.to_departement_number(saint_martin_insee_code) == "om"