2015-12-02 12:31:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: seekdasky
|
|
|
|
* Date: 02/12/15
|
|
|
|
* Time: 12:36
|
|
|
|
*/
|
|
|
|
class MedecinRepo
|
|
|
|
{
|
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
public static function getById($id){
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-26 10:42:52 +00:00
|
|
|
if(!StaticRepo::checkParam($id, 'Numeric')) return false;
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Medecin WHERE Id = :id');
|
2015-12-02 12:31:37 +00:00
|
|
|
$req->execute(['id' => $id]);
|
2015-12-08 08:31:47 +00:00
|
|
|
return StaticRepo::delNumeric( $req->fetch(), true );
|
2015-12-02 12:31:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
public static function add($civilite,$prenom,$nom){
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2016-01-03 17:35:41 +00:00
|
|
|
if(!StaticRepo::checkParam($civilite,'Civilite') | !StaticRepo::checkParam($prenom,'String45') | !StaticRepo::checkParam($nom,'String45')) return false;
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('INSERT INTO Medecin VALUES (DEFAULT,:civilite,:prenom,:nom)');
|
2015-12-03 09:43:27 +00:00
|
|
|
$result = $req->execute(['civilite' => $civilite,
|
2015-12-08 08:31:47 +00:00
|
|
|
'nom' => $nom,
|
2015-12-26 10:42:52 +00:00
|
|
|
'prenom' => $prenom
|
|
|
|
]);
|
|
|
|
|
2015-12-10 10:46:29 +00:00
|
|
|
//PDO renvoie un ID sous forme de char, on transtype
|
|
|
|
$id = StaticRepo::getConnexion()->lastInsertId();
|
2015-12-26 10:42:52 +00:00
|
|
|
settype($id, 'integer');
|
|
|
|
|
|
|
|
|
|
|
|
if($result) return $id;
|
|
|
|
else return false;
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
public static function delete($idMedecin){
|
2015-12-10 10:46:29 +00:00
|
|
|
|
2015-12-26 10:42:52 +00:00
|
|
|
if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false;
|
2015-12-10 10:46:29 +00:00
|
|
|
|
2015-12-26 17:21:44 +00:00
|
|
|
var_dump($idMedecin);
|
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Medecin WHERE Id = :id');
|
|
|
|
return $req->execute(['id' => $idMedecin]);
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 09:58:06 +00:00
|
|
|
public static function search($nom, $prenom){
|
2015-12-10 10:46:29 +00:00
|
|
|
|
2016-01-03 17:35:41 +00:00
|
|
|
if( !StaticRepo::checkParam($prenom,'String45') | !StaticRepo::checkParam($nom,'String45') ) return false;
|
2015-12-10 10:46:29 +00:00
|
|
|
|
2015-12-17 09:58:06 +00:00
|
|
|
// on définit les valeurs (peuvent être nulles)
|
2015-12-22 18:35:35 +00:00
|
|
|
$optPrenom = ( $prenom != 'null' && StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%';
|
|
|
|
$optNom = ( $nom != 'null' && StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%';
|
2015-12-17 09:58:06 +00:00
|
|
|
|
2015-12-26 10:42:52 +00:00
|
|
|
$req = StaticRepo::getConnexion()->query("SELECT Id, Civilite, Prenom, Nom
|
2015-12-17 09:58:06 +00:00
|
|
|
FROM Medecin
|
|
|
|
WHERE Nom LIKE '".$optNom."'
|
|
|
|
AND Prenom LIKE '".$optPrenom."'
|
2015-12-22 18:35:35 +00:00
|
|
|
ORDER BY Nom, Prenom ASC");
|
2015-12-17 09:58:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
return StaticRepo::delNumeric( $req->fetchAll() );
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
public static function getPatients($idMedecin){
|
2015-12-02 12:31:37 +00:00
|
|
|
|
2015-12-26 10:42:52 +00:00
|
|
|
if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false;
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('SELECT Patient.* FROM Patient,Medecin
|
2015-12-03 09:43:27 +00:00
|
|
|
WHERE Medecin.Id = :id
|
|
|
|
AND Medecin.Id = Patient.MedecinTraitant');
|
|
|
|
|
2015-12-08 08:31:47 +00:00
|
|
|
$req->execute(['id' => $idMedecin]);
|
|
|
|
return StaticRepo::delNumeric($req->fetchAll());
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function getAll(){
|
|
|
|
|
|
|
|
$req = StaticRepo::getConnexion()->query('SELECT * FROM Medecin ORDER BY nom, prenom ASC');
|
|
|
|
|
|
|
|
return StaticRepo::delNumeric( $req->fetchAll() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-03 16:15:44 +00:00
|
|
|
|
|
|
|
public static function update($id, $nom, $prenom){
|
|
|
|
|
|
|
|
$req = StaticRepo::getConnexion()->prepare("UPDATE Medecin SET Nom = :nom, Prenom = :prenom WHERE Id = :id");
|
|
|
|
return $req->execute([ ':nom' => strtoupper($nom), ':prenom' => $prenom, ':id' => $id ]);
|
|
|
|
}
|
|
|
|
|
2015-12-03 09:43:27 +00:00
|
|
|
}
|