Projet

Général

Profil

0001-toulouse-maelis-rename-person-schemas-71646.patch

Nicolas Roche, 24 novembre 2022 11:56

Télécharger (13 ko)

Voir les différences:

Subject: [PATCH 1/3] toulouse-maelis: rename person schemas (#71646)

 passerelle/contrib/toulouse_maelis/models.py  |   8 +-
 passerelle/contrib/toulouse_maelis/schemas.py | 204 +++++++++---------
 2 files changed, 109 insertions(+), 103 deletions(-)
passerelle/contrib/toulouse_maelis/models.py
840 840
    @endpoint(
841 841
        display_category='Famille',
842 842
        description="Création d'une personne à prévenir en cas d'urgence",
843 843
        name='create-person',
844 844
        perm='can_access',
845 845
        parameters={
846 846
            'NameID': {'description': 'Publik NameID'},
847 847
        },
848
        post={'request_body': {'schema': {'application/json': schemas.FAMILYPERSON_SCHEMA}}},
848
        post={'request_body': {'schema': {'application/json': schemas.EMERGENCY_PERSON_SCHEMA}}},
849 849
    )
850 850
    def create_person(self, request, NameID, post_data):
851 851
        family_id = self.get_link(NameID).family_id
852 852
        family = self.get_family_raw(family_id)
853 853
        self.assert_person_payload_in_referential(post_data)
854 854

  
855 855
        personList = family['emergencyPersonList']
856 856
        personList.append(post_data)
......
871 871
        display_category='Famille',
872 872
        description="Mise à jour d'une personne à prévenir en cas d'urgence",
873 873
        name='update-person',
874 874
        perm='can_access',
875 875
        parameters={
876 876
            'NameID': {'description': 'Publik NameID'},
877 877
            'person_id': {'description': 'Numéro de la personne'},
878 878
        },
879
        post={'request_body': {'schema': {'application/json': schemas.FAMILYPERSON_SCHEMA}}},
879
        post={'request_body': {'schema': {'application/json': schemas.EMERGENCY_PERSON_SCHEMA}}},
880 880
    )
881 881
    def update_person(self, request, NameID, person_id, post_data):
882 882
        family_id = self.get_link(NameID).family_id
883 883
        family = self.get_family_raw(family_id)
884 884
        self.assert_person_payload_in_referential(post_data)
885 885

  
886 886
        personList = family['emergencyPersonList']
887 887
        for i, person in enumerate(personList):
......
947 947
        display_category='Famille',
948 948
        description="Création d'une personne autorisée à récupérer l'enfant",
949 949
        name='create-child-person',
950 950
        perm='can_access',
951 951
        parameters={
952 952
            'NameID': {'description': 'Publik NameID'},
953 953
            'child_id': {'description': "Numéro de l'enfant"},
954 954
        },
955
        post={'request_body': {'schema': {'application/json': schemas.CHILDPERSON2_SCHEMA}}},
955
        post={'request_body': {'schema': {'application/json': schemas.AUTHORIZED_PERSON_SCHEMA}}},
956 956
    )
957 957
    def create_child_person(self, request, NameID, child_id, post_data):
958 958
        family_id = self.get_link(NameID).family_id
959 959
        child = self.get_child_raw(family_id, child_id)
960 960
        self.assert_child_person_payload_in_referential(post_data)
961 961

  
962 962
        personList = child['authorizedPersonList']
963 963
        personList.append(post_data)
......
976 976
        description="Mise à jour d'une personne autorisée à récupérer l'enfant",
977 977
        name='update-child-person',
978 978
        perm='can_access',
979 979
        parameters={
980 980
            'NameID': {'description': 'Publik NameID'},
981 981
            'child_id': {'description': "Numéro de l'enfant"},
982 982
            'person_id': {'description': 'Numéro de la personne'},
983 983
        },
984
        post={'request_body': {'schema': {'application/json': schemas.CHILDPERSON2_SCHEMA}}},
984
        post={'request_body': {'schema': {'application/json': schemas.AUTHORIZED_PERSON_SCHEMA}}},
985 985
    )
986 986
    def update_child_person(self, request, NameID, child_id, person_id, post_data):
987 987
        family_id = self.get_link(NameID).family_id
988 988
        child = self.get_child_raw(family_id, child_id)
989 989
        self.assert_child_person_payload_in_referential(post_data)
990 990

  
991 991
        personList = child['authorizedPersonList']
992 992
        for i, person in enumerate(personList):
passerelle/contrib/toulouse_maelis/schemas.py
61 61
    'title': 'Exist',
62 62
    'description': "Recherche d'un responsable légal ou d'un enfant dans Maelis",
63 63
    'type': 'object',
64 64
    'required': ['firstname', 'lastname', 'dateBirth'],
65 65
    'properties': BASIC_ID_PROPERTIES,
66 66
    'additionalProperties': False,
67 67
}
68 68

  
69

  
70
CONTACTLIGHT_SCHEMA = {
71
    '$schema': 'http://json-schema.org/draft-04/schema#',
72
    'title': 'Contact light',
73
    'description': "Informations de contact pour les personnes autorisées à récupérer les enfants ou à prévenir en cas d'urgence",
74
    'type': 'object',
75
    'properties': {
76
        'phone': {
77
            'description': 'Téléphone',
78
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
79
        },
80
        'mobile': {
81
            'description': 'Portable',
82
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
83
        },
84
        'mail': {
85
            'description': 'Mail',
86
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
87
        },
88
    },
89
}
90

  
91

  
92
PERSON_PROPERTIES = {
93
    'civility': {
94
        'description': 'civilité (depuis référentiel)',
95
        'oneOf': [{'type': 'string'}, {'type': 'null'}],
96
    },
97
    'sexe': {
98
        'description': 'Sexe (depuis référentiel)',
99
        'oneOf': [{'type': 'string'}, {'type': 'null'}],
100
    },
101
    'contact': {'oneOf': [CONTACTLIGHT_SCHEMA, {'type': 'null'}]},
102
}
103
PERSON_PROPERTIES.update(BASIC_ID_PROPERTIES)
104

  
105

  
106
EMERGENCY_PERSON_SCHEMA = {
107
    '$schema': 'http://json-schema.org/draft-04/schema#',
108
    'title': 'Emergency person',
109
    'description': "Personnes à prévenir en cas d'urgence",
110
    'type': 'object',
111
    'required': ['firstname', 'lastname', 'dateBirth', 'quality'],
112
    'properties': {
113
        'quality': {
114
            'description': 'Qualité',
115
            'type': 'string',
116
            'pattern': '.+',
117
        },
118
    },
119
    'unflatten': True,
120
    'additionalProperties': False,
121
}
122
EMERGENCY_PERSON_SCHEMA['properties'].update(PERSON_PROPERTIES)
123

  
124

  
125
EMERGENCY_PERSON_LIST_SCHEMA = {
126
    '$schema': 'http://json-schema.org/draft-04/schema#',
127
    'title': 'Family persons',
128
    'description': "Liste des personnes à prévenir en cas d'urgence",
129
    'type': 'object',
130
    'properties': {
131
        'personList': {
132
            'oneOf': [
133
                {
134
                    'type': 'array',
135
                    'items': EMERGENCY_PERSON_SCHEMA,
136
                },
137
                {'type': 'null'},
138
            ],
139
        },
140
    },
141
}
142

  
143

  
144
AUTHORIZED_PERSON_SCHEMA = {
145
    '$schema': 'http://json-schema.org/draft-04/schema#',
146
    'title': 'Family persons',
147
    'description': "Personnes autorisées à venir chercher l'enfant",
148
    'type': 'object',
149
    'required': ['personInfo', 'personQuality'],
150
    'properties': {
151
        'personInfo': {
152
            'type': 'object',
153
            'required': ['firstname', 'lastname', 'dateBirth'],
154
            'properties': PERSON_PROPERTIES,
155
        },
156
        'personQuality': {
157
            'type': 'object',
158
            'required': ['code'],
159
            'properties': {
160
                'code': {
161
                    'description': 'Le code (depuis référentiel)',
162
                    'type': 'string',
163
                    'pattern': '.+',
164
                },
165
            },
166
        },
167
    },
168
    'additionalProperties': False,
169
    'unflatten': True,
170
}
171

  
172

  
69 173
BIRTH_SCHEMA = {
70 174
    '$schema': 'http://json-schema.org/draft-04/schema#',
71 175
    'title': 'Birth info',
72 176
    'description': "Informations relatives à la naissance",
73 177
    'type': 'object',
74 178
    'required': ['dateBirth'],
75 179
    'properties': {
76 180
        'dateBirth': {
......
448 552
        },
449 553
        'medicalRecord': {'oneOf': [MEDICALRECORD_SCHEMA, {'type': 'null'}]},
450 554
        'paiInfoBean': {'oneOf': [PAIINFO_SCHEMA, {'type': 'null'}]},
451 555
    },
452 556
    'additionalProperties': False,
453 557
}
454 558
CHILD_SCHEMA['properties'].update(ID_PROPERTIES)
455 559

  
456
CONTACTLIGHT_SCHEMA = {
457
    '$schema': 'http://json-schema.org/draft-04/schema#',
458
    'title': 'Contact light',
459
    'description': "Informations de contact pour les personnes autorisées à récupérer les enfants ou à prévenir en cas d'urgence",
460
    'type': 'object',
461
    'properties': {
462
        'phone': {
463
            'description': 'Téléphone',
464
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
465
        },
466
        'mobile': {
467
            'description': 'Portable',
468
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
469
        },
470
        'mail': {
471
            'description': 'Mail',
472
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
473
        },
474
    },
475
}
476

  
477
FAMILYPERSON_SCHEMA = {
478
    '$schema': 'http://json-schema.org/draft-04/schema#',
479
    'title': 'Family person',
480
    'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence",
481
    'type': 'object',
482
    'required': ['firstname', 'lastname', 'dateBirth', 'quality'],
483
    'properties': {
484
        'civility': {
485
            'description': 'civilité (depuis référentiel)',
486
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
487
        },
488
        'quality': {
489
            'description': 'Qualité',
490
            'type': 'string',
491
            'pattern': '.+',
492
        },
493
        'sexe': {
494
            'description': 'Sexe (depuis référentiel)',
495
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
496
        },
497
        'contact': {'oneOf': [CONTACTLIGHT_SCHEMA, {'type': 'null'}]},
498
    },
499
    'unflatten': True,
500
    'additionalProperties': False,
501
}
502
FAMILYPERSON_SCHEMA['properties'].update(BASIC_ID_PROPERTIES)
503

  
504
AUTHORIZEDPERSON_SCHEMA = {
505
    '$schema': 'http://json-schema.org/draft-04/schema#',
506
    'title': 'Family persons',
507
    'description': "Informations sur les personnes autorisées à venir chercher les enfants ou à prévenir en cas d'urgence",
508
    'type': 'object',
509
    'properties': {
510
        'personList': {
511
            'oneOf': [
512
                {
513
                    'type': 'array',
514
                    'items': FAMILYPERSON_SCHEMA,
515
                },
516
                {'type': 'null'},
517
            ],
518
        },
519
    },
520
}
521

  
522 560
UPDATE_FAMILY_SCHEMA = {
523 561
    '$schema': 'http://json-schema.org/draft-04/schema#',
524 562
    'title': 'Family',
525 563
    'description': 'Informations pour créer ou mettre à jour une famille',
526 564
    'type': 'object',
527 565
    'required': ['category', 'situation'],
528 566
    'properties': {
529 567
        'category': {
......
553 591
            'oneOf': [{'type': 'string'}, {'type': 'null'}],
554 592
        },
555 593
        'rl1': RLINFO_SCHEMA,
556 594
        'rl2': RLINFO_SCHEMA,
557 595
        'emergencyPersonList': {
558 596
            'oneOf': [
559 597
                {
560 598
                    'type': 'array',
561
                    'items': AUTHORIZEDPERSON_SCHEMA,
599
                    'items': EMERGENCY_PERSON_LIST_SCHEMA,
562 600
                },
563 601
                {'type': 'null'},
564 602
            ],
565 603
        },
566 604
        'childList': {
567 605
            'oneOf': [
568 606
                {
569 607
                    'type': 'array',
......
621 659
        'adresse': ADDRESS_SCHEMA,
622 660
        'contact': {'oneOf': [CONTACT_SCHEMA, {'type': 'null'}]},
623 661
        'profession': {'oneOf': [PROFESSION_SCHEMA, {'type': 'null'}]},
624 662
        'CAFInfo': {'oneOf': [CAFINFO_SCHEMA, {'type': 'null'}]},
625 663
    },
626 664
    'unflatten': True,
627 665
    'additionalProperties': False,
628 666
}
629

  
630
CHILDPERSON_SCHEMA = copy.deepcopy(FAMILYPERSON_SCHEMA)
631
CHILDPERSON_SCHEMA['required'] = ['firstname', 'lastname', 'dateBirth']
632
del CHILDPERSON_SCHEMA['properties']['quality']
633

  
634
PERSONQUALITY_SCHEMA = {
635
    '$schema': 'http://json-schema.org/draft-04/schema#',
636
    'title': 'Child person quality',
637
    'description': "Informations sur la qualité des personnes autorisées à venir chercher l'enfant",
638
    'type': 'object',
639
    'required': ['code'],
640
    'properties': {
641
        'code': {
642
            'description': 'Le code (depuis référentiel)',
643
            'type': 'string',
644
            'pattern': '.+',
645
        },
646
    },
647
}
648

  
649
CHILDPERSON2_SCHEMA = {
650
    '$schema': 'http://json-schema.org/draft-04/schema#',
651
    'title': 'Family persons',
652
    'description': "Informations sur les personnes autorisées à venir chercher l'enfant avec leur qualité",
653
    'type': 'object',
654
    'required': ['personInfo', 'personQuality'],
655
    'properties': {
656
        'personInfo': CHILDPERSON_SCHEMA,
657
        'personQuality': PERSONQUALITY_SCHEMA,
658
    },
659
    'unflatten': True,
660
}
661
-