363 |
363 |
})
|
364 |
364 |
def search(self, request, first_name, last_name, date_of_birth):
|
365 |
365 |
try:
|
366 |
|
date_of_birth = datetime.datetime.strptime(date_of_birth, '%Y-%m-%d')
|
|
366 |
date_of_birth = datetime.datetime.strptime(date_of_birth, '%Y-%m-%d').date()
|
367 |
367 |
except (ValueError, TypeError):
|
368 |
368 |
raise APIError('invalid date_of_birth: %r' % date_of_birth)
|
369 |
369 |
beneficiaires = self.call_cherche_beneficiaire(
|
370 |
370 |
prenom=first_name,
|
371 |
371 |
nom=last_name,
|
372 |
372 |
dob=date_of_birth)
|
|
373 |
response = {'data': []}
|
373 |
374 |
for beneficiaire in beneficiaires:
|
374 |
|
ref_per = beneficiaire.get('REF_PER')
|
375 |
|
if not ref_per:
|
|
375 |
id_per = beneficiaire.get('ID_PER')
|
|
376 |
if not id_per:
|
|
377 |
self.logger.warning('no ID_PER')
|
376 |
378 |
continue
|
377 |
|
dossier = self.call_select_usager_by_ref(ref_per)
|
378 |
|
identification = dossier['IDENTIFICATION'][0]
|
379 |
|
beneficiaire['ID_PER'] = identification['ID_PER']
|
380 |
|
beneficiaire['TEL_FIXE'] = identification.get('TEL_FIXE', '')
|
381 |
|
beneficiaire['TEL_MOBILE'] = identification.get('TEL_MOBILE', '')
|
|
379 |
try:
|
|
380 |
dob = beneficiaire['DATE_NAISSANCE']
|
|
381 |
except KeyError:
|
|
382 |
self.logger.warning('id_per %s: no DATE_NAISSANCE', id_per)
|
|
383 |
continue
|
|
384 |
try:
|
|
385 |
dob = datetime.datetime.strptime(dob, '%d/%m/%Y').date()
|
|
386 |
except (ValueError, TypeError):
|
|
387 |
self.logger.warning('id_per %s: invalid DATE_NAISSANCE', id_per)
|
|
388 |
continue
|
|
389 |
if dob != date_of_birth:
|
|
390 |
self.logger.debug('ignoring id_per %s different dob %s != %s', id_per, dob, date_of_birth)
|
|
391 |
continue
|
|
392 |
dossier = self.call_select_usager(id_per)
|
|
393 |
try:
|
|
394 |
identification = dossier['IDENTIFICATION'][0]
|
|
395 |
except KeyError:
|
|
396 |
self.logger.warning('id_per %s: dossier is empty', id_per)
|
|
397 |
continue
|
|
398 |
assert identification['ID_PER'] == id_per
|
|
399 |
beneficiaire['TEL_MOBILE'] = ''.join(c for c in identification.get('TEL_MOBILE', '') if c.isdigit())
|
382 |
400 |
beneficiaire['MAIL'] = identification.get('MAIL', '')
|
383 |
|
return {'data': beneficiaires}
|
|
401 |
if not (beneficiaire['TEL_MOBILE'] or beneficiaire['MAIL']):
|
|
402 |
self.logger.debug('id_per %s: no contact information, ignored', id_per)
|
|
403 |
continue
|
|
404 |
response['data'].append(beneficiaire)
|
|
405 |
return response
|
384 |
406 |
|
385 |
407 |
@endpoint(name='link-by-id-per',
|
386 |
408 |
methods=['post'],
|