2015-12-02 12:31:37 +00:00
< ? php
/**
* Created by PhpStorm .
* User : seekdasky
* Date : 02 / 12 / 15
* Time : 12 : 36
*/
class PatientRepo
{
private $connexion ;
public function __construct (){
$this -> connexion = StaticRepo :: getConnexion ();
}
public function getById ( $id ){
$req = $this -> connexion -> prepare ( 'SELECT * FROM Patient WHERE Id = :id' );
$req -> execute ([ 'id' => $id ]);
2015-12-03 09:43:27 +00:00
return StaticRepo :: delNumeric ( $req -> fetch (), true );
2015-12-02 12:31:37 +00:00
}
2015-12-03 11:25:02 +00:00
public function add ( $civilite , $prenom , $nom , $adresse , $adresse2 , $ville , $codePostal , $dateNaissance , $lieuNaissance , $numSecu , $medecinTraitant = null ){
2015-12-02 12:31:37 +00:00
2015-12-03 11:25:02 +00:00
$dateNaissance = strtotime ( $dateNaissance );
$dateNaissance = Date ( 'o-m-d' , $dateNaissance );
2015-12-03 11:00:22 +00:00
2015-12-03 11:25:02 +00:00
$req = $this -> connexion -> prepare ( 'INSERT INTO Patient VALUES (:civilite,:nom,:prenom,:adresse,:adresse2,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,DEFAULT,:medecin)' );
2015-12-03 09:43:27 +00:00
$result = $req -> execute ([ 'civilite' => $civilite ,
2015-12-02 12:31:37 +00:00
'nom' => $nom ,
'prenom' => $prenom ,
'adresse' => $adresse ,
2015-12-03 11:25:02 +00:00
'adresse2' => $adresse2 ,
2015-12-02 12:31:37 +00:00
'ville' => $ville ,
'codePostal' => $codePostal ,
'dateNaissance' => $dateNaissance ,
'lieuNaissance' => $lieuNaissance ,
'numSecu' => $numSecu ,
'medecin' => $medecinTraitant ]);
2015-12-03 09:43:27 +00:00
if ( $result ){ return [ 'id' => $this -> connexion -> lastInsertId ()];}
else { return false ;}
2015-12-02 12:31:37 +00:00
}
public function delete ( $idPatient ){
2015-12-03 09:43:27 +00:00
$req = $this -> connexion -> prepare ( 'DELETE FROM Patient WHERE Id = :id' );
return $req -> execute ([ 'id' => $idPatient ]);
2015-12-02 12:31:37 +00:00
}
2015-12-03 09:43:27 +00:00
public function updateMedecinTraitant ( $idPatient , $idMedecin ){
$req = $this -> connexion -> prepare ( 'UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id' );
2015-12-03 10:50:53 +00:00
return $req -> execute ([ 'medecin' => $idMedecin ,
2015-12-03 09:43:27 +00:00
'id' => $idPatient ]);
2015-12-02 12:31:37 +00:00
}
public function search ( $nom , $prenom ){
2015-12-03 09:43:27 +00:00
$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 ());
2015-12-02 12:31:37 +00:00
}
2015-12-03 09:43:27 +00:00
}