Hello

Je suis debutant en javascript et j’ai encore du mal avec la notion des promesses.
Dans mon exemple ja’i deux fonctions, une pour recuperer des donnees patients et une autre pour recuperer ses conditions (diagnostics)

bien sur le console.log dans les deux fonctions fonctionnent tres bien mais je ne ne recupere rien dans le return.
Que dois je changer pour recuperer mon tableau de donnees datawiz en retour de la fonction getPatientConditions?

Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html> 
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/ >
		<title>EyeC1</title>
		<script src='http://code.jquery.com/jquery-2.1.4.min.js'></script>
        <script src='fhir-client.js'></script>
 
 
	</head>
	<body>
 
		<div class="eyeChart"></div>
 
		<script src="eyeChart.js"></script>
		<script>
            // recuperer l'IPP depuis l'URL (contexte patient)
            
            var IPP = getUrlVars()["IPP"];
            var patient = {
                serviceUrl: "https://r2.smarthealthit.org",
                patientId: IPP,
                auth: {
                    type: 'none'
                }
            };
            
           
            
            getPatientData(patient);
            getPatientConditions(patient);
 
            
            
            //******************** Fonctions
            function getUrlVars() {
                var vars = {};
                var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                    vars[key] = value;
                });
                return vars;
            }
            function getPatientData(patient){
 
                var eyeDiagFHIR = FHIR.client(patient);
                var monPatient = eyeDiagFHIR.patient.read();
                var formatted="";
                monPatient.then(function(p) {
                    var name = p.name[0]; // a ameliorer et recuperer un nom, prenom de type exact
                    var gender = p.gender;
                    var DN = p.birthDate;
                    var formatted = name.given.join(" ") + " " + name.family.join(" ");
                    console.log(formatted);
                });
                return formatted;
            }
            function getPatientConditions(patient){
                var eyeDiagFHIR = FHIR.client(patient);
                //  reccuperer les conditions du patient
                var datawiz=[];
                // call the function
                //function getConditions(IPP)
                eyeDiagFHIR.patient.api.search({type: 'Condition'}).then(function(results){  
                    // boucler sur le tableau des conditions
                    results.data.entry.forEach(function(condition){
                        diagDate = condition.resource.onsetDateTime;
                        // il est possible d'avoir plusieurs codes pour le meme diag (on considere qu'il y en a 1 seul)
                        condition.resource.code.coding.forEach(function(codes){  
                            diagnostic = codes.code;
                            const request = async () => {
                                const urlSev = "https://bridge.buddyweb.fr/api/cim10snomedald/cim10nomenclature?cim_code="+codes.code;
                                const response = await fetch(urlSev);
                                const json = await response.json();
                                total = json[0].cim_total;
                                index = json[0].cim_index;
                                cmd = json[0].cim_cmd;
                                libelle = json[0].cim_libelle;
                                severite = json[0].cim_niveau_de_severite;
                                datawiz.push({axis:cmd,value:severite,date:diagDate,libelle:libelle,index:index,total:total});
                                console.log(datawiz);
                            }
                            request();
                            return (datawiz);
                        }) 
                    })
                });     
            }
                </script>
	</body>
</html>