start import job

This commit is contained in:
Benjamin Dauvergne 2013-01-03 00:02:51 +01:00
parent c403c30d9b
commit d11b45e303
20 changed files with 4887 additions and 0 deletions

1683
scripts/CPAM.csv Normal file

File diff suppressed because it is too large Load Diff

282
scripts/MISES.TXT Normal file
View File

@ -0,0 +1,282 @@
id code axe libelle
1 1 1 Autisme et Troubles psychotiques
2 2 1 Troubles névrotiques
3 3 1 Pathologies limites
4 4 1 Troubles reactionnels
5 5 1 Deficiences mentales (arriérations, débilités mentales, démences)
6 6 1 Troubles du développement et des fonctions instrumentales
7 7 1 TROUBLES DES CONDUITES ET DES COMPORTEMENTS
8 8 1 TROUBLES A EXPRESSION SOMATIQUE
9 9 1 Variations de la normale
10 10 1 Psychoses Précoces (Troubles envahissants du développement)
11 11 1 Schizophrénies
12 12 1 Troubles délirants
13 13 1 Troubles psychotiques aigus
14 14 1 Troubles thymiques
15 15 1 Etats dépressifs après épisode psychotique
16 18 1 Autres Troubles Psychotiques
17 19 1 Troubles Psychotiques non spécifiés
18 20 1 Troubles névrotiques à dominante anxieuse
19 21 1 Troubles névrotiques à dominante hystérique
20 22 1 Troubles névrotiques à dominante phobique
21 23 1 Troubles névrotiques à dominante obsessionnelle
22 24 1 Troubles névrotiques avec prédominance des inhibitions
23 25 1 Dépression névrotique
24 26 1 Caractères névrotiques, pathologies névrotiques de la personnalité
25 27 1 Troubles névrotiques avec perturbations prédominantes des fonctions instrumentales
26 28 1 Autres
27 29 1 Non spécifiés
28 30 1 Dysharmonies évolutives
29 31 1 Pathologie limite avec dominance des troubles de la personnalité
30 32 1 Pathologie limite à dominante schizotypique
31 33 1 Pathologie limite à dominante comportementale
32 34 1 Dépressions liées à une pathologie limite
33 38 1 Autres pathologies limites
34 39 1 Pathologies limites non spécifiées
35 40 1 Dépression réactionnelle
36 41 1 Manifestations réactionnelles
37 42 1 Syndrome de stress post traumatique
38 50 1 Q I 50 - 69
39 51 1 Q I 35 - 49
40 52 1 Q I 20 - 34
41 53 1 Q I < à 20
42 54 1 Q I Non spécifié
43 60 1 Troubles de la Parole et du Langage
44 61 1 Troubles Cognitifs et des Acquisitions Scolaires
45 62 1 Troubles psychomoteurs
46 70 1 TROUBLES hyperkinétiques
47 71 1 Troubles des conduites alimentaires
48 72 1 Tentatives de suicide
49 73 1 Troubles liés à l'usage de drogues ou d'alcool
50 74 1 Troubles de l'angoisse de séparation
51 75 1 Troubles de l'identité et des conduites sexuelles
52 76 1 Phobies scolaires
53 77 1 Autres troubles caractérisés des conduites
54 78 1 Autres troubles des conduites et des comportements
55 79 1 Troubles des conduites non spécifiés
56 80 1 Affections psychosomatiques
57 81 1 TROUBLES psychofonctionnels
58 82 1 Trouble hypocondriaque
59 83 1 Enurésie
60 84 1 Encoprésie
61 85 1 Troubles du sommeil
62 86 1 Retard de croissance psychogène
63 88 1 Autres troubles à expression somatique
64 89 1 Troubles à expression somatique non spécifiés
65 90 1 Angoisses , rituels, peurs
66 91 1 Moments dépressifs
67 92 1 Conduites d 'opposition
68 93 1 Conduites d 'isolement
69 94 1 Difficultés scolaires non classables dans les catégories précédentes
70 95 1 Retards ou régressions transitoires
71 96 1 Aspects originaux de la personnalité
72 98 1 Autres
73 99 1 Non spécifiées
74 100 1 Autisme infantile précoce - type Kanner
75 101 1 Autres formes de l'autisme
76 102 1 Psychose précoce déficitaire. Retard mental avec troubles autistiques ou psychotiques
77 103 1 Syndrome d 'Asperger
78 104 1 Dysharmonies Psychotiques
79 105 1 Troubles désintégratifs de l'enfance
80 108 1 Autres psychoses précoces ou autres troubles envahissants du développement
81 109 1 Psychoses précoces ou troubles envahissants du développement non spécifiés
82 110 1 Schizophrénie de l'enfant
83 111 1 Troubles schizophréniques à l'adolescence
84 130 1 Trouble psychotique aigu polymorphe sans symptômes schizophréniques
85 131 1 Trouble psychotique aigu polymorphe avec symptômes schizophréniques
86 138 1 Autres
87 140 1 Psychoses dysthymiques de l'enfant
88 141 1 Troubles thymiques de l'adolescent
89 500 1 Q I 50 - 69
90 505 1 Déficiences harmoniques
91 506 1 Déficiences dysharmoniques
92 507 1 Déficience avec polyhandicap sensoriel et/ou moteur
93 508 1 Démences
94 509 1 Non spécifiée
95 510 1 Q I 35 - 49
96 516 1 Q I 35 - 49 Avec Déficience dysharmonique
97 520 1 Q I 20 - 34
98 530 1 Q I < à 20
99 540 1 Q I Non spécifié
100 546 1 Q I Non spécifié Avec Déficience dysharmonique
101 600 1 Troubles isolés de l'articulation .
102 601 1 Troubles du développement du langage
103 602 1 Aphasie acquise
104 603 1 Mutisme
105 604 1 Bégaiement.
106 608 1 Autres troubles de la parole et du langage
107 609 1 Troubles de la parole et du langage non spécifiés
108 610 1 Troubles lexicographiques
109 611 1 Troubles spécifiques de l'arithmétique (dyscalculie).
110 612 1 Troubles du raisonnement (Dysharmonies cognitives)
111 613 1 Troubles de l'attention sans hyperkinésie
112 618 1 Autres troubles cognitifs et des acquisitions scolaires.
113 619 1 Troubles cognitifs et des acquisitions scolaires non spécifiés
114 620 1 Retard psychomoteur (Troubles spécifiques du développement moteur)
115 621 1 Tics
116 628 1 Autres troubles psychomoteurs
117 629 1 Troubles psychomoteurs non spécifiés
118 700 1 Hyperkinésie avec troubles de l'attention
119 708 1 Autres troubles hyperkinétiques
120 709 1 Troubles hyperkinétiques non spécifiés
121 710 1 Anorexie mentale
122 711 1 Anorexie mentale atypique
123 712 1 Boulimie
124 713 1 Boulimie atypique
125 714 1 Troubles des conduites alimentaires du nourrisson et de l'enfant
126 715 1 Troubles alimentaires du nouveau né
127 718 1 Autres Troubles des Conduites Alimentaires
128 719 1 Troubles des Conduites Alimentaires non spécifiés
129 731 1 Usage occasionnel de stupéfiant
130 750 1 Troubles de l'identité sexuelle
131 751 1 Troubles de la préférence sexuelle
132 752 1 Manifestations en rapport avec des préoccupations excessives concernant le développement sexuel et son orientation.
133 758 1 Autres troubles des conduites sexuelles.
134 759 1 Trouble des conduites sexuelles, sans précision.
135 770 1 Pyromanie
136 771 1 Kleptomanie
137 772 1 Trichotillomanie
138 773 1 Fugues
139 774 1 Violence contre les personnes
140 775 1 Conduites à risques
141 776 1 Errance
142 778 1 Autres troubles caractérisés des conduites
143 1110 1 Aspects prodromiques
144 1111 1 Schizophrénie avérée
145 1410 1 Episode maniaque
146 1411 1 Episode dépressif
147 6010 1 Retard de parole
148 6011 1 Retard (simple)de langage
149 6012 1 Dysphasie
150 6018 1 Autres Troubles du Développement du Langage
151 6020 1 Aphasie acquise avec épilepsie (syndrome de Landau-Kleffner)
152 6028 1 Autres aphasies acquises
153 6030 1 Mutisme Total
154 6031 1 Mutisme sélectif
155 6100 1 Dyslexie isolée
156 6101 1 Trouble de l'orthographe sans trouble de la lecture
157 6108 1 Autres troubles lexicographiques
158 6210 1 Tics isolés
159 6211 1 Maladie de Gilles de la Tourette
160 7100 1 Anorexie mentale restrictive
161 7101 1 Anorexie mentale boulimique
162 7300 1 Usage Continu de stupéfiant
163 7301 1 Morphiniques
164 7302 1 Cannabis
165 7303 1 Hypnotiques et Tranquillisant
166 7304 1 Cocaïne
167 7305 1 Autres psychostimulants et dysleptiques
168 7306 1 Tabac - Caféine
169 7307 1 Solvants
170 7308 1 Polytoxicomanies
171 7309 1 Autres ou non spécifié
172 7310 1 Usage occasionnel de stupéfiant
173 7320 1 En rémission
174 7380 1 Autre stupéfiant
175 7390 1 Non spécifié
176 7500 1 Trouble de l'identité sexuelle de l'enfance
177 7501 1 Trouble de l'identité sexuelle chez lez adolescents
178 14100 1 Episode maniaque actuel s'inscrivant dans un trouble affectif bipolaire
179 14101 1 Manie sans symptômes psychotiques
180 14102 1 Manie avec symptômes psychotiques
181 14103 1 etat mixte
182 14104 1 Hypomanie
183 14110 1 Episode dépressif actuel s'inscrivant dans un trouble affectif bipolaire
184 14111 1 Episode dépressif sévère sans dimension mélancolique manifeste
185 14112 1 Episode dépressif sévère sans dimension mélancolique manifeste, avec symptômes psychotiques
186 14113 1 Episode dépressif sévère avec dimension mélancolique
187 14114 1 Episode dépressif sévère avec mélancolie délirante
188 15001 1 B1 - Bébé à risque de troubles sévères du développement
189 15002 1 B2 - Les dépressions du bébé
190 15003 1 B3 - Bébé à risque d'évolution dysharmonique
191 15004 1 B4 - Les états du stress
192 15005 1 B5 - Hypermaturité et hyperécoute pathologiques
193 15006 1 B6 - Distortion du lien
194 15007 1 B7 - Retards d'acquisition divers
195 15008 1 B8 - Troubles des grandes fonctions psychosomatiques
196 10 2 PAS DE FACTEURS ORGANIQUES RECONNUS
204 18 2 AUTRES
205 19 2 PAS DE REPONSE POSSIBLE PAR DEFAUT D'INFORMATION
206 100 2 Pas de facteurs organiques reconnus
207 110 2 Atteinte infectieuse ou parasitaire
208 111 2 Atteinte toxique
209 112 2 Atteinte liée à une maladie maternelle
210 113 2 Autres
211 120 2 Prématurité, dysmaturité
212 121 2 Souffrance cérébrale périnatale
213 122 2 Incompatibilité sanguine foeto-maternelle
214 123 2 Autres
215 130 2 Atteinte cérébrale post-natale d'origine infectieuse ou parasitaire
216 131 2 Atteinte cérébrale post-natale d'origine toxique
217 132 2 Atteinte liée à un traumatisme cérébral
218 133 2 Tumeurs cérébrales
219 134 2 Autres
220 138 2 Autres
221 140 2 Trisomie 21 ou mongolisme
222 141 2 Autre maladie liée à une anomalie chromosomique autosomique
223 142 2 Maladie liée à une anomalie chromosomique gonosomique
224 143 2 Phénylcétonurie
225 144 2 Autres maladies métaboliques
226 145 2 Hypothyroïdies congénitales
227 146 2 Neuro-ectodermoses congénitales
228 147 2 Malformations cérébrales congénitales
229 148 2 Autres
230 150 2 Déficits sensoriels
231 151 2 Atteinte motrice d'origine cérébrale
232 152 2 Atteinte neurologique d'origine non cérébrale
233 153 2 Affections musculaires
234 154 2 Malformations congénitales autres que cérébrales
235 155 2 Séquelles d'accident physique sans atteinte cérébrale
236 156 2 Déficit immunitaire congénital ou acquis
237 157 2 Hémophilie
238 158 2 Maladie somatique à long cours
239 159 2 Autres
240 160 2 Epilepsie idiopathique
241 161 2 Encéphalopathie épileptique évolutive et épilepsies sévères
242 162 2 Autres épilepsies symptomatiques
243 163 2 Manifestations convulsives non épileptiques
244 164 2 Autres
245 168 2 Autres
246 170 2 Antécédents de maladies somatiques dans l'enfance
249 20 3 PAS DE FACTEURS D'ENVIRONNEMENT A RETENIR
256 28 3 AUTRES
257 29 3 PAS DE REPONSE POSSIBLE PAR DEFAUT D'INFORMATION
258 210 3 Psychose puerpérale
259 211 3 Dépression maternelle dans la période post-natale
260 212 3 Discontinuité des processus de soins maternels dans la première année
261 213 3 Autre trouble important des relations précoces
262 214 3 Troubles mentaux d'un ou des parents
263 215 3 Troubles mentaux d'un autre membre de la famille
264 216 3 Alcoolisme ou toxicomanie parentale
265 217 3 Perturbations psychologiques sévères et actuelles dans le réseau familial
266 218 3 Autres
267 219 3 Autres
268 220 3 Carences affectives précoces
269 221 3 Carences affectives ultérieures
270 222 3 Carences socio-éducatives
271 223 3 Autres
272 228 3 Autres
273 230 3 Sévices et violences physiques
274 231 3 Négligences sévères
275 232 3 Abus sexuels
276 233 3 Autres
277 238 3 Autres
278 240 3 Hospitalisation ou séjour institutionnel prolongé ou répétitif de l'enfant
279 241 3 Rupture itérative des modes de garde
280 242 3 Hospitalisation ou séjour institutionnel prolongé ou répétitif des parents
281 243 3 Décès d'un ou des parents
282 244 3 Décès d'un ou des grands-parents
283 245 3 Décès dans la fratrie
284 246 3 Abandon parental
285 247 3 Autres
286 248 3 Autres
287 250 3 Gémelité
288 251 3 Enfant actuellement placé
289 252 3 Enfant adopté
290 253 3 Enfant de parents divorcés ou séparés
291 254 3 Enfant élevé par les grands-parents
292 255 3 Famille mono-parentale
293 256 3 Famille immigrée ou trnaplantée
294 257 3 Maladie organique grave d'un parent
295 258 3 Milieu socio-familial très défavorisé
296 259 3 Autre

View File

@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
import codecs
import string
import random
from datetime import datetime, time
import django.core.management
import calebasse.settings
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, UserWorker
from calebasse.ressources.models import WorkerType, TransportCompany
f = "./scripts/transports.csv"
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
def __iter__(self):
return self
def next(self):
return self.reader.next().encode("utf-8")
class UnicodeReader:
"""
A CSV reader which will iterate over lines in the CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="iso8859-15", **kwds):
f = UTF8Recoder(f, encoding)
self.reader = csv.reader(f, dialect=dialect, **kwds)
def next(self):
row = self.reader.next()
return [unicode(s, "utf-8") for s in row]
def __iter__(self):
return self
def main():
csvfile = open(f, 'rb')
csvlines = UnicodeReader(csvfile, delimiter=';', quotechar='|',encoding='utf-8')
csvlines.next()
for line in csvlines:
TransportCompany(name=line[0],
address = line[1],
address_complement = line[2],
zip_code = line[3],
city = line[4],
phone = line[5],
fax = line[6],
email = line[7],
correspondant = line[8],
old_camsp_id = line[9],
old_cmpp_id = line[10],
old_sessad_dys_id = line[11],
old_sessad_ted_id = line[12]
).save()
if __name__ == "__main__":
main()

280
scripts/import_conges.py Normal file
View File

@ -0,0 +1,280 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday
from calebasse.ressources.models import WorkerType, HolidayType
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
""" """
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
csvfile = open(os.path.join(db_path, db, 'conge.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
tables_data[service.name] = []
for line in csvlines:
data = _get_dict(cols, line)
tables_data[service.name].append(data)
csvfile.close()
motif_unknown = HolidayType.objects.get(pk=18)
conges = {}
sname = 'CAMSP'
l_camsp = []
old_conges = tables_data['CAMSP']
for old_conge in old_conges:
worker = None
date_debut = _to_date(old_conge['date_debut'])
if date_debut > datetime(year=2012, month=1, day=1):
try:
worker = Worker.objects.get(old_camsp_id=old_conge['thera_id'])
if worker.enabled:
motif = int(old_conge['motif'])
if motif == 0:
motif = motif_unknown
else:
motif = HolidayType.objects.get(pk=motif)
end_time = _to_date(old_conge['date_fin'])
if not worker in conges:
conges[worker] = []
conges[worker].append((date_debut, end_time, motif))
except MultipleObjectsReturned:
print 'Plusieurs workers avec id : %s' % old_conge['thera_id']
print Worker.objects.filter(old_camsp_id=old_conge['thera_id'])
except ObjectDoesNotExist:
if not old_conge['thera_id'] in l_camsp:
l_camsp.append(old_conge['thera_id'])
sname = 'CMPP'
l_cmpp = []
l_cmpp_dbl = []
old_conges = tables_data['CMPP']
for old_conge in old_conges:
worker = None
date_debut = _to_date(old_conge['date_debut'])
if date_debut > datetime(year=2012, month=1, day=1):
try:
worker = Worker.objects.get(old_cmpp_id=old_conge['thera_id'])
if worker.enabled:
motif = int(old_conge['motif'])
if motif == 0:
motif = motif_unknown
else:
motif = HolidayType.objects.get(pk=motif)
end_time = _to_date(old_conge['date_fin'])
if not worker in conges:
conges[worker] = []
conges[worker].append((date_debut, end_time, motif))
except MultipleObjectsReturned:
print 'Plusieurs workers avec id : %s' % old_conge['thera_id']
print Worker.objects.filter(old_cmpp_id=old_conge['thera_id'])
except ObjectDoesNotExist:
if not old_conge['thera_id'] in l_cmpp:
l_cmpp.append(old_conge['thera_id'])
sname = 'SESSAD DYS'
l_dys = []
old_conges = tables_data['SESSAD DYS']
for old_conge in old_conges:
worker = None
date_debut = _to_date(old_conge['date_debut'])
if date_debut > datetime(year=2012, month=1, day=1):
try:
worker = Worker.objects.get(old_sessad_dys_id=old_conge['thera_id'])
if worker.enabled:
motif = int(old_conge['motif'])
if motif == 0:
motif = motif_unknown
else:
motif = HolidayType.objects.get(pk=motif)
end_time = _to_date(old_conge['date_fin'])
if not worker in conges:
conges[worker] = []
conges[worker].append((date_debut, end_time, motif))
except MultipleObjectsReturned:
print 'Plusieurs workers avec id : %s' % old_conge['thera_id']
print Worker.objects.filter(old_sessad_dys_id=old_conge['thera_id'])
except ObjectDoesNotExist:
if not old_conge['thera_id'] in l_dys:
l_dys.append(old_conge['thera_id'])
sname = 'SESSAD TED'
l_ted = []
old_conges = tables_data['SESSAD TED']
for old_conge in old_conges:
worker = None
date_debut = _to_date(old_conge['date_debut'])
if date_debut > datetime(year=2012, month=1, day=1):
try:
worker = Worker.objects.get(old_sessad_ted_id=old_conge['thera_id'])
if worker.enabled:
motif = int(old_conge['motif'])
if motif == 0:
motif = motif_unknown
else:
motif = HolidayType.objects.get(pk=motif)
end_time = _to_date(old_conge['date_fin'])
if not worker in conges:
conges[worker] = []
conges[worker].append((date_debut, end_time, motif))
except MultipleObjectsReturned:
print 'Plusieurs workers avec id : %s' % old_conge['thera_id']
print Worker.objects.filter(old_sessad_ted_id=old_conge['thera_id'])
except ObjectDoesNotExist:
if not old_conge['thera_id'] in l_ted:
l_ted.append(old_conge['thera_id'])
for worker, ccs in conges.items():
for date_debut, end_time, motif in set(ccs):
Holiday(worker=worker, holiday_type=motif, start_date=date_debut, end_date=end_time).save()
if __name__ == "__main__":
main()

0
scripts/import_cpam.py Executable file → Normal file
View File

0
scripts/import_db.py Executable file → Normal file
View File

516
scripts/import_dossiers.py Normal file
View File

@ -0,0 +1,516 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import sys
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, ExternalWorker, ExternalTherapist
from calebasse.ressources.models import (WorkerType, ParentalAuthorityType, ParentalCustodyType,
FamilySituationType, TransportType, TransportCompany, Provenance, AnalyseMotive, FamilyMotive,
CodeCFTMEA, SocialisationDuration, School, SchoolLevel, OutMotive, OutTo)
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
#dbs = ["F_ST_ETIENNE_CMPP"]
#tarifs: prix_journee.csv
#Contacts et données secu, assuré
#Adresses
#prise en charges (cmpp)
#état des dossiers
#Croiser, dans le dossier patient: prof mere et mere or nous on veut le mettre sur les contacts
#Notes, si existe mettre en description, mais tous les fichiers vides ?
#Les états des dossiers!
#les contacts sont des people qui apparaissent dans les listes des exterieurs ?
#diag id = 1 trait id = 2
#notes ?
#Ajouter au contact lien avec l'enfant mère, grand mèere, etc.
#table parente champs du dossier: parente.csv associé à la table contact ?
#Ajouter au contact: catégorie socio pro
#Import csp.csv
#Imports adresses et contacts
#Quel contact est l'assuré ?
#Attention caisse il faut les ancien id pour retourber? on peut rechercher sur le numéro de la caisse!
#tables = ["dossiers", "adresses", "contacts", "convocations", "dossiers_ecole", "dossiers_mises", "pc", "periodes_pc","pmt", "rm", , "sor_motifs", "sor_orientation", "suivi"]
#tables = ["dossiers_test"]
def _exist(str):
if str and str != "" and str != '0':
return True
return False
def treat_name(name):
res = ''
for p in name.split():
res += p[0].upper()+p[1:].lower()
res += ' '
return res[:-1]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
""" """
print "====== Début à %s ======" % str(datetime.today())
f1 = open('./scripts/dossiers_ecoles_manuel.csv', 'wb')
writer1 = csv.writer(f1, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
f2 = open('./scripts/dossiers_manuel.csv', 'wb')
writer2 = csv.writer(f2, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
print "====== %s ======" % service.name
print datetime.today()
print "--> Lecture table des dossiers..."
csvfile = open(os.path.join(db_path, db, 'dossiers.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
d_cols = csvlines.next()
writer2.writerow(d_cols + ['service', 'creation'])
tables_data['dossiers'] = []
for line in csvlines:
#Au moins nom et prénom
if _exist(line[1]) and _exist(line[2]):
data = _get_dict(d_cols, line)
tables_data['dossiers'].append(data)
else:
writer2.writerow(line + [service.name, 'Non'])
csvfile.close()
print "<-- Terminé"
print "--> Chargement mises..."
mises = {}
csvfile = open(os.path.join(db_path, db, 'mises.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
mises[line[0]] = (line[1], line[2])
csvfile.close()
print "<-- Terminé"
print "--> Chargement quotations..."
mises_per_patient = {}
csvfile = open(os.path.join(db_path, db, 'dossiers_mises.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
code, axe = mises[line[2]]
quotation = CodeCFTMEA.objects.get(code=int(code), axe=int(axe))
if line[1] in mises_per_patient.keys():
mises_per_patient[line[1]].append(quotation)
else:
mises_per_patient[line[1]] = [quotation]
csvfile.close()
print "<-- Terminé"
print "--> Ajout périodes de socialisation..."
social_duration_per_patient = {}
csvfile = open(os.path.join(db_path, db, 'dossiers_ecoles.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
writer1.writerow(cols + ['service'])
i = 0
for line in csvlines:
i += 1
print "Nombre à traiter : %d" % i
csvfile.close()
csvfile = open(os.path.join(db_path, db, 'dossiers_ecoles.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
csvlines.next()
for line in csvlines:
school = None
if _exist(line[2]):
school = School.objects.get(old_id=line[2], old_service=service.name)
level = None
try:
level = SchoolLevel.objects.get(old_id=line[4], old_service=service.name)
except:
pass
contact = line[3]
if contact != "":
contact += ' ' + line[7]
else:
contact = line[7]
start_date = _to_date(line[5])
social_duration = SocialisationDuration(school=school, level=level, start_date=start_date, contact=contact)
social_duration.save()
if line[1] in social_duration_per_patient.keys():
social_duration_per_patient[line[1]].append(social_duration)
else:
social_duration_per_patient[line[1]] = [social_duration]
#Produce file for manuel treatment:
for j in range(6, 16):
if j != 7 and _exist(line[j]):
writer1.writerow(line + [service.name])
i -= 1
if not (i % 10):
sys.stdout.write('%d' %i)
else:
sys.stdout.write('.')
sys.stdout.flush()
csvfile.close()
print "<-- Terminé"
accueil_status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
print "--> Ajout dossiers..."
print "Nombre à traiter : %d" % len(tables_data['dossiers'])
i = len(tables_data['dossiers'])
for dossier in tables_data['dossiers']:
for col in ('mdph', 'code_archive', 'aeeh', 'mdph_departement', 'pps', 'pps_deb', 'pps_fin', 'mdph_Debut', 'mdph_Fin'):
if _exist(dossier[col]):
writer2.writerow([dossier[c].encode('utf-8') for c in d_cols] + [service.name, 'Oui'])
#People
first_name = treat_name(dossier['prenom'])
last_name = treat_name(dossier['nom'])
display_name = None
gender = _to_int(dossier['nais_sexe'])
if not gender in (1,2):
gender = None
email = None
phone = None
#PatientContact
mobile = None
# Pourra etre init à l'import des contacts après création du dossier
social_security_id = None
birthdate = _to_date(dossier['nais_date'])
twinning_rank = _to_int(dossier['nais_rang'])
# Pourra etre init à l'import des contacts après création du dossier
thirdparty_payer = None
begin_rights = None
end_rights = None
health_center = None
addresses = None
contact_comment = None
#PatientRecord
creator = creator
# Pourra etre init à l'import des contacts après création du dossier
nationality = None
paper_id = None
comment = dossier['infos']
pause = False
# Physiology and health data
size = _to_int(dossier['taille'])
weight = _to_int(dossier['poids'])
pregnancy_term = _to_int(dossier['terme'])
cranium_perimeter = None
chest_perimeter = None
apgar_score_one = _to_int(dossier['apgar_1'])
apgar_score_two = _to_int(dossier['apgar_5'])
# Inscription motive
# Up to now only used at the CAMSP
analysemotive = None
try:
analysemotive = AnalyseMotive.objects.get(id=_to_int(dossier['ins_motif']))
except:
pass
# Up to now only used at the CAMSP
familymotive = None
try:
familymotive = FamilyMotive.objects.get(id=_to_int(dossier['ins_motif_exprim']))
except:
pass
provenance = None
try:
provenance = Provenance.objects.get(old_id=_to_int(dossier['ins_provenance']), old_service=service.name)
except:
pass
#Champs pas trouvé dans le dossier
advicegiver = None
# Inscription motive
# Up to now only used at the CAMSP
outmotive = None
try:
outmotive = OutMotive.objects.get(id=_to_int(dossier['sor_motif']))
except:
pass
# Up to now only used at the CAMSP
outto = None
try:
outto = OutTo.objects.get(id=_to_int(dossier['sor_orientation']))
except:
pass
# Family
sibship_place = _to_int(dossier['nais_fratrie'])
nb_children_family = _to_int(dossier['nbr_enfants'])
parental_authority = None
try:
parental_authority = ParentalAuthorityType.objects.get(id=_to_int(dossier['autorite_parentale']))
except:
pass
# Up to now only used at the CAMSP
family_situation = None
try:
family_situation = FamilySituationType.objects.get(id=_to_int(dossier['situation_familiale']))
except:
pass
# Up to now only used at the CAMSP
child_custody = None
try:
child_custody = ParentalCustodyType.objects.get(id=_to_int(dossier['garde']))
except:
pass
# Transport
transportcompany = None
try:
if service.name == 'CAMSP':
transportcompany = TransportCompany.objects.get(old_camsp_id=_to_int(dossier['transport']))
elif service.name == 'CMPP':
transportcompany = TransportCompany.objects.get(old_cmpp_id=_to_int(dossier['transport']))
elif service.name == 'SESSAD DYS':
transportcompany = TransportCompany.objects.get(old_sessad_dys_id=_to_int(dossier['transport']))
elif service.name == 'SESSAD TED':
transportcompany = TransportCompany.objects.get(old_sessad_ted_id=_to_int(dossier['transport']))
except:
pass
transporttype = None
try:
transporttype = TransportType.objects.get(id=_to_int(dossier['type_transport']))
except:
pass
# FollowUp
externaldoctor = None
try:
externaldoctor = ExternalTherapist.objects.get(old_id=_to_int(dossier['medecin_exterieur']), old_service=service.name)
except:
pass
externalintervener = None
try:
externalintervener = ExternalWorker.objects.get(old_id=_to_int(dossier['intervenant_exterieur']), old_service=service.name)
except:
pass
old_id = dossier['id']
old_old_id = dossier['ancien_numero']
patient, created = PatientRecord.objects.get_or_create(first_name = first_name,
last_name = last_name,
birthdate = birthdate,
twinning_rank = twinning_rank,
gender = gender,
display_name = display_name,
email = email,
phone = phone,
mobile = mobile,
contact_comment = contact_comment,
nationality = nationality,
paper_id = paper_id,
comment = comment,
pause = pause,
size = size,
weight = weight,
pregnancy_term = pregnancy_term,
cranium_perimeter = cranium_perimeter,
chest_perimeter = chest_perimeter,
apgar_score_one = apgar_score_one,
apgar_score_two = apgar_score_two,
analysemotive = analysemotive,
familymotive = familymotive,
provenance = provenance,
advicegiver = advicegiver,
outmotive = outmotive,
outto = outto,
sibship_place = sibship_place,
nb_children_family = nb_children_family,
parental_authority = parental_authority,
family_situation = family_situation,
child_custody = child_custody,
transportcompany = transportcompany,
transporttype = transporttype,
externaldoctor = externaldoctor,
externalintervener = externalintervener,
service=service,
creator=creator,
old_id = old_id,
old_old_id = old_old_id)
# if created:
# print 'Creation de%s' % patient
# else:
# print 'Patient %s existe' % patient
fs = FileState(status=accueil_status[0], author=creator, previous_state=None)
"Date du premier contact"
date_selected = None
if not date_selected:
date_selected = patient.created
fs.patient = patient
fs.date_selected = date_selected
fs.save()
patient.last_state = fs
patient.save()
if old_id in mises_per_patient.keys():
for quotation in mises_per_patient[old_id]:
if quotation.axe == 1:
patient.mises_1.add(quotation)
elif quotation.axe == 2:
patient.mises_2.add(quotation)
elif quotation.axe == 3:
patient.mises_3.add(quotation)
else:
raise
if old_id in social_duration_per_patient.keys():
for social_duration in social_duration_per_patient[old_id]:
patient.socialisation_durations.add(social_duration)
for t_the in ('the_medecin', 'the_referent', 'the_therapeute'):
try:
therapist = None
if service.name == 'CAMSP':
therapist = Worker.objects.get(old_camsp_id=_to_int(dossier[t_the]))
elif service.name == 'CMPP':
therapist = Worker.objects.get(old_cmpp_id=_to_int(dossier[t_the]))
elif service.name == 'SESSAD DYS':
therapist = Worker.objects.get(old_sessad_dys_id=_to_int(dossier[t_the]))
elif service.name == 'SESSAD TED':
therapist = Worker.objects.get(old_sessad_ted_id=_to_int(dossier[t_the]))
patient.coordinators.add(therapist)
except:
pass
# i += 1
# print 'Fin de traitement pour le dossier %s' % patient
# if i >= 10:
# break
i -= 1
if not (i % 10):
sys.stdout.write('%d ' %i)
else:
sys.stdout.write('.')
sys.stdout.flush()
print "<-- Terminé"
print "====== Fin à %s ======" % str(datetime.today())
#Travail manuel pour secreatires
# mdph_requests = models.ManyToManyField('ressources.MDPHRequest',
# mdph_responses = models.ManyToManyField('ressources.MDPHResponse',
# policyholder = None
# contacts = None
if __name__ == "__main__":
main()

View File

@ -0,0 +1,232 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time, date
import calebasse.settings
import django.core.management
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, TimeTable, PERIODICITIES
from calebasse.personnes.forms import PERIOD_LIST_TO_FIELDS
from calebasse.ressources.models import WorkerType, HolidayType, SchoolType, School, SchoolLevel
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
PERIOD_FAURE_NOUS = {1 : 1,
2 : 2,
3 : 3,
4 : 4,
5: 6,
6: 7,
7: 8,
8: 9,
9: None,
10: 10,
12: 11,
13: 12,
}
JOURS = {1: 'lundi',
2: 'mardi',
3: 'mercredi',
4: 'jeudi',
5: 'vendredi'
}
dic_worker = {}
def main():
""" """
t_inconnu = SchoolType.objects.get(name='Inconnu')
t_maternelle = SchoolType.objects.get(name='Ecole maternelle')
t_primaire = SchoolType.objects.get(name='Ecole primaire')
t_college = SchoolType.objects.get(name='Collège')
t_lycee = SchoolType.objects.get(name='Lycée')
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
l = []
csvfile = open(os.path.join(db_path, db, 'classes.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
data = _get_dict(cols, line)
l.append(data)
csvfile.close()
for classe in l:
SchoolLevel(name=classe['libelle'], old_id=classe['id'], old_service=service.name).save()
l = []
csvfile = open(os.path.join(db_path, db, 'ecoles.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
data = _get_dict(cols, line)
l.append(data)
csvfile.close()
for ecole in l:
t = t_inconnu
ecole_nom = ecole['nom'].encode('utf-8')
if 'mat' in ecole_nom or 'Mat' in ecole_nom or 'Maternelle' in ecole_nom or 'maternelle' in ecole_nom or 'MATERNELLE' in ecole_nom:
t = t_maternelle
elif 'Primaire' in ecole_nom or 'primaire' in ecole_nom or 'PRIMAIRE' in ecole_nom:
t = t_primaire
elif 'COLLEGE' in ecole_nom or 'COLLÈGE' in ecole_nom or 'collège' in ecole_nom or 'college' in ecole_nom or 'Collège' in ecole_nom or 'College' in ecole_nom:
t = t_college
elif 'LYCEE' in ecole_nom or 'LYCÉE' in ecole_nom or 'lycée' in ecole_nom or 'lycee' in ecole_nom or 'Lycée' in ecole_nom or 'Lycée' in ecole_nom:
t = t_lycee
School(name=ecole['nom'],
school_type = t,
address = ecole['voie'],
address_complement = ecole['suite'],
zip_code = ecole['codepostal'],
city = ecole['ville'],
phone = ecole['tel'],
fax = ecole['fax'],
email = ecole['email'],
director_name = ecole['nom_dir'],
description = ecole['infos'],
old_id=ecole['id'], old_service=service.name).save()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,209 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, ExternalTherapist, ExternalWorker
from calebasse.ressources.models import WorkerType
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
# Global mappers. This dicts are used to map a Faure id with a calebasse object.
dossiers = {}
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
unknown_type = WorkerType.objects.get(name="Non défini")
l = []
csvfile = open(os.path.join(db_path, db, 'intervenants_exterieurs.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
data = _get_dict(cols, line)
l.append(data)
csvfile.close()
for intervenant in l:
dn = intervenant['nom'].upper() + ' ' + intervenant['prenom']
ExternalWorker(last_name = intervenant['nom'],
first_name = intervenant['prenom'],
display_name = dn,
email = intervenant['email'],
phone = intervenant['tel_port'],
phone_work = intervenant['tel_trav'],
description = intervenant['specialite'],
address = intervenant['voie'],
zip_code = intervenant['codepostal'],
city = intervenant['ville'],
type = unknown_type,
old_id = intervenant['id'], old_service=service.name).save()
l = []
csvfile = open(os.path.join(db_path, db, 'medecins_exterieurs.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
data = _get_dict(cols, line)
l.append(data)
csvfile.close()
for intervenant in l:
dn = intervenant['nom'].upper() + ' ' + intervenant['prenom']
ExternalTherapist(last_name = intervenant['nom'],
first_name = intervenant['prenom'],
display_name = dn,
email = intervenant['email'],
phone = intervenant['tel_port'],
phone_work = intervenant['tel_trav'],
description = intervenant['specialite'],
address = intervenant['voie'],
zip_code = intervenant['codepostal'],
city = intervenant['ville'],
type = unknown_type,
old_id = intervenant['id'], old_service=service.name).save()
if __name__ == "__main__":
main()

340
scripts/import_horaires.py Normal file
View File

@ -0,0 +1,340 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time, date
import calebasse.settings
import django.core.management
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, TimeTable, PERIODICITIES
from calebasse.personnes.forms import PERIOD_LIST_TO_FIELDS
from calebasse.ressources.models import WorkerType, HolidayType
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
PERIOD_FAURE_NOUS = {1 : 1,
2 : 2,
3 : 3,
4 : 4,
5: 6,
6: 7,
7: 8,
8: 9,
9: None,
10: 10,
12: 11,
13: 12,
}
JOURS = {1: 'lundi',
2: 'mardi',
3: 'mercredi',
4: 'jeudi',
5: 'vendredi'
}
dic_worker = {}
def main():
""" """
thera_evt = {}
cf = open('./scripts/horaires_manuel.csv', 'wb')
writer = csv.writer(cf, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(['Jour', 'Nom', 'Prénom', 'Libellé',
'Date début', 'Date fin', 'Horaire', 'Périodicité'])
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
tables_data[service.name] = []
csvfile = open(os.path.join(db_path, db, 'ev.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
i = 0
for line in csvlines:
if line[8] == 'ARRIVEE' or line[8] == 'DEPART':
data = _get_dict(cols, line)
tables_data[service.name].append(data)
i += 1
csvfile.close()
print "%s - Nombre d'evt horaires : %d" % (service.name, i)
thera_evt[service.name] = {}
csvfile = open(os.path.join(db_path, db, 'details_ev.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
not_found = []
for line in csvlines:
worker = None
try:
if service.name == 'CMPP':
worker = Worker.objects.get(old_cmpp_id=line[2])
elif service.name == 'CAMSP':
worker = Worker.objects.get(old_camsp_id=line[2])
elif service.name == 'SESSAD DYS':
worker = Worker.objects.get(old_sessad_dys_id=line[2])
elif service.name == 'SESSAD TED':
worker = Worker.objects.get(old_sessad_ted_id=line[2])
else:
print "service inconnu!!!"
exit(0)
except Exception, e:
not_found.append(line[2])
if worker:
if line[1] in thera_evt.keys():
thera_evt[service.name][line[1]].append(worker)
else:
thera_evt[service.name][line[1]] = [worker]
csvfile.close()
print "%s - Liste des worker not found : %s" % (service.name, str(set(not_found)))
# 7 8 17 n'existe pas au SESSAD TED
# ['91', '89', '17', '77', '76', '75', '74', '73', '72', '82', '90', '85'] n'existe pas au CMPP
i = 0
j = 0
dic_worker[service.name] = {}
for horaire in tables_data[service.name]:
if not horaire['id'] in thera_evt[service.name]:
j += 1
elif not thera_evt[service.name][horaire['id']]:
i += 1
else:
if len(thera_evt[service.name][horaire['id']]) > 1:
print "%s - Horaire %s avec plus d'un worker %s!" % (service.name, horaire['id'], str(len(thera_evt[service.name][horaire['id']])))
exit(0)
worker = thera_evt[service.name][horaire['id']][0]
if not worker in dic_worker[service.name].keys():
dic_worker[service.name][worker] = {}
if 'horaires' in dic_worker[service.name][worker].keys():
dic_worker[service.name][worker]['horaires'].append(horaire)
else:
dic_worker[service.name][worker]['horaires'] = [horaire]
for worker, details in dic_worker[service.name].items():
for horaire in details['horaires']:
date_fin = None
if 'date_fin' in horaire and horaire['date_fin'] != '':
date_fin = datetime.strptime(horaire['date_fin'][:-13], "%Y-%m-%d")
if not date_fin or date_fin > datetime.today():
start_date = datetime.strptime(horaire['date_debut'][:-13], "%Y-%m-%d").date()
weekday = int(start_date.strftime('%w'))
if weekday in dic_worker[service.name][worker].keys():
dic_worker[service.name][worker][weekday].append(horaire)
else:
dic_worker[service.name][worker][weekday] = [horaire]
for i in range(0,8):
if i in dic_worker[service.name][worker].keys():
horaires = sorted(dic_worker[service.name][worker][weekday], key=lambda tup: tup['date_debut'])
dic_worker[service.name][worker][weekday] = horaires
i = 0
j = 0
for worker in dic_worker[service.name].keys():
for day, horaires in dic_worker[service.name][worker].items():
if day != 'horaires':
i += 1
if len(horaires) > 2 or len(horaires)%2:
print 'A'
for horaire in horaires:
print [day, worker.last_name, horaire['libelle'], horaire['date_debut']]
for k, v in PERIODICITIES:
if PERIOD_FAURE_NOUS[int(horaire['rythme'])] == k:
p = v
break
d = JOURS[day]
writer.writerow([d, worker.last_name.encode('utf-8'), worker.first_name.encode('utf-8'), horaire['libelle'],
horaire['date_debut'], horaire['date_fin'], horaire['heure'], p])
else:
arrivee = None
depart = None
for horaire in horaires:
if horaire['libelle'] == 'ARRIVEE':
arrivee = horaire
else:
depart = horaire
if not (arrivee and depart):
print 'B'
for horaire in horaires:
print [day, worker.last_name, horaire['libelle'], horaire['date_debut']]
for k, v in PERIODICITIES:
if PERIOD_FAURE_NOUS[int(horaire['rythme'])] == k:
p = v
break
d = JOURS[day]
writer.writerow([d, worker.last_name.encode('utf-8'), worker.first_name.encode('utf-8'), horaire['libelle'],
horaire['date_debut'], horaire['date_fin'], horaire['heure'], p])
else:
j += 1
# Créer les horaires
start_date = datetime.strptime(arrivee['date_debut'][:-13], "%Y-%m-%d").date()
weekday = day - 1
periodicity = PERIOD_FAURE_NOUS[int(arrivee['rythme'])]
if not periodicity:
periodicity = 1
week_period, week_parity, week_rank = PERIOD_LIST_TO_FIELDS[periodicity - 1]
end_date = None
skip = False
if arrivee['date_fin']:
end_date = datetime.strptime(arrivee['date_fin'][:-13], "%Y-%m-%d").date()
tt = TimeTable(worker=worker,
weekday=weekday,
periodicity=periodicity,
week_period=week_period, week_parity=week_parity, week_rank=week_rank,
start_time = datetime.strptime(arrivee['heure'][11:16], "%H:%M").time(),
end_time = datetime.strptime(depart['heure'][11:16], "%H:%M").time(),
start_date = start_date,
end_date = end_date)
tt.save()
tt.services.add(service)
print '====> %s %s' % (worker.last_name.encode('utf-8'), worker.first_name.encode('utf-8'))
print i
print j
csvfile.close()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,333 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time, date
import calebasse.settings
import django.core.management
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, TimeTable
from calebasse.personnes.forms import PERIOD_LIST_TO_FIELDS
from calebasse.ressources.models import WorkerType, HolidayType
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
PERIOD_FAURE_NOUS = {1 : 1,
2 : 2,
3 : 3,
4 : 4,
5: 6,
6: 7,
7: 8,
8: 9,
9: None,
10: 10,
12: 11,
13: 12,
}
def main():
""" """
thera_evt = {}
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
tables_data[service.name] = []
csvfile = open(os.path.join(db_path, db, 'ev.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
i = 0
for line in csvlines:
# if _to_date(line[1]) > datetime(year=2012, month=1, day=1) and \
# (line[8] == 'ARRIVEE' or line[8] == 'DEPART'):
if line[8] == 'ARRIVEE' or line[8] == 'DEPART':
data = _get_dict(cols, line)
tables_data[service.name].append(data)
i += 1
csvfile.close()
print "%s - Nombre d'evt horaires : %d" % (service.name, i)
thera_evt[service.name] = {}
csvfile = open(os.path.join(db_path, db, 'details_ev.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
not_found = []
for line in csvlines:
worker = None
try:
if service.name == 'CMPP':
worker = Worker.objects.get(old_cmpp_id=line[2])
elif service.name == 'CAMSP':
worker = Worker.objects.get(old_camsp_id=line[2])
elif service.name == 'SESSAD DYS':
worker = Worker.objects.get(old_sessad_dys_id=line[2])
elif service.name == 'SESSAD TED':
worker = Worker.objects.get(old_sessad_ted_id=line[2])
else:
print "service inconnu!!!"
exit(0)
except Exception, e:
# print "error on id %s service %s with exception %s" % (line[2], service.name, str(e))
not_found.append(line[2])
if worker:
if line[1] in thera_evt.keys():
thera_evt[service.name][line[1]].append(worker)
else:
thera_evt[service.name][line[1]] = [worker]
csvfile.close()
print "%s - Liste des worker not found : %s" % (service.name, str(set(not_found)))
# 7 8 17 n'existe pas au SESSAD TED
# ['91', '89', '17', '77', '76', '75', '74', '73', '72', '82', '90', '85'] n'existe pas au CMPP
i = 0
j = 0
t_tmp = []
for horaire in tables_data[service.name]:
if not horaire['id'] in thera_evt[service.name]:
j += 1
# print "horaire sans detail: %s %s" % (horaire['id'], horaire['date_debut'])
elif not thera_evt[service.name][horaire['id']]:
i += 1
else:
if len(thera_evt[service.name][horaire['id']]) > 1:
print "%s - Horaire %s avec plus d'un worker %s!" % (service.name, horaire['id'], str(len(thera_evt[service.name][horaire['id']])))
exit(0)
horaire['worker'] = thera_evt[service.name][horaire['id']][0]
# if thera_evt[service.name][horaire['id']][0].last_name == "Borderon":
# print datetime.strptime(horaire['date_debut'][:-13], "%Y-%m-%d").date()
# print datetime.strptime(horaire['heure'][11:16], "%H:%M").time()
t_tmp.append(horaire)
tables_data[service.name] = t_tmp
print "%s - Nombre d'evt horaires sans details: %d" % (service.name, j)
print "%s - Nombre d'evt horaires sans worker: %d" % (service.name, i)
print "%s - Nombre d'evt horaires: %d" % (service.name, len(tables_data[service.name]))
i = 0
arrivee = None
t_tmp = []
tables_data[service.name]= sorted(tables_data[service.name], key=lambda tup: tup['date_debut'])
for horaire in tables_data[service.name]:
"""regrouper arrivé et départ sinon erreur:
même jour, même récurrence, mêmes intervenants, etc."""
t_tmp.append(horaire)
if horaire['libelle'] == 'ARRIVEE':
if arrivee:
# print "Deux arrivée de suite %s %s" % (str(arrivee), str(horaire))
pass
arrivee = horaire
if horaire['libelle'] == 'DEPART':
if arrivee:
if horaire['date_debut'] == arrivee['date_debut'] and \
horaire['rythme'] == arrivee['rythme'] and \
horaire['type_evenement'] == arrivee['type_evenement'] and \
horaire['worker'] == arrivee['worker']:
# horaire['date_fin'] == arrivee['date_fin'] and \
t_tmp.pop(len(t_tmp) - 1)
t_tmp.pop(len(t_tmp) - 1)
i += 1
# print "worker: %s" % arrivee['worker']
# print "date_debut: %s" % datetime.strptime(arrivee['date_debut'][:-13], "%Y-%m-%d").date()
# if arrivee['date_fin']:
# print "date_fin: %s" % datetime.strptime(arrivee['date_fin'][:-13], "%Y-%m-%d").date()
# print "heure arrivee: %s" % datetime.strptime(arrivee['heure'][11:16], "%H:%M").time()
# print "heure depart: %s" % datetime.strptime(horaire['heure'][11:16], "%H:%M").time()
# print "reccurrence: %s" % arrivee['rythme']
start_date = datetime.strptime(arrivee['date_debut'][:-13], "%Y-%m-%d").date()
weekday = int(start_date.strftime('%w')) + 1
periodicity = PERIOD_FAURE_NOUS[int(arrivee['rythme'])]
if not periodicity:
periodicity = 1
week_period, week_parity, week_rank = PERIOD_LIST_TO_FIELDS[periodicity - 1]
# print "week_period: %s" % week_period
# print "week_parity: %s" % week_parity
# print "week_rank: %s" % week_rank
end_date = None
skip = False
if arrivee['date_fin']:
end_date = datetime.strptime(arrivee['date_fin'][:-13], "%Y-%m-%d").date()
if arrivee['date_fin'] == arrivee['date_debut']:
skip = True
elif end_date < datetime(year=2013, month=1, day=2).date():
skip = True
if not skip:
pass
# tt = TimeTable(worker=arrivee['worker'],
# weekday=weekday,
# periodicity=periodicity,
# week_period=week_period, week_parity=week_parity, week_rank=week_rank,
# start_time = datetime.strptime(arrivee['heure'][11:16], "%H:%M").time(),
# end_time = datetime.strptime(horaire['heure'][11:16], "%H:%M").time(),
# start_date = start_date,
# end_date = end_date)
# tt.save()
# tt.services.add(service)
arrivee = None
else:
# print "Départ sans arrivee %s" % str(horaire)
pass
print "%s - Nombre d'horaires : %d" % (service.name, i)
print "%s - Nombre d'evt horaires restants: %d" % (service.name, len(t_tmp))
# csvfile = open('./scripts/horaires_manuel.csv', 'ab')
# writer = csv.writer(csvfile, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
# colonnes = list(t_tmp[0].keys())
# colonnes.append('service')
# writer.writerow(colonnes)
# for h in t_tmp:
# valeurs = list(h.values())
# valeurs.append(service.name)
# writer.writerow(valeurs)
# csvfile.close()
#Classer par worker, puis par jour: date de début => jour.
#Prendre l'vet arrivée et départ les plus récent pour chaque jour, pour chaque intervenant.
# Avec date de fin pas expriée ou pas de date de fin.
if __name__ == "__main__":
main()

View File

@ -0,0 +1,181 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, ExternalTherapist, ExternalWorker
from calebasse.ressources.models import WorkerType, AnalyseMotive, FamilyMotive, Provenance
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
# Global mappers. This dicts are used to map a Faure id with a calebasse object.
dossiers = {}
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
csvfile = open(os.path.join(db_path, "F_ST_ETIENNE_CAMSP", 'ins_motifs.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
AnalyseMotive(name=line[1]).save()
csvfile.close()
csvfile = open(os.path.join(db_path, "F_ST_ETIENNE_CAMSP", 'ins_motif_exprim.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
FamilyMotive(name=line[1]).save()
csvfile.close()
for db in dbs:
if "F_ST_ETIENNE_CMPP" == db:
service = Service.objects.get(name="CMPP")
elif "F_ST_ETIENNE_CAMSP" == db:
service = Service.objects.get(name="CAMSP")
elif "F_ST_ETIENNE_SESSAD_TED" == db:
service = Service.objects.get(name="SESSAD TED")
elif "F_ST_ETIENNE_SESSAD" == db:
service = Service.objects.get(name="SESSAD DYS")
csvfile = open(os.path.join(db_path, db, 'ins_provenance.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
Provenance(name=line[1], old_id=line[0], old_service=service.name).save()
csvfile.close()
if __name__ == "__main__":
main()

153
scripts/import_mises.py Normal file
View File

@ -0,0 +1,153 @@
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday
from calebasse.ressources.models import WorkerType, CodeCFTMEA
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
# Global mappers. This dicts are used to map a Faure id with a calebasse object.
dossiers = {}
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
""" """
csvfile = open('./scripts/20121221-192258/F_ST_ETIENNE_SESSAD_TED/mises.csv', 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
CodeCFTMEA(code=int(line[1]), axe=int(line[2]), name=line[3]).save()
if __name__ == "__main__":
main()

163
scripts/import_sortie.py Normal file
View File

@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, ExternalTherapist, ExternalWorker
from calebasse.ressources.models import WorkerType, OutMotive, OutTo
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
# Global mappers. This dicts are used to map a Faure id with a calebasse object.
dossiers = {}
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
csvfile = open(os.path.join(db_path, "F_ST_ETIENNE_CAMSP", 'sor_motifs.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
OutMotive(name=line[1]).save()
csvfile.close()
csvfile = open(os.path.join(db_path, "F_ST_ETIENNE_CAMSP", 'sor_orientation.csv'), 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='|')
cols = csvlines.next()
for line in csvlines:
OutTo(name=line[1]).save()
csvfile.close()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,154 @@
#!/usr/bin/env python
import os
import csv
from datetime import datetime, time
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday
from calebasse.ressources.models import WorkerType
# Configuration
db_path = "./scripts/20121221-192258"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
# Global mappers. This dicts are used to map a Faure id with a calebasse object.
dossiers = {}
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
def dossiers_mapper(tables_data, service):
global dossiers
for line in tables_data['dossiers']:
status = Status.objects.filter(type="ACCUEIL").filter(services=service)
creator = User.objects.get(id=1)
gender = _to_int(line['nais_sexe'])
if gender == 0:
gender = None
# TODO: add more fields
patient, created = PatientRecord.objects.get_or_create(first_name=line['prenom'],
last_name=line['nom'], birthdate=_to_date(line['nais_date']),
twinning_rank=_to_int(line['nais_rang']),
gender=gender, service=service, creator=creator)
dossiers[line['id']] = patient
if not created:
if not line['ins_date']:
# Hack when there is no inscription date put 01/01/1970
line['ins_date'] = "1970-01-01 00:00:00.000"
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['ins_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
if line['sor_date']:
status = Status.objects.filter(type="CLOS").filter(services=service)
fs = FileState.objects.create(status=status[0], author=creator,
date_selected=_to_date(line['sor_date']),
previous_state=None, patient=patient)
patient.last_state = fs
patient.save()
def rs_mapper(tables_data, service):
global dossiers
event_type = EventType.objects.get(
label=u"Rendez-vous patient"
)
for line in tables_data['rs']:
if dossiers.has_key(line['enfant_id']):
patient = dossiers[line['enfant_id']]
strdate = line['date_rdv'][:-13] + ' ' + line['heure'][11:-4]
date = datetime.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# TODO: add act_type
# act_event = EventAct.objects.get_or_create(
# title=line['libelle'],
# event_type=event_type,
# patient=patient,
# act_type=act_type,
# date=date
# )
else:
# TODO: if no patient add event
pass
def conge_mapper(tables_data, service):
""" """
for line in tables_data['conge']:
pass
def ev_mapper(tables_data, service):
""" """
pass
def notes_mapper(tables_data, service):
""" """
pass
def _get_dict(cols, line):
""""""
res = {}
for i, data in enumerate(line):
res[cols[i]] = data.decode('utf-8')
return res
tables_data = {}
def main():
""" """
csvfile = open('./scripts/liste_evenements.csv', 'rb')
csvlines = csv.reader(csvfile, delimiter=';', quotechar='"')
cols = csvlines.next()
for line in csvlines:
label = line[1][0].upper()+line[1][1:]
EventType(label=label).save()
if __name__ == "__main__":
main()

183
scripts/import_users.py Normal file
View File

@ -0,0 +1,183 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import csv
import codecs
import string
import random
from datetime import datetime, time
import django.core.management
import calebasse.settings
django.core.management.setup_environ(calebasse.settings)
from django.contrib.auth.models import User
from calebasse.actes.models import EventAct
from calebasse.agenda.models import Event, EventType
from calebasse.dossiers.models import PatientRecord, Status, FileState
from calebasse.ressources.models import Service
from calebasse.personnes.models import Worker, Holiday, UserWorker
from calebasse.ressources.models import WorkerType
wt="./scripts/worker_type.csv"
access_worker_enabled="./scripts/access_worker.csv"
worker_only_disabled="./scripts/worker_only.csv"
db_path = "./scripts/20121219-212026"
dbs = ["F_ST_ETIENNE_SESSAD_TED", "F_ST_ETIENNE_CMPP", "F_ST_ETIENNE_CAMSP", "F_ST_ETIENNE_SESSAD"]
def _to_date(str_date):
if not str_date:
return None
return datetime.strptime(str_date[:-13], "%Y-%m-%d")
def _to_int(str_int):
if not str_int:
return None
return int(str_int)
def discipline_mapper(tables_data, service):
for line in tables_data['discipline']:
# Insert workertype
if not WorkerType.objects.filter(name=line['libelle']):
WorkerType.objects.create(name=line['libelle'])
def intervenants_mapper(tables_data, service):
for line in tables_data['intervenants']:
# Insert workers
for disp in tables_data['discipline']:
if disp['id'] == line['discipline']:
type = WorkerType.objects.get(name=disp['libelle'])
# TODO : import actif or not
worker, created = Worker.objects.get_or_create(
type=type,
last_name=line['nom'],
first_name=line['prenom'],
email=line['email'],
phone=line['tel'],
gender=int(line['titre']),
)
worker.services.add(service)
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
def __iter__(self):
return self
def next(self):
return self.reader.next().encode("utf-8")
class UnicodeReader:
"""
A CSV reader which will iterate over lines in the CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="iso8859-15", **kwds):
f = UTF8Recoder(f, encoding)
self.reader = csv.reader(f, dialect=dialect, **kwds)
def next(self):
row = self.reader.next()
return [unicode(s, "utf-8") for s in row]
def __iter__(self):
return self
def main():
'''User and worker'''
cmpp = Service.objects.get(name="CMPP")
camsp = Service.objects.get(name="CAMSP")
sessad_ted = Service.objects.get(name="SESSAD TED")
sessad_dys = Service.objects.get(name="SESSAD DYS")
csvfile = open(access_worker_enabled, 'rb')
csvlines = UnicodeReader(csvfile, delimiter=';', quotechar='|',encoding='utf-8')
csvlines.next()
for line in csvlines:
user = User(username=line[2])
user.set_password(line[3])
user.save()
last_name = line[0]
first_name = line[1]
gender = 1
if line[14] == 'femme':
gender = 2
email = line[13]
type = WorkerType.objects.get(pk=int(line[8]))
enabled = True
old_camsp_id = None
if line[9] != '':
old_camsp_id = line[9]
old_cmpp_id = None
if line[10] != '':
old_cmpp_id = line[10]
old_sessad_dys_id = None
if line[11] != '':
old_sessad_dys_id = line[11]
old_sessad_ted_id = None
if line[12] != '':
old_sessad_ted_id = line[12]
worker = Worker(last_name=last_name, first_name=first_name,
gender=gender, email=email, type=type,
old_camsp_id=old_camsp_id, old_cmpp_id=old_cmpp_id,
old_sessad_dys_id=old_sessad_dys_id, old_sessad_ted_id=old_sessad_ted_id,
enabled=enabled)
worker.save()
if line[4] != '':
worker.services.add(camsp)
if line[5] != '':
worker.services.add(cmpp)
if line[6] != '':
worker.services.add(sessad_dys)
if line[7] != '':
worker.services.add(sessad_ted)
worker.save()
UserWorker(user=user,worker=worker).save()
'''Worker only'''
csvfile = open(worker_only_disabled, 'rb')
csvlines = UnicodeReader(csvfile, delimiter=';', quotechar='|',encoding='utf-8')
csvlines.next()
for line in csvlines:
old_camsp_id = None
old_cmpp_id = None
old_sessad_dys_id = None
old_sessad_ted_id = None
service = line[5]
if service == 'CAMSP':
old_camsp_id = line[0]
elif service == 'CMPP':
old_cmpp_id = line[0]
elif service == 'SESSAD DYS':
old_sessad_dys_id = line[0]
else:
old_sessad_ted_id = line[0]
last_name = line[1]
first_name = line[2]
gender = 1
if line[3] == 'Femme':
gender = 2
type = WorkerType.objects.get(pk=int(line[4]))
enabled = False
worker = Worker(last_name=last_name, first_name=first_name,
gender=gender, email=None, type=type,
old_camsp_id=old_camsp_id, old_cmpp_id=old_cmpp_id,
old_sessad_dys_id=old_sessad_dys_id, old_sessad_ted_id=old_sessad_ted_id,
enabled=enabled)
worker.save()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,15 @@
n°;type dévénements
1;réunion
2;réunion à l'extérieur
3;en formation
4;donne une formation
5;équipe pluridisciplinaire MLA
6;supervision
7;réunion de service
8;réunion de direction
9;réunion administratifs
10;réunion agents de service
11;concertation direction
12;périnatalité
13;réunion des parents
14;temps de trajet
1 type d’événements
2 1 réunion
3 2 réunion à l'extérieur
4 3 en formation
5 4 donne une formation
6 5 équipe pluridisciplinaire MLA
7 6 supervision
8 7 réunion de service
9 8 réunion de direction
10 9 réunion administratifs
11 10 réunion agents de service
12 11 concertation direction
13 12 périnatalité
14 13 réunion des parents
15 14 temps de trajet

19
scripts/mises.py Normal file
View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import calebasse.settings
import django.core.management
django.core.management.setup_environ(calebasse.settings)
from calebasse.ressources.models import CodeCFTMEA
db="./scripts/MISES.TXT"
f = open(db, 'r')
for line in f.readlines()[1:]:
words = line.split('\t')
c = CodeCFTMEA(name=words[3].strip("\r\n").decode('iso-8859-13'),
axe=int(words[2]), code=int(words[1]))
c.save()
print c

17
scripts/transports.csv Normal file
View File

@ -0,0 +1,17 @@
|nom|;|voie|;|suite|;|codepostal|;|ville|;|tel|;|fax|;|email|;|correspondant|;|old_camsp_id|;|old_cmpp_id|;|old_sessad_dys_id|;|old_sessad_ted_id|
|TAXI REYMONDON|;|Route du Violet|;;|42660|;|SAINT GENEST MALIFAUX|;|04.77.39.08.88|;;|taxi.p.r@orange.fr|;;1;1;1;
|TAXI LAFOND|;|2, Rue C. Coignet|;;|42160|;|ANDREZIEUX BOUTHEON|;|04.7736.61.48|;;;;;2;2;
|TAXI PIAZON|;;;;;;;;;2;3;;
|TAL'AMBULANCES|;|2, Rue du Stade|;;|42350|;|LA TALAUDIERE|;|04.77.53.41.41|;;;;;4;;
|BOURGIN TAXIS|;|Le Bourg|;;|42560|;|SOLEYMIEUX|;|04.77.76.71.41|;;;;;5;;
|TAXI DE VILLE|;|7, Rue Louis Lumière|;;|42000|;|SAINT ETIENNE|;|0427862323|;;;|Madame BRUYAS|;;6;;
|Taxi BOURGIN|;;;|42380|;|ESTIVAREILLES|;;;;;;7;;
|CENTRE AMBULANCIER MONTBRISONNAIS|;|46, Rue des Grands Chênes|;;|42600|;|MONTBRISON|;;;;;;8;;
|TAXI BOGY|;|Résidence Le Mermoz|;|Rue Molière - Allée B|;|42160|;|ANDREZIEUX|;|04.7736.55.85|;;;;;;3;
|CHAMBON AMBULANCES|;|8, Rue du 11 Novembre|;;|42500|;|LE CHAMBON FEUGEROLLES|;|04.77.80.75.88|;;;;;;4;
|FOURNEL|;;;;;;;;;;;5;
|GAGNAIRE|;|1, Place Jean Jaurès|;;|42230|;|ROCHE LA MOLIERE|;|0477906527|;;;;;;6;
|Taxi CHANUT|;|1 Bis, Rue du 19 Mars 1962|;;|42160|;|SAINT CYPRIEN|;|0477369321|;;;;;;7;
|ami de la famille|;;;;;;;;;3;;;
|TAXIS St HEAND|;|1 Allée Chancarte|;;|42570|;|SAINT HEAND|;|04.77.30.95.95|;;;;4;;;
|FAURE -THIZY|;|5 Route de Saint Etienne|;;|42400|;|SAINT CHAMOND|;|04.77.226.239|;;;|JJ FAURE 06.80.28.45.39 Frédéric THIZY 06.07.33.07.27|;5;;;
1 |nom| |voie| |suite| |codepostal| |ville| |tel| |fax| |email| |correspondant| |old_camsp_id| |old_cmpp_id| |old_sessad_dys_id| |old_sessad_ted_id|
2 |TAXI REYMONDON| |Route du Violet| |42660| |SAINT GENEST MALIFAUX| |04.77.39.08.88| |taxi.p.r@orange.fr| 1 1 1
3 |TAXI LAFOND| |2, Rue C. Coignet| |42160| |ANDREZIEUX BOUTHEON| |04.7736.61.48| 2 2
4 |TAXI PIAZON| 2 3
5 |TAL'AMBULANCES| |2, Rue du Stade| |42350| |LA TALAUDIERE| |04.77.53.41.41| 4
6 |BOURGIN TAXIS| |Le Bourg| |42560| |SOLEYMIEUX| |04.77.76.71.41| 5
7 |TAXI DE VILLE| |7, Rue Louis Lumière| |42000| |SAINT ETIENNE| |0427862323| |Madame BRUYAS| 6
8 |Taxi BOURGIN| |42380| |ESTIVAREILLES| 7
9 |CENTRE AMBULANCIER MONTBRISONNAIS| |46, Rue des Grands Chênes| |42600| |MONTBRISON| 8
10 |TAXI BOGY| |Résidence Le Mermoz| |Rue Molière - Allée B| |42160| |ANDREZIEUX| |04.7736.55.85| 3
11 |CHAMBON AMBULANCES| |8, Rue du 11 Novembre| |42500| |LE CHAMBON FEUGEROLLES| |04.77.80.75.88| 4
12 |FOURNEL| 5
13 |GAGNAIRE| |1, Place Jean Jaurès| |42230| |ROCHE LA MOLIERE| |0477906527| 6
14 |Taxi CHANUT| |1 Bis, Rue du 19 Mars 1962| |42160| |SAINT CYPRIEN| |0477369321| 7
15 |ami de la famille| 3
16 |TAXIS St HEAND| |1 Allée Chancarte| |42570| |SAINT HEAND| |04.77.30.95.95| 4
17 |FAURE -THIZY| |5 Route de Saint Etienne| |42400| |SAINT CHAMOND| |04.77.226.239| |JJ FAURE 06.80.28.45.39 Frédéric THIZY 06.07.33.07.27| 5

15
scripts/worker_type.csv Normal file
View File

@ -0,0 +1,15 @@
|Name|;|Intervenant|
|DIRECTRICE PEDAGOGIQUE ET ADMINISTRATIVE|;|x|
|ASSISTANTES SOCIALES|;|x|
|MEDECINS|;|x|
|PSYCHOLOGUES|;|x|
|NEUROPSYCHOLOGUES|;|x|
|ORTHOPHONISTES|;|x|
|PSYCHOMOTRICIENS|;|x|
|ERGOTHERAPEUTES|;|x|
|EDUCATEURS|;|x|
|SECRETAIRES|;
|COMPTABLES|;
|AGENTS D'ENTRETIEN|;
|STAGIAIRES|;
|FORMATEURS|;
Can't render this file because it has a wrong number of fields in line 11.