From ae047130d882193378c80464bbe9a9999704375f Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Thu, 24 Nov 2022 08:25:06 +0100
Subject: [PATCH 2/5] toulouse-maelis: manage new fields on medical record
 (#71642)

---
 passerelle/contrib/toulouse_maelis/schemas.py | 32 +++++++++++++++++++
 .../Q_update_child_medical_record.xml         |  8 +++++
 tests/data/toulouse_maelis/R_read_family.xml  |  7 ++++
 .../toulouse_maelis/R_read_family_relax.xml   |  7 ++++
 .../R_read_family_reordered.xml               |  7 ++++
 tests/test_toulouse_maelis.py                 | 22 +++++++++----
 6 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/passerelle/contrib/toulouse_maelis/schemas.py b/passerelle/contrib/toulouse_maelis/schemas.py
index c677dd57..ab862364 100644
--- a/passerelle/contrib/toulouse_maelis/schemas.py
+++ b/passerelle/contrib/toulouse_maelis/schemas.py
@@ -337,16 +337,48 @@ MEDICALRECORD_SCHEMA = {
     '$schema': 'http://json-schema.org/draft-04/schema#',
     'title': 'Medical record',
     'description': "Informations médicales",
     'oneOf': [
         {
             'type': 'object',
             'properties': {
                 'familyDoctor': FAMILYDOCTOR_SCHEMA,
+                'allergy1': {
+                    'description': 'Allergie 1',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
+                'allergy2': {
+                    'description': 'Allergie 2',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
+                'comment1': {
+                    'description': 'Commentaire 1',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
+                'comment2': {
+                    'description': 'Commentaire 2',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
+                'observ1': {
+                    'description': 'Observation 1',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
+                'observ2': {
+                    'description': 'Observation 2',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
+                'isAuthHospital': {
+                    'description': "Autorisation d'hospitalisation",
+                    'oneOf': BOOLEAN_TYPES,
+                },
+                'hospital': {
+                    'description': 'Hopital',
+                    'oneOf': [{'type': 'string'}, {'type': 'null'}],
+                },
                 'vaccinList': {
                     'oneOf': [
                         {
                             'type': 'array',
                             'items': VACCIN_SCHEMA,
                         },
                         {'type': 'null'},
                     ],
diff --git a/tests/data/toulouse_maelis/Q_update_child_medical_record.xml b/tests/data/toulouse_maelis/Q_update_child_medical_record.xml
index 9cd3b0f4..e51972e7 100644
--- a/tests/data/toulouse_maelis/Q_update_child_medical_record.xml
+++ b/tests/data/toulouse_maelis/Q_update_child_medical_record.xml
@@ -16,16 +16,24 @@
             <name>Dre</name>
             <phone>0612341234</phone>
             <address>
               <street1>Alameda</street1>
               <zipcode>90220</zipcode>
               <town>Compton</town>
             </address>
           </familyDoctor>
+          <allergy1>butterscotch, imitation butterscotch, glow-in-the-dark monster make-up, and shrimp</allergy1>
+          <allergy2>cauliflower</allergy2>
+          <comment1>the shrimp allergy isn't fully identified</comment1>
+          <comment2/>
+          <observ1>Ay Caramba!</observ1>
+          <observ2/>
+          <isAuthHospital>true</isAuthHospital>
+          <hospital>Springfield General Hospital</hospital>
           <vaccinList>
             <code>DTC</code>
             <vaccinationDate>2011-01-11</vaccinationDate>
           </vaccinList>
           <vaccinList>
             <code>ROR</code>
             <vaccinationDate>2022-02-22</vaccinationDate>
           </vaccinList>
diff --git a/tests/data/toulouse_maelis/R_read_family.xml b/tests/data/toulouse_maelis/R_read_family.xml
index cc9c3c68..a2ac0818 100644
--- a/tests/data/toulouse_maelis/R_read_family.xml
+++ b/tests/data/toulouse_maelis/R_read_family.xml
@@ -125,16 +125,23 @@
               <name>DRE</name>
               <phone>0612341234</phone>
               <address>
                 <street1>Alameda</street1>
                 <zipcode>90220</zipcode>
                 <town>Compton</town>
               </address>
             </familyDoctor>
+            <allergy1>butterscotch, imitation butterscotch, glow-in-the-dark monster make-up</allergy1>
+            <allergy2>shrimp and cauliflower</allergy2>
+            <comment1>the shrimp allergy isn't fully identified</comment1>
+            <observ1>Ay Caramba!</observ1>
+            <observ2>Eat my shorts!</observ2>
+            <isAuthHospital>true</isAuthHospital>
+            <hospital>Springfield General Hospital</hospital>
             <vaccinList>
               <code>ROR</code>
               <label>ROUGEOLE-OREILLONS-RUBEOLE</label>
               <vaccinationDate>2012-02-22T00:00:00+01:00</vaccinationDate>
             </vaccinList>
             <vaccinList>
               <code>DTC</code>
               <label>DIPHTERIE TETANOS COQUELUCHE</label>
diff --git a/tests/data/toulouse_maelis/R_read_family_relax.xml b/tests/data/toulouse_maelis/R_read_family_relax.xml
index dda74651..0f9f1618 100644
--- a/tests/data/toulouse_maelis/R_read_family_relax.xml
+++ b/tests/data/toulouse_maelis/R_read_family_relax.xml
@@ -123,16 +123,23 @@
               <name>DRE</name>
               <phone>0612341234</phone>
               <address>
                 <street1>Alameda</street1>
                 <zipcode>90220</zipcode>
                 <town>Compton</town>
               </address>
             </familyDoctor>
+            <allergy1>butterscotch, imitation butterscotch, glow-in-the-dark monster make-up</allergy1>
+            <allergy2>shrimp and cauliflower</allergy2>
+            <comment1>the shrimp allergy isn't fully identified</comment1>
+            <observ1>Ay Caramba!</observ1>
+            <observ2>Eat my shorts!</observ2>
+            <isAuthHospital>true</isAuthHospital>
+            <hospital>Springfield General Hospital</hospital>
             <vaccinList>
               <code>ROR</code>
               <label>ROUGEOLE-OREILLONS-RUBEOLE</label>
               <vaccinationDate>2012-02-22T00:00:00+01:00</vaccinationDate>
             </vaccinList>
             <vaccinList>
               <code>DTC</code>
               <label>DIPHTERIE TETANOS COQUELUCHE</label>
diff --git a/tests/data/toulouse_maelis/R_read_family_reordered.xml b/tests/data/toulouse_maelis/R_read_family_reordered.xml
index 4c8b514f..aadfee96 100644
--- a/tests/data/toulouse_maelis/R_read_family_reordered.xml
+++ b/tests/data/toulouse_maelis/R_read_family_reordered.xml
@@ -124,16 +124,23 @@
               <name>DRE</name>
               <phone>0612341234</phone>
               <address>
                 <street1>Alameda</street1>
                 <zipcode>90220</zipcode>
                 <town>Compton</town>
               </address>
             </familyDoctor>
+            <allergy1>butterscotch, imitation butterscotch, glow-in-the-dark monster make-up</allergy1>
+            <allergy2>shrimp and cauliflower</allergy2>
+            <comment1>the shrimp allergy isn't fully identified</comment1>
+            <observ1>Ay Caramba!</observ1>
+            <observ2>Eat my shorts!</observ2>
+            <isAuthHospital>true</isAuthHospital>
+            <hospital>Springfield General Hospital</hospital>
             <vaccinList>
               <code>ROR</code>
               <label>ROUGEOLE-OREILLONS-RUBEOLE</label>
               <vaccinationDate>2012-02-22T00:00:00+01:00</vaccinationDate>
             </vaccinList>
             <vaccinList>
               <code>DTC</code>
               <label>DIPHTERIE TETANOS COQUELUCHE</label>
diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py
index f2da53a5..c7e377da 100644
--- a/tests/test_toulouse_maelis.py
+++ b/tests/test_toulouse_maelis.py
@@ -661,24 +661,24 @@ def test_read_family(mocked_post, mocked_get, read_family, con, app):
             'description': 'bla bla PAI',
         }
     assert resp.json['data']['childList'][0]['medicalRecord'] == {
         "familyDoctor": {
             "name": "DRE",
             "phone": "0612341234",
             "address": {"street1": "Alameda", "zipcode": "90220", "town": "Compton"},
         },
-        'allergy1': None,
-        'allergy2': None,
-        'comment1': None,
+        'allergy1': 'butterscotch, imitation butterscotch, glow-in-the-dark monster make-up',
+        'allergy2': 'shrimp and cauliflower',
+        'comment1': "the shrimp allergy isn't fully identified",
         'comment2': None,
-        'hospital': None,
-        'isAuthHospital': None,
-        'observ1': None,
-        'observ2': None,
+        'observ1': 'Ay Caramba!',
+        'observ2': 'Eat my shorts!',
+        'isAuthHospital': True,
+        'hospital': 'Springfield General Hospital',
         "vaccinList": [
             {
                 "code": "ROR",
                 "label": "ROUGEOLE-OREILLONS-RUBEOLE",
                 "vaccinationDate": "2012-02-22T00:00:00+01:00",
             },
             {
                 "code": "DTC",
@@ -2696,16 +2696,24 @@ def test_update_child_medical_record(mocked_post, mocked_get, con, app):
     mocked_post.side_effect = [READ_VACCIN, UPDATE_MEDICAL]
     url = get_endpoint('update-child-medical-record')
     params = {
         'familyDoctor/name': 'Dre',
         'familyDoctor/phone': '0612341234',
         'familyDoctor/address/street1': 'Alameda',
         'familyDoctor/address/zipcode': '90220',
         'familyDoctor/address/town': 'Compton',
+        'allergy1': 'butterscotch, imitation butterscotch, glow-in-the-dark monster make-up, and shrimp',
+        'allergy2': 'cauliflower',
+        'comment1': "the shrimp allergy isn't fully identified",
+        'comment2': None,
+        'observ1': 'Ay Caramba!',
+        'observ2': None,
+        'isAuthHospital': True,
+        'hospital': 'Springfield General Hospital',
         'vaccinList/0/code': 'DTC',
         'vaccinList/0/vaccinationDate': '2011-01-11',
         'vaccinList/1/code': 'ROR',
         'vaccinList/1/vaccinationDate': '2022-02-22',
     }
 
     Link.objects.create(resource=con, family_id='1312', name_id='local')
     resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
-- 
2.30.2

