forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyser_merge_healthcare_FR_finess.py
131 lines (115 loc) · 6.88 KB
/
analyser_merge_healthcare_FR_finess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frédéric Rodrigo 2018 ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###########################################################################
import json
import csv
import io
from modules.OsmoseTranslation import T_
from .Analyser_Merge_Dynamic import Analyser_Merge_Dynamic, SubAnalyser_Merge_Dynamic
from .Analyser_Merge import SourceDataGouv, CSV, Load, Conflate, Select, Mapping
class Analyser_Merge_Healthcare_FR_Finess(Analyser_Merge_Dynamic):
def __init__(self, config, logger = None):
Analyser_Merge_Dynamic.__init__(self, config, logger)
if config.db_schema == 'france_guadeloupe':
srid = 2970
is_in = lambda dep: dep == "9A"
elif config.db_schema == 'france_guyane':
srid = 2972
is_in = lambda dep: dep == "9C"
elif config.db_schema == 'france_reunion':
srid = 2975
is_in = lambda dep: dep == "9D"
elif config.db_schema == 'france_martinique':
srid = 2973
is_in = lambda dep: dep == "9B"
elif config.db_schema == 'france_saintpierreetmiquelon':
srid = 32621
is_in = lambda dep: dep == "9E"
elif config.db_schema == 'france_mayotte':
srid = 32738
is_in = lambda dep: dep == "9F"
else:
srid = 2154
is_in = lambda dep: dep not in ("9A", "9B", "9C", "9D")
mapingfile = json.loads(open("merge_data/healthcare_FR_finess.mapping.json").read())
for r in mapingfile:
self.classFactory(SubAnalyser_Merge_Healthcare_FR_Finess, r['classes'], srid, is_in, r['categories'], r['items'], r.get('missing_osm', True), r['classes'], r['level'], r['title:fr'], r['tags_select'], r['tags_generate1'], r['tags_generate2'])
class SubAnalyser_Merge_Healthcare_FR_Finess(SubAnalyser_Merge_Dynamic):
def __init__(self, config, error_file, logger, srid, is_in, categories, items, missing_osm, classs, level, title, tags_select, tags_generate1, tags_generate2):
SubAnalyser_Merge_Dynamic.__init__(self, config, error_file, logger)
self.def_class_missing_official(item =str(items[0]), id = classs+1, level = level, tags = ['merge', 'public equipment', 'fix:imagery', 'fix:survey'],
title = T_('{0} not integrated', title))
if missing_osm is not False:
self.def_class_missing_osm(item =str(items[1]), id = classs+2, level = level, tags = ['merge', 'public equipment', 'fix:chair'],
title = T_('{0} without tag "{1}" or invalid', title, 'ref:FR:FINESS'))
self.def_class_possible_merge(item =str(items[0]+1), id = classs+3, level = level, tags = ['merge', 'public equipment', 'fix:chair', 'fix:survey'],
title = T_('{0}, integration suggestion', title))
self.init(
"https://www.data.gouv.fr/fr/datasets/finess-extraction-du-fichier-des-etablissements/",
"FINESS Extraction du Fichier des établissements",
CSV(Source_Finess(
attribution="Le ministère des solidarités et de la santé",
encoding="ISO-8859-1",
dataset="53699569a3a729239d2046eb",
resource="407bdde4-e6c8-4edf-9b20-1a67ab80fc37")),
Load("coordxet", "coordyet", srid = srid,
select = {"categetab": categories},
where = lambda res: is_in(res["departement"])),
Conflate(
select = Select(
types = ["nodes", "ways", "relations"],
tags = tags_select),
osmRef = "ref:FR:FINESS",
conflationDistance = 200,
mapping = Mapping(
static1 = tags_generate1,
static2 = dict({"source": self.source}, **tags_generate2),
mapping1 = {"ref:FR:FINESS": "nofinesset"},
mapping2 = {
"type:FR:FINESS": "categetab",
"ref:FR:SIRET": "siret",
"phone": lambda fields: self.phone(fields["telephone"]),
"fax": lambda fields: self.phone(fields["telecopie"]),
},
text = lambda tags, fields: {"en": ", ".join(filter(lambda i: i not in (None, 'None'), [fields["rs"], fields["rslongue"], fields["complrs"], fields["compldistrib"], fields["numvoie"], fields["typvoie"], fields["voie"], fields["compvoie"], fields["lieuditbp"], fields["ligneacheminement"], fields["libcategetab"], fields["numuai"]]))} )))
def phone(self, number):
if number and len(number) == 10 and number[0] == "0":
return "+33" + number[1:]
class Source_Finess(SourceDataGouv):
def open(self):
# Cheat the parent open
self.encoding = 'UTF-8'
f = super().open()
csvreader = csv.reader(f, delimiter=u';')
structureet = [u'nofinesset,nofinessej,rs,rslongue,complrs,compldistrib,numvoie,typvoie,voie,compvoie,lieuditbp,commune,departement,libdepartement,ligneacheminement,telephone,telecopie,categetab,libcategetab,categagretab,libcategagretab,siret,codeape,codemft,libmft,codesph,libsph,dateouv,dateautor,datemaj,numuai,coordxet,coordyet,sourcecoordet,datemajcoord'.split(',')]
geolocalisation = {}
for row in csvreader:
if row[0] == 'structureet':
structureet.append(row[1:])
elif row[0] == 'geolocalisation':
geolocalisation[row[1]] = row[2:]
for row in structureet:
row += geolocalisation.get(row[0], [])
csvfile = io.StringIO()
writer = csv.writer(csvfile)
for row in structureet:
writer.writerow(row)
csvfile.seek(0)
return csvfile