Projet

Général

Profil

0005-toulouse_maelis-add-medical-record-webservice-69045.patch

Nicolas Roche, 13 septembre 2022 19:43

Télécharger (11,3 ko)

Voir les différences:

Subject: [PATCH 5/5] toulouse_maelis: add medical record webservice (#69045)

 passerelle/contrib/toulouse_maelis/models.py  | 22 ++++++++
 passerelle/contrib/toulouse_maelis/schemas.py |  7 +--
 .../Q_update_child_medical_record.xml         | 36 +++++++++++++
 .../R_update_child_medical_record.xml         |  5 ++
 ...update_child_medical_record_soap_error.xml |  8 +++
 tests/test_toulouse_maelis.py                 | 54 +++++++++++++++++++
 6 files changed, 129 insertions(+), 3 deletions(-)
 create mode 100644 tests/data/toulouse_maelis/Q_update_child_medical_record.xml
 create mode 100644 tests/data/toulouse_maelis/R_update_child_medical_record.xml
 create mode 100644 tests/data/toulouse_maelis/R_update_child_medical_record_soap_error.xml
passerelle/contrib/toulouse_maelis/models.py
666 666

  
667 667
        # use None to empty optional date passed as an empty string by date filter
668 668
        if post_data.get('dtcPrap1') == '':
669 669
            post_data['dtcPrap1'] = None
670 670

  
671 671
        self.call('Family', 'createOrUpdateFSL', arg0=child_id, arg1=post_data)
672 672
        return {'data': 'ok'}
673 673

  
674
    @endpoint(
675
        display_category='Famille',
676
        description="Créer ou mettre à jour les données médicales d'un enfant",
677
        name='update-child-medical-record',
678
        perm='can_access',
679
        parameters={
680
            'NameID': {'description': 'Publik NameID'},
681
            'child_id': {'description': "Numéro de l'enfant"},
682
        },
683
        post={'request_body': {'schema': {'application/json': schemas.MEDICALRECORD_SCHEMA}}},
684
    )
685
    def update_child_medical_record(self, request, NameID, child_id, post_data):
686
        self.get_link(NameID)
687
        self.replace_null_values(post_data)
688

  
689
        payload = {
690
            'numPerson': child_id,
691
            'medicalRecord': post_data,
692
        }
693
        self.call('Family', 'updateChildMedicalRecord', updateChildMedicalRecordRequest=payload)
694
        return {'data': 'ok'}
695

  
674 696

  
675 697
class Link(models.Model):
676 698
    resource = models.ForeignKey(ToulouseMaelis, on_delete=models.CASCADE)
677 699
    name_id = models.CharField(blank=False, max_length=256)
678 700
    family_id = models.CharField(blank=False, max_length=128)
679 701
    created = models.DateTimeField(auto_now_add=True)
680 702
    updated = models.DateTimeField(auto_now=True)
681 703

  
passerelle/contrib/toulouse_maelis/schemas.py
369 369
DOCTORADDRESS_SCHEMA = {
370 370
    '$schema': 'http://json-schema.org/draft-04/schema#',
371 371
    'title': 'Doctor address',
372 372
    'description': "Informations sur l'adresse du docteur",
373 373
    'type': 'object',
374 374
    'properties': {
375 375
        'street1': {
376 376
            'description': 'Libellé de la voie',
377
            'type': 'string',
377
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
378 378
        },
379 379
        'town': {
380 380
            'description': 'Ville',
381
            'type': 'string',
381
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
382 382
        },
383 383
        'zipcode': {
384 384
            'description': 'Code postal',
385
            'type': 'string',
385
            'oneOf': [{'type': 'null'}, {'type': 'string'}],
386 386
        },
387 387
    },
388 388
}
389 389

  
390 390
FAMILYDOCTOR_SCHEMA = {
391 391
    '$schema': 'http://json-schema.org/draft-04/schema#',
392 392
    'title': 'Family doctor',
393 393
    'description': "Informations sur le docteur",
......
444 444
                            'type': 'array',
445 445
                            'items': VACCIN_SCHEMA,
446 446
                        },
447 447
                    ],
448 448
                },
449 449
            },
450 450
        },
451 451
    ],
452
    'unflatten': True,
452 453
}
453 454

  
454 455
PAIINFO_SCHEMA = {
455 456
    '$schema': 'http://json-schema.org/draft-04/schema#',
456 457
    'title': 'PAI Info',
457 458
    'description': "Informations médicales",
458 459
    'oneOf': [
459 460
        {'type': 'null'},
tests/data/toulouse_maelis/Q_update_child_medical_record.xml
1
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
2
  <soap-env:Header>
3
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
4
      <wsse:UsernameToken>
5
        <wsse:Username>maelis-webservice</wsse:Username>
6
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
7
      </wsse:UsernameToken>
8
    </wsse:Security>
9
  </soap-env:Header>
10
  <soap-env:Body>
11
    <ns0:updateChildMedicalRecord xmlns:ns0="family.ws.maelis.sigec.com">
12
      <updateChildMedicalRecordRequest>
13
        <numPerson>613878</numPerson>
14
        <medicalRecord>
15
          <familyDoctor>
16
            <name>Dre</name>
17
            <phone>0612341234</phone>
18
            <address>
19
              <street1>Alameda</street1>
20
              <zipcode>90220</zipcode>
21
              <town>Compton</town>
22
            </address>
23
          </familyDoctor>
24
          <vaccinList>
25
            <code>DTC</code>
26
            <vaccinationDate>2011-01-11</vaccinationDate>
27
          </vaccinList>
28
          <vaccinList>
29
            <code>ROR</code>
30
            <vaccinationDate>2022-02-22</vaccinationDate>
31
          </vaccinList>
32
        </medicalRecord>
33
      </updateChildMedicalRecordRequest>
34
    </ns0:updateChildMedicalRecord>
35
  </soap-env:Body>
36
</soap-env:Envelope>
tests/data/toulouse_maelis/R_update_child_medical_record.xml
1
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2
  <soap:Body>
3
    <ns2:updateChildMedicalRecordResponse xmlns:ns2="family.ws.maelis.sigec.com"/>
4
  </soap:Body>
5
</soap:Envelope>
tests/data/toulouse_maelis/R_update_child_medical_record_soap_error.xml
1
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
2
  <soap:Body>
3
    <soap:Fault>
4
      <faultcode>soap:Client</faultcode>
5
      <faultstring>Unmarshalling Error: "2012-02-31" ne représente pas une valeur de calendrier grégorien XML valide. </faultstring>
6
    </soap:Fault>
7
  </soap:Body>
8
</soap:Envelope>
tests/test_toulouse_maelis.py
64 64
UPDATE_FAMILY = FakedResponse(content=get_xml_file('R_update_family.xml'), status_code=200)
65 65
UPDATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_update_family_error.xml'), status_code=200)
66 66
UPDATE_FAMILY_500 = FakedResponse(content=get_xml_file('R_update_family_soap_error.xml'), status_code=500)
67 67
UPDATE_DIETCODE = FakedResponse(content=get_xml_file('R_update_child_dietcode.xml'), status_code=200)
68 68
UPDATE_PAI = FakedResponse(content=get_xml_file('R_update_child_pai.xml'), status_code=200)
69 69
UPDATE_PAI_500 = FakedResponse(content=get_xml_file('R_update_child_pai_soap_error.xml'), status_code=500)
70 70
UPDATE_FSL = FakedResponse(content=get_xml_file('R_update_child_fsl.xml'), status_code=200)
71 71
UPDATE_FSL_500 = FakedResponse(content=get_xml_file('R_update_child_fsl_soap_error.xml'), status_code=500)
72
UPDATE_MEDICAL = FakedResponse(content=get_xml_file('R_update_child_fsl.xml'), status_code=200)
73
UPDATE_MEDICAL_500 = FakedResponse(
74
    content=get_xml_file('R_update_child_medical_record_soap_error.xml'), status_code=500
75
)
72 76

  
73 77

  
74 78
def assert_sent_payload(mocked_post, query_file):
75 79
    soap_sent = etree.tostring(etree.fromstring(mocked_post.call_args.kwargs['data']), pretty_print=True)
76 80
    expected = etree.tostring(etree.fromstring(get_xml_file(query_file)), pretty_print=True)
77 81
    assert soap_sent.decode() == expected.decode()
78 82

  
79 83

  
......
1527 1531
    }
1528 1532

  
1529 1533
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1530 1534
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
1531 1535
    assert resp.json['err'] == 'Family-createOrUpdateFSL-soap:Server'
1532 1536
    assert 'Une erreur est survenue' in resp.json['err_desc']
1533 1537
    assert 'valeur trop grande' in resp.json['err_desc']
1534 1538
    assert 'maximum : 70' in resp.json['err_desc']
1539

  
1540

  
1541
@mock.patch('passerelle.utils.Request.get')
1542
@mock.patch('passerelle.utils.Request.post')
1543
def test_update_child_medical_record(mocked_post, mocked_get, con, app):
1544
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1545
    mocked_post.return_value = UPDATE_MEDICAL
1546
    url = get_endpoint('update-child-medical-record')
1547
    params = {
1548
        'familyDoctor/name': 'Dre',
1549
        'familyDoctor/phone': '0612341234',
1550
        'familyDoctor/address/street1': 'Alameda',
1551
        'familyDoctor/address/zipcode': '90220',
1552
        'familyDoctor/address/town': 'Compton',
1553
        'vaccinList/0/code': 'DTC',
1554
        'vaccinList/0/vaccinationDate': '2011-01-11',
1555
        'vaccinList/1/code': 'ROR',
1556
        'vaccinList/1/vaccinationDate': '2022-02-22',
1557
    }
1558

  
1559
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1560
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
1561
    assert_sent_payload(mocked_post, 'Q_update_child_medical_record.xml')
1562
    assert resp.json['err'] == 0
1563
    assert resp.json['data'] == 'ok'
1564

  
1565

  
1566
def test_update_child_medical_record_not_linked_error(con, app):
1567
    url = get_endpoint('update-child-medical-record')
1568

  
1569
    resp = app.post_json(url + '?NameID=local&child_id=613878', params={})
1570
    assert resp.json['err'] == 'not-linked'
1571
    assert resp.json['err_desc'] == 'User not linked to family'
1572

  
1573

  
1574
@mock.patch('passerelle.utils.Request.get')
1575
@mock.patch('passerelle.utils.Request.post')
1576
def test_update_child_medical_record_soap_error(mocked_post, mocked_get, con, app):
1577
    mocked_get.return_value = FAMILY_SERVICE_WSDL
1578
    mocked_post.return_value = UPDATE_MEDICAL_500
1579
    url = get_endpoint('update-child-medical-record')
1580
    params = {
1581
        'vaccinList/0/vaccinationDate': '2022-02-31',
1582
    }
1583

  
1584
    Link.objects.create(resource=con, family_id='1312', name_id='local')
1585
    resp = app.post_json(url + '?NameID=local&child_id=613878', params=params)
1586
    assert resp.json['err'] == 'Family-updateChildMedicalRecord-soap:Client'
1587
    assert 'Unmarshalling Error' in resp.json['err_desc']
1588
    assert 'pas une valeur de calendrier grégorien' in resp.json['err_desc']
1535
-