mirror of
https://github.com/BreizhHardware/ProjetS4COMWEB.git
synced 2026-01-18 16:47:35 +01:00
152 lines
5.4 KiB
PHP
152 lines
5.4 KiB
PHP
<?php
|
|
require_once('src/response.php');
|
|
|
|
/*function dbConnect()
|
|
{
|
|
try
|
|
{
|
|
$db = new PDO('pgsql:host='.DB_SERVER.';port='.DB_PORT.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
}
|
|
catch (PDOException $exception)
|
|
{
|
|
error_log('Connection error: '.$exception->getMessage());
|
|
return false;
|
|
}
|
|
return $db;
|
|
}*/
|
|
|
|
|
|
function dbRequestRdvPraticien($pdo, $id){
|
|
$statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(p_name,' ', p_surname) as patient, p_mail, p_phone
|
|
FROM rendez_vous
|
|
LEFT 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 CURRENT_DATE = rdv_date AND medecin.m_id = :id
|
|
ORDER BY rdv_date, rdv_time ASC");
|
|
|
|
$statement->bindParam(':id', $id);
|
|
$statement->execute();
|
|
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
Response::HTTP200($result);
|
|
}
|
|
|
|
function dbRequestRdvPatient($pdo, $id){
|
|
$statement = $pdo->prepare("SELECT rendez_vous.rdv_id, rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty as med_spe, 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 ASC, rdv_time ASC
|
|
LIMIT 5");
|
|
|
|
$statement->bindParam(':id', $id);
|
|
$statement->execute();
|
|
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
Response::HTTP200($result);
|
|
}
|
|
|
|
function getPastRdvByPatient($pdo, $id){
|
|
$statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty as med_spe, 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 DESC, rdv_time DESC LIMIT 5");
|
|
$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);
|
|
$statement->bindParam(':city', $city);
|
|
$statement->bindParam(':postal', $postal);
|
|
$statement->execute();
|
|
$result = $statement->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!empty($result)) {
|
|
return $result['l_id'];
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function getAllLieux($pdo){
|
|
$statement = $pdo->prepare("SELECT l_adress, l_city, l_postal FROM lieu ORDER BY l_postal ASC");
|
|
$statement->execute();
|
|
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if (!empty($result)) {
|
|
Response::HTTP200($result);
|
|
} else {
|
|
Response::HTTP404(["error" => "No data found"]);
|
|
}
|
|
}
|
|
|
|
function CreateRDV($pdo, $medID, $date, $time, $lieu){
|
|
error_log($lieu. ', ' . $date . ', ' . $time . ', ' . $medID);
|
|
$lieu = explode(', ', $lieu);
|
|
$adress = $lieu[0] . ', ' . $lieu[1];
|
|
$postal = $lieu[2];
|
|
$city = $lieu[3];
|
|
$lieuID = getLieuID($pdo, $adress, $postal, $city);
|
|
|
|
if ($lieuID != null){
|
|
$statement = $pdo->prepare("INSERT INTO rendez_vous (rdv_date, rdv_time, l_id) VALUES (:date, :time, :lieuID)");
|
|
$statement->bindParam(':date', $date);
|
|
$statement->bindParam(':time', $time);
|
|
$statement->bindParam(':lieuID', $lieuID);
|
|
$statement->execute();
|
|
$rdvID = $pdo->lastInsertId();
|
|
|
|
$statement = $pdo->prepare("INSERT INTO propose (m_id, rdv_id) VALUES (:medID, :rdvID)");
|
|
$statement->bindParam(':medID', $medID);
|
|
$statement->bindParam(':rdvID', $rdvID);
|
|
$statement->execute();
|
|
Response::HTTP200(["Success" => "RDV created"]);
|
|
}
|
|
else {
|
|
Response::HTTP404(["Error" => "Lieu not found"]);
|
|
}
|
|
}
|
|
|
|
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) {
|
|
$statement = $pdo->prepare("DELETE FROM rendez_vous WHERE rdv_id = :id");
|
|
$statement->bindParam(':id', $id);
|
|
$statement->execute();
|
|
Response::HTTP200(["Success" => "RDV deleted"]);
|
|
}
|
|
Response::HTTP403(["Forbidden" => "This RDV is not empty"]);
|
|
}
|
|
|
|
function CancelRDVFromPatient($pdo, $id){
|
|
$statement = $pdo->prepare("UPDATE public.rendez_vous SET p_id = null WHERE rdv_id = :id");
|
|
$statement->bindParam(':id', $id);
|
|
$statement->execute();
|
|
Response::HTTP200(["Success" => "RDV deleted"]);
|
|
} |