From 261f4022c9e4ecf1d155b5f6d96f9364e3b725b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Wed, 3 Apr 2024 17:08:49 +0200 Subject: [PATCH 01/15] Calendrier apache --- Request_Test/testHTTP.http | 17 +++++++++++++++++ src/API/requests.php | 25 ++++++++++++++++++------- src/php/db/Calendrier.php | 20 +++++++++++++++----- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index 4286906..abecd6a 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -1,4 +1,21 @@ +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?location=44&type=Généraliste +Accept: application/json + +### +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?location=44 +Accept: application/json + +### GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?type=Généraliste Accept: application/json ### + +GET http://serveur-projet-s4.felix/src/API/requests.php/api/rdv-time?id=1 +Accept: application/json + +### +GET http://serveur-projet-s4.felix/src/API/requests.php/api/rdv-date?date=2024-03-18&id=1 +Accept: application/json + +### \ No newline at end of file diff --git a/src/API/requests.php b/src/API/requests.php index 83b4d2b..3825028 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -4,6 +4,7 @@ require_once 'src/router.php'; require_once '../php/constants.php'; require_once '../php/db/dbconnect.php'; require_once '../php/db/Search.php'; +require_once '../php/db/Calendrier.php'; ini_set('display_errors', 1); error_reporting(E_ALL); $pdo = dbConnect(); @@ -15,22 +16,32 @@ $router->GET('/api/requests', ["test"], function($test){ echo json_encode($test); }); -$router->GET('/api/search', ["type"], function($type){ +$router->GET('/api/search', ["type", "location"], function($type = null, $location = null){ global $pdo; - searchDoctor($pdo, $type); + if ($type && $location){ + searchDoctorByLocation($pdo, $location, $type); + } + else if ($type){ + searchDoctor($pdo, $type); + } + else if ($location) { + searchDoctorByLocation($pdo, $location); + } + else { + echo json_encode([]); + } }); -$router->GET('/api/search', ["type", "location"], function($type, $location){ +$router->GET('/api/rdv-time', ["id"], function($id){ global $pdo; - searchDoctorByLocation($pdo, $location, $type); + selectRDVTimeByID($pdo, $id); }); -$router->GET('/api/search', ["location"], function($location){ +$router->GET('/api/rdv-date', ["date", "id"], function($date, $id){ global $pdo; - searchDoctorByLocation($pdo, $location); + selectRDVForDate($pdo, $date, $id); }); - $router->POST('/api/requests', ["test"], function($test){ echo json_encode($test); }); diff --git a/src/php/db/Calendrier.php b/src/php/db/Calendrier.php index ab18ec9..f9d6fbc 100644 --- a/src/php/db/Calendrier.php +++ b/src/php/db/Calendrier.php @@ -1,20 +1,24 @@ prepare("SELECT * FROM rendez_vous WHERE rdv_id = :id"); $query->bindParam(':id', $id); $query->execute(); $result = $query->fetchAll(); if (!empty($result)) { - return $result[0]['rdv_time']; + Response::HTTP200($result[0]['rdv_time']); } else { - return null; + Response::HTTP404(['error' => 'Rendez-vous not found']); } } -function selectRDVForDate($pdo, $date, $medecin){ +function selectRDVForDate($pdo, $date, $medecin): void +{ $availableHours = array(); $query = $pdo->prepare("select * from rendez_vous rdv join public.propose p using (rdv_id) where p.m_id = :m_id and rdv.rdv_date = :date AND rdv.p_id IS NULL ORDER BY rdv_time ASC"); $query->bindParam(':date', $date); @@ -24,9 +28,14 @@ function selectRDVForDate($pdo, $date, $medecin){ foreach ($outerResult as $row) { array_push($availableHours, $row['rdv_id']); } - return $availableHours; + // Check if the array is empty + if (empty($availableHours)) { + Response::HTTP404(['error' => 'No available hours']); + } + Response::HTTP200($availableHours); } +/* function displayRDVForDate($pdo, $date, $medecin){ $availableHours = selectRDVForDate($pdo, $date, $medecin); if(!$availableHours){ @@ -78,5 +87,6 @@ function addRDVToDBThenRedirect($pdo, $rdv, $patient){ //Redirect to the rdv.php page echo ''; } +*/ ?> \ No newline at end of file From 22cf6cd26f13fd5f509b28077e96eb01fe9fa633 Mon Sep 17 00:00:00 2001 From: sinbad Date: Wed, 3 Apr 2024 17:09:01 +0200 Subject: [PATCH 02/15] PUTAIN D'ERREUR 500 --- src/API/requests.php | 6 ++++++ src/API/test/database.php | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/API/requests.php b/src/API/requests.php index 83b4d2b..46af2ac 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -4,6 +4,7 @@ require_once 'src/router.php'; require_once '../php/constants.php'; require_once '../php/db/dbconnect.php'; require_once '../php/db/Search.php'; +require_once 'test/database.php'; ini_set('display_errors', 1); error_reporting(E_ALL); $pdo = dbConnect(); @@ -43,4 +44,9 @@ $router->DELETE('/api/requests', ["test"], function($test){ echo json_encode($test); }); +$router->GET('/api/rdv-praticient', ["id"], function($id){ + global $pdo; + dbRequestRdvPraticien($pdo, $id); +}); + $router->run(); diff --git a/src/API/test/database.php b/src/API/test/database.php index 14bd436..1f3eb8b 100644 --- a/src/API/test/database.php +++ b/src/API/test/database.php @@ -1,7 +1,8 @@ fetchAll(PDO::FETCH_ASSOC); if (!empty($result)) { - return $result; + Response::HTTP200($result); } else { - return null; + Response::HTTP404(["error" => "No data found"]); } } From 04c479ef532a12cefcc059bb34b114733e0badd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Wed, 3 Apr 2024 17:33:52 +0200 Subject: [PATCH 03/15] Change route to avoid route override and test --- Request_Test/testHTTP.http | 6 +++--- src/API/requests.php | 25 ++++++++++++------------- src/API/test/search.php | 35 ----------------------------------- 3 files changed, 15 insertions(+), 51 deletions(-) delete mode 100644 src/API/test/search.php diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index abecd6a..ce4ede8 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -1,12 +1,12 @@ -GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?location=44&type=Généraliste +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?type=Généraliste&location=35 Accept: application/json ### -GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?location=44 +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search-location?location=44 Accept: application/json ### -GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?type=Généraliste +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search-type?type=Généraliste Accept: application/json ### diff --git a/src/API/requests.php b/src/API/requests.php index 3825028..c5b7b0e 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -16,20 +16,19 @@ $router->GET('/api/requests', ["test"], function($test){ echo json_encode($test); }); -$router->GET('/api/search', ["type", "location"], function($type = null, $location = null){ +$router->GET('/api/search-type', ["type"], function($type){ global $pdo; - if ($type && $location){ - searchDoctorByLocation($pdo, $location, $type); - } - else if ($type){ - searchDoctor($pdo, $type); - } - else if ($location) { - searchDoctorByLocation($pdo, $location); - } - else { - echo json_encode([]); - } + searchDoctor($pdo, $type); +}); + +$router->GET('/api/search-location', ["location"], function($location){ + global $pdo; + searchDoctorByLocation($pdo, $location); +}); + +$router->GET('/api/search', ["type", "location"], function($type, $location){ + global $pdo; + searchDoctorByLocation($pdo, $location, $type); }); $router->GET('/api/rdv-time', ["id"], function($id){ diff --git a/src/API/test/search.php b/src/API/test/search.php deleted file mode 100644 index aa47afb..0000000 --- a/src/API/test/search.php +++ /dev/null @@ -1,35 +0,0 @@ - Date: Wed, 3 Apr 2024 17:39:43 +0200 Subject: [PATCH 04/15] /api/rdv-praticient --- src/API/requests.php | 2 ++ src/API/test/database.php | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/API/requests.php b/src/API/requests.php index 46af2ac..ca31427 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -49,4 +49,6 @@ $router->GET('/api/rdv-praticient', ["id"], function($id){ dbRequestRdvPraticien($pdo, $id); }); + + $router->run(); diff --git a/src/API/test/database.php b/src/API/test/database.php index 1f3eb8b..a211b81 100644 --- a/src/API/test/database.php +++ b/src/API/test/database.php @@ -1,6 +1,5 @@ Date: Wed, 3 Apr 2024 17:41:08 +0200 Subject: [PATCH 05/15] WIP (Felix lit ton error.log la prochaine fois) faut le js et le php --- src/js/AJAX/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 763bdf1..7f3de02 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -1,8 +1,10 @@ +console.log("index.js loaded"); + //Search type = document.getElementById("nom").value; postal = document.getElementById("postal").value; document.getElementById("button-addon2").addEventListener("click", function() { - ajaxRequest('GET',"src/API/test/search.php?type=" + type + "&postal=" + postal, displaySearchResults); + ajaxRequest('GET',"src/API/requests.php/api/search?type=" + type + "&postal=" + postal, displaySearchResults); }); function displaySearchResults(data) { From 6fdf04db9a3404c9e161da2eecf95ef2448510a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Fri, 5 Apr 2024 10:50:12 +0200 Subject: [PATCH 06/15] Add Ajax display WIP for the number of rdv --- Request_Test/testHTTP.http | 7 ++- index.php | 27 ++++++------ src/API/requests.php | 13 ++++-- src/css/styles.css | 22 +++++++++- src/js/AJAX/index.js | 88 ++++++++++++++++++++++++++++++-------- src/php/db/Search.php | 17 ++++++++ 6 files changed, 138 insertions(+), 36 deletions(-) diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index ce4ede8..93e7af9 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -2,7 +2,7 @@ GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?type=Généra Accept: application/json ### -GET http://serveur-projet-s4.felix/src/API/requests.php/api/search-location?location=44 +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search-postal?postal=44 Accept: application/json ### @@ -18,4 +18,9 @@ Accept: application/json GET http://serveur-projet-s4.felix/src/API/requests.php/api/rdv-date?date=2024-03-18&id=1 Accept: application/json +### + +GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?type=G%C3%A9n%C3%A9raliste&postal=35 +Accept: application/json + ### \ No newline at end of file diff --git a/index.php b/index.php index 1212c0b..86ea056 100644 --- a/index.php +++ b/index.php @@ -28,28 +28,31 @@ $pdo = dbConnect(); ?>
- -

- Doct'ISEN -

-
-
- + +
+ img_index

Trouvez un rendez vous avec un medecin

-
+ - +
- img_index
diff --git a/src/API/requests.php b/src/API/requests.php index c5b7b0e..3d2fd02 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -21,14 +21,19 @@ $router->GET('/api/search-type', ["type"], function($type){ searchDoctor($pdo, $type); }); -$router->GET('/api/search-location', ["location"], function($location){ +$router->GET('/api/search-postal', ["postal"], function($postal){ global $pdo; - searchDoctorByLocation($pdo, $location); + searchDoctorByLocation($pdo, $postal); }); -$router->GET('/api/search', ["type", "location"], function($type, $location){ +$router->GET('/api/search', ["type", "postal"], function($type, $postal){ global $pdo; - searchDoctorByLocation($pdo, $location, $type); + searchDoctorByLocation($pdo, $postal, $type); +}); + +$router->GET('/api/rdv', ["id"], function($id){ + global $pdo; + getNumberOfRDVByMedecin($pdo, $id); }); $router->GET('/api/rdv-time', ["id"], function($id){ diff --git a/src/css/styles.css b/src/css/styles.css index 959a2e4..6e5385c 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -1,13 +1,31 @@ +body{ + display: flex; + flex-direction: column; + margin: 0; + padding: 0; + font-family: 'Roboto', sans-serif; +} + #DoctISEN{ font-family: 'Just Me Again Down Here', cursive; color: white; - font-size: 36px + font-size: 36px; + margin-left: 0.5rem; + margin-top: 0; + cursor: pointer; } #topbar{ background-color: #ff0000; - height: 6vh; + height: 22vh; width: 100%; + display: flex; + flex-direction: column; + gap: 1em; +} + +#topInfo{ + height: 5vh; } #acceuil{ diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 7f3de02..50f3098 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -1,19 +1,10 @@ console.log("index.js loaded"); -//Search -type = document.getElementById("nom").value; -postal = document.getElementById("postal").value; -document.getElementById("button-addon2").addEventListener("click", function() { - ajaxRequest('GET',"src/API/requests.php/api/search?type=" + type + "&postal=" + postal, displaySearchResults); -}); - function displaySearchResults(data) { - container = document.getElementById("content"); + let container = document.getElementById("content"); container.innerHTML = ""; - // Create a div for the result with the following classes d-flex flex-row flex-wrap mx-5 gap-5 - mainDiv = document.createElement("div"); + let mainDiv = document.createElement("div"); mainDiv.classList.add("d-flex", "flex-row", "flex-wrap", "mx-5", "gap-5"); - // for each data of the json, create a card and append it to the mainDiv and count the number of results let count = 0; data.forEach(function(element) { count++; @@ -27,20 +18,83 @@ function displaySearchResults(data) {
-
${element.name}
-
${element.type}
-

Disponibilité: ${element.disponibility}

+
${element.m_surname} ${element.m_name}
+
${element.m_specialty}
+

Code Postal: ${element.m_postal}

+ +

Disponibilités: ${element.m_availabilities}

`; mainDiv.appendChild(card); }); + container.appendChild(mainDiv); if(count === 0) { mainDiv.innerHTML = "

Aucun résultats

"; } else { - mainDiv.innerHTML = "

" + count + " résultats

"; - container.appendChild(mainDiv); + let resultText = document.createElement("h1"); + resultText.textContent = count + " résultats"; + container.insertBefore(resultText, mainDiv); } -} \ No newline at end of file +} + +function displaySearchTopBar(){ + let topbar = document.getElementById("topbar"); + let searchbar = document.getElementById("searchbar"); + + let form = topbar.querySelector("form"); + if (form) { + topbar.removeChild(form); + } + + searchbar.innerHTML = ` +
+ + + +
`; + + attachSearchEventListener(); +} + +function performSearch(event){ + event.preventDefault(); + let type = document.getElementById("nom").value; + let postal = document.getElementById("postal").value; + if(postal === ""){ + if(type === "") { + alert("Veuillez remplir au moins un champ"); + return; + } + else{ + ajaxRequest('GET', "src/API/requests.php/api/search-type?type=" + type, function (data){ + displaySearchResults(data); + displaySearchTopBar(); + }) + } + } + else if(type === "") { + ajaxRequest('GET', "src/API/requests.php/api/search-postal?postal=" + postal, function (data){ + displaySearchResults(data); + displaySearchTopBar(); + }); + } + else{ + ajaxRequest('GET', "src/API/requests.php/api/search?type=" + type + "&postal=" + postal, function(data){ + displaySearchResults(data); + displaySearchTopBar(); + }); + } +} + +function attachSearchEventListener() { + document.getElementById("recherche").addEventListener("click", function(event) { + performSearch(event); + }); +} + + + +attachSearchEventListener(); \ No newline at end of file diff --git a/src/php/db/Search.php b/src/php/db/Search.php index 8a4a294..d77ea96 100644 --- a/src/php/db/Search.php +++ b/src/php/db/Search.php @@ -296,5 +296,22 @@ function searchDoctorByLocation($pdo, $location, $type = null): void } } +function getNumberOfRDVByMedecin($pdo, $id): void +{ + $query = $pdo->prepare("SELECT * FROM propose WHERE m_id = :id"); + $query->bindParam(':id', $id); + $query->execute(); + $result = $query->fetchAll(); + $count = 0; + foreach($result as $row){ + $count++; + } + if($count == 0){ + Response::HTTP404(['error' => "Aucun rendez-vous"]); + } + else { + Response::HTTP200(['count' => $count]); + } +} ?> \ No newline at end of file From 607aab38063cf5c7a6f4f17d3803f8c2ed194bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Fri, 5 Apr 2024 11:45:42 +0200 Subject: [PATCH 07/15] Cancel the number of RDV fix the display --- Request_Test/testHTTP.http | 2 +- src/API/requests.php | 2 +- src/css/styles.css | 2 +- src/js/AJAX/index.js | 4 +- src/php/db/Calendrier.php | 11 +- src/php/db/Search.php | 229 ------------------------------------- 6 files changed, 9 insertions(+), 241 deletions(-) diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index 93e7af9..699e10a 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -11,7 +11,7 @@ Accept: application/json ### -GET http://serveur-projet-s4.felix/src/API/requests.php/api/rdv-time?id=1 +GET http://serveur-projet-s4.felix/src/API/requests.php/api/rdv-available?id=1 Accept: application/json ### diff --git a/src/API/requests.php b/src/API/requests.php index 3d2fd02..f6bad4f 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -36,7 +36,7 @@ $router->GET('/api/rdv', ["id"], function($id){ getNumberOfRDVByMedecin($pdo, $id); }); -$router->GET('/api/rdv-time', ["id"], function($id){ +$router->GET('/api/rdv-available', ["id"], function($id){ global $pdo; selectRDVTimeByID($pdo, $id); }); diff --git a/src/css/styles.css b/src/css/styles.css index 6e5385c..f11eb31 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -48,7 +48,7 @@ body{ max-height: 100%; position: fixed; right: 0; - top: 6vh; + top: 9vh; } #cardPos{ diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 50f3098..3443f8a 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -4,7 +4,7 @@ function displaySearchResults(data) { let container = document.getElementById("content"); container.innerHTML = ""; let mainDiv = document.createElement("div"); - mainDiv.classList.add("d-flex", "flex-row", "flex-wrap", "mx-5", "gap-5"); + mainDiv.classList.add("d-flex", "flex-row", "flex-wrap", "mx-5", "gap-5", "justify-content-center"); let count = 0; data.forEach(function(element) { count++; @@ -21,8 +21,6 @@ function displaySearchResults(data) {
${element.m_surname} ${element.m_name}
${element.m_specialty}

Code Postal: ${element.m_postal}

- -

Disponibilités: ${element.m_availabilities}

diff --git a/src/php/db/Calendrier.php b/src/php/db/Calendrier.php index f9d6fbc..04bff14 100644 --- a/src/php/db/Calendrier.php +++ b/src/php/db/Calendrier.php @@ -4,16 +4,15 @@ require_once '../API/src/response.php'; function selectRDVTimeByID($pdo, $id): void { - $query = $pdo->prepare("SELECT * FROM rendez_vous WHERE rdv_id = :id"); + // Display all the RDV from a medecin from today date + $query = $pdo->prepare("SELECT * FROM propose WHERE m_id = :id"); $query->bindParam(':id', $id); $query->execute(); $result = $query->fetchAll(); - - if (!empty($result)) { - Response::HTTP200($result[0]['rdv_time']); - } else { - Response::HTTP404(['error' => 'Rendez-vous not found']); + if (empty($result)) { + Response::HTTP404(['error' => 'No RDV found']); } + Response::HTTP200($result); } diff --git a/src/php/db/Search.php b/src/php/db/Search.php index d77ea96..14d48bd 100644 --- a/src/php/db/Search.php +++ b/src/php/db/Search.php @@ -1,235 +1,6 @@ Veuillez entrer un nom ou un lieu

'; - } - else if($_POST['postal'] == null){ - $query = $pdo->prepare("SELECT * FROM medecin WHERE m_name = :nom"); - $query->bindParam(':nom', $_POST['nom']); - $query->execute(); - $result = $query->fetchAll(); - - if($result == null){ - $query = $pdo->prepare("SELECT * FROM medecin WHERE m_specialty = :specialite"); - $query->bindParam(':specialite', $_POST['nom']); - $query->execute(); - $result = $query->fetchAll(); - } - - $count = 0; - foreach($result as $row){ - $count++; - } - - echo '

'.$count.' Résultats

'; - - if($count == 0){ - echo '

Aucun résultat

'; - } - else{ - echo '
'; - foreach($result as $row){ - echo '
'; - echo '
'; - echo '
'; - $imageUrl = 'https://thispersondoesnotexist.com'; - echo 'doctor'; - echo '
'; - echo '
'; - echo '
'; - echo '
'.$row['m_name'].' '.$row['m_surname'].'
'; - echo '
'.$row['m_specialty'].'
'; - $query = $pdo->prepare("SELECT * FROM propose WHERE m_id = :id"); - $query->bindParam(':id', $row['m_id']); - $query->execute(); - $result = $query->fetchAll(); - $count = 0; - foreach($result as $row2){ - $count++; - } - echo '

Disponiblilité :'. $count .'

'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - } - echo '
'; - } - } - else if($_POST['nom'] == null){ - if(strlen($_POST['postal']) != 5){ - $postal = substr($_POST['postal'], 0, 2); - $postal = $postal.'%'; - $query = $pdo->prepare("SELECT * FROM medecin WHERE CAST(m_postal AS TEXT) LIKE :postal"); - $query->bindParam(':postal', $postal); - $query->execute(); - $result = $query->fetchAll(); - - $count = 0; - foreach($result as $row){ - $count++; - } - - echo '

'.$count.' Résultats

'; - - if($count == 0){ - echo '

Aucun résultat

'; - } - else{ - echo '
'; - foreach($result as $row){ - echo '
'; - echo '
'; - echo '
'; - $imageUrl = 'https://thispersondoesnotexist.com'; - echo 'doctor'; - echo '
'; - echo '
'; - echo '
'; - echo '
'.$row['m_name'].' '.$row['m_surname'].'
'; - echo '
'.$row['m_specialty'].'
'; - echo '

Disponiblilité :'. $count .'

'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - } - echo '
'; - } - } - else{ - $query = $pdo->prepare("SELECT * FROM medecin WHERE m_postal = :postal"); - $query->bindParam(':postal', $_POST['postal']); - $query->execute(); - $result = $query->fetchAll(); - - $count = 0; - foreach($result as $row){ - $count++; - } - - echo '

'.$count.' Résultats

'; - - if($count == 0){ - echo '

Aucun résultat

'; - } - else{ - echo '
'; - foreach($result as $row){ - echo '
'; - echo '
'; - echo '
'; - $imageUrl = 'https://thispersondoesnotexist.com'; - echo 'doctor'; - echo '
'; - echo '
'; - echo '
'; - echo '
'.$row['m_name'].' '.$row['m_surname'].'
'; - echo '
'.$row['m_specialty'].'
'; - echo '

Disponiblilité :'. $count .'

'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - } - echo '
'; - } - } - } - else { - if(strlen($_POST['postal']) != 5){ - $postal = substr($_POST['postal'], 0, 2); - $postal = $postal.'%'; - $query = $pdo->prepare("SELECT * FROM medecin WHERE CAST(m_postal AS TEXT) LIKE :postal AND m_name = :nom"); - $query->bindParam(':postal', $postal); - $query->bindParam(':nom', $_POST['nom']); - $query->execute(); - $result = $query->fetchAll(); - } - else{ - $query = $pdo->prepare("SELECT * FROM medecin WHERE m_name = :nom AND m_postal = :postal"); - $query->bindParam(':nom', $_POST['nom']); - $query->bindParam(':postal', $_POST['postal']); - $query->execute(); - $result = $query->fetchAll(); - } - if ($result == null) { - if(strlen($_POST['postal']) != 5){ - $postal = substr($_POST['postal'], 0, 2); - $postal = $postal.'%'; - $query = $pdo->prepare("SELECT * FROM medecin WHERE CAST(m_postal AS TEXT) LIKE :postal AND m_specialty = :specialite"); - $query->bindParam(':postal', $postal); - $query->bindParam(':specialite', $_POST['nom']); - $query->execute(); - $result = $query->fetchAll(); - } - else{ - $query = $pdo->prepare("SELECT * FROM medecin WHERE m_specialty = :specialite AND m_postal = :postal"); - $query->bindParam(':specialite', $_POST['nom']); - $query->bindParam(':postal', $_POST['postal']); - $query->execute(); - $result = $query->fetchAll(); - } - } - - $count = 0; - foreach ($result as $row) { - $count++; - } - - echo '

' . $count . ' Résultats

'; - - if ($count == 0) { - echo '

Aucun résultat

'; - } else { - echo '
'; - foreach ($result as $row) { - echo '
'; - echo '
'; - echo '
'; - $imageUrl = 'https://thispersondoesnotexist.com'; - echo 'doctor'; - echo '
'; - echo '
'; - echo '
'; - echo '
' . $row['m_name'] . ' ' . $row['m_surname'] . '
'; - echo '
' . $row['m_specialty'] . '
'; - echo '

Disponiblilité :'. $count .'

'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - } - echo '
'; - } - } -} - - -*/ // searchDoctor search doctor by name or specialty and return the result in JSON format function searchDoctor($pdo, $type): void { From 3854cb5f6bcf0d955842843eb3a0447e51725f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Sat, 6 Apr 2024 18:49:03 +0200 Subject: [PATCH 08/15] Start of the display of the rendez vous, Need to add the action on click on a RDV, Fix the display of the card, and fix when click on a practicien that don't have a RDV today --- Request_Test/testHTTP.http | 5 ++ calendrier.php | 90 +++++++++++++++++++++++++ src/API/requests.php | 5 ++ src/js/AJAX/index.js | 130 ++++++++++++++++++++++++++++++++----- src/js/AJAX/utils.js | 4 ++ src/php/db/Calendrier.php | 29 +++++++-- src/php/db/Search.php | 8 +-- 7 files changed, 245 insertions(+), 26 deletions(-) create mode 100644 calendrier.php diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index 699e10a..b43eca4 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -23,4 +23,9 @@ Accept: application/json GET http://serveur-projet-s4.felix/src/API/requests.php/api/search?type=G%C3%A9n%C3%A9raliste&postal=35 Accept: application/json +### + +GET http://serveur-projet-s4.felix/src/API/requests.php/api/praticien?id=1 +Accept: application/json + ### \ No newline at end of file diff --git a/calendrier.php b/calendrier.php new file mode 100644 index 0000000..34c42c4 --- /dev/null +++ b/calendrier.php @@ -0,0 +1,90 @@ + + + + + Oui....Stiti + + + + + + + + + +
+ +
+
+ +
+
+
+ +
+
+
+
+
+
+ +
+ '; + echo ''; + ?> +
+ +
+
+
+ +
+
+
+
+
+ Veuillez choisir une date

'; + } + else{ + displayRDVForDate($pdo, $_POST['start'], $_POST['id']); + } + ?> +
+
+
+
+ + \ No newline at end of file diff --git a/src/API/requests.php b/src/API/requests.php index f6bad4f..1a4caf2 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -46,6 +46,11 @@ $router->GET('/api/rdv-date', ["date", "id"], function($date, $id){ selectRDVForDate($pdo, $date, $id); }); +$router->GET('/api/praticien', ["id"], function($id){ + global $pdo; + getPraticienDetails($pdo, $id); +}); + $router->POST('/api/requests', ["test"], function($test){ echo json_encode($test); }); diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 3443f8a..2572011 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -21,7 +21,7 @@ function displaySearchResults(data) {
${element.m_surname} ${element.m_name}
${element.m_specialty}

Code Postal: ${element.m_postal}

- +
`; @@ -35,6 +35,7 @@ function displaySearchResults(data) { let resultText = document.createElement("h1"); resultText.textContent = count + " résultats"; container.insertBefore(resultText, mainDiv); + attachRDVEventListener(); } } @@ -57,30 +58,117 @@ function displaySearchTopBar(){ attachSearchEventListener(); } -function performSearch(event){ +function displayRDVForDate(data) { + let container = document.getElementById("rdv-list"); + container.innerHTML = ""; + let count = 0; + data.forEach(function(element) { + let card = document.createElement("div"); + card.classList.add("card"); + element.rdv_time = element.rdv_time.slice(0, 5); + card.innerHTML = ` +
+
${element.rdv_time}
+

Addresse: ${element.l_adress}
+ Ville: ${element.l_city} ${element.l_postal}

+
`; + container.appendChild(card); + count++; + }); + if(count === 0) { + container.innerHTML = "

Aucun rendez-vous

"; + } + else { + let resultText = document.createElement("h1"); + resultText.textContent = count + " rendez-vous"; + container.insertBefore(resultText, container.firstChild); + } +} + +function displayCalendar(data) { + let container = document.getElementById("content"); + container.innerHTML = ""; + let mainDiv = document.createElement("div"); + mainDiv.classList.add("row"); + + // Colonne de gauche + let leftCol = document.createElement("div"); + leftCol.classList.add("col", "h-100", "border-dark", "border-3", "justify-content-center", "text-center", "ms-3"); + let leftDiv = document.createElement("div"); + leftDiv.classList.add("d-flex", "flex-column", "justify-content-center", "gap-6"); + + // Calendrier de sélection de date + let form = document.createElement("form"); + form.classList.add("mt-3"); + let label = document.createElement("label"); + label.setAttribute("for", "date"); + label.textContent = "Choisissez une date :"; + form.appendChild(label); + let input = document.createElement("input"); + input.setAttribute("type", "date"); + input.setAttribute("name", "start"); + input.setAttribute("id", "date"); + input.classList.add("mt-2", "form-control"); + form.appendChild(input); + let submit = document.createElement("input"); + submit.setAttribute("type", "submit"); + submit.setAttribute("value", "Valider"); + submit.classList.add("mt-2", "btn", "btn-outline-danger"); + form.appendChild(submit); + leftDiv.appendChild(form); + + // Carte du médecin + let medecinCard = document.createElement("div"); + medecinCard.classList.add("card", "w-50", "mx-auto"); + console.log(data); + medecinCard.innerHTML = ` + doctor +
+
${data[0].m_surname} ${data[0].m_name}
+
${data[0].m_specialty}
+

Code Postal: ${data[0].m_postal}

+
`; + leftDiv.appendChild(medecinCard); + + leftCol.appendChild(leftDiv); + mainDiv.appendChild(leftCol); + + // Colonne de droite + let rightCol = document.createElement("div"); + rightCol.classList.add("col-8", "h-100", "border-start", "border-dark", "border-3", "me-3"); + + // Liste des rendez-vous + let rdvList = document.createElement("div"); + rdvList.classList.add("mt-3", "d-flex", "flex-column", "gap-3"); + rdvList.id = "rdv-list"; + rightCol.appendChild(rdvList); + + mainDiv.appendChild(rightCol); + container.appendChild(mainDiv); + displayRDVForDate(data); +} + +function performSearch(event) { event.preventDefault(); let type = document.getElementById("nom").value; let postal = document.getElementById("postal").value; - if(postal === ""){ - if(type === "") { + if (postal === "") { + if (type === "") { alert("Veuillez remplir au moins un champ"); return; - } - else{ - ajaxRequest('GET', "src/API/requests.php/api/search-type?type=" + type, function (data){ + } else { + ajaxRequest('GET', "src/API/requests.php/api/search-type?type=" + type, function (data) { displaySearchResults(data); displaySearchTopBar(); }) } - } - else if(type === "") { - ajaxRequest('GET', "src/API/requests.php/api/search-postal?postal=" + postal, function (data){ + } else if (type === "") { + ajaxRequest('GET', "src/API/requests.php/api/search-postal?postal=" + postal, function (data) { displaySearchResults(data); displaySearchTopBar(); }); - } - else{ - ajaxRequest('GET', "src/API/requests.php/api/search?type=" + type + "&postal=" + postal, function(data){ + } else { + ajaxRequest('GET', "src/API/requests.php/api/search?type=" + type + "&postal=" + postal, function (data) { displaySearchResults(data); displaySearchTopBar(); }); @@ -88,11 +176,23 @@ function performSearch(event){ } function attachSearchEventListener() { - document.getElementById("recherche").addEventListener("click", function(event) { + document.getElementById("recherche").addEventListener("click", function (event) { performSearch(event); }); } - +function attachRDVEventListener() { + let buttons = document.querySelectorAll("button[id^='m-id-']"); + buttons.forEach(function (button) { + button.addEventListener("click", function (event) { + let id = event.target.id.split("-")[2] + let today = new Date(); + let date = today.getFullYear() + "-" + (today.getMonth() + 1).toString().padStart(2, "0") + "-" + today.getDate().toString().padStart(2, "0"); + ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) { + displayCalendar(data); + }); + }); + }); +} attachSearchEventListener(); \ No newline at end of file diff --git a/src/js/AJAX/utils.js b/src/js/AJAX/utils.js index 0085543..dad39eb 100644 --- a/src/js/AJAX/utils.js +++ b/src/js/AJAX/utils.js @@ -11,6 +11,10 @@ function ajaxRequest(type, url, callback, data = null){ switch (xhr.status) { case 200: case 201: + /* + console.log(xhr.responseText); + console.log(JSON.parse(xhr.responseText)); + */ callback(JSON.parse(xhr.responseText)); break; case 404: diff --git a/src/php/db/Calendrier.php b/src/php/db/Calendrier.php index 04bff14..96902be 100644 --- a/src/php/db/Calendrier.php +++ b/src/php/db/Calendrier.php @@ -19,19 +19,34 @@ function selectRDVTimeByID($pdo, $id): void function selectRDVForDate($pdo, $date, $medecin): void { $availableHours = array(); - $query = $pdo->prepare("select * from rendez_vous rdv join public.propose p using (rdv_id) where p.m_id = :m_id and rdv.rdv_date = :date AND rdv.p_id IS NULL ORDER BY rdv_time ASC"); + $query = $pdo->prepare("SELECT rdv.rdv_id, rdv.rdv_date, l.l_adress, l.l_city, l.l_postal, m.m_id, m.m_name, m.m_surname, m.m_specialty, m.m_phone, rdv.rdv_time +FROM rendez_vous rdv + JOIN public.propose p USING (rdv_id) + JOIN public.lieu l ON rdv.l_id = l.l_id + JOIN public.medecin m ON p.m_id = m.m_id +WHERE p.m_id = :m_id AND rdv.rdv_date = :date AND rdv.p_id IS NULL +ORDER BY rdv_time ASC;"); $query->bindParam(':date', $date); $query->bindParam(':m_id', $medecin); $query->execute(); - $outerResult = $query->fetchAll(); - foreach ($outerResult as $row) { - array_push($availableHours, $row['rdv_id']); - } + $result = $query->fetchAll(); // Check if the array is empty - if (empty($availableHours)) { + if (empty($result)) { Response::HTTP404(['error' => 'No available hours']); } - Response::HTTP200($availableHours); + Response::HTTP200($result); +} + +function getPraticienDetails($pdo, $id): void +{ + $query = $pdo->prepare("SELECT * FROM medecin WHERE m_id = :id"); + $query->bindParam(':id', $id); + $query->execute(); + $result = $query->fetchAll(); + if (empty($result)) { + Response::HTTP404(['error' => 'Praticien not found']); + } + Response::HTTP200($result); } /* diff --git a/src/php/db/Search.php b/src/php/db/Search.php index 14d48bd..91c3c03 100644 --- a/src/php/db/Search.php +++ b/src/php/db/Search.php @@ -4,7 +4,7 @@ require_once '../API/src/response.php'; // searchDoctor search doctor by name or specialty and return the result in JSON format function searchDoctor($pdo, $type): void { - $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone FROM medecin WHERE m_specialty = :type"); + $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE m_specialty = :type"); $query->bindParam(':type', $type); $query->execute(); $result = $query->fetchAll(); @@ -14,7 +14,7 @@ function searchDoctor($pdo, $type): void $count++; } if($count == 0){ - $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone FROM medecin WHERE m_name = :type"); + $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE m_name = :type"); $query->bindParam(':type', $type); $query->execute(); $result = $query->fetchAll(); @@ -49,10 +49,10 @@ function searchDoctorByLocation($pdo, $location, $type = null): void } if($type == null){ - $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone FROM medecin WHERE CAST(m_postal AS TEXT) LIKE :postal"); + $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE CAST(m_postal AS TEXT) LIKE :postal"); $query->bindParam(':postal', $postal); } else { - $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone FROM medecin WHERE (m_specialty = :type OR m_name = :type) AND CAST(m_postal AS TEXT) LIKE :postal"); + $query = $pdo->prepare("SELECT m_name, m_surname, m_postal, m_specialty, m_phone, m_id FROM medecin WHERE (m_specialty = :type OR m_name = :type) AND CAST(m_postal AS TEXT) LIKE :postal"); $query->bindParam(':type', $type); $query->bindParam(':postal', $postal); } From 5115955460a6d609abc93edd852caccd755a49cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Sat, 6 Apr 2024 22:36:54 +0200 Subject: [PATCH 09/15] Fix the display of the rendez vous, fix the issue for when a practicien doesn't have a RDV. # To do next: - Action when pressing the prendre ce rendez vous button - Refactor and clean path on the code (JS mainly) --- src/js/AJAX/index.js | 60 +++++++++++++++++++++++++-------------- src/js/AJAX/utils.js | 6 +--- src/php/db/Calendrier.php | 10 +++++-- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 2572011..ee3b598 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -11,7 +11,6 @@ function displaySearchResults(data) { let card = document.createElement("div"); card.classList.add("card", "w-25"); card.innerHTML = ` -
doctor @@ -23,8 +22,7 @@ function displaySearchResults(data) {

Code Postal: ${element.m_postal}

-
-
`; + `; mainDiv.appendChild(card); }); container.appendChild(mainDiv); @@ -63,17 +61,23 @@ function displayRDVForDate(data) { container.innerHTML = ""; let count = 0; data.forEach(function(element) { - let card = document.createElement("div"); - card.classList.add("card"); - element.rdv_time = element.rdv_time.slice(0, 5); - card.innerHTML = ` -
-
${element.rdv_time}
-

Addresse: ${element.l_adress}
- Ville: ${element.l_city} ${element.l_postal}

-
`; - container.appendChild(card); - count++; + try{ + let card = document.createElement("div"); + card.classList.add("card"); + element.rdv_time = element.rdv_time.slice(0, 5); + card.innerHTML = ` +
+
${element.rdv_time}
+

Adresse: ${element.l_adress}
+ Ville: ${element.l_city} ${element.l_postal}

+ +
`; + container.appendChild(card); + count++; + } catch (e) { + //Do nothing + //console.error(e); + } }); if(count === 0) { container.innerHTML = "

Aucun rendez-vous

"; @@ -100,6 +104,7 @@ function displayCalendar(data) { // Calendrier de sélection de date let form = document.createElement("form"); form.classList.add("mt-3"); + form.id = "date-selection-form"; let label = document.createElement("label"); label.setAttribute("for", "date"); label.textContent = "Choisissez une date :"; @@ -119,14 +124,19 @@ function displayCalendar(data) { // Carte du médecin let medecinCard = document.createElement("div"); - medecinCard.classList.add("card", "w-50", "mx-auto"); - console.log(data); + medecinCard.classList.add("card", "mx-auto", "d-flex", "flex-row"); medecinCard.innerHTML = ` - doctor -
-
${data[0].m_surname} ${data[0].m_name}
-
${data[0].m_specialty}
-

Code Postal: ${data[0].m_postal}

+
+
+ doctor +
+
+
+
${data[0].m_surname} ${data[0].m_name}
+
${data[0].m_specialty}
+

Code Postal: ${data[0].m_postal}

+
+
`; leftDiv.appendChild(medecinCard); @@ -146,6 +156,14 @@ function displayCalendar(data) { mainDiv.appendChild(rightCol); container.appendChild(mainDiv); displayRDVForDate(data); + document.getElementById("date-selection-form").addEventListener("submit", function(event) { + event.preventDefault(); + let date = document.getElementById("date").value; + let id = data[0].m_id; // Assuming 'data' is accessible in this scope and contains the doctor's details + ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) { + displayRDVForDate(data); + }); + }); } function performSearch(event) { diff --git a/src/js/AJAX/utils.js b/src/js/AJAX/utils.js index dad39eb..7d8e17b 100644 --- a/src/js/AJAX/utils.js +++ b/src/js/AJAX/utils.js @@ -11,14 +11,10 @@ function ajaxRequest(type, url, callback, data = null){ switch (xhr.status) { case 200: case 201: - /* - console.log(xhr.responseText); - console.log(JSON.parse(xhr.responseText)); - */ callback(JSON.parse(xhr.responseText)); break; case 404: - alert("404"); + alert("404 Aucun résultat trouvé"); break; case 403: alert("403"); diff --git a/src/php/db/Calendrier.php b/src/php/db/Calendrier.php index 96902be..7ce8158 100644 --- a/src/php/db/Calendrier.php +++ b/src/php/db/Calendrier.php @@ -18,7 +18,6 @@ function selectRDVTimeByID($pdo, $id): void function selectRDVForDate($pdo, $date, $medecin): void { - $availableHours = array(); $query = $pdo->prepare("SELECT rdv.rdv_id, rdv.rdv_date, l.l_adress, l.l_city, l.l_postal, m.m_id, m.m_name, m.m_surname, m.m_specialty, m.m_phone, rdv.rdv_time FROM rendez_vous rdv JOIN public.propose p USING (rdv_id) @@ -30,9 +29,14 @@ ORDER BY rdv_time ASC;"); $query->bindParam(':m_id', $medecin); $query->execute(); $result = $query->fetchAll(); - // Check if the array is empty if (empty($result)) { - Response::HTTP404(['error' => 'No available hours']); + $query = $pdo->prepare("SELECT m_id, m_name, m_surname, m_specialty, m_phone, m_postal FROM medecin WHERE m_id = :id"); + $query->bindParam(':id', $medecin); + $query->execute(); + $result = $query->fetchAll(); + // Put the result in a JSON format + Response::HTTP200($result); + return; } Response::HTTP200($result); } From 9b6b24f1329855cf6db101449663f4ee91a8d8a8 Mon Sep 17 00:00:00 2001 From: BreizhHardware Date: Sun, 7 Apr 2024 12:39:55 +0200 Subject: [PATCH 10/15] =?UTF-8?q?Add=20button=20to=20take=20RDV=20but=20th?= =?UTF-8?q?e=20POST=20request=20don=C2=B4t=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Request_Test/testHTTP.http | 5 +++++ src/API/requests.php | 5 +++++ src/js/AJAX/index.js | 17 +++++++++++++++++ src/php/db/Calendrier.php | 9 +++++++++ 4 files changed, 36 insertions(+) diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index b43eca4..ec704cd 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -28,4 +28,9 @@ Accept: application/json GET http://serveur-projet-s4.felix/src/API/requests.php/api/praticien?id=1 Accept: application/json +### + +POST http://serveur-projet-s4.felix/src/API/requests.php/api/take-rdv?rdv-id=64553&patient-id=1 +Accept: application/json + ### \ No newline at end of file diff --git a/src/API/requests.php b/src/API/requests.php index 1a4caf2..0bff001 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -51,6 +51,11 @@ $router->GET('/api/praticien', ["id"], function($id){ getPraticienDetails($pdo, $id); }); +$router->PUT('/api/rdv', ["rdv-id", "patient-id"], function($rdv_id, $patient_id){ + global $pdo; + takeRDV($pdo, $rdv_id, $patient_id); +}); + $router->POST('/api/requests', ["test"], function($test){ echo json_encode($test); }); diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index ee3b598..5c3fcea 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -86,6 +86,7 @@ function displayRDVForDate(data) { let resultText = document.createElement("h1"); resultText.textContent = count + " rendez-vous"; container.insertBefore(resultText, container.firstChild); + attachPrendreRDVEventListener(); } } @@ -213,4 +214,20 @@ function attachRDVEventListener() { }); } +function attachPrendreRDVEventListener() { + let buttons = document.querySelectorAll("button[id^='rdv-id-']"); + buttons.forEach(function (button) { + button.addEventListener("click", function (event) { + let RDVid = event.target.id.split("-")[2]; + ajaxRequest('POST', "src/API/requests.php/api/rdv" + "?rdv-id=" + RDVid + "&patient-id=" + 1, function (data) { + if (data.success) { + alert("Rendez-vous pris avec succès"); + } else { + alert("Erreur lors de la prise de rendez-vous"); + } + }); + }); + }); +} + attachSearchEventListener(); \ No newline at end of file diff --git a/src/php/db/Calendrier.php b/src/php/db/Calendrier.php index 7ce8158..00fc216 100644 --- a/src/php/db/Calendrier.php +++ b/src/php/db/Calendrier.php @@ -53,6 +53,15 @@ function getPraticienDetails($pdo, $id): void Response::HTTP200($result); } +function takeRDV($pdo, $rdv_id, $patient_id): void +{ + $query = $pdo->prepare("UPDATE rendez_vous SET p_id = :p_id WHERE rdv_id = :rdv_id"); + $query->bindParam(':p_id', $patient_id); + $query->bindParam(':rdv_id', $rdv_id); + $query->execute(); + Response::HTTP200(['success' => 'RDV taken']); +} + /* function displayRDVForDate($pdo, $date, $medecin){ $availableHours = selectRDVForDate($pdo, $date, $medecin); From e1405c24333cf5e1cbbbbb2a6b159e439ee96a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Mon, 8 Apr 2024 08:48:29 +0200 Subject: [PATCH 11/15] Take RDV finish --- Request_Test/testHTTP.http | 8 +++- index.php | 1 + src/API/requests.php | 2 +- src/css/styles.css | 6 +++ src/js/AJAX/index.js | 95 ++++++++++++++++++++++++++++++++++++-- src/js/AJAX/utils.js | 57 ++++++++--------------- src/php/db/Calendrier.php | 12 ++--- 7 files changed, 129 insertions(+), 52 deletions(-) diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index ec704cd..ab8b582 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -30,7 +30,11 @@ Accept: application/json ### -POST http://serveur-projet-s4.felix/src/API/requests.php/api/take-rdv?rdv-id=64553&patient-id=1 -Accept: application/json +# PUT /api/rdv with body in x-www-form-urlencoded +PUT http://serveur-projet-s4.felix/src/API/requests.php/api/rdv +Content-Type: application/x-www-form-urlencoded +rdv-id=64553&patient-id=1 + +ACCEPT: application/json ### \ No newline at end of file diff --git a/index.php b/index.php index 86ea056..9c85ef3 100644 --- a/index.php +++ b/index.php @@ -43,6 +43,7 @@
+
img_index
diff --git a/src/API/requests.php b/src/API/requests.php index 0bff001..c6af605 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -51,7 +51,7 @@ $router->GET('/api/praticien', ["id"], function($id){ getPraticienDetails($pdo, $id); }); -$router->PUT('/api/rdv', ["rdv-id", "patient-id"], function($rdv_id, $patient_id){ +$router->PUT('/api/rdv', ["rdv_id", "patient_id"], function($rdv_id, $patient_id){ global $pdo; takeRDV($pdo, $rdv_id, $patient_id); }); diff --git a/src/css/styles.css b/src/css/styles.css index f11eb31..793c3d9 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -132,4 +132,10 @@ a{ a:hover{ text-decoration: underline; +} + +#Alert{ + position: fixed; + top: 7%; + width: 100%; } \ No newline at end of file diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 5c3fcea..2d062cb 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -56,6 +56,25 @@ function displaySearchTopBar(){ attachSearchEventListener(); } +function removeSearchTopBar(){ + let topbar = document.getElementById("topbar"); + topbar.innerHTML = ""; + topbar.innerHTML = ` + + `; +} + function displayRDVForDate(data) { let container = document.getElementById("rdv-list"); container.innerHTML = ""; @@ -135,7 +154,6 @@ function displayCalendar(data) {
${data[0].m_surname} ${data[0].m_name}
${data[0].m_specialty}
-

Code Postal: ${data[0].m_postal}

`; @@ -167,6 +185,72 @@ function displayCalendar(data) { }); } +function displayAlert(text) { + let alert = document.getElementById("Alert"); + console.log(text); + alert.innerHTML = ""; + alert.innerHTML = ` + `; + setTimeout(clearAlert, 5000); +} + +function clearAlert() { + let alert = document.getElementById("Alert"); + alert.innerHTML = ""; +} + +function displayHome() { + removeSearchTopBar(); + let container = document.getElementById("content"); + container.innerHTML = ""; + container.innerHTML = ` +
+
+ img_index +
+

Trouvez un rendez vous avec un medecin

+
+ + + +
+
+
+
+
+
Information
+
Ligue contre le cancer
+

Mois sans tabac: c’est le moment d’arrêter !

+
+
+
+
+
Information
+
Pharmacie Sanchez
+

Le rôle du phramacien évolue: Venez nous voir.

+
+
+
+
+
Information
+
Doct’ISEN
+

Un empechement: Prevenez votre soignant.

+
+
+
+
+
+

Recherche de praticiens

+

Doct’ISEN, 33 QUATER Av. du Champ de Manœuvre, 44470 Carquefou

+

Conditions générales d'utilisation • Conditions d'utilisation du site Doct'ISEN • Politique relative à la protection des données personnelles • Politique en matière de cookies • Gestion des cookies et consentement • Règles de référencement • Mentions légales

+

Annuaire des médecins du CNOM • Annuaire des chirurgiens-dentistes de l'ONCD • Ordre National des Médecins • Ordre National des Chirurgiens-Dentistes

+
`; + attachSearchEventListener(); + displayAlert("Rendez-vous pris avec succès"); +} + function performSearch(event) { event.preventDefault(); let type = document.getElementById("nom").value; @@ -219,13 +303,14 @@ function attachPrendreRDVEventListener() { buttons.forEach(function (button) { button.addEventListener("click", function (event) { let RDVid = event.target.id.split("-")[2]; - ajaxRequest('POST', "src/API/requests.php/api/rdv" + "?rdv-id=" + RDVid + "&patient-id=" + 1, function (data) { - if (data.success) { - alert("Rendez-vous pris avec succès"); + data = "rdv_id=" + RDVid + "&patient_id=" + 1; + ajaxRequest('PUT', "src/API/requests.php/api/rdv", function (returnData){ + if (returnData.success) { + displayHome(); } else { alert("Erreur lors de la prise de rendez-vous"); } - }); + }, data); }); }); } diff --git a/src/js/AJAX/utils.js b/src/js/AJAX/utils.js index 7d8e17b..3425758 100644 --- a/src/js/AJAX/utils.js +++ b/src/js/AJAX/utils.js @@ -1,53 +1,34 @@ console.log("utils.js loaded"); -function ajaxRequest(type, url, callback, data = null){ - let xhr = new XMLHttpRequest(); +function ajaxRequest(type, url, callback, data = null) +{ + let xhr; + // Create XML HTTP request. + xhr = new XMLHttpRequest(); if (type == 'GET' && data != null) url += '?' + data; - xhr.open(type, url, true); - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.onload = function() { - switch (xhr.status) { + xhr.open(type, url); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + + // Add the onload function. + xhr.onload = () => + { + switch (xhr.status) + { case 200: case 201: + //console.log(xhr.responseText); callback(JSON.parse(xhr.responseText)); break; - case 404: - alert("404 Aucun résultat trouvé"); - break; - case 403: - alert("403"); - break; - case 500: - console.log("server error"); - break; default: - httpErrors(xhr.status); + console.log("Error: " + xhr.status); + alert("Error: " + xhr.status); + break; } }; + + // Send XML HTTP request. xhr.send(data); } -function httpErrors(errorCode) -{ - let messages = { - 400: 'Requête incorrecte', - 401: 'Authentifiez vous', - 403: 'Accès refusé', - 404: 'Page non trouvée', - 500: 'Erreur interne du serveur', - 503: 'Service indisponible' - }; - - // Display error. - if (errorCode in messages) - { - $('#errors').html('' + messages[errorCode] + ''); - $('#errors').show(); - setTimeout(() => - { - $('#errors').hide(); - }, 5000); - } -} diff --git a/src/php/db/Calendrier.php b/src/php/db/Calendrier.php index 00fc216..148c1fd 100644 --- a/src/php/db/Calendrier.php +++ b/src/php/db/Calendrier.php @@ -19,12 +19,12 @@ function selectRDVTimeByID($pdo, $id): void function selectRDVForDate($pdo, $date, $medecin): void { $query = $pdo->prepare("SELECT rdv.rdv_id, rdv.rdv_date, l.l_adress, l.l_city, l.l_postal, m.m_id, m.m_name, m.m_surname, m.m_specialty, m.m_phone, rdv.rdv_time -FROM rendez_vous rdv - JOIN public.propose p USING (rdv_id) - JOIN public.lieu l ON rdv.l_id = l.l_id - JOIN public.medecin m ON p.m_id = m.m_id -WHERE p.m_id = :m_id AND rdv.rdv_date = :date AND rdv.p_id IS NULL -ORDER BY rdv_time ASC;"); + FROM rendez_vous rdv + JOIN public.propose p USING (rdv_id) + JOIN public.lieu l ON rdv.l_id = l.l_id + JOIN public.medecin m ON p.m_id = m.m_id + WHERE p.m_id = :m_id AND rdv.rdv_date = :date AND rdv.p_id IS NULL + ORDER BY rdv_time ASC;"); $query->bindParam(':date', $date); $query->bindParam(':m_id', $medecin); $query->execute(); From 625fe91be2187a7c0779c0d5e6533dfed57186fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Mon, 8 Apr 2024 08:52:59 +0200 Subject: [PATCH 12/15] Fix an issue --- src/js/AJAX/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index 2d062cb..98f6360 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -279,9 +279,15 @@ function performSearch(event) { } function attachSearchEventListener() { - document.getElementById("recherche").addEventListener("click", function (event) { - performSearch(event); - }); + try{ + document.getElementById("recherche").addEventListener("click", function (event) { + performSearch(event); + }); + } + catch (e) { + //Do nothing + //console.error(e); + } } function attachRDVEventListener() { From dfda73b0701035cfda69c27b5d1269d1ae5c7c3b Mon Sep 17 00:00:00 2001 From: sinbad Date: Mon, 8 Apr 2024 09:01:14 +0200 Subject: [PATCH 13/15] Almost end back + start front but missing topbar for test --- src/API/requests.php | 20 +++++++++++++ src/API/src/response.php | 9 ++++++ src/API/test/database.php | 60 +++++++++++++++++++++++++++++++++----- src/js/AJAX/index.js | 61 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 141 insertions(+), 9 deletions(-) diff --git a/src/API/requests.php b/src/API/requests.php index a581b1f..fe8e52d 100644 --- a/src/API/requests.php +++ b/src/API/requests.php @@ -67,8 +67,28 @@ $router->DELETE('/api/requests', ["test"], function($test){ $router->GET('/api/rdv-praticient', ["id"], function($id){ global $pdo; dbRequestRdvPraticien($pdo, $id); + getAllLieux($pdo); }); +$router->GET('/api/rdv-patient', ["id"], function($id){ + global $pdo; + dbRequestRdvPatient($pdo, $id); + getPastRdvByPatient($pdo, $id); +}); +$router->DELETE('/api/delete-empty', ["id"], function($id){ + global $pdo; + DeleteEmptyRdv($pdo, $id); +}); + +$router->DELETE('/api/cancel-rdv', ["id"], function($id){ + global $pdo; + CancelRDV($pdo, $id); +}); + +$router->POST('/api/create-rdv', ["id", "date", "time", "lieu"], function($id, $date, $time, $lieu){ + global $pdo; + createRDV($pdo, $id, $date, $time, $lieu); +}); $router->run(); diff --git a/src/API/src/response.php b/src/API/src/response.php index 12cfd0d..7df29d5 100644 --- a/src/API/src/response.php +++ b/src/API/src/response.php @@ -38,6 +38,15 @@ class Response echo json_encode($data); } + public static function HTTP403($data): void + { + header('Content-Type: application/json; charset=utf-8'); + header('Cache-control: no-store, no-cache, must-revalidate'); + header('Pragma: no-cache'); + http_response_code(403); + echo json_encode($data); + } + static function HTTP404($data): void { header('Content-Type: application/json; charset=utf-8'); diff --git a/src/API/test/database.php b/src/API/test/database.php index a211b81..4c3447d 100644 --- a/src/API/test/database.php +++ b/src/API/test/database.php @@ -40,6 +40,49 @@ function dbRequestRdvPraticien($pdo, $id){ } +function dbRequestRdvPatient($pdo, $id){ + $statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty, medecin.m_id, concat(p_name, ' ', p_surname) as patient, l_adress as adresse, concat(l_postal, ' ', l_city) as ville + FROM rendez_vous + INNER JOIN patient ON rendez_vous.p_id = patient.p_id + INNER JOIN propose ON rendez_vous.rdv_id = propose.rdv_id + INNER JOIN medecin ON propose.m_id = medecin.m_id + INNER JOIN lieu on lieu.l_id = rendez_vous.l_id + + WHERE NOW() <= (rdv_date + rdv_time) AND patient.p_id = :id + ORDER BY rdv_date, rdv_time ASC"); + + $statement->bindParam(':id', $id); + $statement->execute(); + $result = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!empty($result)) { + Response::HTTP200($result); + } else { + Response::HTTP404(["error" => "No data found"]); + } +} + +function getPastRdvByPatient($pdo, $id){ + $statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty, medecin.m_id, concat(p_name, ' ', p_surname) as patient, l_adress as adresse, concat(l_postal, ' ', l_city) as ville + FROM rendez_vous + INNER JOIN patient ON rendez_vous.p_id = patient.p_id + INNER JOIN propose ON rendez_vous.rdv_id = propose.rdv_id + INNER JOIN medecin ON propose.m_id = medecin.m_id + INNER JOIN lieu on lieu.l_id = rendez_vous.l_id + + WHERE NOW() > (rdv_date + rdv_time) AND patient.p_id = :id + ORDER BY rdv_date, rdv_time ASC"); + $statement->bindParam(':id', $id); + $statement->execute(); + $result = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!empty($result)) { + Response::HTTP200($result); + } else { + Response::HTTP404(["error" => "No data found"]); + } +} + function getLieuID($pdo, $adress, $postal, $city){ $statement = $pdo->prepare("SELECT l_id FROM lieu WHERE l_adress = :adress AND l_city = :city AND l_postal = :postal"); $statement->bindParam(':adress', $adress); @@ -61,9 +104,9 @@ function getAllLieux($pdo){ $result = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($result)) { - return $result; + Response::HTTP200($result); } else { - return null; + Response::HTTP404(["error" => "No data found"]); } } @@ -86,21 +129,22 @@ function CreateRDV($pdo, $medID, $date, $time, $lieu){ $statement->bindParam(':medID', $medID); $statement->bindParam(':rdvID', $rdvID); $statement->execute(); - return true; + Response::HTTP200(["Success" => "RDV created"]); } - return false; + Response::HTTP404(["Error" => "Lieu not found"]); } -function DeleteEmptyRdv($pdo, $id){ +function DeleteEmptyRdv($pdo, $id) +{ $statement = $pdo->prepare("SELECT p_id FROM rendez_vous WHERE rdv_id = :id"); $statement->bindParam(':id', $id); $statement->execute(); $result = $statement->fetch(PDO::FETCH_ASSOC); - if($result['p_id'] == null){ + if ($result['p_id'] == null) { $statement = $pdo->prepare("DELETE FROM rendez_vous WHERE rdv_id = :id"); $statement->bindParam(':id', $id); $statement->execute(); - return true; + Response::HTTP200(["Success" => "RDV deleted"]); } - return false; + Response::HTTP403(["Forbidden" => "This RDV is not empty"]); } \ No newline at end of file diff --git a/src/js/AJAX/index.js b/src/js/AJAX/index.js index ee3b598..c504dff 100644 --- a/src/js/AJAX/index.js +++ b/src/js/AJAX/index.js @@ -1,5 +1,7 @@ console.log("index.js loaded"); +//Felix Part + function displaySearchResults(data) { let container = document.getElementById("content"); container.innerHTML = ""; @@ -213,4 +215,61 @@ function attachRDVEventListener() { }); } -attachSearchEventListener(); \ No newline at end of file +//Yanis Part + +function DisplayRDVPraticient(rdv){ + let count = rdv.length; + $('#content').empty(); + $('#content').html('
'); + if(count === 0){ + $('#content').append('

Vous n\'avez pas de rendez-vous

'); + } + else { + for (let i = 0; i < count; i++){ + if (rdv[i].p_mail !== "null") + $('#content').append('' + + '
' + + '
' + + '
' + + '

' + rdv[i].rdv_date + '

' + + '

' + rdv[i].rdv_time + '

' + + '
' + '
' + + '
' + + '
' + rdv[i].patient + '
' + + '' + rdv[i].email + '' + + '
' + + '' + '0' + rdv[i].phone + '' + + '
' + '
'); + else{ + $('#content').append('' + + '
' + + '
' + + '
' + + '

' + rdv[i].rdv_date + '

' + + '

' + rdv[i].rdv_time + '

' + + '
' + '
' + + '
' + + '
Vous n\'avez pas de' + '
' + 'patient pour ce créneau
' + + '
' + '
'); + } + + } + } +} + +function ButtonShowRdvPraticient() { + document.getElementById("CalendarPraticient").addEventListener("click", function () { + ajaxRequest('GET', "src/API/requests.php/api/rdv-praticient?id=" + id, function (data) { + DisplayRDVPraticient(data); + }); + }); +} + + + + + +//End Call + +attachSearchEventListener(); +ButtonShowRdvPraticient(); \ No newline at end of file From 2ec4591b092d415d853991203fc95a256b500e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Mon, 8 Apr 2024 09:07:13 +0200 Subject: [PATCH 14/15] Add new .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03edb8e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Request_Test \ No newline at end of file From 4a3d6fbec4fffd367aef17ea9c99d3ea9e2e9041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Mon, 8 Apr 2024 09:16:14 +0200 Subject: [PATCH 15/15] Update .gitignore --- .gitignore | 3 ++- Request_Test/testHTTP.http | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 03edb8e..6028ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -Request_Test \ No newline at end of file +Request_Test +Request_Test/testHTTP.http \ No newline at end of file diff --git a/Request_Test/testHTTP.http b/Request_Test/testHTTP.http index ab8b582..4f99b02 100644 --- a/Request_Test/testHTTP.http +++ b/Request_Test/testHTTP.http @@ -30,11 +30,25 @@ Accept: application/json ### -# PUT /api/rdv with body in x-www-form-urlencoded PUT http://serveur-projet-s4.felix/src/API/requests.php/api/rdv Content-Type: application/x-www-form-urlencoded -rdv-id=64553&patient-id=1 -ACCEPT: application/json +rdv_id = 46792 & +patient_id = 1 + +### + +PUT http://serveur-projet-s4.felix/src/API/requests.php/api/requests +Content-Type: application/x-www-form-urlencoded + +test = "coucou" + +### + +POST http://serveur-projet-s4.felix/src/API/requests.php/api/requests +Content-Type: application/x-www-form-urlencoded + +test = "coucou" + +### -### \ No newline at end of file