420 lines
13 KiB
Python
420 lines
13 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (C) 2022 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import copy
|
|
|
|
BOOLEAN_TYPES = [
|
|
{'type': 'boolean'},
|
|
{
|
|
'type': 'string',
|
|
'pattern': '^([Oo][Uu][Ii]|[Nn][Oo][Nn]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|1|0)$',
|
|
'pattern_description': 'Les valeurs "0", "1", "true", "false", "oui" ou "non" sont autorisées (insensibles à la casse).',
|
|
},
|
|
]
|
|
|
|
LINK_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Link',
|
|
'description': "Appairage d'un usager Publik à une famille dans Maelis",
|
|
'type': 'object',
|
|
'required': ['family_id', 'firstname', 'lastname', 'dateBirth'],
|
|
'properties': {
|
|
'family_id': {
|
|
'description': 'Numéro DUI',
|
|
'type': 'string',
|
|
},
|
|
'firstname': {
|
|
'description': 'Prénom du RL1',
|
|
'type': 'string',
|
|
},
|
|
'lastname': {
|
|
'description': 'Nom du RL1',
|
|
'type': 'string',
|
|
},
|
|
'dateBirth': {
|
|
'description': 'Date de naissance du RL1',
|
|
'type': 'string',
|
|
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
|
|
},
|
|
},
|
|
}
|
|
|
|
ISRLEXISTS_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Link',
|
|
'description': "Appairage d'un usager Publik à une famille dans Maelis",
|
|
'type': 'object',
|
|
'required': ['firstname', 'lastname', 'datebirth'],
|
|
'properties': {
|
|
'firstname': {
|
|
'description': 'Prénom',
|
|
'type': 'string',
|
|
},
|
|
'lastname': {
|
|
'description': 'Nom',
|
|
'type': 'string',
|
|
},
|
|
'datebirth': {
|
|
'description': 'Date de naissance',
|
|
'type': 'string',
|
|
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
|
|
},
|
|
},
|
|
}
|
|
|
|
ADDRESS_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Address',
|
|
'description': 'Informations sur une adresse',
|
|
'type': 'object',
|
|
'required': ['street1', 'town', 'zipcode'],
|
|
'properties': {
|
|
'num': {
|
|
'description': 'numéro',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'numComp': {
|
|
'description': 'Complément du numéro (B, T ou Q)',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'street1': {
|
|
'description': 'Libellé de la voie',
|
|
'type': 'string',
|
|
},
|
|
'street2': {
|
|
'description': 'Complément de la voie',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'town': {
|
|
'description': 'Ville',
|
|
'type': 'string',
|
|
},
|
|
'zipcode': {
|
|
'description': 'Code postal',
|
|
'type': 'string',
|
|
},
|
|
},
|
|
}
|
|
|
|
CONTACT_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Contact',
|
|
'description': 'Informations sur le contact',
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'phone': {
|
|
'description': 'Téléphone',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'mobile': {
|
|
'description': 'Portable',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'mail': {
|
|
'description': 'Mail',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'isContactMail': {
|
|
'description': 'Accepte de recevoir des mails',
|
|
'oneOf': BOOLEAN_TYPES,
|
|
},
|
|
'isContactSms': {
|
|
'description': 'Accepte de recevoir des sms',
|
|
'oneOf': BOOLEAN_TYPES,
|
|
},
|
|
'isInvoicePdf': {
|
|
'description': 'Accepte de ne plus recevoir de facture papier',
|
|
'oneOf': BOOLEAN_TYPES,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
ADDRESSPROF_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Contact',
|
|
'description': "Informations sur l'adresse professionnelle",
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'num': {
|
|
'description': "Numéro de l'adresse",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'street': {
|
|
'description': 'Nom de la voie',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'town': {
|
|
'description': 'Ville',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'zipcode': {
|
|
'description': 'Code postal',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
PROFESSION_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Profession',
|
|
'description': 'Informations sur la profession',
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'codeCSP': {
|
|
'description': 'Catégorie socio-professionnelle',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'profession': {
|
|
'description': 'Profession',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'employerName': {
|
|
'description': "Nom de l'employeur",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'phone': {
|
|
'description': 'Téléphone',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'addressPro': ADDRESSPROF_SCHEMA,
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
CAFINFO_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Contact',
|
|
'description': 'Informations sur la CAF',
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'number': {
|
|
'description': "Numéro d'allocataire",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'organ': {
|
|
'description': "Nom de l'organisme",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
RLINFO_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'RLInfo',
|
|
'description': "Informations sur le responsable légal",
|
|
'type': 'object',
|
|
'required': ['firstname', 'lastname', 'quality', 'dateBirth', 'adresse'],
|
|
'properties': {
|
|
'civility': {
|
|
'description': 'civilité (depuis référenciel)',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'firstname': {
|
|
'description': 'Prénom',
|
|
'type': 'string',
|
|
},
|
|
'lastname': {
|
|
'description': 'Nom',
|
|
'type': 'string',
|
|
},
|
|
'quality': {
|
|
'description': 'Qualité',
|
|
'type': 'string',
|
|
},
|
|
'dateBirth': {
|
|
'description': 'Date de naissance',
|
|
'type': 'string',
|
|
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
|
|
},
|
|
'adresse': ADDRESS_SCHEMA,
|
|
'contact': CONTACT_SCHEMA,
|
|
'profession': PROFESSION_SCHEMA,
|
|
'CAFInfo': CAFINFO_SCHEMA,
|
|
},
|
|
}
|
|
|
|
CONTACTLIGHT_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Contact',
|
|
'description': "Informations de contact pour les personnes autorisées à récupérer les enfants ou à prévenir en cas d'urgence",
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'object',
|
|
'properties': {
|
|
'phone': {
|
|
'description': 'Téléphone',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'mobile': {
|
|
'description': 'Portable',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'mail': {
|
|
'description': 'Mail',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
FAMILYPERSON_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Family',
|
|
'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence",
|
|
'type': 'object',
|
|
'required': ['firstname', 'lastname', 'dateBirth'],
|
|
'properties': {
|
|
'civility': {
|
|
'description': 'civilité (depuis référenciel)',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'firstname': {
|
|
'description': 'Prénom',
|
|
'type': 'string',
|
|
},
|
|
'lastname': {
|
|
'description': 'Nom',
|
|
'type': 'string',
|
|
},
|
|
'quality': {
|
|
'description': 'Qualité',
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'dateBirth': {
|
|
'description': 'Date de naissance',
|
|
'type': 'string',
|
|
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
|
|
},
|
|
'contact': CONTACTLIGHT_SCHEMA,
|
|
},
|
|
'unflatten': True,
|
|
}
|
|
|
|
AUTHORIZEDPERSON_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Family',
|
|
'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence",
|
|
'type': 'object',
|
|
'properties': {
|
|
'personList': {
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'array',
|
|
'items': FAMILYPERSON_SCHEMA,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
}
|
|
|
|
CREATE_FAMILY_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Family',
|
|
'description': 'Informations pour créer ou mettre à jour une famille',
|
|
'type': 'object',
|
|
'required': ['rl1', 'categorie', 'situation'],
|
|
'properties': {
|
|
'categorie': {
|
|
'description': 'Categorie (depuis référenciel)',
|
|
'type': 'string',
|
|
},
|
|
'situation': {
|
|
'description': 'Situation familiale (depuis référenciel)',
|
|
'type': 'string',
|
|
},
|
|
'flagCom': {
|
|
'description': 'Hors commune',
|
|
'oneOf': BOOLEAN_TYPES,
|
|
},
|
|
'nbChild': {
|
|
'description': "Nombre d'enfants à charge",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'nbTotalChild': {
|
|
'description': "Nombre total d'enfants",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'nbAES': {
|
|
'description': "Nombre d'AES",
|
|
'oneOf': [{'type': 'null'}, {'type': 'string'}],
|
|
},
|
|
'rl1': RLINFO_SCHEMA,
|
|
'rl2': RLINFO_SCHEMA,
|
|
'authorizedPersonList': {
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'array',
|
|
'items': AUTHORIZEDPERSON_SCHEMA,
|
|
},
|
|
],
|
|
},
|
|
'emergencyPersonList': {
|
|
'oneOf': [
|
|
{'type': 'null'},
|
|
{
|
|
'type': 'array',
|
|
'items': AUTHORIZEDPERSON_SCHEMA,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
'unflatten': True,
|
|
}
|
|
|
|
|
|
UPDATE_FAMILY_SCHEMA = copy.deepcopy(CREATE_FAMILY_SCHEMA)
|
|
UPDATE_FAMILY_SCHEMA['required'] = ['categorie', 'situation']
|
|
|
|
|
|
# Schemas below describe parameters of Maelis wrapper around updateFamily endpoint
|
|
|
|
UPDATE_COORDINATE_SCHEMA = {
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'title': 'Update coordinate',
|
|
'description': "Mise à jour des coordonnées d'un responsable légal",
|
|
'type': 'object',
|
|
'properties': {
|
|
'adresse': ADDRESS_SCHEMA,
|
|
'contact': CONTACT_SCHEMA,
|
|
'profession': PROFESSION_SCHEMA,
|
|
'CAFInfo': CAFINFO_SCHEMA,
|
|
},
|
|
'unflatten': True,
|
|
}
|