Implémentation des Repo Patient et Medecin (pas testé)

This commit is contained in:
SeekDaSky 2015-12-03 10:43:27 +01:00
parent c66e7e7dc9
commit c64bf617b9
5 changed files with 45 additions and 11 deletions

View File

@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS `Patient` (
`Adresse` varchar(255) NOT NULL, `Adresse` varchar(255) NOT NULL,
`Adresse 2` varchar(255) DEFAULT NULL, `Adresse 2` varchar(255) DEFAULT NULL,
`Ville` varchar(50) NOT NULL, `Ville` varchar(50) NOT NULL,
`CodePostal` varchar(4) NOT NULL, `CodePostal` varchar(5) NOT NULL,
`DateNaissance` date NOT NULL, `DateNaissance` date NOT NULL,
`LieuNaissance` varchar(50) NOT NULL, `LieuNaissance` varchar(50) NOT NULL,
`NumSecuriteSociale` varchar(15) NOT NULL, `NumSecuriteSociale` varchar(15) NOT NULL,

View File

@ -44,6 +44,9 @@ class StaticRepo{
*/ */
public static function delNumeric($fetchData, $oneDimension=false){ public static function delNumeric($fetchData, $oneDimension=false){
// cas où fetch renvoie FALSE
if( $fetchData === false ) return false;
/* [1] 2 dimensions /* [1] 2 dimensions
===============================================*/ ===============================================*/
if( !$oneDimension ){ if( !$oneDimension ){

View File

@ -22,19 +22,35 @@ class MedecinRepo
} }
public function add($civilite,$prenom,$nom){ public function add($civilite,$prenom,$nom){
$req = $this->connexion->prepare('INSERT INTO Medecin VALUES (DEFAULT,:civilite,:prenom,:nom)');
$result = $req->execute(['civilite' => $civilite,
'nom' => $nom,
'prenom' => $prenom));
if($result){return ['id' => $this->connexion->lastInsertId()];}
else{return false;}
} }
public function delete($idPatient){ public function delete($idMedecin){
$req = $this->connexion->prepare('DELETE FROM Medecin WHERE Id = :id');
return $req->execute(['id' => $idMedecin]);
} }
public function search($nom,$prenom){ public function search($nom,$prenom){
$req = $this->connexion->prepare('SELECT * FROM Medecin WHERE Nom LIKE :nom AND Prenom LIKE :prenom');
$req->execute(['nom' => $nom,
'prenom' => $prenom]);
return StaticRepo::delNumeric($req->fetchAll());
} }
public function getPatients($idMedecin){ public function getPatients($idMedecin){
$req = $this->connexion->prepare('SELECT Patient.* FROM Patient,Medecin
WHERE Medecin.Id = :id
AND Medecin.Id = Patient.MedecinTraitant');
$req->execute(['id' => $idMedecin]);
return StaticRepo::delNumeric($req->fetchAll());
} }
} }

View File

@ -17,14 +17,14 @@ class PatientRepo
public function getById($id){ public function getById($id){
$req = $this->connexion->prepare('SELECT * FROM Patient WHERE Id = :id'); $req = $this->connexion->prepare('SELECT * FROM Patient WHERE Id = :id');
$req->execute(['id' => $id]); $req->execute(['id' => $id]);
return $req->fetchAll(); return StaticRepo::delNumeric( $req->fetch(), true );
} }
public function add($civilite,$prenom,$nom,$adresse,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){ public function add($civilite,$prenom,$nom,$adresse,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){
$req = $this->connexion->prepare('INSERT INTO Patient VALUES (:civilite,:nom,:prenom,:adresse,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,DEFAULT,:medecin)'); $req = $this->connexion->prepare('INSERT INTO Patient VALUES (:civilite,:nom,:prenom,:adresse,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,DEFAULT,:medecin)');
$req->execute(['civilite' => $civilite, $result = $req->execute(['civilite' => $civilite,
'nom' => $nom, 'nom' => $nom,
'prenom' => $prenom, 'prenom' => $prenom,
'adresse' => $adresse, 'adresse' => $adresse,
@ -34,19 +34,34 @@ class PatientRepo
'lieuNaissance' => $lieuNaissance, 'lieuNaissance' => $lieuNaissance,
'numSecu' => $numSecu, 'numSecu' => $numSecu,
'medecin' => $medecinTraitant ]); 'medecin' => $medecinTraitant ]);
if($result){return ['id' => $this->connexion->lastInsertId()];}
else{return false;}
} }
public function delete($idPatient){ public function delete($idPatient){
$req = $this->connexion->prepare('DELETE FROM Patient WHERE Id = :id');
return $req->execute(['id' => $idPatient]);
} }
public function updateMedecinTraitant($idPatient,$IdMedecin){ public function updateMedecinTraitant($idPatient,$idMedecin){
$req = $this->connexion->prepare('UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id');
return $req->execute['medecin' => $idMedecin,
'id' => $idPatient]);
} }
public function search($nom,$prenom){ public function search($nom,$prenom){
$req = $this->connexion->prepare('SELECT * FROM Patient WHERE Nom LIKE :nom AND Prenom LIKE :prenom');
$req->execute(['nom' => $nom,
'prenom' => $prenom]);
return StaticRepo::delNumeric($req->fetchAll());
} }
} }

View File

@ -43,7 +43,7 @@ class Authentification{
$id = uniqid(); $id = uniqid();
$_SESSION['id'] = $id; $_SESSION['id'] = $id;
$_SESSION['token'] = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$id); $_SESSION['token'] = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$id);
setcookie('UserId',$id,time()+10*60,'/'); session_regenerate_id();
$_SESSION['user'] = $user; $_SESSION['user'] = $user;
$_SESSION['role'] = $role; $_SESSION['role'] = $role;
@ -71,7 +71,7 @@ class Authentification{
foreach($_SESSION['role'] as $roleUser){ foreach($_SESSION['role'] as $roleUser){
if(($strict and $roleUser == $role) or (!$strict and $roleUser<= $role)){ if(($strict and $roleUser == $role) or (!$strict and $roleUser<= $role)){
if($_SESSION['token'] == sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_SESSION['id'])){ if($_SESSION['token'] == sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_SESSION['id'])){
setcookie('UserId',$_COOKIE['UserId'],time()+10*60,'/'); session_regenerate_id();
return true; return true;
}; };
} }